Search in sources :

Example 6 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationSerializerTest method testSerializeDataSourceInformation.

/**
 * Test serializing DataSourceInformation list
 */
public void testSerializeDataSourceInformation() {
    List<DataSourceInformation> dataSourceInformationList = new ArrayList<>();
    DataSourceInformation dataSourceInformation1 = new DataSourceInformation();
    dataSourceInformation1.setDriver("org.h2.Driver");
    dataSourceInformation1.setUrl("jdbc:h2:repository/database/test_db1");
    dataSourceInformation1.setAlias("dataSource1");
    SecretInformation secretInformation = new SecretInformation();
    secretInformation.setUser("user1");
    secretInformation.setAliasSecret("user1password");
    dataSourceInformation1.setSecretInformation(secretInformation);
    dataSourceInformationList.add(dataSourceInformation1);
    DataSourceInformation dataSourceInformation2 = new DataSourceInformation();
    dataSourceInformation2.setDriver("org.h2.Driver");
    dataSourceInformation2.setUrl("jdbc:h2:repository/database/test_db2");
    dataSourceInformation2.setAlias("dataSource2");
    dataSourceInformationList.add(dataSourceInformation2);
    DataSourceInformation dataSourceInformation3 = new DataSourceInformation();
    dataSourceInformation3.setDriver("org.h2.Driver");
    dataSourceInformation3.setUrl("jdbc:h2:repository/database/test_db3");
    dataSourceInformation3.setAlias("dataSource3");
    dataSourceInformationList.add(dataSourceInformation3);
    Properties properties = DataSourceInformationListSerializer.serialize(dataSourceInformationList);
    String dataSources = properties.getProperty("synapse.datasources");
    assertTrue("'dataSource1' cannot be found in datasource list ", dataSources.contains("dataSource1"));
    assertTrue("'dataSource2' cannot be found in datasource list ", dataSources.contains("dataSource2"));
    assertTrue("'dataSource3' cannot be found in datasource list ", dataSources.contains("dataSource3"));
}
Also used : SecretInformation(org.wso2.securevault.secret.SecretInformation) ArrayList(java.util.ArrayList) DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Example 7 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class AbstractDBMediatorFactory method readCustomDataSourceConfig.

private void readCustomDataSourceConfig(OMElement pool, AbstractDBMediator mediator) {
    DataSourceInformation dataSourceInformation = new DataSourceInformation();
    String driver = getKey(pool, DRIVER_Q);
    if (driver != null) {
        mediator.setRegistryBasedDriverConfig(true);
    } else {
        driver = getValue(pool, DRIVER_Q);
    }
    dataSourceInformation.setDriver(driver);
    mediator.addDataSourceProperty(DRIVER_Q, driver);
    String url = getKey(pool, URL_Q);
    if (url != null) {
        mediator.setRegistryBasedUrlConfig(true);
    } else {
        url = getValue(pool, URL_Q);
    }
    dataSourceInformation.setUrl(url);
    mediator.addDataSourceProperty(URL_Q, url);
    SecretInformation secretInformation = new SecretInformation();
    String user = getKey(pool, USER_Q);
    if (user != null) {
        mediator.setRegistryBasedUserConfig(true);
    } else {
        user = getValue(pool, USER_Q);
    }
    secretInformation.setUser(user);
    mediator.addDataSourceProperty(USER_Q, user);
    String password = getKey(pool, PASS_Q);
    if (password != null) {
        mediator.setRegistryBasedPassConfig(true);
    } else {
        password = getValue(pool, PASS_Q);
    }
    secretInformation.setAliasSecret(password);
    mediator.addDataSourceProperty(PASS_Q, password);
    dataSourceInformation.setSecretInformation(secretInformation);
    Iterator poolPropIter = pool.getChildrenWithName(PROP_Q);
    while (poolPropIter.hasNext()) {
        OMElement poolProp = (OMElement) poolPropIter.next();
        readPoolProperty(mediator, dataSourceInformation, poolProp);
    }
    mediator.setDataSourceInformation(dataSourceInformation);
}
Also used : SecretInformation(org.wso2.securevault.secret.SecretInformation) Iterator(java.util.Iterator) DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) OMElement(org.apache.axiom.om.OMElement)

Example 8 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationFactoryTest method testCreateDataSourceInformation.

/**
 * Test creating DataSourceInformation from given properties
 */
public void testCreateDataSourceInformation() {
    Properties properties = new Properties();
    properties.put("synapse.datasources.dataSource1.driverClassName", "org.h2.Driver");
    properties.put("synapse.datasources.dataSource1.url", "jdbc:h2:repository/database/test_db");
    properties.put("synapse.datasources.dataSource1.dsName", "dataSource1");
    DataSourceInformation dataSourceInformation = DataSourceInformationFactory.createDataSourceInformation("dataSource1", properties);
}
Also used : DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Example 9 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationFactoryTest method testCreateDataSourceInformationNameNull.

/**
 * Test creating DataSourceInformation data source name = null
 */
public void testCreateDataSourceInformationNameNull() {
    Properties properties = new Properties();
    DataSourceInformation dataSourceInformation = DataSourceInformationFactory.createDataSourceInformation(null, properties);
    assertNull("Expected null value", dataSourceInformation);
}
Also used : DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Example 10 with DataSourceInformation

use of org.apache.synapse.commons.datasource.DataSourceInformation in project wso2-synapse by wso2.

the class DataSourceInformationFactoryTest method testCreateDataSourceInformationWithEmptyName.

/**
 * Test creating DataSourceInformation empty data source name
 */
public void testCreateDataSourceInformationWithEmptyName() {
    Properties properties = new Properties();
    DataSourceInformation dataSourceInformation = DataSourceInformationFactory.createDataSourceInformation("", properties);
    assertNull("Expected null value", dataSourceInformation);
}
Also used : DataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation) Properties(java.util.Properties)

Aggregations

DataSourceInformation (org.apache.synapse.commons.datasource.DataSourceInformation)13 Properties (java.util.Properties)7 SecretInformation (org.wso2.securevault.secret.SecretInformation)4 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)1 DataSource (javax.sql.DataSource)1 OMElement (org.apache.axiom.om.OMElement)1 SynapseCommonsException (org.apache.synapse.commons.SynapseCommonsException)1