Search in sources :

Example 1 with DBLookupMediatorFactory

use of org.apache.synapse.config.xml.DBLookupMediatorFactory in project wso2-synapse by wso2.

the class DBLookupMediatorTest method suite.

public static Test suite() {
    return new TestSetup(new TestSuite(DBLookupMediatorTest.class)) {

        @Override
        protected void setUp() throws Exception {
            String baseDir = System.getProperty("basedir");
            if (baseDir == null) {
                baseDir = ".";
            }
            lookup = (DBLookupMediator) new DBLookupMediatorFactory().createMediator(createOMElement("<dblookup xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "  <connection>\n" + "    <pool>\n" + "      <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>\n" + "      <url>jdbc:derby:" + baseDir + "/target/derbyDB;create=true</url>\n" + "      <user>user</user>\n" + "      <password>pass</password>\n" + "      <property name=\"initialsize\" value=\"2\"/>\n" + "      <property name=\"isolation\" value=\"Connection.TRANSACTION_SERIALIZABLE\"/>\n" + "    </pool>\n" + "  </connection>\n" + "  <statement>\n" + "    <sql>select target, category from destinations where source = ? and type = ?</sql>\n" + "    <parameter expression=\"//source\" type=\"INTEGER\"/>\n" + "    <parameter value=\"GOLD\" type=\"VARCHAR\"/>\n" + "    <result name=\"targetProp\" column=\"target\"/>\n" + "    <result name=\"categoryProp\" column=\"2\"/>\n" + "  </statement>\n" + "</dblookup>"), new Properties());
            lookup.init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
            java.sql.Statement s = lookup.getDataSource().getConnection().createStatement();
            try {
                s.execute("drop table destinations");
            } catch (SQLException ignore) {
            }
            s.execute("create table destinations(target varchar(10), source int, type varchar(10), category varchar(10))");
            s.execute("insert into destinations values ('svr1', 5, 'GOLD', 'A')");
            s.execute("insert into destinations values ('svr2', 5, 'SILVER', 'A')");
            s.execute("insert into destinations values ('svr3', 6, 'GOLD', 'B')");
            s.close();
        }

        @Override
        protected void tearDown() throws Exception {
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestSuite(junit.framework.TestSuite) SQLException(java.sql.SQLException) DBLookupMediatorFactory(org.apache.synapse.config.xml.DBLookupMediatorFactory) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 TestSetup (junit.extensions.TestSetup)1 TestSuite (junit.framework.TestSuite)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 DBLookupMediatorFactory (org.apache.synapse.config.xml.DBLookupMediatorFactory)1 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)1