Search in sources :

Example 6 with Ui

use of org.talend.sdk.component.form.model.Ui in project component-runtime by Talend.

the class UiSpecServiceTest method out.

/*
     * just to log the output
     */
@Test
@Disabled("debug test to log the produced model")
void out() throws Exception {
    final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
    System.out.println(JsonbBuilder.create(new JsonbConfig().withFormatting(true)).toJson(payload));
}
Also used : JsonbConfig(javax.json.bind.JsonbConfig) Ui(org.talend.sdk.component.form.model.Ui) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with Ui

use of org.talend.sdk.component.form.model.Ui in project component-runtime by Talend.

the class UiSpecServiceTest method configuration.

@Test
void configuration() throws Exception {
    final ConfigTypeNodes load = load("config.json", ConfigTypeNodes.class);
    final String family = load.getNodes().entrySet().stream().filter(e -> e.getValue().getParentId() == null).map(e -> e.getValue().getId()).findFirst().orElseThrow(() -> new IllegalArgumentException("No family"));
    final Ui payload = service.convert(family, load.getNodes().values().stream().filter(e -> "amRiYyNkYXRhc3RvcmUjamRiYw".equals(e.getId())).findFirst().orElseThrow(() -> new IllegalArgumentException("No amRiYyNkYXRhc3RvcmUjamRiYw config"))).toCompletableFuture().get();
    assertTrue(payload.getJsonSchema().getProperties().containsKey("connection"), "connection");
    assertEquals(4, payload.getUiSchema().iterator().next().getItems().size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Disabled(org.junit.jupiter.api.Disabled) JsonbConfig(javax.json.bind.JsonbConfig) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Ui(org.talend.sdk.component.form.model.Ui) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Jsonb(javax.json.bind.Jsonb) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Ui(org.talend.sdk.component.form.model.Ui) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) Test(org.junit.jupiter.api.Test)

Example 8 with Ui

use of org.talend.sdk.component.form.model.Ui in project component-runtime by Talend.

the class UiSpecServiceTest method uiSchema.

@Test
void uiSchema() throws Exception {
    final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
    final Collection<UiSchema> uiSchema = payload.getUiSchema();
    assertNotNull(uiSchema);
    assertEquals(1, uiSchema.size());
    assertUiSchema(uiSchema.iterator().next(), "fieldset", "Configuration", "configuration", 2, schema -> {
        final List<UiSchema> items = new ArrayList<>(schema.getItems());
        items.sort(Comparator.comparing(UiSchema::getTitle));
        final Iterator<UiSchema> it = items.iterator();
        assertUiSchema(it.next(), "fieldset", "JDBC Connection", "configuration.connection", 5, connection -> {
            final List<UiSchema> connectionItems = new ArrayList<>(connection.getItems());
            connectionItems.sort(Comparator.comparing(UiSchema::getTitle));
            final Iterator<UiSchema> connectionIt = connectionItems.iterator();
            assertUiSchema(connectionIt.next(), "button", "Validate Datastore", "button_healthcheck_configuration.connection", 0, validateDataStore -> {
                assertEquals(1, validateDataStore.getTriggers().size());
                final UiSchema.Trigger trigger = validateDataStore.getTriggers().iterator().next();
                assertEquals(4, trigger.getParameters().size());
                assertEquals(Stream.of("driver", "password", "url", "username").map(p -> "configuration.connection." + p).collect(toSet()), trigger.getParameters().stream().map(UiSchema.Parameter::getPath).collect(toSet()));
                assertEquals(Stream.of("driver", "password", "url", "username").map(p -> "datastore." + p).collect(toSet()), trigger.getParameters().stream().map(UiSchema.Parameter::getKey).collect(toSet()));
            });
            assertUiSchema(connectionIt.next(), "multiSelectTag", "driver", "configuration.connection.driver", 0, driver -> {
                assertNotNull(driver.getTriggers());
                assertEquals(1, driver.getTriggers().size());
                final Collection<UiSchema.NameValue> titleMap = driver.getTitleMap();
                assertEquals(1, titleMap.size());
                final UiSchema.NameValue firstTitleMap = titleMap.iterator().next();
                assertEquals("some.driver.Jdbc", firstTitleMap.getName());
                assertEquals("Jdbc driver", firstTitleMap.getValue());
                final UiSchema.Trigger trigger = driver.getTriggers().iterator().next();
                assertEquals("driver", trigger.getAction());
                assertEquals("jdbc", trigger.getFamily());
                assertEquals("validation", trigger.getType());
                assertEquals(1, trigger.getParameters().size());
                final UiSchema.Parameter parameter = trigger.getParameters().iterator().next();
                assertEquals("value", parameter.getKey());
                assertEquals("configuration.connection.driver", parameter.getPath());
            });
            assertUiSchema(connectionIt.next(), "text", "password", "configuration.connection.password", 0, pwd -> {
                assertEquals("password", pwd.getType());
            });
            assertUiSchema(connectionIt.next(), "text", "url", "configuration.connection.url", 0, url -> {
            });
            assertUiSchema(connectionIt.next(), "text", "username", "configuration.connection.username", 0, username -> {
            });
            assertFalse(connectionIt.hasNext());
        });
        assertUiSchema(it.next(), "fieldset", "query", "configuration.query", 2, query -> {
            final List<UiSchema> queryItems = new ArrayList<>(query.getItems());
            queryItems.sort(Comparator.comparing(UiSchema::getKey));
            final Iterator<UiSchema> queryIt = queryItems.iterator();
            assertUiSchema(queryIt.next(), "text", "query", "configuration.query.query", 0, q -> {
            });
            assertUiSchema(queryIt.next(), "text", "timeout", "configuration.query.timeout", 0, timeout -> {
            });
            assertFalse(queryIt.hasNext());
        });
        assertFalse(it.hasNext());
    });
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) ArrayList(java.util.ArrayList) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 9 with Ui

use of org.talend.sdk.component.form.model.Ui in project component-runtime by Talend.

the class UiSpecServiceTest method guessSchema.

@Test
void guessSchema() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema root = payload.getUiSchema().iterator().next();
    final UiSchema advanced = root.getItems().stream().filter(i -> i.getTitle().equals("Advanced")).findFirst().get();
    final UiSchema commongConfig = advanced.getItems().stream().filter(i -> i.getTitle().equals("commonConfig")).findFirst().get();
    assertTrue(commongConfig.getItems().stream().anyMatch(i -> i.getKey().equals("button_schema_tableDataSet.commonConfig")));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Disabled(org.junit.jupiter.api.Disabled) JsonbConfig(javax.json.bind.JsonbConfig) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) ConfigTypeNodes(org.talend.sdk.component.server.front.model.ConfigTypeNodes) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors.toSet(java.util.stream.Collectors.toSet) JsonbBuilder(javax.json.bind.JsonbBuilder) Iterator(java.util.Iterator) Collection(java.util.Collection) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Ui(org.talend.sdk.component.form.model.Ui) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Jsonb(javax.json.bind.Jsonb) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 10 with Ui

use of org.talend.sdk.component.form.model.Ui in project component-runtime by Talend.

the class UiSpecServiceTest method gridLayout.

@Test
void gridLayout() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema tableDataSet = payload.getUiSchema().iterator().next();
    assertEquals(2, tableDataSet.getItems().size());
    final Iterator<UiSchema> tableDataSetIt = tableDataSet.getItems().iterator();
    final UiSchema tableDataSetMain = tableDataSetIt.next();
    assertEquals("Main", tableDataSetMain.getTitle());
    assertEquals(5, tableDataSetMain.getItems().size());
    assertEquals(asList("dataStore", "commonConfig", "Query", "Ordered", "Order"), tableDataSetMain.getItems().stream().map(UiSchema::getTitle).collect(toList()));
    final Iterator<UiSchema> mainIt = tableDataSetMain.getItems().iterator();
    final UiSchema dataStore = mainIt.next();
    Iterator<UiSchema> dataStoreIt = dataStore.getItems().iterator();
    dataStoreIt.next();
    final UiSchema credentials = dataStoreIt.next();
    assertEquals("columns", credentials.getWidget());
    assertEquals(asList("Username", "Password"), credentials.getItems().stream().map(UiSchema::getTitle).collect(toList()));
    final UiSchema tableDataSetAdvanced = tableDataSetIt.next();
    assertEquals("Advanced", tableDataSetAdvanced.getTitle());
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Aggregations

Ui (org.talend.sdk.component.form.model.Ui)12 Test (org.junit.jupiter.api.Test)11 UiSchema (org.talend.sdk.component.form.model.uischema.UiSchema)7 ArrayList (java.util.ArrayList)6 JsonbConfig (javax.json.bind.JsonbConfig)6 JsonSchema (org.talend.sdk.component.form.model.jsonschema.JsonSchema)6 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 CompletionStage (java.util.concurrent.CompletionStage)5 Collectors.toSet (java.util.stream.Collectors.toSet)5 Jsonb (javax.json.bind.Jsonb)5 JsonbBuilder (javax.json.bind.JsonbBuilder)5 Disabled (org.junit.jupiter.api.Disabled)5 ComponentDetail (org.talend.sdk.component.server.front.model.ComponentDetail)5 InputStream (java.io.InputStream)4 Arrays.asList (java.util.Arrays.asList)4