use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method htmlJavaDoc.
@Test
public void htmlJavaDoc() {
ComponentFunctionData functionData = new ComponentFunctionData();
functionData.setName("my-method");
// @formatter:off
functionData.setDescription("" + "This is my method documentation," + "```html\n" + "<my-component\n" + "label=\"myLabel\">\n" + "</my-component>\n" + "```");
// @formatter:on
componentMetadata.setMethods(Collections.singletonList(functionData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("JavaDoc must have escaped HTML", generatedClass.contains("<my-component"));
Assert.assertTrue("JavaDoc must have escaped HTML", generatedClass.contains("label="myLabel">"));
Assert.assertFalse("JavaDoc must not have @code", generatedClass.contains("@code"));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsMethodWithObjectParameter_generatedClassContainsInnerClass.
@Test
public void classContainsMethodWithObjectParameter_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));
ComponentFunctionParameterData parameter = new ComponentFunctionParameterData();
parameter.setName("somethingParam");
parameter.setObjectType(Collections.singletonList(objectType));
ComponentFunctionData function = new ComponentFunctionData();
function.setName("callSomething");
function.setParameters(Collections.singletonList(parameter));
componentMetadata.setMethods(Collections.singletonList(function));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue("Generated class should contain the CallSomethingSomethingParam nested class", generatedClass.contains("public static class CallSomethingSomethingParam implements JsonSerializable"));
Assert.assertTrue("Generated class should contain the callSomething method", generatedClass.contains("public void callSomething(CallSomethingSomethingParam somethingParam)"));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method generateClassWithMethod_methodContainsJavaDoc.
@Test
public void generateClassWithMethod_methodContainsJavaDoc() {
ComponentFunctionData functionData = new ComponentFunctionData();
functionData.setName("my-method");
functionData.setDescription("This is my method documentation.");
componentMetadata.setMethods(Collections.singletonList(functionData));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
Assert.assertTrue("Method javaDoc was not found", generatedClass.contains("* " + functionData.getDescription()));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes_withObjectTypes.
@Test
public void classContainsOverloadedMethodsForMethodsThatAcceptMultipleTypes_withObjectTypes() {
ComponentObjectTypeInnerType stringObjectTypeInnerType = new ComponentObjectTypeInnerType();
stringObjectTypeInnerType.setName("internalString");
stringObjectTypeInnerType.setType(Collections.singletonList(ComponentBasicType.STRING));
ComponentObjectType stringObjectType = new ComponentObjectType();
stringObjectType.setInnerTypes(Collections.singletonList(stringObjectTypeInnerType));
ComponentFunctionParameterData firstParameter = new ComponentFunctionParameterData();
firstParameter.setName("firstParam");
firstParameter.setObjectType(Collections.singletonList(stringObjectType));
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(CallSomethingFirstParam firstParam, String secondParam)"));
Assert.assertTrue(generatedClass.contains("public void callSomething(CallSomethingFirstParam firstParam, boolean secondParam)"));
}
use of com.vaadin.generator.metadata.ComponentFunctionData in project flow by vaadin.
the class ComponentGeneratorTest method componentContainsFunctionsWithUnregognizedParameterTypes_methodsAreGeneratedAsProtected.
@Test
public void componentContainsFunctionsWithUnregognizedParameterTypes_methodsAreGeneratedAsProtected() {
ComponentFunctionParameterData objectParameter = new ComponentFunctionParameterData();
objectParameter.setName("objectParam");
objectParameter.setType(Collections.singleton(ComponentBasicType.OBJECT));
ComponentFunctionData function1 = new ComponentFunctionData();
function1.setName("callSomethingWithObject");
function1.setParameters(Collections.singletonList(objectParameter));
ComponentFunctionParameterData stringParameter = new ComponentFunctionParameterData();
stringParameter.setName("stringParam");
stringParameter.setType(Collections.singleton(ComponentBasicType.STRING));
ComponentFunctionData function2 = new ComponentFunctionData();
function2.setName("callSomethingWithObjectAndString");
function2.setParameters(Arrays.asList(objectParameter, stringParameter));
ComponentFunctionParameterData multiParameter = new ComponentFunctionParameterData();
multiParameter.setName("multiParam");
multiParameter.setType(new HashSet<>(Arrays.asList(ComponentBasicType.STRING, ComponentBasicType.OBJECT, ComponentBasicType.ARRAY, ComponentBasicType.UNDEFINED)));
ComponentFunctionData function3 = new ComponentFunctionData();
function3.setName("callSomethingWithMultiTypes");
function3.setParameters(Collections.singletonList(multiParameter));
componentMetadata.setMethods(Arrays.asList(function1, function2, function3));
String generatedClass = generator.generateClass(componentMetadata, "com.my.test", null);
generatedClass = ComponentGeneratorTestUtils.removeIndentation(generatedClass);
Assert.assertTrue(generatedClass.contains("protected void callSomethingWithObject(JsonObject objectParam)"));
Assert.assertTrue(generatedClass.contains("protected void callSomethingWithObjectAndString(JsonObject objectParam, String stringParam)"));
Assert.assertTrue(generatedClass.contains("public void callSomethingWithMultiTypes(String multiParam)"));
Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonObject multiParam)"));
Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonArray multiParam)"));
Assert.assertTrue(generatedClass.contains("protected void callSomethingWithMultiTypes(JsonValue multiParam)"));
}
Aggregations