Search in sources :

Example 16 with ComponentEventData

use of com.vaadin.generator.metadata.ComponentEventData 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 17 with ComponentEventData

use of com.vaadin.generator.metadata.ComponentEventData 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

ComponentEventData (com.vaadin.generator.metadata.ComponentEventData)17 Test (org.junit.Test)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 ComponentPropertyData (com.vaadin.generator.metadata.ComponentPropertyData)10 ComponentPropertyBaseData (com.vaadin.generator.metadata.ComponentPropertyBaseData)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 ComponentGenerator (com.vaadin.generator.ComponentGenerator)3 ComponentMetadata (com.vaadin.generator.metadata.ComponentMetadata)3 ComponentObjectType (com.vaadin.generator.metadata.ComponentObjectType)2 EventData (com.vaadin.flow.component.EventData)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 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1 Before (org.junit.Before)1