1 package org.objectweb.celtix.systest.ws.rm; 2 3 import java.net.URL ; 4 import java.util.List ; 5 6 import javax.xml.namespace.QName ; 7 import javax.xml.soap.SOAPMessage ; 8 import javax.xml.ws.BindingProvider; 9 import javax.xml.ws.handler.Handler; 10 import javax.xml.ws.handler.LogicalMessageContext; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 15 import org.objectweb.celtix.Bus; 16 import org.objectweb.celtix.BusException; 17 import org.objectweb.celtix.bindings.AbstractBindingImpl; 18 import org.objectweb.celtix.bus.busimpl.BusConfigurationBuilder; 19 import org.objectweb.celtix.bus.ws.rm.Names; 20 import org.objectweb.celtix.configuration.ConfigurationBuilder; 21 import org.objectweb.celtix.configuration.ConfigurationBuilderFactory; 22 import org.objectweb.celtix.greeter_control.Greeter; 23 import org.objectweb.celtix.greeter_control.GreeterService; 24 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 25 import org.objectweb.celtix.systest.common.ClientServerTestBase; 26 27 30 public class ShutdownTest extends ClientServerTestBase { 31 32 private static final String APP_NAMESPACE = "http://celtix.objectweb.org/greeter_control"; 33 private static final String GREETMEONEWAY_ACTION = APP_NAMESPACE + "/types/Greeter/greetMeOneWay"; 34 35 private static final QName SERVICE_NAME = new QName (APP_NAMESPACE, "GreeterService"); 36 private static final QName PORT_NAME = new QName (APP_NAMESPACE, "GreeterPort"); 37 38 private Bus bus; 39 private MessageFlow mf; 40 private GreeterService greeterService; 41 private Greeter greeter; 42 43 44 public static void main(String [] args) { 45 junit.textui.TestRunner.run(ShutdownTest.class); 46 } 47 48 public static Test suite() throws Exception { 49 TestSuite suite = new TestSuite(ShutdownTest.class); 50 return new ClientServerSetupBase(suite) { 51 public void startServers() throws Exception { 52 assertTrue("server did not launch correctly", launchServer(ShutdownTestServer.class, 56 "Windows 2000".equals(System.getProperty("os.name")))); 57 } 58 59 public void setUp() throws Exception { 60 61 URL url = getClass().getResource("oneway-terminate-on-shutdown.xml"); 62 assertNotNull("cannot find test resource", url); 63 configFileName = url.toString(); 64 ConfigurationBuilder builder = ConfigurationBuilderFactory.getBuilder(); 65 builder.buildConfiguration(BusConfigurationBuilder.BUS_CONFIGURATION_URI, "celtix"); 66 67 super.setUp(); 68 69 } 70 }; 71 } 72 73 public void setUp() throws BusException { 74 75 bus = Bus.init(); 79 80 URL wsdl = getClass().getResource("/wsdl/greeter_control.wsdl"); 81 greeterService = new GreeterService(wsdl, SERVICE_NAME); 82 83 greeter = greeterService.getPort(PORT_NAME, Greeter.class); 84 85 BindingProvider provider = (BindingProvider)greeter; 86 AbstractBindingImpl abi = (AbstractBindingImpl)provider.getBinding(); 87 List <Handler> handlerChain = abi.getPostProtocolSystemHandlers(); 88 assertTrue(handlerChain.size() > 0); 89 90 List <SOAPMessage > outboundMessages = null; 91 List <LogicalMessageContext> inboundContexts = null; 92 93 94 boolean found = false; 95 for (Handler h : handlerChain) { 96 if (!found && h instanceof SOAPMessageRecorder) { 97 SOAPMessageRecorder recorder = (SOAPMessageRecorder)h; 98 outboundMessages = recorder.getOutboundMessages(); 99 outboundMessages.clear(); 100 found = true; 101 break; 102 } 103 } 104 assertTrue("Could not find SOAPMessageRecorder in post protocol handler chain", found); 105 handlerChain = abi.getPreLogicalSystemHandlers(); 106 assertTrue(handlerChain.size() > 0); 107 found = false; 108 for (Handler h : handlerChain) { 109 if (!found && h instanceof LogicalMessageContextRecorder) { 110 LogicalMessageContextRecorder recorder = (LogicalMessageContextRecorder)h; 111 inboundContexts = recorder.getInboundContexts(); 112 inboundContexts.clear(); 113 found = true; 114 break; 115 } 116 } 117 assertTrue("Could not find LogicalMessageContextRecorder in pre logical handler chain", found); 118 119 mf = new MessageFlow(outboundMessages, inboundContexts); 120 121 } 122 123 public void testOnewayTerminateOnShutdown() throws Exception { 124 125 try { 126 greeter.greetMeOneWay("once"); 127 greeter.greetMeOneWay("twice"); 128 greeter.greetMeOneWay("thrice"); 129 } finally { 130 bus.shutdown(true); 131 } 132 133 mf.verifyMessages(6, true); 134 String [] expectedActions = new String [] {Names.WSRM_CREATE_SEQUENCE_ACTION, 135 GREETMEONEWAY_ACTION, 136 GREETMEONEWAY_ACTION, 137 GREETMEONEWAY_ACTION, 138 Names.WSRM_LAST_MESSAGE_ACTION, 139 Names.WSRM_TERMINATE_SEQUENCE_ACTION}; 140 mf.verifyActions(expectedActions, true); 141 mf.verifyMessageNumbers(new String [] {null, "1", "2", "3", "4", null}, true); 142 143 144 mf.verifyMessages(7, false); 145 expectedActions = new String [] {null, 146 Names.WSRM_CREATE_SEQUENCE_RESPONSE_ACTION, 147 null, null, null, null, null}; 148 mf.verifyActions(expectedActions, false); 149 mf.verifyMessageNumbers(new String [] {null, null, null, null, null, null, null}, false); 150 boolean[] expectedAcks = new boolean[7]; 151 expectedAcks[5] = true; 152 mf.verifyAcknowledgements(expectedAcks, false); 153 } 154 } 155 | Popular Tags |