01: package org.objectweb.celtix.bus.bindings.soap;
02:
03: import java.io.InputStream;
04:
05: import javax.xml.bind.JAXBContext;
06: import javax.xml.namespace.QName;
07: import javax.xml.soap.MessageFactory;
08: import javax.xml.soap.SOAPMessage;
09: import javax.xml.ws.handler.soap.SOAPMessageContext;
10:
11: import junit.framework.TestCase;
12:
13: import org.objectweb.celtix.context.GenericMessageContext;
14: import org.objectweb.header_test.types.TestHeader1;
15: import org.objectweb.header_test.types.TestHeader2Response;
16:
17: public class SoapMessageContextImplTest extends TestCase {
18: private MessageFactory factory;
19:
20: public SoapMessageContextImplTest(String arg0) {
21: super (arg0);
22: }
23:
24: public static void main(String[] args) {
25: junit.textui.TestRunner.run(SoapMessageContextImplTest.class);
26: }
27:
28: protected void setUp() throws Exception {
29: super .setUp();
30:
31: factory = MessageFactory.newInstance();
32: }
33:
34: public void testGetHeaders() throws Exception {
35: SOAPMessageContext smc = new SOAPMessageContextImpl(
36: new GenericMessageContext());
37: assertNotNull(smc);
38:
39: JAXBContext jaxbContext = JAXBContext
40: .newInstance(TestHeader1.class.getPackage().getName());
41: //Test 1 No Headers in SOAP Message
42: setSOAPMessage(smc, "resources/TestIntDocLitTypeTestReq.xml");
43: Object[] obj1 = smc.getHeaders(null, jaxbContext, true);
44:
45: assertEquals(0, obj1.length);
46:
47: //Test 2 Headers in SOAP Message
48: QName headerName2 = new QName(
49: "http://objectweb.org/header_test/types", "testHeader1");
50: setSOAPMessage(smc, "resources/TestHeader1Req.xml");
51: Object[] obj2 = smc.getHeaders(headerName2, jaxbContext, true);
52:
53: assertEquals(1, obj2.length);
54: assertTrue(TestHeader1.class.isAssignableFrom(obj2[0]
55: .getClass()));
56:
57: //Test 2 Headers in SOAP Message
58: QName headerName3 = new QName(
59: "http://objectweb.org/header_test/types",
60: "testHeader2Response");
61: setSOAPMessage(smc, "resources/TestHeader2.xml");
62: Object[] obj3 = smc.getHeaders(headerName3, jaxbContext, true);
63:
64: assertEquals(2, obj3.length);
65: assertTrue(TestHeader2Response.class.isAssignableFrom(obj3[0]
66: .getClass()));
67: assertTrue(TestHeader2Response.class.isAssignableFrom(obj3[1]
68: .getClass()));
69:
70: TestHeader2Response val = (TestHeader2Response) obj3[0];
71: assertEquals("Header1", val.getResponseType());
72:
73: val = (TestHeader2Response) obj3[1];
74: assertEquals("Header2", val.getResponseType());
75:
76: }
77:
78: private void setSOAPMessage(SOAPMessageContext context,
79: String resource) throws Exception {
80: InputStream is = getClass().getResourceAsStream(resource);
81: SOAPMessage msg = factory.createMessage(null, is);
82: context.setMessage(msg);
83: }
84: }
|