001: package org.objectweb.celtix.systest.ws.rm;
002:
003: import java.net.URL;
004: import java.util.List;
005:
006: import javax.xml.namespace.QName;
007: import javax.xml.soap.SOAPMessage;
008: import javax.xml.ws.BindingProvider;
009: import javax.xml.ws.handler.Handler;
010: import javax.xml.ws.handler.LogicalMessageContext;
011:
012: import junit.framework.Test;
013: import junit.framework.TestSuite;
014:
015: import org.objectweb.celtix.Bus;
016: import org.objectweb.celtix.BusException;
017: import org.objectweb.celtix.bindings.AbstractBindingImpl;
018: import org.objectweb.celtix.bus.busimpl.BusConfigurationBuilder;
019: import org.objectweb.celtix.bus.ws.rm.Names;
020: import org.objectweb.celtix.configuration.ConfigurationBuilder;
021: import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
022: import org.objectweb.celtix.greeter_control.Greeter;
023: import org.objectweb.celtix.greeter_control.GreeterService;
024: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
025: import org.objectweb.celtix.systest.common.ClientServerTestBase;
026:
027: /**
028: * Tests Reliable Messaging.
029: */
030: public class ShutdownTest extends ClientServerTestBase {
031:
032: private static final String APP_NAMESPACE = "http://celtix.objectweb.org/greeter_control";
033: private static final String GREETMEONEWAY_ACTION = APP_NAMESPACE
034: + "/types/Greeter/greetMeOneWay";
035:
036: private static final QName SERVICE_NAME = new QName(APP_NAMESPACE,
037: "GreeterService");
038: private static final QName PORT_NAME = new QName(APP_NAMESPACE,
039: "GreeterPort");
040:
041: private Bus bus;
042: private MessageFlow mf;
043: private GreeterService greeterService;
044: private Greeter greeter;
045:
046: public static void main(String[] args) {
047: junit.textui.TestRunner.run(ShutdownTest.class);
048: }
049:
050: public static Test suite() throws Exception {
051: TestSuite suite = new TestSuite(ShutdownTest.class);
052: return new ClientServerSetupBase(suite) {
053: public void startServers() throws Exception {
054: // special case handling for WS-Addressing system test to avoid
055: // UUID related issue when server is run as separate process
056: // via maven on Win2k
057: assertTrue("server did not launch correctly",
058: launchServer(ShutdownTestServer.class,
059: "Windows 2000".equals(System
060: .getProperty("os.name"))));
061: }
062:
063: public void setUp() throws Exception {
064:
065: URL url = getClass().getResource(
066: "oneway-terminate-on-shutdown.xml");
067: assertNotNull("cannot find test resource", url);
068: configFileName = url.toString();
069: ConfigurationBuilder builder = ConfigurationBuilderFactory
070: .getBuilder();
071: builder.buildConfiguration(
072: BusConfigurationBuilder.BUS_CONFIGURATION_URI,
073: "celtix");
074:
075: super .setUp();
076:
077: }
078: };
079: }
080:
081: public void setUp() throws BusException {
082:
083: // Map<String, Object> busProperties = new HashMap<String, Object>();
084: // busProperties.put(BusConfigurationBuilder.BUS_ID_PROPERTY, "oneway-terminate-on-shutdown");
085: // bus = Bus.init(null, busProperties);
086: bus = Bus.init();
087:
088: URL wsdl = getClass().getResource("/wsdl/greeter_control.wsdl");
089: greeterService = new GreeterService(wsdl, SERVICE_NAME);
090:
091: greeter = greeterService.getPort(PORT_NAME, Greeter.class);
092:
093: BindingProvider provider = (BindingProvider) greeter;
094: AbstractBindingImpl abi = (AbstractBindingImpl) provider
095: .getBinding();
096: List<Handler> handlerChain = abi
097: .getPostProtocolSystemHandlers();
098: assertTrue(handlerChain.size() > 0);
099:
100: List<SOAPMessage> outboundMessages = null;
101: List<LogicalMessageContext> inboundContexts = null;
102:
103: boolean found = false;
104: for (Handler h : handlerChain) {
105: if (!found && h instanceof SOAPMessageRecorder) {
106: SOAPMessageRecorder recorder = (SOAPMessageRecorder) h;
107: outboundMessages = recorder.getOutboundMessages();
108: outboundMessages.clear();
109: found = true;
110: break;
111: }
112: }
113: assertTrue(
114: "Could not find SOAPMessageRecorder in post protocol handler chain",
115: found);
116: handlerChain = abi.getPreLogicalSystemHandlers();
117: assertTrue(handlerChain.size() > 0);
118: found = false;
119: for (Handler h : handlerChain) {
120: if (!found && h instanceof LogicalMessageContextRecorder) {
121: LogicalMessageContextRecorder recorder = (LogicalMessageContextRecorder) h;
122: inboundContexts = recorder.getInboundContexts();
123: inboundContexts.clear();
124: found = true;
125: break;
126: }
127: }
128: assertTrue(
129: "Could not find LogicalMessageContextRecorder in pre logical handler chain",
130: found);
131:
132: mf = new MessageFlow(outboundMessages, inboundContexts);
133:
134: }
135:
136: public void testOnewayTerminateOnShutdown() throws Exception {
137:
138: try {
139: greeter.greetMeOneWay("once");
140: greeter.greetMeOneWay("twice");
141: greeter.greetMeOneWay("thrice");
142: } finally {
143: bus.shutdown(true);
144: }
145:
146: mf.verifyMessages(6, true);
147: String[] expectedActions = new String[] {
148: Names.WSRM_CREATE_SEQUENCE_ACTION,
149: GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION,
150: GREETMEONEWAY_ACTION, Names.WSRM_LAST_MESSAGE_ACTION,
151: Names.WSRM_TERMINATE_SEQUENCE_ACTION };
152: mf.verifyActions(expectedActions, true);
153: mf.verifyMessageNumbers(new String[] { null, "1", "2", "3",
154: "4", null }, true);
155:
156: mf.verifyMessages(7, false);
157: expectedActions = new String[] { null,
158: Names.WSRM_CREATE_SEQUENCE_RESPONSE_ACTION, null, null,
159: null, null, null };
160: mf.verifyActions(expectedActions, false);
161: mf.verifyMessageNumbers(new String[] { null, null, null, null,
162: null, null, null }, false);
163: boolean[] expectedAcks = new boolean[7];
164: expectedAcks[5] = true;
165: mf.verifyAcknowledgements(expectedAcks, false);
166: }
167: }
|