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 [16/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/faulttests/SequenceClosedFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceClosedFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceClosedFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceClosedFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,182 @@
+/*
+ * 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.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 SequenceClosedFaultTest 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 SequenceClosedFaultTest() {
+		super("SequenceClosedFaultTest");
+	}
+
+	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 sequence closed fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testSequenceClosedFault() 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 RMDBean
+		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());
+		// Flag that the sequence is closed.
+		rmdBean.setClosed(true);
+		
+		// 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:SequenceClosed") > -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 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(1);
+		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();
+	}
+}
+

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTerminatedFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTerminatedFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTerminatedFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTerminatedFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,549 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.axiom.soap.SOAP12Constants;
+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.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+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.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SequenceReport;
+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.RangeString;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.AckRequested;
+import org.apache.sandesha2.wsrm.CloseSequence;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.MessageNumber;
+import org.apache.sandesha2.wsrm.Sequence;
+
+
+public class SequenceTerminatedFaultTest 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;
+	
+	private static boolean serverStarted = false;
+	
+	public SequenceTerminatedFaultTest() {
+		super("SequenceTerminatedFaultTest");
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+		if (!serverStarted) {
+			serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+		}
+		serverStarted = true;
+	}
+
+	public void tearDown () {
+	}
+
+	/**
+	 * Sends an application message to the RMD.
+	 * The RMD should reject the message with a sequence terminated fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testSequenceTerminatedFault() 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 RMDBean
+		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());
+		// Flag that the sequence is terminated.
+		rmdBean.setTerminated(true);
+		
+		// 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 Sequence Terminated tag    
+    assertTrue(message.indexOf("wsrm:SequenceTerminated") > -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 a Close message to the RMD.
+	 * The RMD should reject the message with a sequence terminated fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testSequenceTerminatedOnCloseFault() throws Exception {
+    // Open a connection to the endpoint
+		HttpURLConnection connection = 
+			FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+					Sandesha2Constants.SPEC_2007_02.Actions.ACTION_CLOSE_SEQUENCE);
+
+		StorageManager storageManager = 
+			SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+		
+		RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
+		
+		String seqID = SandeshaUtil.getUUID();
+		
+		// Mockup an RMDBean
+		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());
+		// Flag that the sequence is terminated.
+		rmdBean.setTerminated(true);
+		
+		// Create a transaction and insert the RMSBean
+		Transaction tran = storageManager.getTransaction();
+		
+		rmdBeanMgr.insert(rmdBean);
+		
+		tran.commit();
+
+		
+		OutputStream tmpOut2 = connection.getOutputStream();
+
+		byte ar[] = getCloseMessageAsBytes(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 Sequence Terminated tag    
+    assertTrue(message.indexOf("wsrm:SequenceTerminated") > -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 a AckRequest message to the RMD.
+	 * The RMD should reject the message with a sequence terminated fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testSequenceTerminatedOnAckRequestFault() throws Exception {
+    // Open a connection to the endpoint
+		HttpURLConnection connection = 
+			FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+					Sandesha2Constants.SPEC_2007_02.Actions.ACTION_ACK_REQUEST);
+
+		StorageManager storageManager = 
+			SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+		
+		RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
+		
+		String seqID = SandeshaUtil.getUUID();
+		
+		// Mockup an RMDBean
+		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());
+		// Flag that the sequence is terminated.
+		rmdBean.setTerminated(true);
+		
+		// Create a transaction and insert the RMSBean
+		Transaction tran = storageManager.getTransaction();
+		
+		rmdBeanMgr.insert(rmdBean);
+		
+		tran.commit();
+
+		
+		OutputStream tmpOut2 = connection.getOutputStream();
+
+		byte ar[] = getAckRequestMessageAsBytes(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 Sequence Terminated tag    
+    assertTrue(message.indexOf("wsrm:SequenceTerminated") > -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();
+	}
+
+	/**
+	 * When sending application messages, if the RMD sequence returns a sequence terminated
+	 * fault, then the RMS Sequence should be terminated	 
+	 */
+	public void testRMSSequenceTerminatedOnSequenceTerminatedFault() throws Exception {
+		runSequenceTerminated(false, false);
+	}
+
+	/**
+	 * When sending application messages, if the RMD sequence returns a sequence terminated
+	 * fault, then the RMS Sequence should be terminated.
+	 * 
+	 * Runs at SOAP12 level	 
+	 */
+	public void testRMSSequenceTerminatedOnSequenceTerminatedFaultSOAP12() throws Exception {
+		runSequenceTerminated(false, true);
+	}
+
+	/**
+	 * When sending application messages, if the RMD sequence returns a sequence terminated
+	 * fault, then the RMS Sequence should be terminated	 
+	 */
+	public void testRMSSequenceTerminatedOnSequenceUnknownFault() throws Exception {		
+		runSequenceTerminated(true, false);
+	}
+
+	/**
+	 * When sending application messages, if the RMD sequence returns a sequence terminated
+	 * fault, then the RMS Sequence should be terminated	 
+	 * 
+	 * Runs at SOAP12 level	 
+	 */
+	public void testRMSSequenceTerminatedOnSequenceUnknownFaultSOAP12() throws Exception {	
+		runSequenceTerminated(true, true);
+	}
+
+	private void runSequenceTerminated(boolean deleteRMSBean, boolean soap12) 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.setTo(new EndpointReference (to));
+
+		String sequenceKey = SandeshaUtil.getUUID();
+		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,Sandesha2Constants.SPEC_VERSIONS.v1_1);
+		
+		if (soap12)
+			clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+		
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+		serviceClient.setOptions(clientOptions);
+
+    // Send a single ping message
+		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
+			
+			// Check that the sequence has been deleted.
+			StorageManager storageManager = 
+				SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+			
+			Transaction tran = storageManager.getTransaction();
+			
+			RMDBean finderBean = new RMDBean();
+			finderBean.setTerminated(false);
+			List rmdBeans = storageManager.getRMDBeanMgr().find(finderBean);
+			
+			tran.commit();
+			
+			lastError = null;
+			
+			if (rmdBeans.isEmpty())
+				lastError = new Error("rmdBeans empty " + rmdBeans);
+			else {
+				RMDBean bean = (RMDBean)rmdBeans.get(0);
+				if (!bean.getServerCompletedMessages().getContainedElementsAsNumbersList().contains(new Integer(1))) {
+					tran = storageManager.getTransaction();
+					if (deleteRMSBean) {
+						storageManager.getRMDBeanMgr().delete(bean.getSequenceID());
+					} else {
+						bean.setTerminated(true);
+						storageManager.getRMDBeanMgr().update(bean);
+					}
+					tran.commit();
+					break;				
+				}
+				
+				lastError = new Error("App message has not arrived");
+			}
+		}
+
+		if(lastError != null) throw lastError;
+
+		// Send a second application message.
+		serviceClient.fireAndForget(getPingOMBlock("ping2"));
+		
+		while(System.currentTimeMillis() < limit) {
+			Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+			
+			try {
+        //Check that the outgoing sequence is terminated
+				SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+				assertEquals(sequenceReport.getSequenceStatus(),SequenceReport.SEQUENCE_STATUS_TERMINATED);
+				assertEquals(sequenceReport.getSequenceDirection(),SequenceReport.SEQUENCE_DIRECTION_OUT);
+				
+				lastError = null;
+				break;
+			} catch(Error e) {
+				lastError = e;
+			}
+		}
+
+		if(lastError != null) throw lastError;
+		
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+
+	}
+	
+	/**
+	 * Get an application message as bytes
+	 * 
+	 * @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(1);
+		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();
+	}
+	
+	/**
+	 * Get a close message as bytes
+	 * 
+	 * @return
+	 */
+	private byte[] getCloseMessageAsBytes(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 Close field.
+		// -------------------------------
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+		CloseSequence sequence = new CloseSequence(rmNamespaceValue);
+		Identifier id1 = new Identifier(rmNamespaceValue);
+		id1.setIndentifer(uuid);
+		sequence.setIdentifier(id1);
+		applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE, sequence);
+		applicationRMMsg.addSOAPEnvelope();
+
+		// --------------------------------------------
+		// Finished generating Close 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();
+	}
+
+	/**
+	 * Get a close message as bytes
+	 * 
+	 * @return
+	 */
+	private byte[] getAckRequestMessageAsBytes(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 Close field.
+		// -------------------------------
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+		AckRequested sequence = new AckRequested(rmNamespaceValue);
+		Identifier id1 = new Identifier(rmNamespaceValue);
+		id1.setIndentifer(uuid);
+		sequence.setIdentifier(id1);
+		applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE, sequence);
+		applicationRMMsg.addSOAPEnvelope();
+
+		// --------------------------------------------
+		// Finished generating Close 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();
+	}
+
+}
+
+

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTimedOutTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTimedOutTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTimedOutTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/SequenceTimedOutTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,372 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+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.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+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.policy.SandeshaPolicyBean;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.Transaction;
+import org.apache.sandesha2.storage.beans.RMDBean;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class SequenceTimedOutTest extends SandeshaTestCase {
+	
+	public SequenceTimedOutTest() {
+		super("SequenceTimedOutTest");
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+	}
+	
+	public void tearDown() {
+		
+	}
+	
+	/**
+	 * Test to check that when a sequence times out - that we alert the client to the
+	 * fact that the sequence has now gone.
+	 * 
+	 * @throws Exception
+	 */
+	public void testSOAP11CreateSequenceRefusedInboundFault () throws Exception {
+		
+		String to = "http://127.0.0.1:" + 9999 + "/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);
+		
+
+		HashMap axisServices = configContext.getAxisConfiguration().getServices();
+		
+		AxisService service = null;
+		Iterator values = axisServices.values().iterator();
+		while(values.hasNext())
+			service = (AxisService)values.next();
+
+		// Set the Sequence timout property to 1 second.
+    Iterator operations = service.getOperations();
+    
+    while (operations.hasNext())
+    {
+    	AxisOperation op = (AxisOperation) operations.next();
+  		SandeshaPolicyBean propertyBean = 
+  			SandeshaUtil.getPropertyBean(op);
+
+  		// Indicate that the sequence should timeout after 1 second
+  		if (propertyBean != null)
+  			propertyBean.setInactiveTimeoutInterval(1, "seconds");
+    }
+		
+		// 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_TIMED_OUT);
+				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();
+
+	}
+	
+	/**
+	 * Test to check that when a sequence times out - it gets deleted after the timeout interval.
+	 * 
+	 * @throws Exception
+	 */
+	public void testRMSSequenceTimeoutSequenceDeleted () throws Exception {
+		
+		String to = "http://127.0.0.1:" + 9999 + "/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);		
+
+		HashMap axisServices = configContext.getAxisConfiguration().getServices();
+		
+		AxisService service = null;
+		Iterator values = axisServices.values().iterator();
+		while(values.hasNext())
+			service = (AxisService)values.next();
+
+		// Set the Sequence timout property to 1 second.
+    Iterator operations = service.getOperations();
+    
+    while (operations.hasNext())
+    {
+    	AxisOperation op = (AxisOperation) operations.next();
+  		SandeshaPolicyBean propertyBean = 
+  			SandeshaUtil.getPropertyBean(op);
+
+  		// Indicate that the sequence should timeout after 1 second
+  		// And that it should be deleted after 2 seconds
+  		if (propertyBean != null) {
+  			propertyBean.setInactiveTimeoutInterval(1, "seconds");
+  			propertyBean.setSequenceRemovalTimeoutInterval(2, "seconds");
+  		}
+    }
+		
+		// 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_TIMED_OUT);
+				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;
+
+		while(System.currentTimeMillis() < limit) {
+			Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+			
+			// Check that the sequence has been deleted.
+			StorageManager storageManager = 
+				SandeshaUtil.getSandeshaStorageManager(configContext, configContext.getAxisConfiguration());
+			
+			Transaction tran = storageManager.getTransaction();
+			
+			RMSBean finderBean = new RMSBean();
+			List rmsBeans = storageManager.getRMSBeanMgr().find(finderBean);
+			
+			tran.commit();
+			
+			lastError = null;
+			
+			if (!rmsBeans.isEmpty())
+				lastError = new Error("rmsBeans not empty " + rmsBeans);
+			else
+				break;
+			
+		}
+
+		if(lastError != null) throw lastError;
+		
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+
+	}
+	
+	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";
+
+	/**
+	 * Checks that an RMDSequence is terminated once the timeout interval arrives.
+	 * Also that the RMDBean is deleted once the SequenceRemovalTimeout arrives.
+	 */
+	public void testRMDSequenceTerminatedDeleted() throws Exception{ 
+		ConfigurationContext serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+		
+		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.setTo(new EndpointReference (to));
+
+		String sequenceKey = SandeshaUtil.getUUID();
+		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+		serviceClient.setOptions(clientOptions);
+
+		HashMap axisServices = serverConfigContext.getAxisConfiguration().getServices();
+		
+		AxisService service = null;
+		Iterator values = axisServices.values().iterator();
+		while(values.hasNext())
+			service = (AxisService)values.next();
+
+		// Set the Sequence timout property to 1 second.
+    Iterator operations = service.getOperations();
+    
+    while (operations.hasNext())
+    {
+    	AxisOperation op = (AxisOperation) operations.next();
+  		SandeshaPolicyBean propertyBean = 
+  			SandeshaUtil.getPropertyBean(op);
+
+  		// Indicate that the sequence should timeout after 2 second
+  		// And that it should be deleted after 2 seconds
+  		if (propertyBean != null) {
+  			propertyBean.setInactiveTimeoutInterval(2, "seconds");
+  			propertyBean.setSequenceRemovalTimeoutInterval(2, "seconds");
+  		}
+    }
+    
+    // Send a single ping message
+		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
+			
+			// Check that the sequence has been deleted.
+			StorageManager storageManager = 
+				SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+			
+			Transaction tran = storageManager.getTransaction();
+			
+			RMDBean finderBean = new RMDBean();
+			List rmdBeans = storageManager.getRMDBeanMgr().find(finderBean);
+			
+			tran.commit();
+			
+			lastError = null;
+			
+			if (rmdBeans.isEmpty())
+				lastError = new Error("rmdBeans empty " + rmdBeans);
+			else {
+				RMDBean bean = (RMDBean)rmdBeans.get(0);
+				if (bean.isTerminated())
+					break;
+				
+				lastError = new Error("RMDBean not deleted " + bean);
+			}
+		}
+
+		if(lastError != null) throw lastError;
+
+		while(System.currentTimeMillis() < limit) {
+			Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
+			
+			// Check that the sequence has been deleted.
+			StorageManager storageManager = 
+				SandeshaUtil.getSandeshaStorageManager(serverConfigContext, serverConfigContext.getAxisConfiguration());
+			
+			Transaction tran = storageManager.getTransaction();
+			
+			RMDBean finderBean = new RMDBean();
+			List rmdBeans = storageManager.getRMDBeanMgr().find(finderBean);
+			
+			tran.commit();
+			
+			lastError = null;
+			
+			if (!rmdBeans.isEmpty())
+				lastError = new Error("rmdBeans not empty " + rmdBeans);
+			else
+				break;
+		}
+
+		if(lastError != null) throw lastError;
+		
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+
+	}
+	
+}
+
+

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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 UnknownSequenceFaultTest 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 UnknownSequenceFaultTest() {
+		super("UnknownSequenceFaultTest");
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+		serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+	}
+
+	/**
+	 * Sends an Application message to an RM Destination that will be refused and should be
+	 * rejected with an unknown sequence fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testUnknownSequenceAppMsgSOAPFault() throws Exception {
+    // Open a connection to the endpoint
+		HttpURLConnection connection = 
+			FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+					pingAction);
+
+		OutputStream tmpOut2 = connection.getOutputStream();
+		String seqID = SandeshaUtil.getUUID();
+		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 wsrm:CreateSequenceRefused tag    
+    assertTrue(message.indexOf("wsrm:UnknownSequence") > -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 Create Sequence message as bytes
+	 * 
+	 * This generates an "application" message that has a "sequecnce id" that the RMD
+	 * will not recognise and should generate a fault.
+	 * 
+	 * @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(1);
+		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();
+	}
+}
+
+

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/mtom/MTOMRMTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/mtom/MTOMRMTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/mtom/MTOMRMTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/mtom/MTOMRMTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,238 @@
+/*
+ * 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.mtom;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.xml.namespace.QName;
+
+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.OMText;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
+import org.apache.axis2.transport.http.SimpleHTTPServer;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.SandeshaTestCase;
+
+public class MTOMRMTest extends SandeshaTestCase {
+
+	SimpleHTTPServer httpServer = null;
+
+	private final String applicationNamespaceName = "http://tempuri.org/";
+
+	private final String MTOMping = "MTOMping";
+
+	private final String Attachment = "Attachment";
+
+	private final String SOURCE_IMAGE_FILE = "test-resources/mtom-image.jpg";
+
+	private final String DESTINATION_IMAGE_FILE = "target/mtom-image1.jpg";
+
+	private final String PING_OPERATION_NAME = "ping";
+
+	private Log log = LogFactory.getLog(getClass());
+
+	int serverPort = DEFAULT_SERVER_TEST_PORT;
+
+	long sourceLength;
+
+	public MTOMRMTest() {
+		super("MTOMRMTest");
+	}
+
+	public void setUp() throws AxisFault {
+		String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+		String axis2_xml = "test-resources" + File.separator + "server_mtom_axis2.xml";
+		ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+				repoPath, axis2_xml);
+
+		AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
+		AxisService axisService = axisConfiguration.getService("RMSampleService");
+		AxisOperation operation = AxisOperationFactory.getAxisOperation(WSDLConstants.MEP_CONSTANT_IN_ONLY);
+		operation.setMessageReceiver(new MTOMTestMessageReceiver());
+		operation.setName(new QName(MTOMping));
+		axisService.addOperation(operation);
+
+		AxisOperation pingOperation = axisService.getOperation(new QName(PING_OPERATION_NAME));
+		if (pingOperation == null)
+			throw new AxisFault("Cant find the ping operation");
+
+		// setting the operation specific phase chain
+		operation.setRemainingPhasesInFlow(pingOperation.getRemainingPhasesInFlow());
+
+		String serverPortStr = getTestProperty("test.server.port");
+		if (serverPortStr != null) {
+			try {
+				serverPort = Integer.parseInt(serverPortStr);
+			} catch (NumberFormatException e) {
+				log.error(e);
+			}
+		}
+
+		httpServer = new SimpleHTTPServer(configContext, serverPort);
+		httpServer.start();
+		try {
+			Thread.sleep(300);
+		} catch (InterruptedException e) {
+			throw new SandeshaException("sleep interupted");
+		}
+	}
+
+	public void tearDown() throws SandeshaException {
+		if (httpServer != null)
+			httpServer.stop();
+
+		try {
+			Thread.sleep(300);
+		} catch (InterruptedException e) {
+			throw new SandeshaException("sleep interupted");
+		}
+	}
+
+	public void testMTOMPing() throws AxisFault, InterruptedException {
+
+//		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 = "test-resources" + File.separator + "client_mtom_axis2.xml";
+//
+//		ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+//				repoPath, axis2_xml);
+//		Options clientOptions = new Options();
+//		clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+//		clientOptions.setTo(new EndpointReference(to));
+//		clientOptions.setProperty(MessageContextConstants.TRANSPORT_URL, transportTo);
+//		String sequenceKey = "sequence1";
+//		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey);
+//		ServiceClient serviceClient = new ServiceClient(configContext, null);
+//		clientOptions.setAction("http://testAction");
+//		serviceClient.setOptions(clientOptions);
+//
+//		clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+//		serviceClient.fireAndForget(getMTOMPingOMBlock());
+//
+//		Thread.sleep(10000);
+//
+//		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);
+//
+//
+//		configContext.getListenerManager().stop();
+//		serviceClient.cleanup();
+		
+	}
+
+	private OMElement getMTOMPingOMBlock() throws AxisFault {
+		OMFactory fac = OMAbstractFactory.getOMFactory();
+		OMNamespace namespace = fac.createOMNamespace(applicationNamespaceName, "ns1");
+		OMElement pingElem = fac.createOMElement(MTOMping, namespace);
+
+		OMElement attachElem = fac.createOMElement(Attachment, namespace);
+
+		File file = new File(SOURCE_IMAGE_FILE);
+		assertTrue(file.exists());
+
+		sourceLength = file.length();
+
+		DataSource dataSource = new FileDataSource(file);
+		assertNotNull(dataSource);
+		DataHandler dataHandler = new DataHandler(dataSource);
+
+		OMText textData = fac.createOMText(dataHandler, true);
+		attachElem.addChild(textData);
+		pingElem.addChild(attachElem);
+
+		return pingElem;
+	}
+
+	private class MTOMTestMessageReceiver extends RawXMLINOnlyMessageReceiver {
+
+		public void invokeBusinessLogic(MessageContext msgContext) throws AxisFault {
+			try {
+				doInvocation(msgContext);
+			} catch (Exception e) {
+				fail(e.getMessage());
+			}
+		}
+
+	}
+
+	private void doInvocation(MessageContext mc) throws AxisFault {
+		SOAPEnvelope envelope = mc.getEnvelope();
+
+		assertNotNull(envelope);
+
+		SOAPBody body = envelope.getBody();
+
+		OMElement payload = body.getFirstElement();
+		OMElement attachmentElem = payload.getFirstChildWithName(new QName(applicationNamespaceName, Attachment));
+		if (attachmentElem == null)
+			throw new AxisFault("'Attachment' element is not present as a child of the 'Ping' element");
+
+		OMText binaryElem = (OMText) attachmentElem.getFirstOMChild();
+
+		binaryElem.setOptimize(true);
+		DataHandler dataHandler = (DataHandler) binaryElem.getDataHandler();
+
+		try {
+			File destinationFile = new File(DESTINATION_IMAGE_FILE);
+			if (destinationFile.exists())
+				destinationFile.delete();
+
+			FileOutputStream fileOutputStream = new FileOutputStream(DESTINATION_IMAGE_FILE);
+
+			InputStream inputStream = dataHandler.getDataSource().getInputStream();
+			byte[] bytes = new byte[5000];
+			int length = inputStream.read(bytes);
+			fileOutputStream.write(bytes, 0, length);
+			fileOutputStream.close();
+
+			destinationFile = new File(DESTINATION_IMAGE_FILE);
+			assertTrue(destinationFile.exists());
+			long destLength = destinationFile.length();
+			assertEquals(sourceLength, destLength);
+
+			destinationFile.delete();
+
+		} catch (Exception e) {
+			throw AxisFault.makeFault(e);
+		}
+	}
+
+}

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/OptionalReliabilityTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/OptionalReliabilityTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/OptionalReliabilityTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/OptionalReliabilityTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.scenarios;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.axiom.om.OMElement;
+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.SandeshaTestCase;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SequenceReport;
+
+public class OptionalReliabilityTest extends SandeshaTestCase {
+
+	public OptionalReliabilityTest() {
+		super ("OptionalReliabilityTest");
+	}
+	
+	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 testPing () 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);
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+		Options clientOptions = new Options ();
+		clientOptions.setAction(pingAction);
+		clientOptions.setTo(new EndpointReference (to));
+		clientOptions.setProperty(SandeshaClientConstants.UNRELIABLE_MESSAGE, "true");
+		serviceClient.setOptions(clientOptions);
+		
+		serviceClient.fireAndForget(getPingOMBlock("echo1"));
+		
+		//assertions for the out sequence.
+		SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+		assertTrue(sequenceReport.getCompletedMessages().isEmpty());
+		
+		//assertions for the in sequence
+		List inboundReports = SandeshaClient.getIncomingSequenceReports(configContext);
+		assertTrue(inboundReports.isEmpty());
+		
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+	}
+
+	public void testSyncEcho () throws AxisFault {
+		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);
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+		Options clientOptions = new Options ();
+		clientOptions.setAction(echoAction);
+		clientOptions.setTo(new EndpointReference (to));
+		clientOptions.setProperty(SandeshaClientConstants.UNRELIABLE_MESSAGE,"true");
+		serviceClient.setOptions(clientOptions);
+		
+		OMElement result = serviceClient.sendReceive(getEchoOMBlock("echo1", "sync"));
+		
+		// Check the response
+		String echoStr = checkEchoOMBlock(result);
+		assertEquals(echoStr, "echo1");
+		
+		//assertions for the out sequence.
+		SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+		assertTrue(sequenceReport.getCompletedMessages().isEmpty());
+		
+		//assertions for the in sequence
+		List inboundReports = SandeshaClient.getIncomingSequenceReports(configContext);
+		assertTrue(inboundReports.isEmpty());
+		
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+	}
+
+	public void testAsyncEcho () 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);
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+		Options clientOptions = new Options ();
+		clientOptions.setAction(echoAction);
+		clientOptions.setTo(new EndpointReference (to));
+		clientOptions.setProperty(SandeshaClientConstants.UNRELIABLE_MESSAGE,"true");
+		clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+		clientOptions.setUseSeparateListener(true);
+		serviceClient.setOptions(clientOptions);
+		
+		TestCallback callback1 = new TestCallback ("Callback 1");
+		serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo1", "async"),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().isEmpty());
+				
+				assertTrue(callback1.isComplete());
+				assertEquals(callback1.getResult(),"echo1");
+				
+				//assertions for the in sequence
+				List inboundReports = SandeshaClient.getIncomingSequenceReports(configContext);
+				assertTrue(inboundReports.isEmpty());
+				
+				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/scenarios/RMScenariosTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/RMScenariosTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/RMScenariosTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/RMScenariosTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,296 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * 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.scenarios;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import junit.framework.AssertionFailedError;
+
+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.Sandesha2Constants;
+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;
+import org.apache.sandesha2.versions.RMVersionTest;
+
+public class RMScenariosTest extends SandeshaTestCase {
+
+	private static boolean serverStarted = false; 
+	private static ConfigurationContext configContext = null;
+
+	protected String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+	
+	protected String repoPath = "target" + File.separator + "repos" + File.separator + "server";
+	protected String axis2_xml = "target" + File.separator + "repos" + File.separator + "server" + File.separator + "server_axis2.xml";
+
+	protected String repoPathClient = "target" + File.separator + "repos" + File.separator + "client";
+	protected String axis2_xmlClient = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+	
+	public RMScenariosTest () {
+		super ("RMScenariosTest");
+	}
+	
+	public RMScenariosTest (String name) {
+		super(name);
+	}
+
+	public void setUp () throws Exception {
+		super.setUp();
+
+		if (!serverStarted) {
+			startServer(repoPath, axis2_xml);
+			configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPathClient,axis2_xmlClient);
+		}
+		serverStarted = true;
+	}
+	
+	/**
+	 * Override the teardown processing
+	 */
+	public void tearDown () {
+	
+	}
+
+	public void testPing() throws Exception  {
+		// Run a ping test with sync acks
+		runPing(false);
+		
+		// Run a ping test with async acks
+		runPing(true);
+	}
+
+	public void testAsyncEcho() throws Exception {
+		// Test async echo with sync acks
+		Options clientOptions = new Options();
+		runEcho(clientOptions, true, false, false,true);
+		
+		// Test async echo with async acks
+		clientOptions = new Options();
+		runEcho(clientOptions, true, true, false,true);
+		
+		// Test async echo with async acks and offer
+		clientOptions = new Options();
+		clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,SandeshaUtil.getUUID());
+		runEcho(clientOptions, true, true, false,true);
+	}
+		
+	public void testSyncEcho() throws Exception {
+		// Test sync echo with an offer, and the 1.1 spec
+		Options clientOptions = new Options();
+		clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,SandeshaUtil.getUUID());
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,Sandesha2Constants.SPEC_VERSIONS.v1_1);
+		runEcho(clientOptions, false, false, true,true);
+		
+//		// Test sync echo with an offer, and the 1.0 spec. In this case the offer is automatic
+		clientOptions = new Options();
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,Sandesha2Constants.SPEC_VERSIONS.v1_0);
+		runEcho(clientOptions, false, false, true,false);
+//		
+//		// Test sync echo with no offer, and the 1.1 spec
+		clientOptions = new Options();
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,Sandesha2Constants.SPEC_VERSIONS.v1_1);
+		runEcho(clientOptions, false, false, true,true);
+	}
+
+	public void runPing(boolean asyncAcks) throws Exception {
+		
+		Options clientOptions = new Options();
+
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+		serviceClient.setOptions(clientOptions);
+
+		String sequenceKey = SandeshaUtil.getUUID();
+
+		clientOptions.setAction(pingAction);
+		clientOptions.setTo(new EndpointReference (to));
+		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+		
+		if(asyncAcks) {
+			String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+			clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+			clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+			clientOptions.setUseSeparateListener(true);
+		}
+
+		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);
+				System.out.println("Checking Outbound Sequence: " + sequenceReport.getSequenceID());
+				assertTrue("Checking completed messages", sequenceReport.getCompletedMessages().contains(new Long(1)));
+				assertEquals("Checking sequence terminated", SequenceReport.SEQUENCE_STATUS_TERMINATED, sequenceReport.getSequenceStatus());
+				assertEquals("Checking sequence direction", SequenceReport.SEQUENCE_DIRECTION_OUT, sequenceReport.getSequenceDirection());
+
+				lastError = null;
+				break;
+			} catch(Error e) {
+				System.out.println("Possible error:" + e);
+				lastError = e;
+			}
+		}
+
+		if(lastError != null) throw lastError;
+
+		serviceClient.cleanup();
+	}
+
+	public void runEcho(Options clientOptions, boolean asyncReply, boolean asyncAcks, boolean explicitTermination, boolean checkInboundTermination) throws Exception {
+		
+		String sequenceKey = SandeshaUtil.getUUID();
+
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+		serviceClient.setOptions(clientOptions);
+
+		clientOptions.setAction(echoAction);
+		clientOptions.setTo(new EndpointReference (to));
+		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+		if(asyncReply || asyncAcks) {
+			clientOptions.setUseSeparateListener(true);
+			
+			if(asyncAcks) {
+				String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+				clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+			} else {
+				String acksTo = AddressingConstants.Final.WSA_ANONYMOUS_URL;
+				clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+			}
+		}
+		
+		if(asyncAcks) {
+			String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+			clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+		} else {
+			String acksTo = AddressingConstants.Final.WSA_ANONYMOUS_URL;
+			clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+		}
+
+		// Establish a baseline count for inbound sequences
+		ArrayList oldIncomingReports = SandeshaClient.getIncomingSequenceReports(configContext);
+		
+		TestCallback callback1 = new TestCallback ("Callback 1");
+		serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo1",sequenceKey),callback1);
+		
+		TestCallback callback2 = new TestCallback ("Callback 2");
+		serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo2",sequenceKey),callback2);
+		
+		if (!explicitTermination 
+				&& 
+			!Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(clientOptions.getProperty(SandeshaClientConstants.RM_SPEC_VERSION))) {
+			
+			clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
+		}
+		
+		TestCallback callback3 = new TestCallback ("Callback 3");		
+		serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo3",sequenceKey),callback3);
+		
+		if (explicitTermination) {
+			Thread.sleep(10000);
+			SandeshaClient.terminateSequence(serviceClient);
+		}
+		
+		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 outgoingSequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+				System.out.println("Checking Outbound Sequence: " + outgoingSequenceReport.getSequenceID());
+				assertTrue("Outbound message #1", outgoingSequenceReport.getCompletedMessages().contains(new Long(1)));
+				assertTrue("Outbound message #2", outgoingSequenceReport.getCompletedMessages().contains(new Long(2)));
+				assertTrue("Outbound message #3", outgoingSequenceReport.getCompletedMessages().contains(new Long(3)));
+				assertEquals("Outbound sequence status: TERMINATED", SequenceReport.SEQUENCE_STATUS_TERMINATED, outgoingSequenceReport.getSequenceStatus());
+				assertEquals("Outbound sequence direction: OUT", SequenceReport.SEQUENCE_DIRECTION_OUT, outgoingSequenceReport.getSequenceDirection());
+				
+				//assertions for the inbound sequence. The one we care about is a new sequence,
+				//so it will not exist in the oldSequences list.
+				ArrayList incomingSequences = SandeshaClient.getIncomingSequenceReports(configContext);
+				SequenceReport incomingSequenceReport = getNewReport(incomingSequences, oldIncomingReports);
+				System.out.println("Checking Inbound Sequence: " + incomingSequenceReport.getSequenceID());
+				String offer = (String) clientOptions.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
+				if(offer != null) assertEquals("Inbound seq id", offer, incomingSequenceReport.getSequenceID());
+				assertEquals ("Inbound message count", 3, incomingSequenceReport.getCompletedMessages().size());
+				assertTrue("Inbound message #1", incomingSequenceReport.getCompletedMessages().contains(new Long(1)));
+				assertTrue("Inbound message #2", incomingSequenceReport.getCompletedMessages().contains(new Long(2)));
+				assertTrue("Inbound message #3", incomingSequenceReport.getCompletedMessages().contains(new Long(3)));
+				
+				if (checkInboundTermination)
+					assertEquals("Inbound sequence status: TERMINATED", SequenceReport.SEQUENCE_STATUS_TERMINATED, incomingSequenceReport.getSequenceStatus());
+				
+				assertEquals("Inbound sequence direction: IN", SequenceReport.SEQUENCE_DIRECTION_IN, incomingSequenceReport.getSequenceDirection());
+				
+				assertTrue("Callback #1", callback1.isComplete());
+				assertEquals("Callback #1 data", "echo1", callback1.getResult());
+				
+				assertTrue("Callback #2", callback2.isComplete());
+				assertEquals("Callback #2 data", "echo1echo2", callback2.getResult());
+				
+				assertTrue("Callback #3", callback3.isComplete());
+				assertEquals("Callback #3 data", "echo1echo2echo3", callback3.getResult());
+				
+				lastError = null;
+				break;
+			} catch(Error e) {
+				System.out.println("Possible error:" + e);
+				lastError = e;
+			}
+		}
+		if(lastError != null) throw lastError;
+		
+		serviceClient.cleanup();
+	}
+
+	// Scan through lists of old and new incoming sequences, to find the sequence that
+	// was established by this test. Note that some of the old sequences may have timed out.
+	private SequenceReport getNewReport(ArrayList incomingSequences, ArrayList oldIncomingReports) {
+		HashSet sequenceIds = new HashSet();
+		for(Iterator oldSequences = oldIncomingReports.iterator(); oldSequences.hasNext(); ) {
+			SequenceReport report = (SequenceReport) oldSequences.next();
+			sequenceIds.add(report.getSequenceID());
+		}
+		for(Iterator currentSequences = incomingSequences.iterator(); currentSequences.hasNext(); ) {
+			SequenceReport report = (SequenceReport) currentSequences.next();
+			if(!sequenceIds.contains(report.getSequenceID())) {
+				return report;
+			}
+		}
+		throw new AssertionFailedError("Failed to find a new reply sequence");
+	}
+
+
+}

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/SerializableScenariosTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/SerializableScenariosTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/SerializableScenariosTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/scenarios/SerializableScenariosTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * 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.scenarios;
+
+import java.io.File;
+
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.client.Options;
+
+public class SerializableScenariosTest extends RMScenariosTest {
+
+	public SerializableScenariosTest() {
+		super("SerializableScenariosTest");
+		this.repoPath = "target" + File.separator + "repos" + File.separator + "serialize-server";
+		this.axis2_xml = repoPath + File.separator + "server_axis2.xml";
+		
+		this.repoPathClient = "target" + File.separator + "repos" + File.separator + "serialize-client";
+		this.axis2_xmlClient = repoPathClient + File.separator + "client_axis2.xml";
+	}
+
+  public void testMustUnderstandSerialization() throws Exception {
+    
+    Options clientOptions = new Options();
+    clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+    clientOptions.setProperty(org.apache.axis2.addressing.AddressingConstants.ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS, 
+        Boolean.TRUE.toString());
+    
+    // Run the echo test
+    runEcho(clientOptions, true, true, false, true);
+  }
+}

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityScenariosTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityScenariosTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityScenariosTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityScenariosTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * 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.security;
+
+import java.io.File;
+
+import org.apache.sandesha2.scenarios.RMScenariosTest;
+
+public class SecurityScenariosTest extends RMScenariosTest {
+
+	public SecurityScenariosTest() {
+		super("SecurityScenariosTest");
+		this.repoPath = "target" + File.separator + "repos" + File.separator + "secure-server";
+		this.axis2_xml = repoPath + File.separator + "server_axis2.xml";
+		
+		this.repoPathClient = "target" + File.separator + "repos" + File.separator + "secure-client";
+		this.axis2_xmlClient = repoPathClient + File.separator + "client_axis2.xml";
+	}
+
+}

Added: webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityTest.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityTest.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/org/apache/sandesha2/security/SecurityTest.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.security;
+
+import java.io.File;
+
+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.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SequenceReport;
+
+/**
+ * Low-level testcases for the Security handling. This test mostly checks that the code can
+ * read and write the SecurityTokenReference elements that we expect to find within the create
+ * sequence messgaes.
+ */
+public class SecurityTest extends SandeshaTestCase {
+
+	public SecurityTest(String name) {
+		super(name);
+	}
+	
+	public void setUp () throws Exception {
+		super.setUp();
+
+		String repoPath = "target" + File.separator + "repos" + File.separator + "secure-server";
+		String axis2_xml = repoPath + File.separator + "server_axis2.xml";
+
+		startServer(repoPath, axis2_xml);
+	}
+	
+	// Test the create sequence flow for the 2 spec versions
+	public void testCreateSequence()
+	throws Exception
+	{
+		createSequence(Sandesha2Constants.SPEC_VERSIONS.v1_0);
+		createSequence(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+	}
+
+	// Check that we can send a create sequence that includes a token reference.
+	public void createSequence(String spec) throws Exception {
+		String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+		String repoPath = "target" + File.separator + "repos" + File.separator + "secure-client";
+		String axis2_xml = repoPath + File.separator + "client_axis2.xml";
+		
+		ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+		ServiceClient serviceClient = new ServiceClient (configContext,null);
+		
+//		String sequenceKey = SandeshaUtil.getUUID();
+
+		Options clientOptions = new Options ();
+
+		clientOptions.setTo(new EndpointReference (to));
+
+//		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION, spec);
+		serviceClient.setOptions(clientOptions);
+		
+		String sequenceKey = SandeshaClient.createSequence(serviceClient,false);
+		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);
+				assertTrue(sequenceReport.isSecureSequence());
+
+				lastError = null;
+				break;
+			} catch(Error e) {
+				lastError = e;
+			}
+		}
+
+		if(lastError != null) throw lastError;
+
+		configContext.getListenerManager().stop();
+		serviceClient.cleanup();
+	}
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org