use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SalesforceMetadataRetrievalTest method shouldAdaptObjectMetadataForProperties.
@Test
public void shouldAdaptObjectMetadataForProperties() {
final Map<String, Object> properties = new HashMap<>();
properties.put("sObjectName", "SimpleObject");
properties.put("sObjectIdName", null);
final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties, MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
assertThat(metadata.properties).containsKey("sObjectIdName");
final List<PropertyPair> values = metadata.properties.get("sObjectIdName");
assertThat(values).containsOnly(new PropertyPair("uniqueProperty1", "Unique property 1"), new PropertyPair("uniqueProperty2", "Unique property 2"));
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SalesforceMetadataRetrievalTest method shouldAdaptObjectTypesMetadataForProperties.
@Test
public void shouldAdaptObjectTypesMetadataForProperties() {
final ObjectSchema globalObjectsPayload = new ObjectSchema();
final HashSet<Object> oneOf = new HashSet<>();
oneOf.add(simpleObjectSchema("Object1", "Object1 Label"));
oneOf.add(simpleObjectSchema("Object2", "Object2 Label"));
globalObjectsPayload.setOneOf(oneOf);
final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED, MetaDataBuilder.on(CONTEXT).withPayload(globalObjectsPayload).build());
assertThat(metadata.properties).containsKey("sObjectName");
final List<PropertyPair> values = metadata.properties.get("sObjectName");
assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"), new PropertyPair("Object2", "Object2 Label"));
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SqlMetadataAdapterTest method adaptForSqlStoredTest.
@Test
public void adaptForSqlStoredTest() throws IOException, JSONException {
CamelContext camelContext = new DefaultCamelContext();
SqlStoredConnectorMetaDataExtension ext = new SqlStoredConnectorMetaDataExtension(camelContext);
Map<String, Object> parameters = new HashMap<>();
for (final String name : properties.stringPropertyNames()) {
parameters.put(name.substring(name.indexOf(".") + 1), properties.getProperty(name));
}
Optional<MetaData> metadata = ext.meta(parameters);
SqlMetadataRetrieval adapter = new SqlMetadataRetrieval();
SyndesisMetadata syndesisMetaData = adapter.adapt(camelContext, "sql", "sql-stored-connector", parameters, metadata.get());
String expectedListOfProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8).trim();
ObjectWriter writer = Json.writer();
String actualListOfProcedures = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData);
assertEquals(expectedListOfProcedures, actualListOfProcedures, JSONCompareMode.STRICT);
parameters.put(SqlMetadataRetrieval.PATTERN, SqlMetadataRetrieval.FROM_PATTERN);
String expectedListOfStartProcedures = IOUtils.toString(this.getClass().getResource("/sql/stored_procedure_list.json"), StandardCharsets.UTF_8).trim();
String actualListOfStartProcedures = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData);
assertEquals(expectedListOfStartProcedures, actualListOfStartProcedures, JSONCompareMode.STRICT);
parameters.put("procedureName", "DEMO_ADD");
SyndesisMetadata syndesisMetaData2 = adapter.adapt(camelContext, "sql", "sql-stored-connector", parameters, metadata.get());
String expectedMetadata = IOUtils.toString(this.getClass().getResource("/sql/demo_add_metadata.json"), StandardCharsets.UTF_8).trim();
String actualMetadata = writer.with(writer.getConfig().getDefaultPrettyPrinter()).writeValueAsString(syndesisMetaData2);
assertEquals(expectedMetadata, actualMetadata, JSONCompareMode.STRICT);
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class SqlMetadataRetrieval method adaptForSql.
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity" })
public SyndesisMetadata adaptForSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) {
final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>();
final List<PropertyPair> ppList = new ArrayList<>();
@SuppressWarnings("unchecked") final SqlStatementMetaData sqlStatementMetaData = (SqlStatementMetaData) metadata.getPayload();
if (sqlStatementMetaData != null) {
ppList.add(new PropertyPair(sqlStatementMetaData.getSqlStatement(), QUERY));
enrichedProperties.put(QUERY, ppList);
// build the input and output schemas
final ObjectSchema builderIn = new ObjectSchema();
builderIn.set$schema("http://json-schema.org/schema#");
builderIn.setTitle("SQL_PARAM_IN");
for (SqlParam inParam : sqlStatementMetaData.getInParams()) {
builderIn.putProperty(inParam.getName(), schemaFor(inParam.getJdbcType()));
}
final ObjectSchema builderOut = new ObjectSchema();
builderOut.setTitle("SQL_PARAM_OUT");
builderOut.set$schema("http://json-schema.org/schema#");
for (SqlParam outParam : sqlStatementMetaData.getOutParams()) {
builderOut.putProperty(outParam.getName(), schemaFor(outParam.getJdbcType()));
}
try {
DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type(builderIn.getTitle());
if (builderIn.getProperties().isEmpty()) {
inDataShapeBuilder.kind(DataShapeKinds.NONE);
} else {
inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Parameter").description(String.format("Parameters of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderIn));
}
DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type(builderOut.getTitle());
if (builderOut.getProperties().isEmpty()) {
outDataShapeBuilder.kind(DataShapeKinds.NONE);
} else {
outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Result").description(String.format("Result of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderOut));
}
return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build());
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
} else {
return new SyndesisMetadata(enrichedProperties, null, null);
}
}
use of io.syndesis.connector.support.verifier.api.SyndesisMetadata in project syndesis by syndesisio.
the class ActionDefinitionEndpointTest method shouldMetadata.
@Test
public void shouldMetadata() throws Exception {
final CamelContext context = new DefaultCamelContext();
context.addComponent("petstore", new PetstoreComponent(PAYLOAD));
try {
context.start();
final PetstoreMetadataRetrieval adapter = new PetstoreMetadataRetrieval(PAYLOAD, PROPERTIES, INPUT, OUTPUT);
final SyndesisMetadata metadata = adapter.fetch(context, "petstore", "dog-food", Collections.emptyMap());
assertThat(metadata.properties).isSameAs(PROPERTIES);
assertThat(metadata.inputShape).isSameAs(INPUT);
assertThat(metadata.outputShape).isSameAs(OUTPUT);
} finally {
context.stop();
}
}
Aggregations