Search in sources :

Example 11 with JsonValue

use of elemental.json.JsonValue 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)

Example 12 with JsonValue

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

the class JsonRpcRequestTest method shouldToStringWhenParseStringParamsWithoutIdAndWithoutParams.

@Test
public void shouldToStringWhenParseStringParamsWithoutIdAndWithoutParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    expected.remove("params");
    expected.remove("id");
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest(request.toJson(), jsonFactory, jsonRpcFactory);
    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 13 with JsonValue

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

the class JsonRpcRequestTest method shouldToStringWhenParseStringParamsWithIdAndWithParams.

@Test
public void shouldToStringWhenParseStringParamsWithIdAndWithParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest(request.toJson(), jsonFactory, jsonRpcFactory);
    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 14 with JsonValue

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

the class JsonRpcRequestTest method shouldToStringWhenParseStringParamsWithIdAndWithoutParams.

@Test
public void shouldToStringWhenParseStringParamsWithIdAndWithoutParams() {
    when(params.emptyOrAbsent()).thenReturn(false);
    JsonObject expected = request;
    expected.remove("params");
    JsonRpcRequest jsonRpcRequest = new JsonRpcRequest(request.toJson(), jsonFactory, jsonRpcFactory);
    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 15 with JsonValue

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

the class JsonRpcParams method toJsonValue.

public JsonValue toJsonValue() {
    if (params != null) {
        return params;
    } else {
        JsonArray array = jsonFactory.createArray();
        for (int i = 0; i < paramsList.size(); i++) {
            JsonValue value = paramsList.get(i);
            array.set(i, value);
        }
        return array;
    }
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue)

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