use of com.vaadin.generator.metadata.ComponentFunctionData 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.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes.
@Test
public void classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes() {
ComponentFunctionParameterData firstParameter = new ComponentFunctionParameterData();
firstParameter.setName("firstParam");
firstParameter.setType(new HashSet<>(Arrays.asList(ComponentBasicType.STRING, ComponentBasicType.BOOLEAN)));
ComponentFunctionParameterData secondParameter = new ComponentFunctionParameterData();
secondParameter.setName("secondParam");
secondParameter.setType(new HashSet<>(Arrays.asList(ComponentBasicType.STRING, ComponentBasicType.BOOLEAN)));
ComponentFunctionData function = new ComponentFunctionData();
function.setName("callSomething");
function.setParameters(Arrays.asList(firstParameter, secondParameter));
componentMetadata.setMethods(Collections.singletonList(function));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue(generatedClass.contains("public void callSomething(String firstParam, String secondParam)"));
Assert.assertTrue(generatedClass.contains("public void callSomething(String firstParam, boolean secondParam)"));
Assert.assertTrue(generatedClass.contains("public void callSomething(boolean firstParam, String secondParam)"));
Assert.assertTrue(generatedClass.contains("public void callSomething(boolean firstParam, boolean secondParam)"));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithMethodWithParameters_methodContainsParamInJavaDoc.
@Test
public void generateClassWithMethodWithParameters_methodContainsParamInJavaDoc() {
ComponentFunctionData functionData = new ComponentFunctionData();
functionData.setName("my-method");
functionData.setDescription("This is my method documentation.");
ComponentFunctionParameterData parameter = new ComponentFunctionParameterData();
parameter.setName("text");
parameter.setType(Collections.singleton(ComponentBasicType.STRING));
functionData.setParameters(Collections.singletonList(parameter));
componentMetadata.setMethods(Collections.singletonList(functionData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("JavaDoc for method parameter text was not found", generatedClass.contains("* @param " + parameter.getName()));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method assertCallBackMethodIsNotGenerated.
private void assertCallBackMethodIsNotGenerated(String callback) {
ComponentFunctionData functionData = new ComponentFunctionData();
functionData.setName(callback);
componentMetadata.setMethods(Collections.singletonList(functionData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertFalse("Callback methods are generated", generatedClass.contains(callback));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method withProtectedMethods.
@Test
public void withProtectedMethods() {
generator.withProtectedMethods(true);
ComponentPropertyData property = new ComponentPropertyData();
property.setName("something");
property.setType(Collections.singleton(ComponentBasicType.STRING));
property.setNotify(true);
ComponentPropertyData value = new ComponentPropertyData();
value.setName("value");
value.setType(Collections.singleton(ComponentBasicType.NUMBER));
value.setNotify(true);
componentMetadata.setProperties(Arrays.asList(property, value));
ComponentFunctionData function = new ComponentFunctionData();
function.setName("function");
componentMetadata.setMethods(Collections.singletonList(function));
componentMetadata.setSlots(Arrays.asList("", "named"));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertThat(generatedClass, CoreMatchers.not(CoreMatchers.containsString("HasComponents")));
Assert.assertThat(generatedClass, CoreMatchers.not(CoreMatchers.containsString("HasValue")));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setSomething(String something)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected String getSomethingString()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected Registration addSomethingChangeListener("));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected double getValueDouble()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void setValue(double value)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected Registration addValueChangeListener("));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void function()"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void addToNamed(Component... components)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void remove(Component... components)"));
Assert.assertThat(generatedClass, CoreMatchers.containsString("protected void removeAll()"));
}
Aggregations