Search in sources :

Example 1 with TestFormatDefinition1Impl

use of org.talend.components.common.format.instances.TestFormatDefinition1Impl in project components by Talend.

the class FormatPropertiesProviderTest method testProperties.

@Test
public void testProperties() throws Throwable {
    FormatPropertiesProvider<AbstractTestFormatProperties> propertiesProvider = new FormatPropertiesProvider<AbstractTestFormatProperties>("propertiesProvider", AbstractTestFormatDefinition.class) {
    };
    DefinitionRegistry reg = new DefinitionRegistry();
    TestFormatDefinition1Impl def1 = new TestFormatDefinition1Impl();
    TestFormatDefinition2Impl def2 = new TestFormatDefinition2Impl();
    reg.registerDefinition(Arrays.asList(def1, def2));
    reg.injectDefinitionRegistry(propertiesProvider);
    propertiesProvider.init();
    // Check that possible format values include both of registered definitions
    Assert.assertEquals(propertiesProvider.format.getPossibleValues().size(), 2);
    // Set the format value to first registered definition
    propertiesProvider.format.setValue(def1.getName());
    PropertiesDynamicMethodHelper.afterProperty(propertiesProvider, propertiesProvider.format.getName());
    AbstractTestFormatProperties formatProperties = propertiesProvider.getFormatProperties();
    Assert.assertNotEquals(def2.getName(), propertiesProvider.format.getValue());
    Assert.assertEquals(def1.getName(), propertiesProvider.format.getValue());
    // Format properties class in PropertiesProvider should be the same as properties class for definition
    Assert.assertEquals(def1.getPropertiesClass(), formatProperties.getClass());
    propertiesProvider.format.setValue(def2.getName());
    PropertiesDynamicMethodHelper.afterProperty(propertiesProvider, propertiesProvider.format.getName());
    formatProperties = propertiesProvider.getFormatProperties();
    Assert.assertNotEquals(def1.getName(), propertiesProvider.format.getValue());
    Assert.assertEquals(def2.getName(), propertiesProvider.format.getValue());
    Assert.assertEquals(TestFormatProperties2Impl.class, formatProperties.getClass());
}
Also used : TestFormatDefinition2Impl(org.talend.components.common.format.instances.TestFormatDefinition2Impl) AbstractTestFormatProperties(org.talend.components.common.format.instances.AbstractTestFormatProperties) TestFormatDefinition1Impl(org.talend.components.common.format.instances.TestFormatDefinition1Impl) DefinitionRegistry(org.talend.components.api.service.common.DefinitionRegistry) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DefinitionRegistry (org.talend.components.api.service.common.DefinitionRegistry)1 AbstractTestFormatProperties (org.talend.components.common.format.instances.AbstractTestFormatProperties)1 TestFormatDefinition1Impl (org.talend.components.common.format.instances.TestFormatDefinition1Impl)1 TestFormatDefinition2Impl (org.talend.components.common.format.instances.TestFormatDefinition2Impl)1