You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ve...@apache.org on 2008/06/11 22:09:33 UTC
svn commit: r666819 - in
/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport:
AbstractTransportTest.java mail/MailEchoRawXMLTest.java
Author: veithen
Date: Wed Jun 11 13:09:32 2008
New Revision: 666819
URL: http://svn.apache.org/viewvc?rev=666819&view=rev
Log:
Refactored duplicate code in MailEchoRawXMLTest into methods (no functional changes).
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/AbstractTransportTest.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailEchoRawXMLTest.java
Modified: synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/AbstractTransportTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/AbstractTransportTest.java?rev=666819&r1=666818&r2=666819&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/AbstractTransportTest.java (original)
+++ synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/AbstractTransportTest.java Wed Jun 11 13:09:32 2008
@@ -44,15 +44,19 @@
* Create the payload for an echoOMElement request
* @return
*/
- protected OMElement createPayload() {
+ protected OMElement createPayload(String textValue) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://localhost/axis2/services/EchoXMLService", "my");
OMElement method = fac.createOMElement("echoOMElement", omNs);
OMElement value = fac.createOMElement("myValue", omNs);
- value.addChild(fac.createOMText(value, "omTextValue"));
+ value.addChild(fac.createOMText(value, textValue));
method.addChild(value);
return method;
}
+
+ protected OMElement createPayload() {
+ return createPayload("omTextValue");
+ }
/**
* Get the default axis2 configuration context for a client
Modified: synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailEchoRawXMLTest.java?rev=666819&r1=666818&r2=666819&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailEchoRawXMLTest.java (original)
+++ synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailEchoRawXMLTest.java Wed Jun 11 13:09:32 2008
@@ -36,10 +36,7 @@
import javax.mail.internet.InternetAddress;
import javax.xml.stream.XMLStreamReader;
-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.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.om.util.UUIDGenerator;
@@ -96,6 +93,42 @@
props.put("mail.smtp.auth", "true");
}
+ private void assertPOXEchoResponse(String textValue, Object reply) throws Exception {
+ if (reply != null && reply instanceof String) {
+ log.debug("Result Body : " + reply);
+ XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
+ OMElement res = new StAXOMBuilder(reader).getDocumentElement();
+ if (res != null) {
+ AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
+ xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
+ Object result = xpath.evaluate(res);
+ if (result != null && result instanceof OMElement) {
+ assertEquals(textValue, ((OMElement) result).getText());
+ }
+ }
+ } else {
+ fail("Did not receive the reply mail");
+ }
+ }
+
+ private void assertSOAPEchoResponse(String textValue, Object reply) throws Exception {
+ if (reply != null && reply instanceof String) {
+ log.debug("Result Body : " + reply);
+ XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
+ SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
+ if (env != null) {
+ AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
+ xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
+ Object result = xpath.evaluate(env);
+ if (result != null && result instanceof OMElement) {
+ assertEquals(textValue, ((OMElement) result).getText());
+ }
+ }
+ } else {
+ fail("Did not receive the reply mail");
+ }
+ }
+
public void testRoundTripPOX() throws Exception {
String msgId = UUIDGenerator.getUUID();
@@ -120,41 +153,7 @@
msg.setText(POX_MESSAGE);
Transport.send(msg);
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
-
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- OMElement res = new StAXOMBuilder(reader).getDocumentElement();
- if (res != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(res);
- if (result != null && result instanceof OMElement) {
- assertEquals("omTextValue", ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertPOXEchoResponse("omTextValue", waitForReply(msgId));
}
public void testRoundTripMultiPart() throws Exception {
@@ -172,41 +171,7 @@
sender.setOptions(options);
sender.fireAndForget(createPayload());
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
-
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
- if (env != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(env);
- if (result != null && result instanceof OMElement) {
- assertEquals("omTextValue", ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertSOAPEchoResponse("omTextValue", waitForReply(msgId));
}
public void testRoundTripMultiPartKorean() throws Exception {
@@ -222,43 +187,9 @@
ServiceClient sender = new ServiceClient(getClientCfgCtx(), null);
sender.setOptions(options);
- sender.fireAndForget(createKoreanPayload());
-
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
+ sender.fireAndForget(createPayload(KOREAN_TEXT));
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
- if (env != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(env);
- if (result != null && result instanceof OMElement) {
- assertEquals("omTextValue", ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertSOAPEchoResponse("omTextValue", waitForReply(msgId));
}
public void testRoundTripPOPDefaultCharsetSOAP12() throws Exception {
@@ -275,41 +206,7 @@
sender.setOptions(options);
sender.fireAndForget(createPayload());
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
-
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
- if (env != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(env);
- if (result != null && result instanceof OMElement) {
- assertEquals("omTextValue", ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertSOAPEchoResponse("omTextValue", waitForReply(msgId));
}
public void testRoundTripIMAPUTF8Charset() throws Exception {
@@ -323,43 +220,9 @@
ServiceClient sender = new ServiceClient(getClientCfgCtx(), null);
sender.setOptions(options);
- sender.fireAndForget(createKoreanPayload());
-
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
+ sender.fireAndForget(createPayload(KOREAN_TEXT));
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
- if (env != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(env);
- if (result != null && result instanceof OMElement) {
- assertEquals(KOREAN_TEXT, ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertSOAPEchoResponse(KOREAN_TEXT, waitForReply(msgId));
}
public void testRoundTripIMAPKoreanCharset() throws Exception {
@@ -374,43 +237,9 @@
ServiceClient sender = new ServiceClient(getClientCfgCtx(), null);
sender.setOptions(options);
- sender.fireAndForget(createKoreanPayload());
-
- Thread.yield();
- Thread.sleep(100);
-
- Object reply = null;
- boolean replyNotFound = true;
- int retryCount = 50;
- while (replyNotFound) {
- log.debug("Checking for response ... with MessageID : " + msgId);
- reply = getMessage(msgId);
- if (reply != null) {
- replyNotFound = false;
- } else {
- if (retryCount-- > 0) {
- Thread.sleep(100);
- } else {
- break;
- }
- }
- }
+ sender.fireAndForget(createPayload(KOREAN_TEXT));
- if (reply != null && reply instanceof String) {
- log.debug("Result Body : " + reply);
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply));
- SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
- if (env != null) {
- AXIOMXPath xpath = new AXIOMXPath("//my:myValue");
- xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService");
- Object result = xpath.evaluate(env);
- if (result != null && result instanceof OMElement) {
- assertEquals(KOREAN_TEXT, ((OMElement) result).getText());
- }
- }
- } else {
- fail("Did not receive the reply mail");
- }
+ assertSOAPEchoResponse(KOREAN_TEXT, waitForReply(msgId));
}
private Object getMessage(String requestMsgId) {
@@ -451,6 +280,29 @@
}
return null;
}
+
+ private Object waitForReply(String msgId) throws Exception {
+ Thread.yield();
+ Thread.sleep(100);
+
+ Object reply = null;
+ boolean replyNotFound = true;
+ int retryCount = 50;
+ while (replyNotFound) {
+ log.debug("Checking for response ... with MessageID : " + msgId);
+ reply = getMessage(msgId);
+ if (reply != null) {
+ replyNotFound = false;
+ } else {
+ if (retryCount-- > 0) {
+ Thread.sleep(100);
+ } else {
+ break;
+ }
+ }
+ }
+ return reply;
+ }
/**
* Create a axis2 configuration context that 'knows' about the Mail transport
@@ -479,14 +331,4 @@
trpSender.init(cfgCtx, trpOutDesc);
return cfgCtx;
}
-
- protected OMElement createKoreanPayload() {
- OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace omNs = fac.createOMNamespace("http://localhost/axis2/services/EchoXMLService", "my");
- OMElement method = fac.createOMElement("echoOMElement", omNs);
- OMElement value = fac.createOMElement("myValue", omNs);
- value.addChild(fac.createOMText(value, KOREAN_TEXT));
- method.addChild(value);
- return method;
- }
}