use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ModelDescriptorTest method assertComplexModeType.
private <T extends Serializable> void assertComplexModeType(Class<T> clazz, T wrappedValue, T value) {
Optional<ComplexModelType<?>> type = BasicComplexModelType.get(clazz);
StateNode stateNode = type.get().applicationToModel(wrappedValue, null);
Assert.assertEquals(wrappedValue, stateNode.getFeature(BasicTypeValue.class).getValue());
stateNode.getFeature(BasicTypeValue.class).setValue(value);
Object modelValue = type.get().modelToApplication(stateNode);
Assert.assertEquals(value, modelValue);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class TemplateModelTest method beanModelType_emptySubBeanAsInitialValue.
@Test
public void beanModelType_emptySubBeanAsInitialValue() {
SubBeansTemplate template = new SubBeansTemplate();
// Check that even before calling any model method the properties are
// available via features
Serializable bean = template.getElement().getNode().getFeature(ElementPropertyMap.class).getProperty("bean");
StateNode node = (StateNode) bean;
Serializable subBean = node.getFeature(ElementPropertyMap.class).getProperty("bean");
Assert.assertTrue(subBean instanceof StateNode);
// Now check properties via API
Assert.assertNotNull(template.getModel().getBean().getBean());
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ListChangeTest method testBasicJson.
@Test
public void testBasicJson() {
StateNode child1 = StateNodeTest.createEmptyNode("child1");
StateNode child2 = StateNodeTest.createEmptyNode("child2");
ListAddChange<StateNode> change = new ListAddChange<>(feature, true, 0, Arrays.asList(child1, child2));
JsonObject json = change.toJson(null);
Assert.assertEquals(change.getNode().getId(), (int) json.getNumber(JsonConstants.CHANGE_NODE));
Assert.assertEquals(NodeFeatureRegistry.getId(feature.getClass()), (int) json.getNumber(JsonConstants.CHANGE_FEATURE));
Assert.assertEquals(JsonConstants.CHANGE_TYPE_SPLICE, json.getString(JsonConstants.CHANGE_TYPE));
Assert.assertEquals(0, (int) json.getNumber(JsonConstants.CHANGE_SPLICE_INDEX));
JsonArray addNodes = json.getArray(JsonConstants.CHANGE_SPLICE_ADD_NODES);
Assert.assertEquals(2, addNodes.length());
Assert.assertEquals(child1.getId(), (int) addNodes.getNumber(0));
Assert.assertEquals(child2.getId(), (int) addNodes.getNumber(1));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachExistingElementFeatureTest method unregister_dataIsNotAvailaleByNode.
@Test
public void unregister_dataIsNotAvailaleByNode() {
StateNode node = new StateNode();
AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
Element element = Mockito.mock(Element.class);
StateNode child = Mockito.mock(StateNode.class);
ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
Node<?> parent = Mockito.mock(Node.class);
feature.register(parent, element, child, callback);
feature.unregister(child);
Assert.assertNull(feature.getCallback(child));
Assert.assertNull(feature.getParent(child));
Assert.assertNull(feature.getPreviousSibling(child));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachExistingElementFeatureTest method forEachChild_register_registeredStatNodeIsAChild.
@Test
public void forEachChild_register_registeredStatNodeIsAChild() {
StateNode node = new StateNode();
AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
Element element = Mockito.mock(Element.class);
StateNode child = Mockito.mock(StateNode.class);
ChildElementConsumer callback = Mockito.mock(ChildElementConsumer.class);
Node<?> parent = Mockito.mock(Node.class);
feature.register(parent, element, child, callback);
List<StateNode> children = new ArrayList<>(1);
feature.forEachChild(children::add);
Assert.assertEquals(1, children.size());
Assert.assertEquals(child, children.get(0));
}
Aggregations