1 22 package org.jboss.test.webservice.handlerflow; 23 24 import java.util.Arrays ; 25 import java.util.List ; 26 27 import javax.naming.InitialContext ; 28 29 import junit.framework.Test; 30 import junit.framework.TestSuite; 31 32 import org.jboss.test.JBossTestCase; 33 import org.jboss.test.webservice.WebserviceTestBase; 34 35 43 public class HandlerFlowTestCase extends WebserviceTestBase 44 { 45 private static HelloRemote ejb; 46 47 public HandlerFlowTestCase(String name) 48 { 49 super(name); 50 } 51 52 public static Test suite() throws Exception 53 { 54 TestSuite suite = new TestSuite(); 57 suite.addTest(new HandlerFlowTestCase("testHandlerFlowAllPass")); 58 suite.addTest(new HandlerFlowTestCase("testHandlerFlowClientReturn")); 59 suite.addTest(new HandlerFlowTestCase("testHandlerFlowServerReturn")); 60 61 return JBossTestCase.getDeploySetup(suite, "ws4ee-handlerflow.jar, ws4ee-handlerflow.war"); 62 } 63 64 public void setUp() throws Exception 65 { 66 super.setUp(); 67 68 if (ejb == null) 69 { 70 InitialContext iniCtx = getClientContext(); 71 HelloHome home = (HelloHome)iniCtx.lookup("ejb/HelloEjb"); 72 ejb = home.create(); 73 } 74 } 75 76 79 public void testHandlerFlowAllPass() throws Exception 80 { 81 List protocol = Arrays.asList(ejb.sayHello("Hello")); 83 84 String [] exp = { 85 "ClientHandler1 init", 86 "ClientHandler2 init", 87 "ClientHandler1 handleRequest", 88 "ClientHandler2 handleRequest", 89 "ServerHandler1 init", 90 "ServerHandler2 init", 91 "ServerHandler1 handleRequest", 92 "ServerHandler2 handleRequest", 93 "jse: 'Hello' to you too!", 94 "ServerHandler2 handleResponse", 95 "ServerHandler1 handleResponse", 96 "ClientHandler2 handleResponse", 97 "ClientHandler1 handleResponse", 98 "ejb: 'Hello' to you too!" 99 }; 100 101 assertHandlerProtocol(exp, protocol); 102 } 103 104 107 public void testHandlerFlowClientReturn() throws Exception 108 { 109 if (isWS4EEAvailable() == false) 110 { 111 List protocol = Arrays.asList(ejb.sayHello("ClientReturn")); 112 113 String [] exp = { 114 "ClientHandler1 handleRequest", 115 "ClientHandler2 handleRequest", 116 "ClientHandler2 handleResponse", 117 "ClientHandler1 handleResponse", 118 "ejb: Return in ClientHandler2" }; 119 120 assertHandlerProtocol(exp, protocol); 121 } 122 } 123 124 125 128 public void testHandlerFlowServerReturn() throws Exception 129 { 130 if (isWS4EEAvailable() == false) 131 { 132 List protocol = Arrays.asList(ejb.sayHello("ServerReturn")); 133 134 String [] exp = { 135 "ClientHandler1 handleRequest", 136 "ClientHandler2 handleRequest", 137 "ServerHandler1 handleRequest", 138 "ServerHandler2 handleRequest", 139 "ServerHandler2 handleResponse", 140 "ServerHandler1 handleResponse", 141 "ClientHandler2 handleResponse", 142 "ClientHandler1 handleResponse", 143 "ejb: Return in ServerHandler2" }; 144 145 assertHandlerProtocol(exp, protocol); 146 } 147 } 148 149 private void assertHandlerProtocol(String [] exp, List protocol) 150 { 151 assertEquals("Wrong number of entries: " + protocol, exp.length, protocol.size()); 152 153 for (int i = 0; i < protocol.size(); i++) 154 { 155 String msg = (String )protocol.get(i); 156 boolean equals = msg.startsWith(exp[i]); 157 assertTrue("Wrong entry: " + msg + " in " + protocol, equals); 158 } 159 } 160 } 161 | Popular Tags |