use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsObjectProperty_generatedClassContainsInnerClass.
@Test
public void classContainsObjectProperty_generatedClassContainsInnerClass() {
// note: the tests for the nested class are covered by the
// NestedClassGeneratorTest
ComponentObjectTypeInnerType stringObjectType = new ComponentObjectTypeInnerType();
stringObjectType.setName("internalString");
stringObjectType.setType(Collections.singletonList(ComponentBasicType.STRING));
ComponentObjectType objectType = new ComponentObjectType();
objectType.setInnerTypes(Collections.singletonList(stringObjectType));
ComponentPropertyData property = new ComponentPropertyData();
property.setName("something");
property.setObjectType(Collections.singletonList(objectType));
componentMetadata.setProperties(Collections.singletonList(property));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue("Generated class should contain the SomethingProperty nested class", generatedClass.contains("public static class SomethingProperty implements JsonSerializable"));
Assert.assertTrue("Generated class should contain the getSomething method", generatedClass.contains("public SomethingProperty getSomething()"));
Assert.assertTrue("Generated class should contain the setSomething method", generatedClass.contains("public void setSomething(SomethingProperty property)"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsUnrecognizedPropertyTypes_methodsAreGeneratedAsProtected.
@Test
public void componentContainsUnrecognizedPropertyTypes_methodsAreGeneratedAsProtected() {
ComponentPropertyData objectProperty = new ComponentPropertyData();
objectProperty.setName("objectProperty");
objectProperty.setType(Collections.singleton(ComponentBasicType.OBJECT));
ComponentPropertyData arrayProperty = new ComponentPropertyData();
arrayProperty.setName("arrayProperty");
arrayProperty.setType(Collections.singleton(ComponentBasicType.ARRAY));
ComponentPropertyData undefinedProperty = new ComponentPropertyData();
undefinedProperty.setName("undefinedProperty");
undefinedProperty.setType(Collections.singleton(ComponentBasicType.UNDEFINED));
componentMetadata.setProperties(Arrays.asList(objectProperty, arrayProperty, undefinedProperty));
ComponentFunctionParameterData objectParameter = new ComponentFunctionParameterData();
objectParameter.setName("objectParam");
objectParameter.setType(Collections.singleton(ComponentBasicType.OBJECT));
ComponentFunctionData function = new ComponentFunctionData();
function.setName("callSomething");
function.setParameters(Collections.singletonList(objectParameter));
componentMetadata.setMethods(Collections.singletonList(function));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonObject getObjectPropertyJsonObject()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setObjectProperty(JsonObject objectProperty)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonArray getArrayPropertyJsonArray()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setArrayProperty(JsonArray arrayProperty)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected JsonValue getUndefinedPropertyJsonValue()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setUndefinedProperty(JsonValue undefinedProperty)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void callSomething(JsonObject objectParam)"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class PropertyNameRemapRegistryTest method hasValueWithRemapping_remapFromOtherToValue.
@Test
public void hasValueWithRemapping_remapFromOtherToValue() {
ComponentGenerator generator = new ComponentGenerator();
ComponentMetadata componentMetadata = new ComponentMetadata();
componentMetadata.setName("test-name");
componentMetadata.setTag(TEST_COMPONENT_TAG);
componentMetadata.setBaseUrl("");
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("map-to-value");
propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
componentMetadata.setProperties(Arrays.asList(propertyData));
ComponentEventData eventData = new ComponentEventData();
eventData.setName("map-to-value-changed");
componentMetadata.setEvents(Arrays.asList(eventData));
String generated = generator.generateClass(componentMetadata, "com.my.test", null);
ComponentGeneratorTestUtils.assertClassImplementsInterface(generated, "TestTag", HasValue.class);
Assert.assertFalse("Remapped value change event should not be generated", generated.contains("ValueChangeEvent"));
Assert.assertTrue("HasValue getClientValuePropertyName overridden", generated.contains("String getClientValuePropertyName()"));
Assert.assertTrue("HasValue getClientValuePropertyName overridden", generated.contains("return \"map-to-value\";"));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithBooleanGetterAndNonFluentSetter_setterDoesNotSetEmptyForNullValue.
@Test
public void generateClassWithBooleanGetterAndNonFluentSetter_setterDoesNotSetEmptyForNullValue() {
ComponentPropertyData propertyData = new ComponentPropertyData();
propertyData.setName("required");
propertyData.setType(Collections.singleton(ComponentBasicType.BOOLEAN));
propertyData.setDescription("This is a required field.");
componentMetadata.setProperties(Collections.singletonList(propertyData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("No setter found", generatedClass.contains("public void setRequired(boolean required)"));
Assert.assertFalse("Setter checks for null value", generatedClass.contains(propertyData.getName() + " == null ? \"\" : " + propertyData.getName()));
}
use of com.vaadin.generator.metadata.ComponentPropertyData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsObjectProperty_componentContainsValueProperty_generatedClassImplementsHasValue.
@Test
public void classContainsObjectProperty_componentContainsValueProperty_generatedClassImplementsHasValue() {
ComponentObjectType objectType = new ComponentObjectType();
ComponentPropertyData property = new ComponentPropertyData();
property.setName("value");
property.setObjectType(Collections.singletonList(objectType));
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 ValueProperty getValue() { JsonObject _obj = (JsonObject) getElement().getPropertyRaw("));
Assert.assertThat(generatedClass, CoreMatchers.containsString("@Override public void setValue(ValueProperty property) { if (!Objects.equals(property, getValue()))"));
}
Aggregations