diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml index cddd88268..3f783b068 100644 --- a/modules/integration/pom.xml +++ b/modules/integration/pom.xml @@ -57,9 +57,9 @@ - + @@ -81,7 +81,11 @@ - + + + + + diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/DerbyServerController.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/DerbyServerController.java index 5af733a33..0b24448f6 100644 --- a/modules/integration/src/test/java/org/apache/synapse/samples/framework/DerbyServerController.java +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/DerbyServerController.java @@ -82,7 +82,18 @@ private void initData() throws Exception { //client String dbName = "synapsedb"; - String createTableQuery = "CREATE table company(name varchar(10), id varchar(10), price double)"; + String createCompanyTableQuery = "CREATE table company(name varchar(10), id varchar(10), price double)"; + final String createJDBCMessageStoreQuery = "CREATE TABLE jdbc_message_store" + + "(indexId INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY(Start with 1, Increment by 1)," + + "msg_id VARCHAR(200) NOT NULL,message BLOB NOT NULL)"; + final String createResequenceMessageStoreQuery = "CREATE TABLE tbl_resequence" + + "(indexId INTEGER GENERATED ALWAYS AS IDENTITY(Start with 1, Increment by 1) PRIMARY KEY," + + "msg_id VARCHAR(200) NOT NULL UNIQUE," + + "seq_id INTEGER NOT NULL UNIQUE," + + "message BLOB NOT NULL)"; + final String createLastProcessedIdTblQuery = "CREATE TABLE tbl_lastprocessid" + + "(statement VARCHAR(20) PRIMARY KEY,seq_id INTEGER NOT NULL UNIQUE)"; + String connectionURL = "jdbc:derby://localhost:1527/" + dbName + ";create=true"; java.util.Properties props = new java.util.Properties(); @@ -96,7 +107,10 @@ private void initData() throws Exception { Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); conn = DriverManager.getConnection(connectionURL, props); Statement s = conn.createStatement(); - s.execute(createTableQuery); + s.execute(createCompanyTableQuery); + s.execute(createJDBCMessageStoreQuery); + s.execute(createResequenceMessageStoreQuery); + s.execute(createLastProcessedIdTblQuery); s.execute("INSERT into company values ('IBM','c1',0.0)"); s.execute(" INSERT into company values ('SUN','c2',0.0)"); s.execute(" INSERT into company values ('MSFT','c3',0.0)"); diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/SynapseTestCase.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/SynapseTestCase.java index fbec07fa3..0da6d5317 100644 --- a/modules/integration/src/test/java/org/apache/synapse/samples/framework/SynapseTestCase.java +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/SynapseTestCase.java @@ -66,6 +66,36 @@ protected SynapseTestCase(int sampleId) { loadConfiguration(); } + /** + * Apply configuration values to message store XML. + * + * @param synapseRepoPath path to the synapse XML repository. + * @param axis2BlockingConfigPath path to axis2 blocking client. + */ + private void applyMessageStoreConfigurationToFile(OMElement synapseRepoPath, OMElement axis2BlockingConfigPath, + OMElement config) { + try { + if (null != synapseRepoPath && null != axis2BlockingConfigPath) { + String currentDir = SynapseTestUtils.getCurrentDir(); + String sampleFilePath = SynapseTestUtils.getRequiredParameter(config.getFirstChildWithName + (new QName(SampleConfigConstants.TAG_SYNAPSE_CONF)), + SampleConfigConstants.TAG_SYNAPSE_CONF_XML); + String normalizeFilePath = FilenameUtils.normalize(currentDir + sampleFilePath); + File synapseSampleFile = new File(normalizeFilePath); + String synapseXml = FileUtils.readFileToString(synapseSampleFile); + String modifiedSynapseAxis2 = SynapseTestUtils.replace(synapseXml, "${AXIS2_REPO}", + FilenameUtils.normalize(currentDir + synapseRepoPath.getText())); + String modifiedAxis2Blocking = SynapseTestUtils.replace(modifiedSynapseAxis2, "${AXIS2_CONFIG}", + FilenameUtils.normalize(currentDir + axis2BlockingConfigPath.getText())); + FileUtils.writeStringToFile(synapseSampleFile, modifiedAxis2Blocking); + } + } catch (IOException e) { + String message = "Error occurred while reading the sample configuration"; + log.error(message, e); + fail(message); + } + } + private void loadConfiguration() { // Parse the sample descriptor OMElement sampleConfig = loadDescriptorInfoFile(); @@ -91,6 +121,17 @@ private void loadConfiguration() { this.sampleName = sampleNameElt.getText(); } + // Load synapse repo name and axis2blocking client, needed for message stores + OMElement synapseConfigElement = + sampleConfig.getFirstChildWithName(new QName(SampleConfigConstants.TAG_SYNAPSE_CONF)); + OMElement synapseRepoPath = synapseConfigElement.getFirstChildWithName( + new QName(SampleConfigConstants.TAG_SYNAPSE_CONF_AXIS2_REPO)); + OMElement axis2BlockingConfigPath = synapseConfigElement.getFirstChildWithName( + new QName(SampleConfigConstants.TAG_AXIS2_BLOCKING_CONFIG)); + + //Apply the configurations to the file + applyMessageStoreConfigurationToFile(synapseRepoPath, axis2BlockingConfigPath, sampleConfig); + // Load Synapse, backend server and client configurations synapseController = initSynapseConfigInfo(sampleConfig); backendServerControllers = initBackEndServersConfigInfo(sampleConfig); diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java index 18b441700..12c3a2d1a 100644 --- a/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java @@ -244,6 +244,8 @@ private static void populateSamplesMap() { sampleClassRepo.put("451", Sample451.class); sampleClassRepo.put("452", Sample452.class); sampleClassRepo.put("460", Sample460.class); + sampleClassRepo.put("706", Sample706.class); + sampleClassRepo.put("707", Sample707.class); sampleClassRepo.put("800", Sample800.class); sampleClassRepo.put("10001", Sample10001.class); diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/config/SampleConfigConstants.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/config/SampleConfigConstants.java index 08708f72c..6c6d610b5 100644 --- a/modules/integration/src/test/java/org/apache/synapse/samples/framework/config/SampleConfigConstants.java +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/config/SampleConfigConstants.java @@ -44,6 +44,7 @@ public class SampleConfigConstants { public static final String TAG_BE_SERVER_CONF_AXIS2_REPO = "axis2Repo"; public static final String TAG_BE_SERVER_CONF_AXIS2_XML = "axis2Xml"; + public static final String TAG_AXIS2_BLOCKING_CONFIG = "axis2BlockingXml"; public static final String TAG_BE_SERVER_CONF_AXIS2_HTTP_PORT = "httpPort"; public static final String TAG_BE_SERVER_CONF_AXIS2_HTTPS_PORT = "httpsPort"; public static final String TAG_BE_SERVER_CONF_AXIS2_COUNTER_ENABLED = "counterEnabled"; diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample706.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample706.java new file mode 100644 index 000000000..07238e053 --- /dev/null +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample706.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.synapse.samples.framework.tests.advanced; + +import org.apache.synapse.samples.framework.SampleClientResult; +import org.apache.synapse.samples.framework.SynapseTestCase; +import org.apache.synapse.samples.framework.clients.StockQuoteSampleClient; + +public class Sample706 extends SynapseTestCase { + public Sample706() { + super(706); + } + + public void testJDBCMessageStore() throws InterruptedException { + String trpUrl = "http://localhost:8280/"; + StockQuoteSampleClient client = getStockQuoteClient(); + log.info("Running test: Introduction to JDBC message store "); + SampleClientResult result = client.placeOrder(null, trpUrl, null, "WSO2-1"); + assertTrue("Client received response successfully ", result.responseReceived()); + Thread.sleep(7000); + assertEquals(1, getAxis2Server().getMessageCount("SimpleStockQuoteService", "placeOrder")); + } +} diff --git a/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample707.java b/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample707.java new file mode 100644 index 000000000..92b3a75eb --- /dev/null +++ b/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/advanced/Sample707.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.synapse.samples.framework.tests.advanced; + +import org.apache.synapse.samples.framework.SynapseTestCase; +import org.apache.synapse.samples.framework.clients.StockQuoteSampleClient; + +public class Sample707 extends SynapseTestCase { + public Sample707() { + super(707); + } + + public void testResequenceMessageStore() throws InterruptedException { + String trpUrl = "http://localhost:8280/"; + StockQuoteSampleClient client = getStockQuoteClient(); + log.info("Running test: Introduction to the script mediator using js scripts "); + client.placeOrder(null, trpUrl, null, "WSO2-4"); + client.placeOrder(null, trpUrl, null, "WSO2-2"); + client.placeOrder(null, trpUrl, null, "WSO2-3"); + client.placeOrder(null, trpUrl, null, "WSO2-1"); + Thread.sleep(10000); + assertEquals(4, getAxis2Server().getMessageCount("SimpleStockQuoteService", "placeOrder")); + + } +} diff --git a/modules/integration/src/test/resources/axis2Xml/synapse/axis2_blocking_client.xml b/modules/integration/src/test/resources/axis2Xml/synapse/axis2_blocking_client.xml new file mode 100644 index 000000000..8aa5d6508 --- /dev/null +++ b/modules/integration/src/test/resources/axis2Xml/synapse/axis2_blocking_client.xml @@ -0,0 +1,325 @@ + + + + + + + true + false + false + false + + + + + + 30000 + + + + false + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + services + rest + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8200 + + + + + + + + + + + + + + + + + + HTTP/1.1 + chunked + true + 200 + + + + + + HTTP/1.1 + chunked + true + 200 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/src/test/resources/extras/synapse_sample_706_altered_msmp.xml b/modules/integration/src/test/resources/extras/synapse_sample_706_altered_msmp.xml new file mode 100644 index 000000000..f3b836efe --- /dev/null +++ b/modules/integration/src/test/resources/extras/synapse_sample_706_altered_msmp.xml @@ -0,0 +1,66 @@ + + + + + + + +
+ + -1 + 1.0 + +
+
+ + + + + + + + + + + + + + + + + The main sequence for the message mediation + + + org.apache.derby.jdbc.ClientDriver + false + synapse + jdbc:derby://localhost:1527/synapsedb + synapse + jdbc_message_store + + + 10000 + ${AXIS2_REPO} + ${AXIS2_CONFIG} + +
diff --git a/modules/integration/src/test/resources/extras/synapse_sample_707_altered_msmp.xml b/modules/integration/src/test/resources/extras/synapse_sample_707_altered_msmp.xml new file mode 100644 index 000000000..5da49b249 --- /dev/null +++ b/modules/integration/src/test/resources/extras/synapse_sample_707_altered_msmp.xml @@ -0,0 +1,71 @@ + + + + + + + +
+ + -1 + 1.0 + +
+
+ + + + + + + + + + + + + + + + + The main sequence for the message mediation + + + -1 + false + MyStore + + synapse + org.apache.derby.jdbc.ClientDriver + synapse + jdbc:derby://localhost:1527/synapsedb + tbl_resequence + + + 10000 + ${AXIS2_REPO} + ${AXIS2_CONFIG} + +
diff --git a/modules/integration/src/test/resources/sample706.xml b/modules/integration/src/test/resources/sample706.xml new file mode 100644 index 000000000..6dfd6f96c --- /dev/null +++ b/modules/integration/src/test/resources/sample706.xml @@ -0,0 +1,42 @@ + + + + + 706 + Introduction to JDBC Message Store + + modules/integration/target/test_repos/synapse + modules/integration/target/test_repos/synapse/conf/axis2_def.xml + modules/integration/target/test_repos/synapse/conf/axis2_blocking_client.xml + modules/integration/target/test_repos/synapse/samples/synapse_sample_706_altered_msmp.xml + + + + modules/integration/target/test_repos/axis2Server + modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml + true + + + + + + modules/integration/target/test_repos/axis2Client + + diff --git a/modules/integration/src/test/resources/sample707.xml b/modules/integration/src/test/resources/sample707.xml new file mode 100644 index 000000000..83ea0d023 --- /dev/null +++ b/modules/integration/src/test/resources/sample707.xml @@ -0,0 +1,42 @@ + + + + + 707 + Introduction to Resequence Message Store + + modules/integration/target/test_repos/synapse + modules/integration/target/test_repos/synapse/conf/axis2_def.xml + modules/integration/target/test_repos/synapse/conf/axis2_blocking_client.xml + modules/integration/target/test_repos/synapse/samples/synapse_sample_707_altered_msmp.xml + + + + modules/integration/target/test_repos/axis2Server + modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml + true + + + + + + modules/integration/target/test_repos/axis2Client + +