1   package org.codehaus.xfire.aegis;
2   
3   import java.util.HashMap;
4   import org.codehaus.xfire.aegis.operation.WrappedOperation;
5   import org.codehaus.xfire.aegis.type.BeanType;
6   import org.codehaus.xfire.plexus.PlexusXFireTest;
7   import org.codehaus.xfire.wsdl.WSDL;
8   import org.dom4j.Document;
9   import org.dom4j.DocumentHelper;
10  import org.dom4j.Element;
11  
12  /***
13   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
14   * @since Feb 21, 2004
15   */
16  public class AegisServiceProviderTest
17      extends PlexusXFireTest
18  {
19      public void testServiceRegister() throws Exception
20      {
21          AegisService hello = (AegisService) lookup( AegisService.ROLE, "Book" );
22          
23          assertEquals("http://xfire.codehaus.org/book", hello.getDefaultNamespace());
24          assertEquals("http://www.w3.org/2003/05/soap-envelope", hello.getSoapVersion());
25          
26          assertNotNull( hello.getOperations() );
27          assertEquals( 2, hello.getOperations().size() );
28          
29          WrappedOperation op = (WrappedOperation) hello.getOperations().iterator().next();
30          assertNotNull( op.getRequest() );
31          assertEquals( 1, op.getRequest().size() );
32          assertEquals( "Finds a book.", op.getDocumentation() );
33          
34          assertNotNull( op.getResponse() );
35          assertEquals( 1, op.getResponse().size() );
36          BeanType bt = (BeanType) op.getResponse().get(0);
37          assertNotNull( bt.getChildren() );
38          assertEquals( 3, bt.getChildren().size() );
39          
40          Document doc = DocumentHelper.createDocument();
41          Element root = doc.addElement("root");
42          
43          HashMap map = new HashMap();
44          map.put("author", "Dan Diephouse");
45          map.put("title", "Boring Biography");
46          
47          bt.write(root, map);
48          
49          addNamespace("book", "http://xfire.codehaus.org/book");
50          assertValid("/root/book:Book/book:author[text()='Dan Diephouse']", root);
51          assertValid("/root/book:Book/book:title[text()='Boring Biography']", root);
52      }
53      
54      public void testFindBook() throws Exception
55      {
56          WSDL wsdl = getWSDL("Book");
57  
58          Document wsdlDoc = getWSDLDocument("Book");
59          
60          Document response = invokeService("Book", "/org/codehaus/xfire/aegis/book/FindBook.xml");
61          
62          addNamespace("book", "http://xfire.codehaus.org/book");
63          assertValid("/soap12:Envelope/soap12:Body/book:FindBookResponse/book:Book", response);
64          assertValid("//book:Book/book:author[text()='Dan Diephouse']", response);
65          assertValid("//book:Book/book:title[text()='Boring Biography']", response);
66          assertValid("//book:Book/book:isbn[text()='0123456789']", response);
67     }
68  
69      public void testSearchBooks() throws Exception
70      {
71          Document response = invokeService("Book", "/org/codehaus/xfire/aegis/book/SearchBooks.xml");
72  
73          addNamespace("book", "http://xfire.codehaus.org/book");
74          assertValid("/soap12:Envelope/soap12:Body/book:SearchResponse/book:BookArray", response);
75          assertValid("//book:BookArray/book:Book/book:author[text()='Dan Diephouse']", response);
76          assertValid("//book:BookArray/book:Book/book:title[text()='Boring Biography']", response);
77          assertValid("//book:BookArray/book:Book/book:isbn[text()='0123456789']", response);
78      }
79      
80      public void testPrimitives() throws Exception
81      {
82          Document response = invokeService("Test", "/org/codehaus/xfire/aegis/test/PrimitiveTest.xml");
83          
84          addNamespace("t", "urn:Test");
85          assertValid("/soap12:Envelope/soap12:Body/t:PrimitiveTestResponse/t:string[text()='bleh']", response);
86          assertValid("/soap12:Envelope/soap12:Body/t:PrimitiveTestResponse/t:long[text()='10']", response);
87          assertValid("/soap12:Envelope/soap12:Body/t:PrimitiveTestResponse/t:int[text()='10']", response);
88      }
89      
90      public void testEmptyRequest() throws Exception
91      {
92          Document response = invokeService("Test", "/org/codehaus/xfire/aegis/test/EmptyRequest.xml");
93          
94          addNamespace("book", "urn:Test");
95          assertValid("/soap12:Envelope/soap12:Body/book:EmptyRequestResponse", response);
96          assertValid("//book:EmptyRequestResponse/book:test[text()='test']", response);
97      }
98  
99      public void testEmptyResponse() throws Exception
100     {
101         Document response = invokeService("Test", "/org/codehaus/xfire/aegis/test/EmptyResponse.xml");
102         
103         addNamespace("book", "urn:Test");
104         assertValid("/soap12:Envelope/soap12:Body/book:EmptyResponseResponse", response);
105     }
106     
107     public void testHeaders() throws Exception
108     {
109         Document response = invokeService("Test", "/org/codehaus/xfire/aegis/test/HeaderTest.xml");
110         
111         addNamespace("t", "urn:Test");
112         assertValid("/soap12:Envelope/soap12:Header/t:test[text()='bleh']", response);
113         assertValid("/soap12:Envelope/soap12:Body/t:HeaderTestResponse", response);
114     }
115     
116     public void testFlatArray() throws Exception
117     {
118         Document response = invokeService("Test", "/org/codehaus/xfire/aegis/test/GetFlatArray.xml");
119         
120         addNamespace("t", "urn:Test");
121         assertValid("/soap12:Envelope/soap12:Body/t:GetFlatArrayResponse/t:string[text()='hi']", response);
122         assertValid("/soap12:Envelope/soap12:Body/t:GetFlatArrayResponse/t:string[text()='ho']", response);
123     }
124     
125     /*public void testCustomTypes() throws Exception
126     {
127         WSDL wsdl = getWSDL("Test");
128         Document response = wsdl.getDocument();
129         
130         wsdl.write(System.out);
131         addNamespace("wsdl", WSDL.WSDL11_NS);
132         addNamespace("xsd", SOAPConstants.XSD);
133         assertValid("//xsd:schema[@targetNamespace='urn:Test']/xsd:element[@name='State'][@type='tns:State']", response);
134         assertValid("//xsd:schema[@targetNamespace='urn:Test']/xsd:complexType[@name='State']", response);
135     }*/
136 }