You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sandesha-dev@ws.apache.org by ch...@apache.org on 2007/04/23 11:55:16 UTC
svn commit: r531400 [15/18] - in /webservices/sandesha/trunk/java/modules:
client/ core/ core/src/ core/src/main/ core/src/main/java/
core/src/main/java/org/ core/src/main/java/org/apache/
core/src/main/java/org/apache/sandesha2/ core/src/main/java/org...
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaClientTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaClientTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaClientTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaClientTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,405 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axis2.Constants;
+import org.apache.axis2.Constants.Configuration;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SequenceReport;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beanmanagers.SenderBeanMgr;
+import org.apache.sandesha2.storage.beans.SenderBean;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class SandeshaClientTest extends SandeshaTestCase {
+
+ String server_repoPath = "target" + File.separator + "repos" + File.separator + "server";
+ String server_axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+ private static boolean startedServer = false;
+
+ public SandeshaClientTest () {
+ super ("SandeshaClientTest");
+ }
+
+ public void setUp () throws Exception {
+ super.setUp();
+ String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+ if (!startedServer)
+ startServer(repoPath, axis2_xml);
+ startedServer = true;
+ }
+
+ /**
+ * Override the teardown processing
+ */
+ public void tearDown () {
+
+ }
+
+ public void testCreateSequenceWithOffer () throws Exception {
+
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+ String transportTo = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+ Options clientOptions = new Options ();
+
+ clientOptions.setTo(new EndpointReference (to));
+ clientOptions.setProperty(Configuration.TRANSPORT_URL,transportTo);
+
+// String sequenceKey = SandeshaUtil.getUUID();
+// clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ try
+ {
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+ String offeredSequenceID = SandeshaUtil.getUUID();
+ clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,offeredSequenceID);
+
+ serviceClient.setOptions(clientOptions);
+ //serviceClient.
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ clientOptions.setUseSeparateListener(true);
+
+ serviceClient.setOptions(clientOptions);
+
+ String sequenceKey = SandeshaClient.createSequence(serviceClient,true);
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+
+ assertNotNull(sequenceReport.getSequenceID());
+ assertFalse(sequenceReport.isSecureSequence());
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+ }
+ finally
+ {
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+
+ }
+
+ public void testSequenceCloseTerminate()throws Exception{
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+ clientOptions.setAction(pingAction);
+ clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,
+ Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ clientOptions.setTo(new EndpointReference (to));
+
+ String sequenceKey = "some_sequence_key";
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ //serviceClient.
+ serviceClient.setOptions(clientOptions);
+
+ try{
+
+ serviceClient.fireAndForget(getPingOMBlock("ping1"));
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertNotNull(sequenceReport.getSequenceID());
+
+ //now close the sequence
+ SandeshaClient.closeSequence(serviceClient);
+
+ //try and send another msg - this should fail
+ try{
+ serviceClient.fireAndForget(getPingOMBlock("ping2"));
+ fail(); //this should have failed
+ }
+ catch(Exception e){
+ //good
+ }
+
+ //finally terminate the sequence
+ terminateAndCheck(serviceClient);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+ }
+ finally{
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+
+ }
+
+ private void terminateAndCheck(ServiceClient srvcClient)throws Exception{
+ SandeshaClient.terminateSequence(srvcClient);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ //now check the sequence is terminated
+ SequenceReport report = SandeshaClient.getOutgoingSequenceReport(srvcClient);
+ assertNotNull(report);
+ assertEquals(report.getSequenceStatus(), SequenceReport.SEQUENCE_STATUS_TERMINATED);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+ }
+
+// public void testCreateSequenceWithoutOffer () {
+//// SandeshaClient.createSequence(serviceClient,true);
+//
+//
+// }
+
+// public void testCreateSequenceWithSequenceKey () {
+//
+// }
+//
+
+ /**
+ * Checks the following scenario
+ *
+ * 1) send an application message (will generate the create sequence)
+ * 2) terminate the sequence
+ * 3) Issue wait until sequence completed (with a wait time)
+ * 4) Create a new sequence
+ * 5) send another application message
+ * 6) terminate the sequence
+ * 7) Ensure that the sequence was terminated
+ *
+ */
+ public void testTerminateCreateWithWait () throws Exception {
+
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+ clientOptions.setAction(pingAction);
+ clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,
+ Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ clientOptions.setTo(new EndpointReference (to));
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ //serviceClient.
+ serviceClient.setOptions(clientOptions);
+
+ try{
+ // 1) Send the application message
+ serviceClient.fireAndForget(getPingOMBlock("ping1"));
+
+ // 2) Terminate the sequence
+ SandeshaClient.terminateSequence(serviceClient);
+
+ // 3) wait for the sequence completion (30 second wait)
+ SandeshaClient.waitUntilSequenceCompleted(serviceClient, 30000);
+
+ // 4) Create a new Sequence to the same endpoint
+ SandeshaClient.createSequence(serviceClient, false, null);
+
+ // 5) Send the second application message (this should use a new sequence)
+ serviceClient.fireAndForget(getPingOMBlock("ping2"));
+
+ // 6) Terminate the sequence
+ SandeshaClient.terminateSequence(serviceClient);
+
+ // 7) wait for the sequence completion (30 second wait)
+ SandeshaClient.waitUntilSequenceCompleted(serviceClient, 30000);
+
+ // 8) Check that the sequence has terminated
+ SequenceReport report = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertNotNull(report);
+ assertEquals(SequenceReport.SEQUENCE_STATUS_TERMINATED, report.getSequenceStatus());
+
+ }
+ finally {
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+ }
+
+//
+// public void testCloseSequence () {
+//
+// }
+//
+ /**
+ * Test that sending an ACK request gets transmitted
+ * This doesn't check the content of the Ack Request, only that the
+ * SenderBean no longer exists for it.
+ */
+ public void testAckRequest () throws Exception {
+
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+ String transportTo = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+
+ clientOptions.setTo(new EndpointReference (to));
+ clientOptions.setProperty(Configuration.TRANSPORT_URL,transportTo);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION, Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ clientOptions.setUseSeparateListener(true);
+
+ serviceClient.setOptions(clientOptions);
+
+ // Create a sequence
+ SandeshaClient.createSequence(serviceClient, false, null);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ //now check the sequence is running
+ SequenceReport report = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertEquals(report.getSequenceStatus(), SequenceReport.SEQUENCE_STATUS_ESTABLISHED);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+
+ // Send the ACK request
+ SandeshaClient.sendAckRequest(serviceClient);
+
+ limit = System.currentTimeMillis() + waitTime;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ // Get the storage manager from the ConfigurationContext
+ StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext, configContext.getAxisConfiguration());
+
+ // Get the sequence id for this sequence.
+ String sequenceId = SandeshaClient.getSequenceID(serviceClient);
+
+ // Get the SenderBeanManager
+ SenderBeanMgr senderManager = storageManager.getSenderBeanMgr();
+
+ // Check that there are no sender beans inside the SenderBeanMgr.
+ SenderBean senderBean = new SenderBean();
+ senderBean.setSequenceID(sequenceId);
+ senderBean.setSend(true);
+ senderBean.setReSend(false);
+
+ // Find any sender beans for the to address.
+ List beans = senderManager.find(senderBean);
+ assertTrue("SenderBeans found when the list should be empty", beans.isEmpty());
+
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+
+ assertNotNull(sequenceReport.getSequenceID());
+ assertFalse(sequenceReport.isSecureSequence());
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+//
+// public void getSequenceIDTest () {
+//
+// }
+
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaReportsTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaReportsTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaReportsTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaReportsTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,294 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SandeshaReport;
+import org.apache.sandesha2.client.SequenceReport;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class SandeshaReportsTest extends SandeshaTestCase {
+
+ private static boolean startedServer = false;
+
+ public SandeshaReportsTest () {
+ super ("SandeshaReportsTest");
+ }
+
+ public void setUp () throws Exception {
+ super.setUp();
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+
+ if (!startedServer)
+ startServer(repoPath, axis2_xml);
+ startedServer = true;
+ }
+
+ /**
+ * Override the teardown processing
+ */
+ public void tearDown () {
+
+ }
+
+ public void testSequenceReports () throws Exception {
+
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+ clientOptions.setAction(echoAction);
+ clientOptions.setTo(new EndpointReference (to));
+
+ String sequenceKey = SandeshaUtil.getUUID();
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+
+ serviceClient.setOptions(clientOptions);
+ //serviceClient.
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ clientOptions.setUseSeparateListener(true);
+
+ serviceClient.setOptions(clientOptions);
+
+ TestCallback callback1 = new TestCallback ("Callback 1");
+ serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo1",sequenceKey),callback1);
+
+ TestCallback callback2 = new TestCallback ("Callback 2");
+ serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo2",sequenceKey),callback2);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ //testing outgoing sequence reports
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertTrue(sequenceReport.getCompletedMessages().contains(new Long(1)));
+ assertTrue(sequenceReport.getCompletedMessages().contains(new Long(2)));
+ assertEquals(sequenceReport.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_ESTABLISHED);
+ assertEquals(sequenceReport.getSequenceDirection(),SequenceReport.SEQUENCE_DIRECTION_OUT);
+
+ //testing incoming sequence reports
+ ArrayList incomingSequenceReports = SandeshaClient.getIncomingSequenceReports(configContext);
+ assertEquals(incomingSequenceReports.size(),1);
+ SequenceReport incomingSequenceReport = (SequenceReport) incomingSequenceReports.get(0);
+ assertEquals(incomingSequenceReport.getCompletedMessages().size(),2);
+ assertNotNull(incomingSequenceReport.getSequenceID());
+ assertEquals(incomingSequenceReport.getSequenceDirection(),SequenceReport.SEQUENCE_DIRECTION_IN);
+ assertNotNull(incomingSequenceReport.getInternalSequenceID());
+
+ assertEquals(incomingSequenceReport.getSequenceID(),incomingSequenceReport.getInternalSequenceID()); //for the incoming side, internalSequenceID==sequenceID
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+
+ SandeshaClient.terminateSequence(serviceClient, sequenceKey);
+ SandeshaClient.waitUntilSequenceCompleted(serviceClient, sequenceKey);
+
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertEquals(sequenceReport.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+
+ public void testRMReport () throws AxisFault,InterruptedException {
+
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ //clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ Options clientOptions = new Options ();
+ clientOptions.setAction(pingAction);
+// clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
+ clientOptions.setTo(new EndpointReference (to));
+
+ String sequenceKey1 = "sequence3";
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey1);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ serviceClient.setOptions(clientOptions);
+
+
+ serviceClient.fireAndForget(getPingOMBlock("ping1"));
+ clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+ serviceClient.fireAndForget(getPingOMBlock("ping2"));
+
+ String sequenceKey2 = "sequence4";
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey2);
+
+ clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "false");
+ serviceClient.fireAndForget(getPingOMBlock("ping1"));
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ SandeshaReport rmReport = SandeshaClient.getSandeshaReport(configContext);
+
+ SequenceReport sequence1Report = null;
+ SequenceReport sequence2Report = null;
+
+ Iterator iterator = rmReport.getOutgoingSequenceList().iterator();
+ while (iterator.hasNext()) {
+ String sequenceID = (String) iterator.next();
+
+ String internalSequenceID = rmReport.getInternalSequenceIdOfOutSequence(sequenceID);
+
+ if (internalSequenceID.indexOf(sequenceKey1)>=0) {
+ sequence1Report = SandeshaClient.getOutgoingSequenceReport(to,sequenceKey1,configContext);
+ } else if (internalSequenceID.indexOf(sequenceKey2)>=0){
+ sequence2Report = SandeshaClient.getOutgoingSequenceReport(to,sequenceKey2,configContext);
+ }
+ }
+
+ assertNotNull(sequence1Report);
+ assertNotNull(sequence2Report);
+
+ assertEquals(sequence1Report.getCompletedMessages().size(),2);
+ assertEquals(sequence2Report.getCompletedMessages().size(),1);
+
+ assertEquals(sequence1Report.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+ assertEquals(sequence2Report.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_ESTABLISHED);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+ if(lastError != null) throw lastError;
+
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+
+
+// public void testSequenceTermination () throws AxisFault,InterruptedException {
+//
+// String to = "http://127.0.0.1:8060/axis2/services/RMSampleService";
+// String transportTo = "http://127.0.0.1:8060/axis2/services/RMSampleService";
+//
+// String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+// String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+//
+// ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+//
+// //clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+// Options clientOptions = new Options ();
+// clientOptions.setProperty(Options.COPY_PROPERTIES,new Boolean (true));
+// clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+//
+// clientOptions.setTo(new EndpointReference (to));
+// clientOptions.setProperty(MessageContextConstants.TRANSPORT_URL,transportTo);
+//
+// String sequenceKey1 = "sequence1";
+// clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey1);
+//
+// ServiceClient serviceClient = new ServiceClient (configContext,null);
+//
+// serviceClient.setOptions(clientOptions);
+//
+// serviceClient.fireAndForget(getPingOMBlock("ping11"));
+// serviceClient.fireAndForget(getPingOMBlock("ping12"));
+//
+// String sequenceKey2 = "sequence2";
+// clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey2);
+//
+// serviceClient.fireAndForget(getPingOMBlock("ping21"));
+//
+// SandeshaClient.terminateSequence(serviceClient,sequenceKey1);
+//
+// clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+// serviceClient.fireAndForget(getPingOMBlock("ping22"));
+// try {
+// //waiting till the messages exchange finishes.
+// Thread.sleep(10000);
+// } catch (InterruptedException e) {
+// throw new SandeshaException ("sleep interupted");
+// }
+//
+//
+// SandeshaReport rmReport = SandeshaClient.getSandeshaReport(configContext);
+//
+// SequenceReport sequence1Report = null;
+// SequenceReport sequence2Report = null;
+//
+// Iterator iterator = rmReport.getOutgoingSequenceList().iterator();
+// while (iterator.hasNext()) {
+// String sequenceID = (String) iterator.next();
+//
+// String internalSequenceID = rmReport.getInternalSequenceIdOfOutSequence(sequenceID);
+//
+// if (internalSequenceID.indexOf(sequenceKey1)>=0) {
+// sequence1Report = SandeshaClient.getOutgoingSequenceReport(to,sequenceKey1,configContext);
+// } else if (internalSequenceID.indexOf(sequenceKey2)>=0){
+// sequence2Report = SandeshaClient.getOutgoingSequenceReport(to,sequenceKey2,configContext);
+// }
+// }
+//
+// assertNotNull(sequence1Report);
+// assertNotNull(sequence2Report);
+//
+// assertEquals(sequence1Report.getCompletedMessages().size(),2);
+// assertEquals(sequence2Report.getCompletedMessages().size(),2);
+//
+// assertEquals(sequence1Report.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+// assertEquals(sequence2Report.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+// }
+
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaTestCase.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaTestCase.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaTestCase.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaTestCase.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.client.async.AsyncResult;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.transport.http.SimpleHTTPServer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SandeshaTestCase extends TestCase {
+
+ String resourceDir = ""; //"test-resources";
+ Properties properties = null;
+ final String PROPERTY_FILE_NAME = "sandesha2-test.properties";
+ public final int DEFAULT_SERVER_TEST_PORT = 8060;
+ public ConfigurationContext serverConfigurationContext = null;
+ private final String RMServiceName = "RMSampleService";
+ private Log log = LogFactory.getLog(getClass());
+
+ private final static String applicationNamespaceName = "http://tempuri.org/";
+ private final static String echoString = "echoString";
+ private final static String ping = "ping";
+ private final static String Text = "Text";
+ private final static String Sequence = "Sequence";
+ private final static String echoStringResponse = "echoStringResponse";
+ private final static String EchoStringReturn = "EchoStringReturn";
+
+ protected SimpleHTTPServer httpServer = null;
+ protected int serverPort = DEFAULT_SERVER_TEST_PORT;
+ protected int waitTime = 60000; // Each test will wait up to 60 seconds, unless we override it here
+ protected int tickTime = 1000; // Each wait will check the test assertions each second
+ protected String pingAction = "urn:wsrm:Ping";
+ protected String echoAction = "urn:wsrm:EchoString";
+
+ public SandeshaTestCase(String name) {
+ super(name);
+ File baseDir = new File("");
+ String testRource = baseDir.getAbsolutePath() + File.separator + "test-resources";
+ resourceDir = new File(testRource).getPath();
+
+ String propFileStr = resourceDir + File.separator + PROPERTY_FILE_NAME;
+ properties = new Properties ();
+
+ try {
+ FileInputStream propertyFile = new FileInputStream (new File(propFileStr));
+ properties.load(propertyFile);
+ } catch (FileNotFoundException e) {
+ log.error(e);
+ } catch (IOException e) {
+ log.error(e);
+ }
+ }
+
+ public void setUp () throws Exception {
+ super.setUp();
+
+ String serverPortStr = getTestProperty("test.server.port");
+ if (serverPortStr!=null) {
+ try {
+ serverPort = Integer.parseInt(serverPortStr);
+ } catch (NumberFormatException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ public ConfigurationContext startServer(String repoPath, String axis2_xml)
+ throws Exception {
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ httpServer = new SimpleHTTPServer (configContext,serverPort);
+ httpServer.start();
+ Thread.sleep(300);
+
+ return configContext;
+ }
+
+ public void tearDown () throws Exception {
+ if (httpServer!=null)
+ httpServer.stop();
+
+ Thread.sleep(300);
+ }
+
+ protected InputStreamReader getResource(String relativePath, String resourceName) {
+ String resourceFile = resourceDir + relativePath + File.separator + resourceName;
+ try {
+ FileReader reader = new FileReader(resourceFile);
+ return reader;
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("cannot load the test-resource", e);
+ }
+ }
+
+ protected SOAPEnvelope getSOAPEnvelope() {
+ return OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ }
+
+ protected SOAPEnvelope getSOAPEnvelope(String relativePath, String resourceName) {
+ try {
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
+ getResource(relativePath, resourceName));
+ OMXMLParserWrapper wrapper = OMXMLBuilderFactory.createStAXSOAPModelBuilder(
+ OMAbstractFactory.getSOAP11Factory(), reader);
+ return (SOAPEnvelope) wrapper.getDocumentElement();
+
+ } catch (XMLStreamException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected SOAPEnvelope getEmptySOAPEnvelope() {
+ return OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ }
+
+ protected static OMElement getEchoOMBlock(String text, String sequenceKey) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace applicationNamespace = fac.createOMNamespace(applicationNamespaceName,"ns1");
+ OMElement echoStringElement = fac.createOMElement(echoString, applicationNamespace);
+ OMElement textElem = fac.createOMElement(Text,applicationNamespace);
+ OMElement sequenceElem = fac.createOMElement(Sequence,applicationNamespace);
+
+ textElem.setText(text);
+ sequenceElem.setText(sequenceKey);
+ echoStringElement.addChild(textElem);
+ echoStringElement.addChild(sequenceElem);
+
+ return echoStringElement;
+ }
+
+ protected OMElement getPingOMBlock(String text) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace namespace = fac.createOMNamespace(applicationNamespaceName,"ns1");
+ OMElement pingElem = fac.createOMElement(ping, namespace);
+ OMElement textElem = fac.createOMElement(Text, namespace);
+
+ textElem.setText(text);
+ pingElem.addChild(textElem);
+
+ return pingElem;
+ }
+
+ protected String checkEchoOMBlock(OMElement response) {
+ assertEquals("Response namespace", applicationNamespaceName, response.getNamespace().getNamespaceURI());
+ assertEquals("Response local name", echoStringResponse, response.getLocalName());
+
+ OMElement echoStringReturnElem = response.getFirstChildWithName(new QName (applicationNamespaceName,EchoStringReturn));
+ assertNotNull("Echo String Return", echoStringReturnElem);
+
+ String resultStr = echoStringReturnElem.getText();
+ return resultStr;
+ }
+
+ public String getTestProperty (String key) {
+ if (properties!=null)
+ return properties.getProperty(key);
+
+ return null;
+ }
+
+ public void overrideConfigurationContext (ConfigurationContext context,MessageReceiver messageReceiver, String operationName, boolean newOperation, int mep) throws Exception {
+
+
+ AxisService rmService = context.getAxisConfiguration().getService(RMServiceName);
+
+ AxisOperation operation = null;
+
+ if (newOperation) {
+ operation = rmService.getOperation(new QName (operationName));
+ if (operation==null)
+ throw new Exception ("Given operation not found");
+ } else {
+ operation = AxisOperationFactory.getAxisOperation(mep);
+ rmService.addOperation(operation);
+ }
+
+ operation.setMessageReceiver(messageReceiver);
+ }
+
+ protected class TestCallback extends Callback {
+
+ String name = null;
+ boolean completed = false;
+ boolean errorRported = false;
+ String resultStr;
+
+ public boolean isCompleted() {
+ return completed;
+ }
+
+ public boolean isErrorRported() {
+ return errorRported;
+ }
+
+ public String getResult () {
+ return resultStr;
+ }
+
+ public TestCallback (String name) {
+ this.name = name;
+ }
+
+ public void onComplete(AsyncResult result) {
+ SOAPBody body = result.getResponseEnvelope().getBody();
+ OMElement contents = body.getFirstElement();
+ this.resultStr = checkEchoOMBlock(contents);
+ completed = true;
+ System.out.println("TestCallback got text: '" + resultStr + "'");
+ }
+
+ public void onError (Exception e) {
+ e.printStackTrace();
+ errorRported = true;
+ }
+ }
+
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaUtilTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaUtilTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaUtilTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SandeshaUtilTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,199 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.util.MessageContextBuilder;
+import org.apache.sandesha2.util.Range;
+import org.apache.sandesha2.util.RangeString;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+
+import junit.framework.TestCase;
+
+public class SandeshaUtilTest extends TestCase {
+
+ public void testUUIDGen () {
+ String UUID1 = SandeshaUtil.getUUID();
+ String UUID2 = SandeshaUtil.getUUID();
+
+ assertTrue(UUID1!=null);
+ assertTrue(UUID2!=null);
+ assertTrue(!UUID1.equals(UUID2));
+
+ assertTrue(UUID1.startsWith("urn:uuid:"));
+ assertTrue(UUID2.startsWith("urn:uuid:"));
+ }
+
+ public void testInternalSequenceIDToSequenceKeyConversion() {
+ String toEPR = "http://127.0.0.1:1111/some_random_uri";
+ String sequenceKey = "1234abcd";
+
+ String internalSequenceID = SandeshaUtil.getInternalSequenceID(toEPR, sequenceKey);
+
+ //check that we can parse out the sequence key
+ assertEquals(sequenceKey, SandeshaUtil.getSequenceKeyFromInternalSequenceID(internalSequenceID, toEPR));
+
+ //try an internal sequenceID without a sequenceKey - should get null
+ internalSequenceID = SandeshaUtil.getSequenceKeyFromInternalSequenceID(toEPR, null);
+ assertNull(SandeshaUtil.getSequenceKeyFromInternalSequenceID(internalSequenceID, toEPR));
+
+ //for badly formed sequences, or for server-side response sequences, check
+ //we just get null
+ String outgoingSequenceID = SandeshaUtil.getOutgoingSideInternalSequenceID(SandeshaUtil.getUUID());
+ assertNull(SandeshaUtil.getSequenceKeyFromInternalSequenceID(outgoingSequenceID, toEPR));
+
+ }
+
+ public void testGetAckRangesFromRangeStringOutOfOrder()throws SandeshaException{
+
+ RangeString rangeString = new RangeString();
+ rangeString.addRange(new Range(3));
+ rangeString.addRange(new Range(6));
+ rangeString.addRange(new Range(1));
+ rangeString.addRange(new Range(5));
+ rangeString.addRange(new Range(8));
+ rangeString.addRange(new Range(2));
+
+ ArrayList list = SandeshaUtil.getAckRangeArrayList(rangeString,Sandesha2Constants.SPEC_2005_02.NS_URI);
+ assertNotNull(list);
+ assertEquals(list.size(),3);
+
+ Iterator it = list.iterator();
+ AcknowledgementRange ackRange = null;
+
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),1);
+ assertEquals(ackRange.getUpperValue(),3);
+
+ ackRange = null;
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),5);
+ assertEquals(ackRange.getUpperValue(),6);
+
+ ackRange = null;
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),8);
+ assertEquals(ackRange.getUpperValue(),8);
+
+ assertFalse(it.hasNext());
+ }
+
+ public void testGetAckRangesFromRangeStringGapFilling () throws SandeshaException {
+ //build a range string to represent the completed messages
+ RangeString rangeString = new RangeString();
+ rangeString.addRange(new Range(1,3));
+ rangeString.addRange(new Range(4));
+ //insert a gap - number 5 is missing
+ rangeString.addRange(new Range(6));
+ //insert a gap - 7 and 8 are missing
+ rangeString.addRange(new Range(9, 10));
+
+ ArrayList list = SandeshaUtil.getAckRangeArrayList(rangeString,Sandesha2Constants.SPEC_2005_02.NS_URI);
+ assertNotNull(list);
+ //we expect 3 ranges: [1-4] [6] [9-10]
+ assertEquals(list.size(),3);
+
+ Iterator it = list.iterator();
+ AcknowledgementRange ackRange = null;
+
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),1);
+ assertEquals(ackRange.getUpperValue(),4);
+
+ ackRange = null;
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),6);
+ assertEquals(ackRange.getUpperValue(),6);
+
+ ackRange = null;
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),9);
+ assertEquals(ackRange.getUpperValue(),10);
+
+ assertFalse(it.hasNext());
+
+ //ok, now plug a gap at msg 5
+ rangeString.addRange(new Range(5));
+ list = SandeshaUtil.getAckRangeArrayList(rangeString,Sandesha2Constants.SPEC_2005_02.NS_URI);
+ assertNotNull(list);
+ //we expect 2 ranges: [1-6] [9-10]
+ it = list.iterator();
+ ackRange = null;
+
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),1);
+ assertEquals(ackRange.getUpperValue(),6);
+
+ ackRange = null;
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),9);
+ assertEquals(ackRange.getUpperValue(),10);
+
+ assertFalse(it.hasNext());
+
+ //plug all of the gaps - 7 and 8
+ rangeString.addRange(new Range(8));
+ rangeString.addRange(new Range(7,8));
+ list = SandeshaUtil.getAckRangeArrayList(rangeString,Sandesha2Constants.SPEC_2005_02.NS_URI);
+ assertNotNull(list);
+ //we expect 1 ranges: [1-10]
+ it = list.iterator();
+ ackRange = null;
+
+ ackRange = (AcknowledgementRange) it.next();
+ assertNotNull(ackRange);
+ assertEquals(ackRange.getLowerValue(),1);
+ assertEquals(ackRange.getUpperValue(),10);
+
+ assertFalse(it.hasNext());
+ }
+
+ /**
+ * Checks that a Fault message can be created from an empty MessageContext
+ *
+ * @throws Exception
+ */
+ public void testCreateFaultMessageContext() throws Exception {
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+ MessageContext messageContext = new MessageContext();
+ messageContext.setConfigurationContext(configContext);
+ messageContext = MessageContextBuilder.createFaultMessageContext(messageContext, new Exception());
+ }
+
+
+
+
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SquenceOfferTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SquenceOfferTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SquenceOfferTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/SquenceOfferTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SandeshaReport;
+import org.apache.sandesha2.client.SequenceReport;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class SquenceOfferTest extends SandeshaTestCase {
+
+ public SquenceOfferTest () {
+ super ("SquenceOfferTest");
+ }
+
+ public void setUp () throws Exception {
+ super.setUp();
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+
+ startServer(repoPath, axis2_xml);
+ }
+
+ public void testSequenceOffer () throws Exception {
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+ clientOptions.setAction(echoAction);
+ clientOptions.setTo(new EndpointReference (to));
+
+ String sequenceKey = SandeshaUtil.getUUID();
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+ String offeredSequenceID = SandeshaUtil.getUUID();
+ clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,offeredSequenceID);
+
+ serviceClient.setOptions(clientOptions);
+ //serviceClient.
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ clientOptions.setUseSeparateListener(true);
+
+ serviceClient.setOptions(clientOptions);
+
+
+ clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+ TestCallback callback1 = new TestCallback ("Callback 1");
+ serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo1",sequenceKey),callback1);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ //assertions for the out sequence.
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertTrue(sequenceReport.getCompletedMessages().contains(new Long(1)));
+ assertEquals(sequenceReport.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+ assertEquals(sequenceReport.getSequenceDirection(),SequenceReport.SEQUENCE_DIRECTION_OUT);
+
+ assertTrue(callback1.isComplete());
+ assertEquals(callback1.getResult(),"echo1");
+
+ //checking weather the incomingSequenceReport has the offered sequence ID
+ SandeshaReport rmReport = SandeshaClient.getSandeshaReport(configContext);
+ ArrayList incomingSeqList = rmReport.getIncomingSequenceList();
+ assertEquals(incomingSeqList.size(),1);
+ assertEquals(incomingSeqList.get(0),offeredSequenceID);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+
+ if(lastError != null) throw lastError;
+
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
+
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.util.RMMsgCreator;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.AcksTo;
+import org.apache.sandesha2.wsrm.CreateSequence;
+
+
+public class CreateSequenceRefusedFaultTest extends SandeshaTestCase {
+
+ private static final String server_repoPath = "target" + File.separator
+ + "repos" + File.separator + "server";
+
+ private static final String server_axis2_xml = "target" + File.separator
+ + "repos" + File.separator + "server" + File.separator
+ + "server_axis2.xml";
+
+ private static ConfigurationContext serverConfigContext;
+
+ public CreateSequenceRefusedFaultTest() {
+ super("CreateSequenceProcessorTest");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+ }
+
+ /**
+ * Sends a Create Sequence message to an RM Destination that will be refused.
+ *
+ * @throws Exception
+ */
+ public void testCreateSequenceSOAPFault() throws Exception {
+
+ // Open a connection to the endpoint
+ HttpURLConnection connection =
+ FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+ "http://docs.oasis-open.org/ws-rx/wsrm/200702/CreateSequence");
+
+ OutputStream tmpOut2 = connection.getOutputStream();
+
+ byte ar[] = getMessageAsBytes();
+
+ // Send the message to the socket.
+ tmpOut2.write(ar);
+ tmpOut2.flush();
+
+ // Get the response message from the connection
+ String message = FaultTestUtils.retrieveResponseMessage(connection);
+
+ // Check that the fault message isn't null
+ assertNotNull(message);
+
+ // Check that the response contains the wsrm:CreateSequenceRefused tag
+ assertTrue(message.indexOf("CreateSequenceRefused") > -1);
+
+ // Disconnect at the end of the test
+ connection.disconnect();
+ }
+
+ /**
+ * Get a Create Sequence message as bytes
+ *
+ * This generates a CreateSequenceMessage that has a "bad" AcksTo value which
+ * will generate a Fault from the service.
+ * @return
+ */
+ private byte[] getMessageAsBytes() throws Exception
+ {
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ SOAPFactory factory = new SOAP11Factory();
+ SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+
+ // Create a "new" application message
+ MessageContext messageContext = new MessageContext();
+ messageContext.setConfigurationContext(serverConfigContext);
+ messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));
+ messageContext.setEnvelope(dummyEnvelope);
+
+ RMMsgContext applicationRMMsg = new RMMsgContext(messageContext);
+
+ // Create an RMSBean so the create sequence message can be created
+ RMSBean rmsBean = new RMSBean();
+ rmsBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ rmsBean.setToEPR(to);
+ rmsBean.setAcksToEPR(AddressingConstants.Final.WSA_NONE_URI);
+
+ // Create a Create Sequence message
+ // generating a new create sequeuce message.
+ RMMsgContext createSeqRMMessage = RMMsgCreator.createCreateSeqMsg(rmsBean, applicationRMMsg);
+ messageContext = createSeqRMMessage.getMessageContext();
+ messageContext.setWSAAction(SpecSpecificConstants.getCreateSequenceAction(Sandesha2Constants.SPEC_VERSIONS.v1_1));
+
+ CreateSequence createSeqResPart = (CreateSequence) createSeqRMMessage
+ .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+
+ createSeqResPart.setAcksTo(
+ new AcksTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI),
+ SpecSpecificConstants.getRMNamespaceValue(rmsBean.getRMVersion()),
+ AddressingConstants.Final.WSA_NAMESPACE));
+
+ // Update the SOAP Envelope of the message
+ createSeqRMMessage.addSOAPEnvelope();
+
+ SOAPEnvelope envelope = createSeqRMMessage.getMessageContext().getEnvelope();
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ envelope.serialize(outputStream);
+
+ return outputStream.toByteArray();
+ }
+}
+
+
+
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedInboundFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedInboundFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedInboundFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedInboundFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.File;
+
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SequenceReport;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class CreateSequenceRefusedInboundFaultTest extends SandeshaTestCase {
+
+ private static boolean startedServer = false;
+
+ public CreateSequenceRefusedInboundFaultTest() {
+ super("CreateSequenceRefusedInboundFaultTest");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+
+ if (!startedServer) {
+ startServer(repoPath, axis2_xml);
+ startedServer = true;
+ }
+ }
+
+ public void tearDown() {
+
+ }
+
+ /** Test removed for the moment as RM 1.0 faults are not processed by the chain.
+ * The GlobalInHandler needs to detect if the message is a fault and assign an appropriate
+ * operation.
+ * @throws Exception
+ */
+ public void testSOAP11CreateSequenceRefusedInboundFault () throws Exception {
+ runTest(false);
+ }
+
+ public void testSOAP12CreateSequenceRefusedInboundFault () throws Exception {
+ runTest(true);
+ }
+
+ private void runTest(boolean runSoap12) throws Exception{
+ String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+
+ Options clientOptions = new Options ();
+ clientOptions.setAction(echoAction);
+ clientOptions.setTo(new EndpointReference (to));
+
+ //setting the SOAP version as 1.2
+ if (runSoap12)
+ clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+
+ String sequenceKey = SandeshaUtil.getUUID();
+ clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ // Set a bad acks to so the CreateSequence will be refused.
+ String acksTo = AddressingConstants.Final.WSA_NONE_URI;
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ clientOptions.setUseSeparateListener(true);
+ clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+ serviceClient.setOptions(clientOptions);
+
+ TestCallback callback1 = new TestCallback ("Callback 1");
+ serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo1",sequenceKey),callback1);
+
+ long limit = System.currentTimeMillis() + waitTime;
+ Error lastError = null;
+ while(System.currentTimeMillis() < limit) {
+ Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+
+ try {
+ //assertions for the out sequence.
+ SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertEquals(sequenceReport.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+ assertEquals(sequenceReport.getSequenceDirection(),SequenceReport.SEQUENCE_DIRECTION_OUT);
+
+ assertTrue(callback1.isErrorRported());
+ assertEquals(callback1.getResult(),null);
+
+ lastError = null;
+ break;
+ } catch(Error e) {
+ lastError = e;
+ }
+ }
+
+ if(lastError != null) throw lastError;
+
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+
+ }
+
+}
+
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/FaultTestUtils.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/FaultTestUtils.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/FaultTestUtils.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/FaultTestUtils.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class FaultTestUtils {
+
+ /**
+ * Sets up a connection to an HTTP endpoint
+ * @return
+ */
+ public static HttpURLConnection getHttpURLConnection(String uri, String soapAction) throws Exception {
+ // Open a connection to the endpoint
+ URL endPointURL = new URL(uri);
+
+ HttpURLConnection connection = (HttpURLConnection) endPointURL.openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestMethod("POST");
+ connection.addRequestProperty("SOAPAction", soapAction);
+ connection.setRequestProperty("Content-Type", "text/xml");
+
+ connection.connect();
+
+ return connection;
+ }
+
+ /**
+ * Reads a response from the HttpURLConnection instance
+ * @param connection
+ * @return
+ * @throws IOException
+ */
+ public static final String retrieveResponseMessage(HttpURLConnection connection) throws IOException {
+
+ InputStream tmpIn2 = connection.getInputStream();
+
+ // Read the sync response
+ boolean done = false;
+
+ byte[] buffer = new byte[4096];
+ String message = null;
+ int saved = 0 ;
+ int len ;
+
+ a:
+ for (;;) {
+ if (done) {
+ break;
+ }
+
+ len = buffer.length;
+ // Used to be 1, but if we block it doesn't matter
+ // however 1 will break with some servers, including apache
+ if (len == 0) {
+ len = buffer.length;
+ }
+ if (saved + len > buffer.length) {
+ len = buffer.length - saved;
+ }
+ int len1 = 0;
+
+ while (len1 == 0) {
+ try {
+ len1 = tmpIn2.read(buffer, saved, len);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ if (done && saved == 0) {
+ break a;
+ }
+ len1 = -1;
+ break;
+ }
+ }
+ len = len1;
+
+ if (len == -1 && saved == 0) {
+ break;
+ }
+ if (len == -1) {
+ done = true;
+ }
+
+ // No matter how we may (or may not) format it, send it
+ // on unformatted - we don't want to mess with how its
+ // sent to the other side, just how its displayed
+
+ message = new String(buffer, 0, len);
+
+ System.out.println(message);
+ }
+
+ return message;
+ }
+}
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/InvalidAcknowledgementTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/InvalidAcknowledgementTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/InvalidAcknowledgementTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/InvalidAcknowledgementTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.Transaction;
+import org.apache.sandesha2.storage.beanmanagers.RMSBeanMgr;
+import org.apache.sandesha2.storage.beanmanagers.SenderBeanMgr;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.storage.beans.SenderBean;
+import org.apache.sandesha2.util.RangeString;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+
+
+public class InvalidAcknowledgementTest extends SandeshaTestCase {
+
+ private static final String server_repoPath = "target" + File.separator
+ + "repos" + File.separator + "server";
+
+ private static final String server_axis2_xml = "target" + File.separator
+ + "repos" + File.separator + "server" + File.separator
+ + "server_axis2.xml";
+
+ private ConfigurationContext serverConfigContext;
+
+ public InvalidAcknowledgementTest() {
+ super("InvalidAcknowledgementTest");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+ }
+
+ /**
+ * Sends an ACK message to an RM Source that will be refused and should be
+ * rejected with an InvalidAck fault
+ *
+ * We mock up a RMS sequence on the server, this is for us to then use for the fault.
+ *
+ * @throws Exception
+ */
+ public void testInvalidAcknowledgementSOAPFault() throws Exception {
+ // Create an RMS on the service.
+ StorageManager storageManager =
+ SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+
+ RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
+
+ String seqID = SandeshaUtil.getUUID();
+
+ // Mockup an RMSBean
+ RMSBean rmsBean = new RMSBean();
+ rmsBean.setCreateSeqMsgID(SandeshaUtil.getUUID());
+ rmsBean.setSequenceID(seqID);
+ rmsBean.setInternalSequenceID(SandeshaUtil.getInternalSequenceID(seqID, null));
+ rmsBean.setToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setAcksToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setReplyToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ rmsBean.setClientCompletedMessages(new RangeString());
+ rmsBean.setNextMessageNumber(1);
+
+ // Create a transaction and insert the RMSBean
+ Transaction tran = storageManager.getTransaction();
+
+ rmsBeanMgr.insert(rmsBean);
+
+ tran.commit();
+
+ // Open a connection to the endpoint, using the sequence ack as the action
+ HttpURLConnection connection =
+ FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+ "http://docs.oasis-open.org/ws-rx/wsrm/200702/SequenceAcknowledgement");
+
+ OutputStream tmpOut2 = connection.getOutputStream();
+ byte ar[] = getAppMessageAsBytes(seqID);
+
+ // Send the message to the socket.
+ tmpOut2.write(ar);
+ tmpOut2.flush();
+
+ // Get the response message from the connection
+ String message = FaultTestUtils.retrieveResponseMessage(connection);
+
+ // Check that the fault message isn't null
+ assertNotNull(message);
+
+ // Check that the response contains the InvalidAcknowledgement tag
+ assertTrue(message.indexOf("InvalidAcknowledgement") > -1);
+
+ // Check that the <wsrm:Identifier>seqID</wsrm:Identifier> matches the sequence ID specified
+ String faultID = message.substring(message.indexOf("<wsrm:Identifier>") + 17, message.indexOf("</wsrm:Identifier>"));
+ assertEquals(seqID, faultID);
+
+ // Disconnect at the end of the test
+ connection.disconnect();
+ }
+
+ /**
+ * Sends an ACK message to an RM Source that will be refused and should be
+ * rejected with an InvalidAck fault
+ *
+ * We mock up a RMS sequence on the server, this is for us to then use for the fault.
+ * Mock up a couple of SenderBeans which match the 1, 2, 3 message numbers
+ * Set the highest out message number to be 3
+ *
+ * Send an ack range in for 1 - 3, Indicate that message 1 has been sent, but no more.
+ *
+ * @throws Exception
+ */
+ public void testInvalidAcknowledgementFromBeanNotSentSOAPFault() throws Exception {
+
+ // Create an RMS on the service.
+ StorageManager storageManager =
+ SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+
+ RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
+ SenderBeanMgr senderMgr = storageManager.getSenderBeanMgr();
+
+ String seqID = SandeshaUtil.getUUID();
+
+ // Mockup an RMSBean
+ RMSBean rmsBean = new RMSBean();
+ rmsBean.setCreateSeqMsgID(SandeshaUtil.getUUID());
+ rmsBean.setSequenceID(seqID);
+ rmsBean.setInternalSequenceID(SandeshaUtil.getInternalSequenceID(seqID, null));
+ rmsBean.setToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setAcksToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setReplyToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmsBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ rmsBean.setClientCompletedMessages(new RangeString());
+ rmsBean.setNextMessageNumber(4);
+ rmsBean.setHighestOutMessageNumber(3);
+
+ SenderBean bean1 = getSenderBean(seqID, 1, 1);
+ SenderBean bean2 = getSenderBean(seqID, 0, 2);
+ SenderBean bean3 = getSenderBean(seqID, 1, 3);
+
+ // Create a transaction and insert the RMSBean
+ Transaction tran = storageManager.getTransaction();
+
+ rmsBeanMgr.insert(rmsBean);
+ senderMgr.insert(bean1);
+ senderMgr.insert(bean2);
+ senderMgr.insert(bean3);
+
+ tran.commit();
+
+ // Open a connection to the endpoint, using the sequence ack as the action
+ HttpURLConnection connection =
+ FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+ "http://docs.oasis-open.org/ws-rx/wsrm/200702/SequenceAcknowledgement");
+
+ OutputStream tmpOut2 = connection.getOutputStream();
+ byte ar[] = getAppMessageAsBytes(seqID);
+
+ // Send the message to the socket.
+ tmpOut2.write(ar);
+ tmpOut2.flush();
+
+ // Get the response message from the connection
+ String message = FaultTestUtils.retrieveResponseMessage(connection);
+
+ // Check that the fault message isn't null
+ assertNotNull(message);
+
+ // Check that the response contains the InvalidAcknowledgement tag
+ assertTrue(message.indexOf("wsrm:InvalidAcknowledgement") > -1);
+
+ // Check that the <wsrm:Identifier>seqID</wsrm:Identifier> matches the sequence ID specified
+ String faultID = message.substring(message.indexOf("<wsrm:Identifier>") + 17, message.indexOf("</wsrm:Identifier>"));
+ assertEquals(seqID, faultID);
+
+ // Disconnect at the end of the test
+ connection.disconnect();
+ }
+
+ /**
+ * Get a SequenceAck message as bytes
+ *
+ * @return
+ */
+ private byte[] getAppMessageAsBytes(String sequenceId) throws Exception
+ {
+ SOAPFactory factory = new SOAP11Factory();
+ SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+
+ // Create a "new" application message
+ MessageContext messageContext = new MessageContext();
+ messageContext.setConfigurationContext(serverConfigContext);
+ messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));
+ messageContext.setEnvelope(dummyEnvelope);
+
+ RMMsgContext applicationRMMsg = new RMMsgContext(messageContext);
+
+ // Generate the SequenceAck field.
+ // -------------------------------
+ String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+ SequenceAcknowledgement sequenceAck = new SequenceAcknowledgement(rmNamespaceValue);
+ // Set the sequenceId
+ Identifier id = new Identifier(rmNamespaceValue);
+ id.setIndentifer(sequenceId);
+ sequenceAck.setIdentifier(id);
+
+ // Set the Invalid range!
+ AcknowledgementRange ackRange = new AcknowledgementRange(rmNamespaceValue);
+ ackRange.setLowerValue(1);
+ ackRange.setUpperValue(3);
+ sequenceAck.addAcknowledgementRanges(ackRange);
+
+ // Set the SequenceAcknowledgement part in the message
+ applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT, sequenceAck);
+ applicationRMMsg.addSOAPEnvelope();
+
+ // --------------------------------------------
+ // Finished generating SequenceAck part
+
+ // Create an RMSBean so the create sequence message can be created
+ messageContext.setWSAAction("http://docs.oasis-open.org/ws-rx/wsrm/200702/SequenceAcknowledgement");
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ // Serialize the application message
+ applicationRMMsg.getMessageContext().getEnvelope().serialize(outputStream);
+
+ return outputStream.toByteArray();
+ }
+
+ private static SenderBean getSenderBean(String seqID, int sendCount, int messageNo) {
+ SenderBean bean = new SenderBean();
+ bean.setInternalSequenceID(SandeshaUtil.getInternalSequenceID(seqID, null));
+ bean.setSequenceID(seqID);
+ bean.setMessageID(SandeshaUtil.getUUID());
+ bean.setSentCount(sendCount);
+ bean.setSend(true);
+ bean.setReSend(true);
+ bean.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
+ bean.setMessageNumber(messageNo);
+
+ return bean;
+ }
+}
+
+
+
Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.msgreceivers.RMMessageReceiver;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.Transaction;
+import org.apache.sandesha2.storage.beanmanagers.RMDBeanMgr;
+import org.apache.sandesha2.storage.beans.RMDBean;
+import org.apache.sandesha2.util.Range;
+import org.apache.sandesha2.util.RangeString;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.MessageNumber;
+import org.apache.sandesha2.wsrm.Sequence;
+
+
+public class MessageNumberRolloverFaultTest extends SandeshaTestCase {
+
+ private static final String server_repoPath = "target" + File.separator
+ + "repos" + File.separator + "server";
+
+ private static final String server_axis2_xml = "target" + File.separator
+ + "repos" + File.separator + "server" + File.separator
+ + "server_axis2.xml";
+
+ private ConfigurationContext serverConfigContext;
+
+ public MessageNumberRolloverFaultTest() {
+ super("MessageNumberRolloverFaultTest");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+ }
+
+ /**
+ * Sends an application message to the RMD.
+ * The RMD should reject the message with a MessageRolloverFault
+ *
+ * @throws Exception
+ */
+ public void testMessageNumberRolloverFault() throws Exception {
+ // Open a connection to the endpoint
+ HttpURLConnection connection =
+ FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+ pingAction);
+
+ StorageManager storageManager =
+ SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+
+ RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
+
+ String seqID = SandeshaUtil.getUUID();
+
+ // Mockup an RMSBean
+ RMDBean rmdBean = new RMDBean();
+ rmdBean.setSequenceID(seqID);
+ rmdBean.setToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmdBean.setAcksToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmdBean.setReplyToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+ rmdBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ rmdBean.setServerCompletedMessages(new RangeString());
+ rmdBean.getServerCompletedMessages().addRange(new Range(1, Long.MAX_VALUE -1));
+ rmdBean.getServerCompletedMessages().addRange(new Range(Long.MAX_VALUE, Long.MAX_VALUE));
+
+ // Create a transaction and insert the RMSBean
+ Transaction tran = storageManager.getTransaction();
+
+ rmdBeanMgr.insert(rmdBean);
+
+ tran.commit();
+
+
+ OutputStream tmpOut2 = connection.getOutputStream();
+
+ byte ar[] = getAppMessageAsBytes(seqID);
+
+ // Send the message to the socket.
+ tmpOut2.write(ar);
+ tmpOut2.flush();
+
+ // Get the response message from the connection
+ String message = FaultTestUtils.retrieveResponseMessage(connection);
+
+ // Check that the fault message isn't null
+ assertNotNull(message);
+
+ // Check that the response contains the MessageNumberRollover tag
+ assertTrue(message.indexOf("wsrm:MessageNumberRollover") > -1);
+
+ // Disconnect at the end of the test
+ connection.disconnect();
+ }
+
+ /**
+ * Get an application message as bytes
+ *
+ * This sets the message number to "Long.maxValue"
+ *
+ * @return
+ */
+ private byte[] getAppMessageAsBytes(String uuid) throws Exception
+ {
+ SOAPFactory factory = new SOAP11Factory();
+ SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+
+ // Create a "new" application message
+ MessageContext messageContext = new MessageContext();
+ messageContext.setConfigurationContext(serverConfigContext);
+ messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));
+ messageContext.setEnvelope(dummyEnvelope);
+
+ RMMsgContext applicationRMMsg = new RMMsgContext(messageContext);
+
+ // Generate the Sequence field.
+ // -------------------------------
+ String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+ Sequence sequence = new Sequence(rmNamespaceValue);
+ MessageNumber msgNumber = new MessageNumber(rmNamespaceValue);
+ msgNumber.setMessageNumber(Long.MAX_VALUE);
+ sequence.setMessageNumber(msgNumber);
+ Identifier id1 = new Identifier(rmNamespaceValue);
+ id1.setIndentifer(uuid);
+ sequence.setIdentifier(id1);
+ applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE, sequence);
+ applicationRMMsg.addSOAPEnvelope();
+
+ // --------------------------------------------
+ // Finished generating Sequence part
+
+ // Create an RMSBean so the create sequence message can be created
+ messageContext.setWSAAction(pingAction);
+
+ // Set the AxisOperation to be InOut
+ AxisOperation operation = messageContext.getAxisService().getOperation(Sandesha2Constants.RM_IN_OUT_OPERATION);
+ operation.setMessageReceiver(new RMMessageReceiver());
+ messageContext.setAxisOperation(operation);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ // Serialize the application message
+ applicationRMMsg.getMessageContext().getEnvelope().serialize(outputStream);
+
+ return outputStream.toByteArray();
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org