Search in sources :

Example 6 with ComponentPropertyData

use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.

the class ComponentGeneratorTest method generateClassWithGetter_methodContainsJavaDoc_noSetter.

@Test
public void generateClassWithGetter_methodContainsJavaDoc_noSetter() {
    ComponentPropertyData propertyData = new ComponentPropertyData();
    propertyData.setName("name");
    propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
    propertyData.setDescription("This is the 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.assertFalse("Found setter even if it shouldn't exist", generatedClass.contains("setName"));
    Assert.assertTrue("Method javaDoc was not found", generatedClass.contains("* " + propertyData.getDescription()));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 7 with ComponentPropertyData

use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.

the class ComponentGeneratorTest method classContainsGetterAndRelatedChangeEvent_getterContainsSynchronizeAnnotation.

@Test
public void classContainsGetterAndRelatedChangeEvent_getterContainsSynchronizeAnnotation() {
    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.assertTrue("Wrong getter definition. It should contains @Synchronize(property = \"somepropery\", value = \"someproperty-changed\")", generatedClass.contains("@Synchronize(property = \"someproperty\", value = \"someproperty-changed\") " + "public String getSomeproperty() {"));
}
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 8 with ComponentPropertyData

use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.

the class ComponentGeneratorTest method generateClassWithStringGetterAndNonFluentSetter_setterSetsEmptyForNullValue.

@Test
public void generateClassWithStringGetterAndNonFluentSetter_setterSetsEmptyForNullValue() {
    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 setter found", generatedClass.contains("public void setName(String name)"));
    Assert.assertTrue("Setter doesn't check for null value", generatedClass.contains(propertyData.getName() + " == null ? \"\" : " + propertyData.getName()));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Test(org.junit.Test)

Example 9 with ComponentPropertyData

use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.

the class ComponentGeneratorTest method generateClassWithGetterJavaDocBlock_methodContainsJavaDocWithAtCodeWrap.

@Test
public void generateClassWithGetterJavaDocBlock_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 10 with ComponentPropertyData

use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.

the class ComponentGeneratorTest method componentContainsValueProperty_generatedSetValuePreventsSettingTheSameValue.

@Test
public void componentContainsValueProperty_generatedSetValuePreventsSettingTheSameValue() {
    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);
    Assert.assertTrue(generatedClass.contains("@Override public void setValue(String value) {" + " Objects.requireNonNull(value, \"value cannot be null\");" + " if (!Objects.equals(value, getValue())) {"));
    Assert.assertTrue(generatedClass.contains("@Override public String getEmptyValue() { return \"\"; }"));
}
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