Search in sources :

Example 16 with ComponentPropertyData

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; }"));
}
Also used : ComponentEventData(com.vaadin.generator.metadata.ComponentEventData) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 17 with ComponentPropertyData

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)"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 18 with ComponentPropertyData

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()));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 19 with ComponentPropertyData

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."));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 20 with ComponentPropertyData

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) {"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Aggregations

ComponentPropertyData (com.vaadin.generator.metadata.ComponentPropertyData)24 Test (org.junit.Test)23 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)21 ComponentEventData (com.vaadin.generator.metadata.ComponentEventData)10 ComponentGenerator (com.vaadin.generator.ComponentGenerator)3 ComponentMetadata (com.vaadin.generator.metadata.ComponentMetadata)3 ComponentFunctionData (com.vaadin.generator.metadata.ComponentFunctionData)2 ComponentObjectType (com.vaadin.generator.metadata.ComponentObjectType)2 ComponentFunctionParameterData (com.vaadin.generator.metadata.ComponentFunctionParameterData)1 ComponentObjectTypeInnerType (com.vaadin.generator.metadata.ComponentObjectType.ComponentObjectTypeInnerType)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 Before (org.junit.Before)1