Search in sources :

Example 31 with JsonValue

use of elemental.json.JsonValue in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayCreatedDtoArray.

@Test
public void shouldToJsonArrayCreatedDtoArray() throws Exception {
    Dto dto = mock(Dto.class);
    when(dto.toString()).thenReturn(DTO);
    when(dto.getParameter()).thenReturn("value");
    when(dtoFactory.createDtoFromJson(DTO, Dto.class)).thenReturn(dto);
    JsonArray expected = jsonFactory.createArray();
    JsonValue parse = jsonFactory.parse(dto.toString());
    expected.set(0, parse);
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList(dto), jsonFactory, dtoFactory);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 32 with JsonValue

use of elemental.json.JsonValue in project che by eclipse.

the class JsonRpcListTest method shouldParseDtoArray.

@Test
public void shouldParseDtoArray() throws Exception {
    Dto expected = mock(Dto.class);
    when(expected.toString()).thenReturn(DTO);
    when(expected.getParameter()).thenReturn("value");
    when(dtoFactory.createDtoFromJson(DTO, Dto.class)).thenReturn(expected);
    JsonValue parse = jsonFactory.parse(DTO);
    JsonArray array = jsonFactory.createArray();
    array.set(0, parse);
    String message = array.toJson();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonFactory, dtoFactory);
    Dto actual = jsonRpcList.get(0, Dto.class);
    assertEquals(expected.getParameter(), actual.getParameter());
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 33 with JsonValue

use of elemental.json.JsonValue in project che by eclipse.

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsAListOfNumber.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsAListOfNumber() throws Exception {
    Double value = 0D;
    JsonArray expected = jsonFactory.createArray();
    expected.set(0, value);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(value), jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcResult.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 34 with JsonValue

use of elemental.json.JsonValue in project che by eclipse.

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsAListOfNumber.

@Test
public void shouldToJsonValueWhenParsingStringWithResultAsAListOfNumber() throws Exception {
    JsonNumber number = jsonFactory.create(0D);
    JsonArray expected = jsonFactory.createArray();
    expected.set(0, number);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(expected.toJson(), jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcResult.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonNumber(elemental.json.JsonNumber) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 35 with JsonValue

use of elemental.json.JsonValue in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonValueForParsedListDtoParams.

@Test
public void shouldToJsonValueForParsedListDtoParams() throws Exception {
    JsonArray array = jsonFactory.createArray();
    JsonObject jsonObject = jsonFactory.parse(DTO_JSON);
    array.set(0, jsonObject);
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + DTO_JSON + "]", jsonFactory, dtoFactory);
    JsonValue jsonValue = jsonRpcParams.toJsonValue();
    assertEquals(array.toJson(), jsonValue.toJson());
    assertTrue(array.jsEquals(jsonValue));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonValue (elemental.json.JsonValue)55 Test (org.junit.Test)52 JsonArray (elemental.json.JsonArray)23 JsonObject (elemental.json.JsonObject)19 JsonString (elemental.json.JsonString)10 Matchers.anyString (org.mockito.Matchers.anyString)5 JsonNumber (elemental.json.JsonNumber)3 ArrayList (java.util.ArrayList)2