Search in sources :

Example 1 with Ui

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

the class UiSpecServiceTest method properties.

@Test
void properties() throws Exception {
    final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
    final Map<String, Object> properties = Map.class.cast(payload.getProperties());
    assertEquals(1, properties.size());
    final Map<String, Object> configuration = Map.class.cast(properties.get("configuration"));
    assertEquals(2, configuration.size());
    final Map<String, Object> connection = Map.class.cast(configuration.get("connection"));
    assertEquals(2, connection.size());
    assertEquals("", connection.get("password"));
    assertEquals("sa", connection.get("username"));
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) Test(org.junit.jupiter.api.Test)

Example 2 with Ui

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

the class UiSpecServiceTest method condition.

@Test
void condition() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final UiSchema root = payload.getUiSchema().iterator().next();
    final Collection<UiSchema.Condition> conditions = root.getItems().stream().filter(i -> i.getTitle().equals("Main")).findFirst().get().getItems().stream().filter(i -> i.getTitle().equals("Order")).findFirst().get().getConditions();
    assertEquals(1, conditions.size());
    final UiSchema.Condition condition = conditions.iterator().next();
    assertEquals("tableDataSet.ordered", condition.getPath());
    assertEquals(singletonList(true), condition.getValues());
    // typed serialization
    try (final Jsonb jsonb = JsonbBuilder.create()) {
        assertEquals("{\"path\":\"tableDataSet.ordered\",\"values\":[true]}", jsonb.toJson(condition));
    }
}
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) Jsonb(javax.json.bind.Jsonb) Ui(org.talend.sdk.component.form.model.Ui) UiSchema(org.talend.sdk.component.form.model.uischema.UiSchema) Test(org.junit.jupiter.api.Test)

Example 3 with Ui

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

the class UiSpecServiceTest method triggerRelativeParameters.

@Test
void triggerRelativeParameters() throws Exception {
    final Ui payload = service.convert(load("relative-params.json")).toCompletableFuture().get();
    final Collection<UiSchema> schema = payload.getUiSchema();
    final UiSchema.Trigger driverTrigger = schema.iterator().next().getItems().stream().filter(c -> c.getTitle().equals("JDBC Connection")).findFirst().orElseThrow(() -> new IllegalArgumentException("No connection")).getItems().iterator().next().getTriggers().iterator().next();
    assertEquals("driver", driverTrigger.getAction());
    // here is what the test validates: the parameters are flattened and translated
    // for the ui
    assertEquals(3, driverTrigger.getParameters().size(), driverTrigger.toString());
    final Iterator<UiSchema.Parameter> params = driverTrigger.getParameters().iterator();
    assertTrue(params.hasNext());
    assertTriggerParameter(params.next(), "value.driver", "configuration.connection.driver");
    assertTriggerParameter(params.next(), "query.timeout", "configuration.query.timeout");
    assertTriggerParameter(params.next(), "query.sql", "configuration.query.sql");
}
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)

Example 4 with Ui

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

the class UiSpecServiceTest method jsonSchemaArray.

@Test
void jsonSchemaArray() throws Exception {
    final Ui payload = service.convert(load("rest-api.json")).toCompletableFuture().get();
    final JsonSchema commonConfig = payload.getJsonSchema().getProperties().values().iterator().next().getProperties().entrySet().stream().filter(e -> e.getKey().equals("commonConfig")).findFirst().map(Map.Entry::getValue).orElseThrow(IllegalStateException::new);
    assertTrue(commonConfig.getProperties().keySet().stream().anyMatch(p -> p.equals("fields")));
    assertTrue(commonConfig.getProperties().keySet().stream().noneMatch(p -> p.equals("fields[]")));
}
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) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test)

Example 5 with Ui

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

the class UiSpecServiceTest method jsonSchema.

@Test
void jsonSchema() throws Exception {
    final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
    final JsonSchema jsonSchema = payload.getJsonSchema();
    assertNotNull(jsonSchema);
    assertEquals("JDBC Input", jsonSchema.getTitle());
    assertEquals("object", jsonSchema.getType());
    assertEquals(1, jsonSchema.getProperties().size());
    assertProperty(jsonSchema.getProperties().get("configuration"), "object", "Configuration", p -> {
        final Map<String, JsonSchema> nestedProperties = p.getProperties();
        assertEquals(2, nestedProperties.size());
        assertTrue(TreeMap.class.isInstance(nestedProperties));
        assertEquals(asList("connection", "query"), new ArrayList<>(nestedProperties.keySet()));
        assertProperty(nestedProperties.get("query"), "object", "query", q -> {
            final Map<String, JsonSchema> queryNestedProperties = q.getProperties();
            assertEquals(2, queryNestedProperties.size());
            assertProperty(queryNestedProperties.get("query"), "string", "query", query -> assertNull(query.getProperties()));
            assertProperty(queryNestedProperties.get("timeout"), "number", "timeout", timeout -> assertNull(timeout.getProperties()));
        });
        assertProperty(nestedProperties.get("connection"), "object", "JDBC Connection", q -> {
            final Map<String, JsonSchema> queryNestedProperties = q.getProperties();
            assertEquals(4, queryNestedProperties.size());
            assertProperty(queryNestedProperties.get("password"), "string", "password", pwd -> assertNull(pwd.getProperties()));
            assertProperty(queryNestedProperties.get("driver"), "string", "driver", driver -> assertNull(driver.getProperties()));
            assertProperty(queryNestedProperties.get("url"), "string", "url", url -> assertNull(url.getProperties()));
            assertProperty(queryNestedProperties.get("username"), "string", "username", username -> {
                assertNull(username.getProperties());
                assertEquals("sa", username.getDefaultValue());
            });
        });
    });
}
Also used : Ui(org.talend.sdk.component.form.model.Ui) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) TreeMap(java.util.TreeMap) 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