use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsGetterAndRelatedChangeEvent_eventContainsPropertyAndGetter.
@Test
public void classContainsGetterAndRelatedChangeEvent_eventContainsPropertyAndGetter() {
ComponentPropertyData property = new ComponentPropertyData();
property.setName("someproperty");
property.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Collections.singletonList(property));
ComponentEventData event = new ComponentEventData();
event.setName("someproperty-changed");
componentMetadata.setEvents(Collections.singletonList(event));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertThat("Event should save the property value from the source component", generatedClass, containsString("someproperty = source.getSomeproperty();"));
Assert.assertThat("Event should have getter for the property", generatedClass, containsString("public String getSomeproperty() { return someproperty; }"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsValuePropertyWithNotify_generatedClassImplementsHasValue.
@Test
public void componentContainsValuePropertyWithNotify_generatedClassImplementsHasValue() {
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.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 generateClassWithGetterAndNonFluentSetter_methodContainsJavaDoc.
@Test
public void generateClassWithGetterAndNonFluentSetter_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 generateClassWithGetter_methodContainsJavaDocWithAtCodeWrap.
@Test
public void generateClassWithGetter_methodContainsJavaDocWithAtCodeWrap() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("name");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
propertyData.setDescription("This is the `<input value=\"name\">` property of the component.");
propertyData.setReadOnly(true);
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("Method javaDoc was not found", generatedClass.contains("* This is the {@code <input value=\"name\">} property of the component."));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method propertyContainsNotify_eventIsGenerated.
@Test
public void propertyContainsNotify_eventIsGenerated() {
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(generatedClass, CoreMatchers.containsString("public void setSomething(String something) {"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("public Registration addSomethingChangeListener( ComponentEventListener<SomethingChangeEvent<R>> listener) {"));
}
Aggregations