Search in sources :

Example 16 with JsonValue

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

the class JsonRpcErrorTest method shouldToStringProperly.

@Test
public void shouldToStringProperly() {
    JsonRpcError real = new JsonRpcError(ERROR_JSON, jsonFactory);
    JsonValue expected = jsonFactory.parse(ERROR_JSON);
    assertEquals(real.toString(), expected.toJson());
}
Also used : JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 17 with JsonValue

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

the class JsonRpcListTest method shouldToStringArrayParsedDtoArray.

@Test
public void shouldToStringArrayParsedDtoArray() 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);
    String actual = jsonRpcList.toString();
    assertEquals(message, actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 18 with JsonValue

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

the class JsonRpcParamsTest method shouldToJsonValueForParsedListBooleanParams.

@Test
public void shouldToJsonValueForParsedListBooleanParams() throws Exception {
    Boolean expected = false;
    JsonArray array = jsonFactory.createArray();
    array.set(0, expected);
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + expected + "]", jsonFactory, dtoFactory);
    JsonValue jsonValue = jsonRpcParams.toJsonValue();
    assertTrue(array.jsEquals(jsonValue));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 19 with JsonValue

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

the class JsonRpcParamsTest method shouldToJsonForCreatedSingleDtoParams.

@Test
public void shouldToJsonForCreatedSingleDtoParams() throws Exception {
    JsonValue expected = jsonFactory.parse(dto.toString());
    JsonRpcParams jsonRpcParams = new JsonRpcParams(dto, dtoFactory, jsonFactory);
    JsonValue actual = jsonRpcParams.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 20 with JsonValue

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

the class JsonRpcListTest method shouldToListParsedDtoArray.

@Test
public void shouldToListParsedDtoArray() 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);
    List<Dto> actual = jsonRpcList.toList(Dto.class);
    assertEquals(singletonList(expected), actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) 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