use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method withProtectedMethods.
@Test
public void withProtectedMethods() {
generator.withProtectedMethods(true);
ComponentPropertyData property = new ComponentPropertyData();
property.setName("something");
property.setType(Collections.singleton(ComponentBasicType.STRING));
property.setNotify(true);
ComponentPropertyData value = new ComponentPropertyData();
value.setName("value");
value.setType(Collections.singleton(ComponentBasicType.NUMBER));
value.setNotify(true);
componentMetadata.setProperties(Arrays.asList(property, value));
ComponentFunctionData function = new ComponentFunctionData();
function.setName("function");
componentMetadata.setMethods(Collections.singletonList(function));
componentMetadata.setSlots(Arrays.asList("", "named"));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertThat(generatedClass, CoreMatchers.not(CoreMatchers.containsString("HasComponents")));
Assert.assertThat(generatedClass, CoreMatchers.not(CoreMatchers.containsString("HasValue")));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setSomething(String something)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected String getSomethingString()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected Registration addSomethingChangeListener("));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected double getValueDouble()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setValue(double value)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected Registration addValueChangeListener("));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void function()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void addToNamed(Component... components)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void remove(Component... components)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void removeAll()"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsNumberValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTypes.
@Test
public void componentContainsNumberValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTypes() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("value");
property.setType(Collections.singleton(ComponentBasicType.NUMBER));
componentMetadata.setProperties(Collections.singletonList(property));
ComponentEventData event = new ComponentEventData();
event.setName("value-changed");
componentMetadata.setEvents(Collections.singletonList(event));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
ComponentGeneratorTestUtils.assertClassImplementsInterface(generatedClass, "MyComponent", HasValue.class);
Assert.assertTrue(generatedClass.contains("@Override public Double getValue()"));
Assert.assertTrue(generatedClass.contains("@Override public void setValue(Double value)"));
Assert.assertTrue(generatedClass.contains("public void setValue(Number value)"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData 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.metadata.ComponentPropertyData 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