use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithGetterAndSetter_methodContainsJavaDoc.
@Test
public void generateClassWithGetterAndSetter_methodContainsJavaDoc() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
propertyData.setDescription("This is the name property of the component.");
componentMetadata.setProperties(Collections.singletonList(propertyData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("No getter found", generatedClass.contains("public String getName()"));
Assert.assertTrue("No setter found", generatedClass.contains("public void setName(String name)"));
Assert.assertTrue("Method javaDoc was not found", generatedClass.contains("* " + propertyData.getDescription()));
Assert.assertTrue("JavaDoc parameter for setter was not found", generatedClass.contains("* @param " + propertyData.getName()));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method ComponentContainsStringValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTyeps.
@Test
public void ComponentContainsStringValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTyeps() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("value");
property.setType(Collections.singleton(ComponentBasicType.STRING));
property.setNotify(true);
componentMetadata.setProperties(Collections.singletonList(property));
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 String getValue() { String value = getElement().getProperty(\"value\"); return value == null ? getEmptyValue() : value; }"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsNotifiedProperty_generatedListenerUsesComponentAsEventSource.
@Test
public void componentContainsNotifiedProperty_generatedListenerUsesComponentAsEventSource() {
generator.withProtectedMethods(true);
ComponentPropertyData property = new ComponentPropertyData();
property.setName("something");
property.setType(Collections.singleton(ComponentBasicType.STRING));
property.setNotify(true);
componentMetadata.setProperties(Collections.singletonList(property));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertThat("Generated listener should use component as event source", generatedClass, containsString("ChangeEvent<R>( (R) this, event.isUserOriginated())));"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsValueProperty_generatedClassImplementsHasValue.
@Test
public void componentContainsValueProperty_generatedClassImplementsHasValue() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("value");
property.setType(Collections.singleton(ComponentBasicType.STRING));
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.assertThat(generatedClass, CoreMatchers.containsString("@Override public String getValue()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("@Override public void setValue(String value)"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsNumberValueProperty_generatedSetValuesPreventSettingTheSameValue.
@Test
public void componentContainsNumberValueProperty_generatedSetValuesPreventSettingTheSameValue() {
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);
Assert.assertTrue(generatedClass.contains("@Override public void setValue(Double value) { Objects.requireNonNull(value, \"MyComponent value must not be null\"); if (!Objects.equals(value, getValue())) {"));
Assert.assertTrue(generatedClass.contains("public void setValue(Number value) { Objects.requireNonNull(value, \"MyComponent value must not be null\"); if (!Objects.equals(value, getValue())) {"));
}
Aggregations