Search in sources :

Example 21 with JsonValue

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

the class JsonRpcListTest method shouldToJsonArrayParsedDtoArray.

@Test
public void shouldToJsonArrayParsedDtoArray() 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);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(array.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 22 with JsonValue

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

the class JsonRpcListTest method shouldToStringCreatedDtoArray.

@Test
public void shouldToStringCreatedDtoArray() 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 array = jsonFactory.createArray();
    JsonValue parse = jsonFactory.parse(dto.toString());
    array.set(0, parse);
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList(dto), jsonFactory, dtoFactory);
    assertEquals(array.toJson(), jsonRpcList.toString());
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 23 with JsonValue

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

the class JsonRpcParamsTest method shouldToJsonValueForParsedSingleStringParams.

@Test
public void shouldToJsonValueForParsedSingleStringParams() throws Exception {
    String expected = "\"value\"";
    JsonRpcParams jsonRpcParams = new JsonRpcParams(expected, jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcParams.toJsonValue();
    assertEquals(expected, actual.toJson());
}
Also used : JsonValue(elemental.json.JsonValue) JsonString(elemental.json.JsonString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 24 with JsonValue

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

the class JsonRpcParamsTest method shouldToJsonForCreatedListDtoParams.

@Test
public void shouldToJsonForCreatedListDtoParams() throws Exception {
    List<Dto> list = singletonList(dto);
    JsonArray expected = jsonFactory.createArray();
    JsonValue jsonValue = jsonFactory.parse(dto.toString());
    expected.set(0, jsonValue);
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcParams.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 25 with JsonValue

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

the class JsonRpcParamsTest method shouldToJsonForCreatedSingleStringParams.

@Test
public void shouldToJsonForCreatedSingleStringParams() throws Exception {
    String value = "value";
    String expected = "\"" + value + "\"";
    JsonRpcParams jsonRpcParams = new JsonRpcParams(value, dtoFactory, jsonFactory);
    JsonValue actual = jsonRpcParams.toJsonValue();
    assertEquals(expected, actual.toJson());
}
Also used : JsonValue(elemental.json.JsonValue) JsonString(elemental.json.JsonString) Matchers.anyString(org.mockito.Matchers.anyString) 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