Search in sources :

Example 26 with JsonObject

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

the class JsonRpcResultTest method shouldGetAsListOfDtoWhenParsingStringWithResultAsListOfDto.

@Test
public void shouldGetAsListOfDtoWhenParsingStringWithResultAsListOfDto() throws Exception {
    JsonArray array = jsonFactory.createArray();
    JsonObject value = jsonFactory.parse(dto.toString());
    array.set(0, value);
    List<Dto> expected = singletonList(dto);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(array.toJson(), jsonFactory, dtoFactory);
    List<Dto> actual = jsonRpcResult.getAsListOf(Dto.class);
    assertEquals(expected, actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 27 with JsonObject

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

the class JsonRpcResultTest method shouldGetAsVoidWhenParsingStringWithResultAsVoid.

//Void
@Test
public void shouldGetAsVoidWhenParsingStringWithResultAsVoid() throws Exception {
    JsonObject value = jsonFactory.createObject();
    Void expected = null;
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value.toJson(), jsonFactory, dtoFactory);
    Void actual = jsonRpcResult.getAs(Void.class);
    assertEquals(expected, actual);
}
Also used : JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 28 with JsonObject

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

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsASingleDto.

@Test
public void shouldToJsonValueWhenParsingStringWithResultAsASingleDto() throws Exception {
    JsonObject value = jsonFactory.parse(dto.toString());
    JsonRpcResult jsonRpcResult = new JsonRpcResult(dto.toString(), jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcResult.toJsonValue();
    assertTrue(value.jsEquals(actual));
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 29 with JsonObject

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

the class JsonRpcRequestTest method shouldToStringWhenPassStringParamsWithIdAndWithParams.

@Test
public void shouldToStringWhenPassStringParamsWithIdAndWithParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest("0", "method", params, jsonFactory);
    JsonValue actual = jsonFactory.parse(jsonRpcRequest.toString());
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 30 with JsonObject

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

the class JsonRpcRequestTest method shouldToStringWhenPassStringParamsWithoutIdAndWithParams.

@Test
public void shouldToStringWhenPassStringParamsWithoutIdAndWithParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    expected.remove("id");
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest("method", params, jsonFactory);
    JsonValue actual = jsonFactory.parse(jsonRpcRequest.toString());
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonObject (elemental.json.JsonObject)70 Test (org.junit.Test)49 JsonValue (elemental.json.JsonValue)19 JsonArray (elemental.json.JsonArray)14 JsonString (elemental.json.JsonString)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Promise (org.eclipse.che.api.promises.client.Promise)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 JsonException (elemental.json.JsonException)2 List (java.util.List)2 Map (java.util.Map)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 StateComponent (org.eclipse.che.ide.api.component.StateComponent)2 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)2 Perspective (org.eclipse.che.ide.api.parts.Perspective)2 Before (org.junit.Before)2 ArrayOf (elemental.util.ArrayOf)1