use of com.vaadin.generator.ComponentGenerator in project flow by vaadin.
the class PropertyNameRemapRegistryTest method hasValueWithRemapping_remapFromOtherToValue.
@Test
public void hasValueWithRemapping_remapFromOtherToValue() {
ComponentGenerator generator = new ComponentGenerator();
ComponentMetadata componentMetadata = new ComponentMetadata();
componentMetadata.setName("test-name");
componentMetadata.setTag(TEST_COMPONENT_TAG);
componentMetadata.setBaseUrl("");
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("map-to-value");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Arrays.asList(propertyData));
ComponentEventData eventData = new ComponentEventData();
eventData.setName("map-to-value-changed");
componentMetadata.setEvents(Arrays.asList(eventData));
String generated = generator.generateClass(componentMetadata, "com.my.test", null);
ComponentGeneratorTestUtils.assertClassImplementsInterface(generated, "TestTag", HasValue.class);
Assert.assertFalse("Remapped value change event should not be generated", generated.contains("ValueChangeEvent"));
Assert.assertTrue("HasValue getClientValuePropertyName overridden", generated.contains("String getClientValuePropertyName()"));
Assert.assertTrue("HasValue getClientValuePropertyName overridden", generated.contains("return \"map-to-value\";"));
}
use of com.vaadin.generator.ComponentGenerator in project flow by vaadin.
the class PropertyNameRemapRegistryTest method init.
@Before
public void init() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
Field registryField = PropertyNameRemapRegistry.class.getDeclaredField("REGISTRY");
registryField.setAccessible(true);
@SuppressWarnings("rawtypes") Map registry = (Map) registryField.get(null);
registry.clear();
Method putMethod = PropertyNameRemapRegistry.class.getDeclaredMethod("put", String.class, String.class, String.class);
putMethod.setAccessible(true);
putMethod.invoke(null, TEST_COMPONENT_TAG, "original-property-name", "renamed");
putMethod.invoke(null, TEST_COMPONENT_TAG, "value", "other-value");
putMethod.invoke(null, TEST_COMPONENT_TAG, "map-to-value", "value");
ComponentGenerator generator = new ComponentGenerator();
ComponentMetadata componentMetadata = new ComponentMetadata();
componentMetadata.setName("test-name");
componentMetadata.setTag(TEST_COMPONENT_TAG);
componentMetadata.setBaseUrl("");
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("original-property-name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Arrays.asList(propertyData));
ComponentEventData eventData = new ComponentEventData();
eventData.setName("original-property-name-changed");
componentMetadata.setEvents(Arrays.asList(eventData));
generatedSource = generator.generateClass(componentMetadata, "com.my.test", null);
}
use of com.vaadin.generator.ComponentGenerator in project flow by vaadin.
the class PropertyNameRemapRegistryTest method hasValueWithRemapping_remapFromValueToOther.
@Test
public void hasValueWithRemapping_remapFromValueToOther() {
ComponentGenerator generator = new ComponentGenerator();
ComponentMetadata componentMetadata = new ComponentMetadata();
componentMetadata.setName("test-name");
componentMetadata.setTag(TEST_COMPONENT_TAG);
componentMetadata.setBaseUrl("");
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("value");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Arrays.asList(propertyData));
ComponentEventData eventData = new ComponentEventData();
eventData.setName("value-changed");
componentMetadata.setEvents(Arrays.asList(eventData));
String generated = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertFalse("Remapped value property should not generate the HasValue interface", generated.contains("HasValue"));
Assert.assertTrue("Remapped change event should be generated", generated.contains("OtherValueChangeEvent"));
}
Aggregations