001: package org.objectweb.celtix.bus.context;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005: import javax.xml.bind.JAXBContext;
006: import javax.xml.bind.JAXBException;
007: import javax.xml.ws.handler.MessageContext;
008: import junit.framework.TestCase;
009:
010: import org.objectweb.celtix.context.ObjectMessageContext;
011: import org.objectweb.celtix.context.ObjectMessageContextImpl;
012: import org.objectweb.handler_test.HandlerTest;
013: import org.objectweb.handler_test.types.PingResponse;
014: import org.objectweb.hello_world_soap_http.Greeter;
015: import org.objectweb.hello_world_soap_http.types.GreetMe;
016: import org.objectweb.hello_world_soap_http.types.GreetMeResponse;
017:
018: public class LogicalMessageImplTest extends TestCase {
019:
020: private final ObjectMessageContextImpl ctx = new ObjectMessageContextImpl();
021: private final LogicalMessageImpl lm = new LogicalMessageImpl(
022: new LogicalMessageContextImpl(ctx));
023: private JAXBContext jaxbCtx;
024:
025: public void setUp() throws Exception {
026:
027: ctx.setMethod(Greeter.class.getMethod("greetMe", String.class));
028: jaxbCtx = JAXBContext.newInstance(GreetMe.class.getPackage()
029: .getName());
030: }
031:
032: public void testGetPayloadJAXBOutboundArguments()
033: throws NoSuchMethodException, JAXBException {
034:
035: ctx.put(ObjectMessageContext.MESSAGE_INPUT, false);
036: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
037:
038: doGetArgumentsFromPayloadTest();
039: }
040:
041: private void doGetArgumentsFromPayloadTest() {
042: Object[] args = { "test string parameter" };
043: ctx.setMessageObjects(args);
044:
045: Object payload = lm.getPayload(jaxbCtx);
046: assertNotNull(payload);
047: assertTrue(payload instanceof GreetMe);
048: assertEquals(args[0], ((GreetMe) payload).getRequestType());
049: }
050:
051: public void testGetPayloadJAXBOutboundNoArguments()
052: throws NoSuchMethodException, JAXBException {
053:
054: ctx.put(ObjectMessageContext.MESSAGE_INPUT, false);
055: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
056:
057: Object payload = lm.getPayload(jaxbCtx);
058: assertNull(payload);
059: }
060:
061: public void testGetPayloadJAXBInboundReturn() {
062:
063: ctx.put(ObjectMessageContext.MESSAGE_INPUT, true);
064: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, false);
065:
066: final String returnValue = "test return value";
067: ctx.setReturn(returnValue);
068:
069: Object o = lm.getPayload(jaxbCtx);
070: assertNotNull(o);
071: assertTrue(o instanceof GreetMeResponse);
072: assertEquals(returnValue, ((GreetMeResponse) o)
073: .getResponseType());
074: }
075:
076: public void testSetPayloadJAXBOutboundArgs() {
077:
078: ctx.put(ObjectMessageContext.MESSAGE_INPUT, false);
079: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
080:
081: final String testArg = "test argument set";
082: GreetMe wrapper = new GreetMe();
083: wrapper.setRequestType(testArg);
084: lm.setPayload(wrapper, jaxbCtx);
085:
086: GreetMe payload = (GreetMe) lm.getPayload(jaxbCtx);
087: assertEquals(wrapper.getRequestType(), payload.getRequestType());
088:
089: Object[] args = ctx.getMessageObjects();
090:
091: assertNotNull(args);
092: assertEquals(1, args.length);
093: assertTrue(args[0] instanceof String);
094: assertEquals(testArg, args[0]);
095: }
096:
097: public void testSetPayloadJAXInboundReturn() {
098:
099: ctx.put(ObjectMessageContext.MESSAGE_INPUT, true);
100: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, false);
101:
102: final String testResponse = "test replaced response";
103: GreetMeResponse wrapper = new GreetMeResponse();
104: wrapper.setResponseType(testResponse);
105: lm.setPayload(wrapper, jaxbCtx);
106:
107: GreetMeResponse payload = (GreetMeResponse) lm
108: .getPayload(jaxbCtx);
109: assertEquals(wrapper.getResponseType(), payload
110: .getResponseType());
111:
112: Object ret = ctx.getReturn();
113:
114: assertNotNull(ret);
115: assertTrue(ret instanceof String);
116: assertEquals(testResponse, ret);
117:
118: }
119:
120: // server side tests
121:
122: public void testSetPayloadJAXOutboundReturnListProperty()
123: throws Exception {
124:
125: ctx.put(ObjectMessageContext.MESSAGE_INPUT, true);
126: ctx.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, true);
127: ctx.setMethod(HandlerTest.class.getMethod("ping"));
128:
129: List<String> l = new ArrayList<String>();
130: l.add("foo");
131: l.add("bar");
132: l.add("baz");
133: ctx.setReturn(l);
134:
135: Object o = lm.getPayload(jaxbCtx);
136:
137: assertNotNull(o);
138: assertEquals(PingResponse.class, o.getClass());
139: assertEquals(l, ((PingResponse) o).getHandlersInfo());
140: }
141:
142: public void testGetPayloadJAXBInbountArgs() {
143: ctx.put(ObjectMessageContext.MESSAGE_INPUT, false);
144: }
145: }
|