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"));
}
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));
}
}
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");
}
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[]")));
}
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());
});
});
});
}
Aggregations