WebComponentWrapper extends Component { @ClientCallable public void sync(String property, JsonValue newValue) { try { webComponentBinding.updateProperty(property, newValue); } catch (IllegalArgumentException e) { LoggerFactory.getLogger(webComponentBinding.getComponent().getClass()) .error("Failed to synchronise property '{}'", property, e); } } WebComponentWrapper(Element rootElement,
            WebComponentBinding<?> binding); protected  WebComponentWrapper(Element rootElement,
            WebComponentBinding<?> binding, List<Element> bootstrapElements); @ClientCallable void sync(String property, JsonValue newValue); @ClientCallable void reconnect(); @ClientCallable void disconnected();  }
@Test public void wrappedMyComponent_syncSetsCorrectValuesToFields() { wrapper.sync(MSG_PROPERTY, Json.create("MyMessage")); Assert.assertEquals("Message field should have updated with new value", "MyMessage", component.message); wrapper.sync(INT_PROPERTY, Json.create(10)); Assert.assertEquals( "IntegerValue field should contain a matching integer value", 10, component.integerValue); }
@Test public void wrappedComponentPropertyListener_listenerFiredWithCorrectValuesOnSync() { wrapper.sync(MSG_PROPERTY, Json.create("one")); wrapper.sync(INT_PROPERTY, Json.create(2)); wrapper.sync(MSG_PROPERTY, Json.create("three")); wrapper.sync(INT_PROPERTY, Json.create(4)); Assert.assertEquals("Three string messages should have come through", 3, component.oldMessages.size()); Assert.assertEquals("Three integer messages should have come through", 3, component.oldIntegers.size()); Assert.assertEquals("String messages arrived in correct order", Arrays.asList("", "one", "three"), component.oldMessages); Assert.assertEquals("Integer messages arrived in correct order", Arrays.asList(0, 2, 4), component.oldIntegers); }
@Test public void exportingExtendedComponent_inheritedFieldsAreAvailableAndOverridden() { WebComponentBinding<MyExtension> binding = constructWrapperAndGetBinding(new MyExtensionExporter(), null, null); MyExtension component = binding.getComponent(); wrapper.sync(MSG_PROPERTY, Json.create("one")); wrapper.sync(INT_PROPERTY, Json.create(2)); wrapper.sync(MSG_PROPERTY, Json.create("three")); wrapper.sync(INT_PROPERTY, Json.create(4)); Assert.assertEquals("Three string messages should have come through", 3, component.oldMessages.size()); Assert.assertEquals("Three integer messages should have come through", 3, component.oldIntegers.size()); Assert.assertEquals("String messages arrived in correct order", Arrays.asList("Extended ", "Extended one", "Extended three"), component.oldMessages); Assert.assertEquals("Integer messages arrived in correct order", Arrays.asList(0, 2, 4), component.oldIntegers); }
@Test public void extendedExporter_propertiesAreOverwrittenAndAvailable() { WebComponentBinding<MyComponent> binding = constructWrapperAndGetBinding(new ExtendedExporter(), null, null); MyComponent component = binding.getComponent(); wrapper.sync(MSG_PROPERTY, Json.create("one")); wrapper.sync(INT_PROPERTY, Json.create(2)); wrapper.sync(MSG_PROPERTY, Json.create("three")); wrapper.sync(INT_PROPERTY, Json.create(4)); wrapper.sync(BOOLEAN_PROPERTY, Json.create(true)); Assert.assertEquals("Three string messages should have come through", 3, component.oldMessages.size()); Assert.assertEquals("Three integer messages should have come through", 3, component.oldIntegers.size()); Assert.assertEquals("String messages arrived in correct order", Arrays.asList("Default", "one", "three"), component.oldMessages); Assert.assertEquals("Integer messages arrived in correct order", Arrays.asList(0, 2, 4), component.oldIntegers); Assert.assertTrue("Boolean property should have been set to true", component.booleanValue); }