Search in sources :

Example 1 with JsonString

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

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsAListOfString.

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

Example 2 with JsonString

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

the class JsonRpcResultTest method shouldGetAsStringWhenParsingStringWithResultAsString.

// String
@Test
public void shouldGetAsStringWhenParsingStringWithResultAsString() throws Exception {
    JsonString value = jsonFactory.create("a");
    String expected = value.asString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value.toJson(), jsonFactory, dtoFactory);
    String actual = jsonRpcResult.getAs(String.class);
    assertEquals(expected, actual);
}
Also used : JsonString(elemental.json.JsonString) JsonString(elemental.json.JsonString) Test(org.junit.Test)

Example 3 with JsonString

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

the class JsonRpcResultTest method shouldToStringWhenParsingStringWithResultAsAListOfString.

@Test
public void shouldToStringWhenParsingStringWithResultAsAListOfString() throws Exception {
    JsonString string = jsonFactory.create("a");
    JsonArray array = jsonFactory.createArray();
    array.set(0, string);
    String expected = array.toJson();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(array.toJson(), jsonFactory, dtoFactory);
    String actual = jsonRpcResult.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonString(elemental.json.JsonString) JsonString(elemental.json.JsonString) Test(org.junit.Test)

Example 4 with JsonString

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

the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsASingleString.

@Test
public void shouldToJsonValueWhenParsingStringWithResultAsASingleString() throws Exception {
    JsonString expected = jsonFactory.create("a");
    JsonRpcResult jsonRpcResult = new JsonRpcResult(expected.toJson(), jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcResult.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonValue(elemental.json.JsonValue) JsonString(elemental.json.JsonString) Test(org.junit.Test)

Example 5 with JsonString

use of elemental.json.JsonString in project flow by vaadin.

the class JsonCodecTest method decodeAs_stringJson.

@Test
public void decodeAs_stringJson() {
    JsonString json = Json.create("Test123 String\n !%");
    Assert.assertTrue(JsonCodec.decodeAs(json, Boolean.class));
    Assert.assertEquals("Test123 String\n !%", JsonCodec.decodeAs(json, String.class));
    Assert.assertEquals(Integer.valueOf(0), JsonCodec.decodeAs(json, Integer.class));
    Assert.assertTrue(JsonCodec.decodeAs(json, Double.class).isNaN());
    Assert.assertEquals(json, JsonCodec.decodeAs(json, JsonValue.class));
}
Also used : JsonValue(elemental.json.JsonValue) JsonString(elemental.json.JsonString) JsonString(elemental.json.JsonString) JsonBoolean(elemental.json.JsonBoolean) Test(org.junit.Test)

Aggregations

JsonString (elemental.json.JsonString)10 Test (org.junit.Test)10 JsonValue (elemental.json.JsonValue)6 JsonArray (elemental.json.JsonArray)3 JsonBoolean (elemental.json.JsonBoolean)2 JsonNumber (elemental.json.JsonNumber)1