1 package org.codehaus.xfire.message.wrapped;
2
3 import javax.xml.namespace.QName;
4
5 import org.codehaus.xfire.service.object.ObjectService;
6 import org.codehaus.xfire.services.BeanService;
7 import org.codehaus.xfire.services.SimpleBean;
8 import org.codehaus.xfire.soap.SoapConstants;
9 import org.codehaus.xfire.test.AbstractXFireTypeTest;
10 import org.codehaus.xfire.type.TypeMappingRegistry;
11 import org.codehaus.xfire.type.basic.BeanType;
12 import org.codehaus.xfire.wsdl.WSDLWriter;
13 import org.dom4j.Document;
14
15
16 /***
17 * @author <a href="mailto:peter.royal@pobox.com">peter royal</a>
18 */
19 public class WrappedCustomTypeTest extends AbstractXFireTypeTest
20 {
21 ObjectService service;
22
23 public void setUp() throws Exception
24 {
25 super.setUp();
26
27 service = (ObjectService) getServiceBuilder().create(BeanService.class);
28
29 registerSimpleBeanType( getRegistry() );
30 }
31
32 private void registerSimpleBeanType( final TypeMappingRegistry tmr )
33 {
34 service.getTypeMapping().register( SimpleBean.class,
35 new QName( "urn:ReallyNotSoSimpleBean", "SimpleBean" ),
36 new BeanType() );
37 }
38
39 public void testBeanService() throws Exception
40 {
41 final Document response =
42 invokeService( "BeanService",
43 "/org/codehaus/xfire/message/wrapped/WrappedCustomTypeTest.bean11.xml" );
44
45 printNode( response );
46
47 addNamespace( "sb", "http://services.xfire.codehaus.org" );
48 assertValid( "/s:Envelope/s:Body/sb:getSubmitBeanResponse", response );
49 assertValid( "//sb:getSubmitBeanResponse/sb:out", response );
50 assertValid( "//sb:getSubmitBeanResponse/sb:out[text()=\"blah\"]", response );
51 }
52
53 public void testBeanServiceWSDL() throws Exception
54 {
55 final Document doc = getWSDLDocument( "BeanService" );
56
57 addNamespace( "wsdl", WSDLWriter.WSDL11_NS );
58 addNamespace( "wsdlsoap", WSDLWriter.WSDL11_SOAP_NS );
59 addNamespace( "xsd", SoapConstants.XSD );
60
61 assertValid( "/wsdl:definitions/wsdl:types", doc );
62 assertValid( "/wsdl:definitions/wsdl:types/xsd:schema", doc );
63 assertValid( "/wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://services.xfire.codehaus.org']",
64 doc );
65 assertValid(
66 "//xsd:schema[@targetNamespace='http://services.xfire.codehaus.org']/xsd:element[@name='getSubmitBean']",
67 doc );
68 assertValid(
69 "//xsd:element[@name='getSubmitBean']/xsd:complexType/xsd:sequence/xsd:element[@name='in1'][@type='xsd:string']",
70 doc );
71 assertValid(
72 "//xsd:element[@name='getSubmitBean']/xsd:complexType/xsd:sequence/xsd:element[@name='in0'][@type='ns1:SimpleBean']",
73 doc );
74
75 assertValid( "/wsdl:definitions/wsdl:types" +
76 "/xsd:schema[@targetNamespace='urn:ReallyNotSoSimpleBean']" +
77 "/xsd:complexType", doc );
78 assertValid( "/wsdl:definitions/wsdl:types" +
79 "/xsd:schema[@targetNamespace='urn:ReallyNotSoSimpleBean']" +
80 "/xsd:complexType[@name=\"SimpleBean\"]", doc );
81 assertValid( "/wsdl:definitions/wsdl:types" +
82 "/xsd:schema[@targetNamespace='urn:ReallyNotSoSimpleBean']" +
83 "/xsd:complexType[@name=\"SimpleBean\"]/xsd:sequence/xsd:element[@name=\"bleh\"]", doc );
84 assertValid( "/wsdl:definitions/wsdl:types" +
85 "/xsd:schema[@targetNamespace='urn:ReallyNotSoSimpleBean']" +
86 "/xsd:complexType[@name=\"SimpleBean\"]/xsd:sequence/xsd:element[@name=\"howdy\"]", doc );
87 assertValid( "/wsdl:definitions/wsdl:types" +
88 "/xsd:schema[@targetNamespace='urn:ReallyNotSoSimpleBean']" +
89 "/xsd:complexType[@name=\"SimpleBean\"]/xsd:sequence/xsd:element[@type=\"xsd:string\"]", doc );
90
91 assertValid(
92 "/wsdl:definitions/wsdl:service/wsdl:port/wsdlsoap:address[@location='http://localhost/services/BeanService']",
93 doc );
94 }
95 }