Author: veithen Date: Sun Mar 27 21:17:44 2011 New Revision: 1086038 URL: http://svn.apache.org/viewvc?rev=1086038&view=rev Log: Eliminated several instances of the catch-and-fail JUnit anti-pattern.
Modified: axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingFinalInHandlerTest.java axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingInHandlerTestBase.java axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingSubmissionInHandlerTest.java Modified: axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingFinalInHandlerTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingFinalInHandlerTest.java?rev=1086038&r1=1086037&r2=1086038&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingFinalInHandlerTest.java (original) +++ axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingFinalInHandlerTest.java Sun Mar 27 21:17:44 2011 @@ -53,27 +53,20 @@ public class AddressingFinalInHandlerTes secondRelationshipType = "http://some.custom.relationship"; } - public void testExtractAddressingInformationFromHeaders() { - try { - Options options = extractAddressingInformationFromHeaders(null); + public void testExtractAddressingInformationFromHeaders() throws Exception { + Options options = extractAddressingInformationFromHeaders(null); - assertNotNull(options); - assertNotNull(options.getTo()); + assertNotNull(options); + assertNotNull(options.getTo()); - Map allReferenceParameters = options.getTo().getAllReferenceParameters(); - assertNotNull(allReferenceParameters); - QName qName = new QName("http://ws.apache.org/namespaces/axis2", "ParamOne", "axis2"); - assertNotNull(allReferenceParameters.get(qName)); - - assertEPRHasCorrectMetadata(options.getFrom()); - assertEPRHasCorrectMetadata(options.getFaultTo()); - assertEPRHasCorrectMetadata(options.getReplyTo()); - - } catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } + Map allReferenceParameters = options.getTo().getAllReferenceParameters(); + assertNotNull(allReferenceParameters); + QName qName = new QName("http://ws.apache.org/namespaces/axis2", "ParamOne", "axis2"); + assertNotNull(allReferenceParameters.get(qName)); + + assertEPRHasCorrectMetadata(options.getFrom()); + assertEPRHasCorrectMetadata(options.getFaultTo()); + assertEPRHasCorrectMetadata(options.getReplyTo()); } public void testExtractAddressingInformationFromHeadersCustomRole() throws Exception { @@ -120,7 +113,7 @@ public class AddressingFinalInHandlerTes } - public void testMessageWithOmittedAction() { + public void testMessageWithOmittedAction() throws Exception { try { testMessageWithOmittedHeaders("noAction"); fail("An AxisFault should have been thrown due to a missing Action header."); @@ -128,14 +121,9 @@ public class AddressingFinalInHandlerTes catch (AxisFault af) { //test passed } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedFaultTo() { + public void testMessageWithOmittedFaultTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noFaultTo"); EndpointReference epr = options.getFaultTo(); @@ -147,14 +135,9 @@ public class AddressingFinalInHandlerTes log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing FaultTo header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedFrom() { + public void testMessageWithOmittedFrom() throws Exception { try { Options options = testMessageWithOmittedHeaders("noFrom"); EndpointReference epr = options.getFrom(); @@ -166,14 +149,9 @@ public class AddressingFinalInHandlerTes log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing From header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedMessageID() { + public void testMessageWithOmittedMessageID() throws Exception { try { Options options = testMessageWithOmittedHeaders("noMessageID"); String messageID = options.getMessageId(); @@ -185,14 +163,9 @@ public class AddressingFinalInHandlerTes log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing MessageID header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedReplyTo() { + public void testMessageWithOmittedReplyTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noReplyTo"); EndpointReference epr = options.getReplyTo(); @@ -206,14 +179,9 @@ public class AddressingFinalInHandlerTes log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing ReplyTo header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedTo() { + public void testMessageWithOmittedTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noTo"); EndpointReference epr = options.getTo(); @@ -227,11 +195,6 @@ public class AddressingFinalInHandlerTes log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing To header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } public void testDifferentSoapActionProcessing() throws Exception { Modified: axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingInHandlerTestBase.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingInHandlerTestBase.java?rev=1086038&r1=1086037&r2=1086038&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingInHandlerTestBase.java (original) +++ axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingInHandlerTestBase.java Sun Mar 27 21:17:44 2011 @@ -106,60 +106,55 @@ public abstract class AddressingInHandle return options; } - private void testExtractAddressingInformationFromHeadersInvalidCardinality(String headerName) { + private void testExtractAddressingInformationFromHeadersInvalidCardinality(String headerName) throws Exception { String testfile = "invalid-cardinality-messages/" + versionDirectory + "/invalidCardinality" + headerName + "Message.xml"; + + MessageContext mc = new MessageContext(); + mc.setConfigurationContext( + ConfigurationContextFactory.createEmptyConfigurationContext()); try { - MessageContext mc = new MessageContext(); - mc.setConfigurationContext( - ConfigurationContextFactory.createEmptyConfigurationContext()); - try { - basicExtractAddressingInformationFromHeaders(testfile, mc); - fail("An AxisFault should have been thrown due to 2 wsa:" + headerName + - " headers."); - } catch (AxisFault af) { - if (headerName.equals(AddressingConstants.WSA_REPLY_TO)) { - assertNull("No ReplyTo should be set on the MessageContext", mc.getReplyTo()); - } else { - assertReplyToEPR(mc.getReplyTo()); - } + basicExtractAddressingInformationFromHeaders(testfile, mc); + fail("An AxisFault should have been thrown due to 2 wsa:" + headerName + + " headers."); + } catch (AxisFault af) { + if (headerName.equals(AddressingConstants.WSA_REPLY_TO)) { + assertNull("No ReplyTo should be set on the MessageContext", mc.getReplyTo()); + } else { + assertReplyToEPR(mc.getReplyTo()); + } - if (headerName.equals(AddressingConstants.WSA_FAULT_TO)) { - assertNull("No FaultTo should be set on the MessageContext", mc.getFaultTo()); - } else { - assertFaultEPR(mc.getFaultTo()); - } + if (headerName.equals(AddressingConstants.WSA_FAULT_TO)) { + assertNull("No FaultTo should be set on the MessageContext", mc.getFaultTo()); + } else { + assertFaultEPR(mc.getFaultTo()); + } - if (headerName.equals(AddressingConstants.WSA_ACTION)) { - assertNull("No Action should be set on the MessageContext", mc.getWSAAction()); - } else { - assertEquals("WSAAction property is not correct", mc.getWSAAction(), action); - } + if (headerName.equals(AddressingConstants.WSA_ACTION)) { + assertNull("No Action should be set on the MessageContext", mc.getWSAAction()); + } else { + assertEquals("WSAAction property is not correct", mc.getWSAAction(), action); + } - if (headerName.equals(AddressingConstants.WSA_MESSAGE_ID)) { - assertNull("No MessageID should be set on the MessageContext", - mc.getMessageID()); - } else { - assertEquals("MessageID property is not correct", mc.getMessageID().trim(), - messageID.trim()); - } + if (headerName.equals(AddressingConstants.WSA_MESSAGE_ID)) { + assertNull("No MessageID should be set on the MessageContext", + mc.getMessageID()); + } else { + assertEquals("MessageID property is not correct", mc.getMessageID().trim(), + messageID.trim()); + } - if (headerName.equals(AddressingConstants.WSA_FROM)) { - assertNull("No From should be set on the MessageContext", mc.getFrom()); - } else { - assertFromEPR(mc.getFrom()); - } + if (headerName.equals(AddressingConstants.WSA_FROM)) { + assertNull("No From should be set on the MessageContext", mc.getFrom()); + } else { + assertFromEPR(mc.getFrom()); + } - if (headerName.equals(AddressingConstants.WSA_TO)) { - assertNull("No To should be set on the MessageContext", mc.getTo()); - } else { - assertToEPR(mc.getTo()); - } + if (headerName.equals(AddressingConstants.WSA_TO)) { + assertNull("No To should be set on the MessageContext", mc.getTo()); + } else { + assertToEPR(mc.getTo()); } - } catch (Exception e) { - e.printStackTrace(); - log.info(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); } } @@ -175,31 +170,31 @@ public abstract class AddressingInHandle return mc.getOptions(); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityReplyTo() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityReplyTo() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality( AddressingConstants.WSA_REPLY_TO); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityFaultTo() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityFaultTo() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality( AddressingConstants.WSA_FAULT_TO); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityAction() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityAction() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality( AddressingConstants.WSA_ACTION); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityMessageID() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityMessageID() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality( AddressingConstants.WSA_MESSAGE_ID); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityFrom() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityFrom() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality(AddressingConstants.WSA_FROM); } - public void testExtractAddressingInformationFromHeadersInvalidCardinalityTo() { + public void testExtractAddressingInformationFromHeadersInvalidCardinalityTo() throws Exception { testExtractAddressingInformationFromHeadersInvalidCardinality(AddressingConstants.WSA_TO); } Modified: axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingSubmissionInHandlerTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingSubmissionInHandlerTest.java?rev=1086038&r1=1086037&r2=1086038&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingSubmissionInHandlerTest.java (original) +++ axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingSubmissionInHandlerTest.java Sun Mar 27 21:17:44 2011 @@ -70,7 +70,7 @@ public class AddressingSubmissionInHandl }); } - public void testMessageWithOmittedAction() { + public void testMessageWithOmittedAction() throws Exception { try { testMessageWithOmittedHeaders("noAction"); fail("An AxisFault should have been thrown due to a missing Action header."); @@ -78,14 +78,9 @@ public class AddressingSubmissionInHandl catch (AxisFault af) { //test passed } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedFaultTo() { + public void testMessageWithOmittedFaultTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noFaultTo"); EndpointReference epr = options.getFaultTo(); @@ -97,14 +92,9 @@ public class AddressingSubmissionInHandl log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing FaultTo header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedFrom() { + public void testMessageWithOmittedFrom() throws Exception { try { Options options = testMessageWithOmittedHeaders("noFrom"); EndpointReference epr = options.getFrom(); @@ -116,14 +106,9 @@ public class AddressingSubmissionInHandl log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing From header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedMessageID() { + public void testMessageWithOmittedMessageID() throws Exception { try { testMessageWithOmittedHeaders("noMessageID"); fail("An AxisFault should have been thrown due to a missing MessageID header."); @@ -131,14 +116,9 @@ public class AddressingSubmissionInHandl catch (AxisFault af) { //test passed } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedMessageIDReplyToAndFaultTo() { + public void testMessageWithOmittedMessageIDReplyToAndFaultTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noMessageIDNoReplyToNoFaultTo"); String messageID = options.getMessageId(); @@ -150,14 +130,9 @@ public class AddressingSubmissionInHandl log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to missing MessageID, ReplyTo, and FaultTo headers."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedReplyTo() { + public void testMessageWithOmittedReplyTo() throws Exception { try { Options options = testMessageWithOmittedHeaders("noReplyTo"); EndpointReference epr = options.getReplyTo(); @@ -171,14 +146,9 @@ public class AddressingSubmissionInHandl log.error(af.getMessage()); fail("An unexpected AxisFault was thrown due to a missing ReplyTo header."); } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } - public void testMessageWithOmittedTo() { + public void testMessageWithOmittedTo() throws Exception { try { testMessageWithOmittedHeaders("noTo"); fail("An AxisFault should have been thrown due to a missing To header."); @@ -186,10 +156,5 @@ public class AddressingSubmissionInHandl catch (AxisFault af) { //test passed } - catch (Exception e) { - e.printStackTrace(); - log.error(e.getMessage()); - fail(" An Exception has occured " + e.getMessage()); - } } }