Search in sources :

Example 1 with PropertyEditorRegistry

use of org.apache.xbean.propertyeditor.PropertyEditorRegistry in project component-runtime by Talend.

the class ReflectionServiceTest method truncatedObjectArray.

@Test
void truncatedObjectArray() throws NoSuchMethodException {
    final Method factory = TableOwner.class.getMethod("factory", TableOwner.class);
    final PropertyEditorRegistry propertyEditorRegistry = new PropertyEditorRegistry();
    final Object[] tests = new ReflectionService(new ParameterModelService(propertyEditorRegistry), propertyEditorRegistry).parameterFactory(factory, emptyMap(), null).apply(new HashMap<String, String>() {

        {
            put("root.table[0].value1", "test1");
            put("root.table[0].value2", "12");
            put("root.table[1].value1", "test2");
            put("root.table[1].value2", "22");
            put("root.table[0].nestedList[0].value1", "nested");
            put("root.table[0].nestedList[0].value2", "1");
            put("root.table[0].nestedList[length]", "0");
            put("root.table[length]", "1");
        }
    });
    assertEquals(1, tests.length);
    assertTrue(TableOwner.class.isInstance(tests[0]));
    final TableOwner tableOwner = TableOwner.class.cast(tests[0]);
    assertNotNull(tableOwner.table);
    assertEquals(1, tableOwner.table.size());
    assertEquals(singletonList("test1"), tableOwner.table.stream().map(Column::getValue1).collect(toList()));
    assertArrayEquals(new int[] { 12 }, tableOwner.table.stream().mapToInt(Column::getValue2).toArray());
    assertNotNull(tableOwner.table.get(0).nestedList);
    assertTrue(tableOwner.table.get(0).nestedList.isEmpty());
}
Also used : PropertyEditorRegistry(org.apache.xbean.propertyeditor.PropertyEditorRegistry) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Test(org.junit.jupiter.api.Test)

Example 2 with PropertyEditorRegistry

use of org.apache.xbean.propertyeditor.PropertyEditorRegistry in project component-runtime by Talend.

the class ReflectionServiceTest method tables.

@Test
void tables() throws NoSuchMethodException {
    final Method factory = TableOwner.class.getMethod("factory", TableOwner.class);
    final PropertyEditorRegistry propertyEditorRegistry = new PropertyEditorRegistry();
    final Object[] tests = new ReflectionService(new ParameterModelService(propertyEditorRegistry), propertyEditorRegistry).parameterFactory(factory, emptyMap(), null).apply(new HashMap<String, String>() {

        {
            put("root.table[0].value1", "test1");
            put("root.table[0].value2", "12");
            put("root.table[1].value1", "test2");
            put("root.table[1].value2", "22");
            put("root.table[1].nestedList[0].value1", "nested");
            put("root.table[1].nestedList[0].value2", "1");
            put("root.map.key[0]", "test1k");
            put("root.map.value[0].value1", "test1v");
            put("root.map.key[1]", "test2k");
            put("root.map.value[1].value1", "test2v");
        }
    });
    assertEquals(1, tests.length);
    assertTrue(TableOwner.class.isInstance(tests[0]));
    final TableOwner tableOwner = TableOwner.class.cast(tests[0]);
    {
        assertNotNull(tableOwner.table);
        assertEquals(2, tableOwner.table.size());
        assertEquals(Stream.of("test1", "test2").collect(toList()), tableOwner.table.stream().map(Column::getValue1).collect(toList()));
        assertArrayEquals(IntStream.of(12, 22).toArray(), tableOwner.table.stream().mapToInt(Column::getValue2).toArray());
        assertNotNull(tableOwner.table.get(1).nestedList);
        assertEquals(1, tableOwner.table.get(1).nestedList.size());
        assertEquals("nested", tableOwner.table.get(1).nestedList.get(0).value1);
        assertEquals(1, tableOwner.table.get(1).nestedList.get(0).value2);
    }
    {
        assertNotNull(tableOwner.map);
        assertEquals(2, tableOwner.map.size());
        assertEquals("test1v", tableOwner.map.get("test1k").value1);
        assertEquals("test2v", tableOwner.map.get("test2k").value1);
    }
}
Also used : PropertyEditorRegistry(org.apache.xbean.propertyeditor.PropertyEditorRegistry) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Test(org.junit.jupiter.api.Test)

Example 3 with PropertyEditorRegistry

use of org.apache.xbean.propertyeditor.PropertyEditorRegistry in project component-runtime by Talend.

the class HttpClientFactoryImplTest method decoderWithServices.

@Test
void decoderWithServices() throws IOException {
    final HttpServer server = createTestServer(HttpURLConnection.HTTP_OK);
    try {
        server.start();
        final PropertyEditorRegistry propertyEditorRegistry = new PropertyEditorRegistry();
        final DecoderWithService client = new HttpClientFactoryImpl("test", new ReflectionService(new ParameterModelService(propertyEditorRegistry), propertyEditorRegistry), JsonbBuilder.create(), new HashMap<Class<?>, Object>() {

            {
                put(MyService.class, new MyService());
                put(MyI18nService.class, (MyI18nService) () -> "error from i18n service");
            }
        }).create(DecoderWithService.class, null);
        client.base("http://localhost:" + server.getAddress().getPort() + "/api");
        assertThrows(IllegalStateException.class, () -> client.error("search yes"));
        assertEquals(MyService.class.getCanonicalName(), client.ok().value);
    } finally {
        server.stop(0);
    }
}
Also used : PropertyEditorRegistry(org.apache.xbean.propertyeditor.PropertyEditorRegistry) HashMap(java.util.HashMap) HttpServer(com.sun.net.httpserver.HttpServer) HttpClientFactoryImpl(org.talend.sdk.component.runtime.manager.service.http.HttpClientFactoryImpl) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Test(org.junit.jupiter.api.Test)

Example 4 with PropertyEditorRegistry

use of org.apache.xbean.propertyeditor.PropertyEditorRegistry in project component-runtime by Talend.

the class InjectorImplTest method init.

@BeforeEach
void init() {
    final Map<Class<?>, Object> services = new HashMap<>(2);
    services.put(LocalCache.class, new LocalCacheService("LocalCacheServiceTest", System::currentTimeMillis, executor));
    services.put(LocalConfiguration.class, new LocalConfigurationService(Collections.singletonList(new LocalConfiguration() {

        @Override
        public String get(final String key) {
            return "test.foo.name".equals(key) ? "ok" : "ko";
        }

        @Override
        public Set<String> keys() {
            return singleton("foo.name");
        }
    }), "test"));
    final PropertyEditorRegistry propertyEditorRegistry = new PropertyEditorRegistry();
    injector = new InjectorImpl("LocalCacheServiceTest", new ReflectionService(new ParameterModelService(propertyEditorRegistry), propertyEditorRegistry), new ProxyGenerator(), services);
    DynamicContainerFinder.LOADERS.put("LocalCacheServiceTest", Thread.currentThread().getContextClassLoader());
    DynamicContainerFinder.SERVICES.put(Injector.class, injector);
}
Also used : ProxyGenerator(org.talend.sdk.component.runtime.manager.asm.ProxyGenerator) Set(java.util.Set) HashMap(java.util.HashMap) PropertyEditorRegistry(org.apache.xbean.propertyeditor.PropertyEditorRegistry) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) LocalConfiguration(org.talend.sdk.component.api.service.configuration.LocalConfiguration) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with PropertyEditorRegistry

use of org.apache.xbean.propertyeditor.PropertyEditorRegistry in project component-runtime by Talend.

the class PropertiesServiceTest method booleanDefault.

@Test
void booleanDefault() throws NoSuchMethodException {
    final List<SimplePropertyDefinition> props = propertiesService.buildProperties(new ParameterModelService(new PropertyEditorRegistry()).buildParameterMetas(getClass().getDeclaredMethod("boolWrapper", BoolBool.class), null, new BaseParameterEnricher.Context(new LocalConfigurationService(emptyList(), "tools"))), Thread.currentThread().getContextClassLoader(), Locale.ROOT, null).collect(toList());
    assertEquals("true", props.stream().filter(p -> p.getName().equals("val")).findFirst().get().getDefaultValue());
}
Also used : LocalConfigurationService(org.talend.sdk.component.runtime.manager.service.LocalConfigurationService) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) PropertyEditorRegistry(org.apache.xbean.propertyeditor.PropertyEditorRegistry) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) BaseParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.BaseParameterEnricher) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyEditorRegistry (org.apache.xbean.propertyeditor.PropertyEditorRegistry)10 ParameterModelService (org.talend.sdk.component.runtime.manager.reflect.ParameterModelService)9 Test (org.junit.jupiter.api.Test)7 ReflectionService (org.talend.sdk.component.runtime.manager.reflect.ReflectionService)6 HashMap (java.util.HashMap)5 ParameterMeta (org.talend.sdk.component.runtime.manager.ParameterMeta)4 BaseParameterEnricher (org.talend.sdk.component.runtime.manager.reflect.parameterenricher.BaseParameterEnricher)4 List (java.util.List)3 Collectors.toList (java.util.stream.Collectors.toList)3 Method (java.lang.reflect.Method)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonList (java.util.Collections.singletonList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Stream (java.util.stream.Stream)2 JsonObject (javax.json.JsonObject)2 LocalConfigurationService (org.talend.sdk.component.runtime.manager.service.LocalConfigurationService)2