Search in sources :

Example 1 with SqlStoredConnectorMetaDataExtension

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);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) SqlStoredConnectorMetaDataExtension(io.syndesis.connector.sql.stored.SqlStoredConnectorMetaDataExtension) HashMap(java.util.HashMap) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 SqlStoredConnectorMetaDataExtension (io.syndesis.connector.sql.stored.SqlStoredConnectorMetaDataExtension)1 SyndesisMetadata (io.syndesis.connector.support.verifier.api.SyndesisMetadata)1 HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 MetaData (org.apache.camel.component.extension.MetaDataExtension.MetaData)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Test (org.junit.Test)1