use of elemental.json.JsonValue in project flow by vaadin.
the class UidlWriterTest method parentViewDependenciesAreAddedFirst.
@Test
public void parentViewDependenciesAreAddedFirst() {
UI ui = initializeUIForDependenciesTest(new UI());
UidlWriter uidlWriter = new UidlWriter();
ui.add(new BaseClass());
JsonObject response = uidlWriter.createUidl(ui, false);
assertFalse("Did not expect to have lazy dependencies in uidl", response.hasKey(LoadMode.LAZY.name()));
assertFalse("Did not expect to have inline dependencies in uidl", response.hasKey(LoadMode.INLINE.name()));
assertTrue("Expected to have eager dependencies in uidl", response.hasKey(LoadMode.EAGER.name()));
JsonArray eagerDependencies = response.getArray(LoadMode.EAGER.name());
assertEquals("Expected to have exactly 3 eager dependencies in uidl, actual: %d", eagerDependencies.length(), 3);
List<Class<?>> expectedClassOrder = Arrays.asList(SuperParentClass.class, ParentClass.class, BaseClass.class);
for (int i = 0; i < expectedClassOrder.size(); i++) {
Class<?> expectedClass = expectedClassOrder.get(i);
HtmlImport htmlImport = expectedClass.getAnnotation(HtmlImport.class);
JsonValue actualDependency = eagerDependencies.get(i);
JsonObject expectedDependency = new Dependency(Dependency.Type.HTML_IMPORT, htmlImport.value(), htmlImport.loadMode()).toJson();
assertTrue(String.format("Unexpected dependency. Expected: '%s', actual: '%s', class: '%s'", expectedDependency, actualDependency, expectedClass), expectedDependency.jsEquals(actualDependency));
}
}
use of elemental.json.JsonValue in project flow by vaadin.
the class JsonCodecTest method encodeWithTypeInfo_attachedElement.
@Test
public void encodeWithTypeInfo_attachedElement() {
Element element = ElementFactory.createDiv();
StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
tree.getRootNode().getFeature(ElementChildrenList.class).add(0, element.getNode());
JsonValue json = JsonCodec.encodeWithTypeInfo(element);
assertJsonEquals(JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(element.getNode().getId())), json);
}
use of elemental.json.JsonValue in project flow by vaadin.
the class JsonSerializerTest method serializeEmptyObjectWithObjects_returnJsonObjectWithNullProperties.
@Test
public void serializeEmptyObjectWithObjects_returnJsonObjectWithNullProperties() {
ObjectWithOtherObjects bean = new ObjectWithOtherObjects();
JsonValue json = JsonSerializer.toJson(bean);
Assert.assertTrue("The JsonValue should be instanceof JsonObject", json instanceof JsonObject);
JsonObject jsonObject = (JsonObject) json;
Assert.assertTrue(jsonObject.hasKey("object1"));
Assert.assertTrue(jsonObject.get("object1") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("object2"));
Assert.assertTrue(jsonObject.get("object2") instanceof JsonNull);
bean = JsonSerializer.toObject(ObjectWithOtherObjects.class, json);
Assert.assertNotNull("The deserialized object should not be null", bean);
Assert.assertNull(bean.getObject1());
Assert.assertNull(bean.getObject2());
}
use of elemental.json.JsonValue in project flow by vaadin.
the class JsonSerializerTest method serializeEmptyObjectWithBasicCollections_returnJsonObjectWithNullProperties.
@Test
public void serializeEmptyObjectWithBasicCollections_returnJsonObjectWithNullProperties() {
ObjectWithBasicCollections bean = new ObjectWithBasicCollections();
/*
* private List<String> listOfStrings; private Set<Integer>
* setOfIntegers; private LinkedList<Boolean> linkedListOfBooleans;
* private ArrayList<Double> arrayListOfDoubles;
*
*/
JsonValue json = JsonSerializer.toJson(bean);
Assert.assertTrue("The JsonValue should be instanceof JsonObject", json instanceof JsonObject);
JsonObject jsonObject = (JsonObject) json;
Assert.assertTrue(jsonObject.hasKey("listOfStrings"));
Assert.assertTrue(jsonObject.get("listOfStrings") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("setOfIntegers"));
Assert.assertTrue(jsonObject.get("setOfIntegers") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("linkedListOfBooleans"));
Assert.assertTrue(jsonObject.get("linkedListOfBooleans") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("arrayListOfDoubles"));
Assert.assertTrue(jsonObject.get("arrayListOfDoubles") instanceof JsonNull);
bean = JsonSerializer.toObject(ObjectWithBasicCollections.class, json);
Assert.assertNotNull("The deserialized object should not be null", bean);
Assert.assertNull(bean.getListOfStrings());
Assert.assertNull(bean.getSetOfIntegers());
Assert.assertNull(bean.getLinkedListOfBooleans());
Assert.assertNull(bean.getArrayListOfDoubles());
}
use of elemental.json.JsonValue in project flow by vaadin.
the class JsonSerializerTest method serializeEmptyRecursiveObject_returnJsonObjectWithNullProperties.
@Test
public void serializeEmptyRecursiveObject_returnJsonObjectWithNullProperties() {
RecursiveObject bean = new RecursiveObject();
JsonValue json = JsonSerializer.toJson(bean);
Assert.assertTrue("The JsonValue should be instanceof JsonObject", json instanceof JsonObject);
JsonObject jsonObject = (JsonObject) json;
Assert.assertTrue(jsonObject.hasKey("recursive"));
Assert.assertTrue(jsonObject.get("recursive") instanceof JsonNull);
Assert.assertEquals(0, jsonObject.getNumber("index"), PRECISION);
bean = JsonSerializer.toObject(RecursiveObject.class, json);
Assert.assertNotNull("The deserialized object should not be null", bean);
Assert.assertNull(bean.getRecursive());
Assert.assertEquals(0, bean.getIndex());
}
Aggregations