use of io.syndesis.connector.sql.stored.SqlStoredConnectorMetaDataExtension 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);
}
Aggregations