Search in sources :

Example 21 with ComponentPropertyData

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

Example 22 with ComponentPropertyData

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

the class ComponentGeneratorTest method componentContainsNumberValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTypes.

@Test
public void componentContainsNumberValueProperty_generatedClassImplementsHasValueWithoutPrimitiveTypes() {
    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);
    ComponentGeneratorTestUtils.assertClassImplementsInterface(generatedClass, "MyComponent", HasValue.class);
    Assert.assertTrue(generatedClass.contains("@Override public Double getValue()"));
    Assert.assertTrue(generatedClass.contains("@Override public void setValue(Double value)"));
    Assert.assertTrue(generatedClass.contains("public void setValue(Number 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 23 with ComponentPropertyData

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

the class PropertyNameRemapRegistryTest method init.

@Before
public void init() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
    Field registryField = PropertyNameRemapRegistry.class.getDeclaredField("REGISTRY");
    registryField.setAccessible(true);
    @SuppressWarnings("rawtypes") Map registry = (Map) registryField.get(null);
    registry.clear();
    Method putMethod = PropertyNameRemapRegistry.class.getDeclaredMethod("put", String.class, String.class, String.class);
    putMethod.setAccessible(true);
    putMethod.invoke(null, TEST_COMPONENT_TAG, "original-property-name", "renamed");
    putMethod.invoke(null, TEST_COMPONENT_TAG, "value", "other-value");
    putMethod.invoke(null, TEST_COMPONENT_TAG, "map-to-value", "value");
    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("original-property-name");
    propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
    componentMetadata.setProperties(Arrays.asList(propertyData));
    ComponentEventData eventData = new ComponentEventData();
    eventData.setName("original-property-name-changed");
    componentMetadata.setEvents(Arrays.asList(eventData));
    generatedSource = generator.generateClass(componentMetadata, "com.my.test", null);
}
Also used : Field(java.lang.reflect.Field) ComponentGenerator(com.vaadin.generator.ComponentGenerator) ComponentEventData(com.vaadin.generator.metadata.ComponentEventData) Method(java.lang.reflect.Method) ComponentMetadata(com.vaadin.generator.metadata.ComponentMetadata) ComponentPropertyData(com.vaadin.generator.metadata.ComponentPropertyData) Map(java.util.Map) Before(org.junit.Before)

Example 24 with ComponentPropertyData

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

the class PropertyNameRemapRegistryTest method hasValueWithRemapping_remapFromValueToOther.

@Test
public void hasValueWithRemapping_remapFromValueToOther() {
    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("value");
    propertyData.setType(Collections.singleton(ComponentBasicType.STRING));
    componentMetadata.setProperties(Arrays.asList(propertyData));
    ComponentEventData eventData = new ComponentEventData();
    eventData.setName("value-changed");
    componentMetadata.setEvents(Arrays.asList(eventData));
    String generated = generator.generateClass(componentMetadata, "com.my.test", null);
    Assert.assertFalse("Remapped value property should not generate the HasValue interface", generated.contains("HasValue"));
    Assert.assertTrue("Remapped change event should be generated", generated.contains("OtherValueChangeEvent"));
}
Also used : ComponentGenerator(com.vaadin.generator.ComponentGenerator) ComponentEventData(com.vaadin.generator.metadata.ComponentEventData) ComponentMetadata(com.vaadin.generator.metadata.ComponentMetadata) 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