Search in sources :

Example 1 with ComponentPropertyData

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

Example 2 with ComponentPropertyData

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

Example 3 with ComponentPropertyData

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

Example 4 with ComponentPropertyData

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)"));
}
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 5 with ComponentPropertyData

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())) {"));
}
Also used : ComponentEventData(com.vaadin.generator.metadata.ComponentEventData) 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