Debian Codegraph @

test/wsdl/extensibility/ExtensibilityQueryTestCase.java

raw
1 /**
2 * ExtensibilityQueryTestCase.java
3 *
4 * This file was auto-generated from WSDL
5 * by the Apache Axis Wsdl2java emitter.
6 */
7
8 package test.wsdl.extensibility;
9
10 import org.apache.axis.client.AdminClient;
11 import org.apache.axis.components.logger.LogFactory;
12 import org.apache.axis.message.MessageElement;
13 import org.apache.axis.message.Text;
14 import org.apache.axis.utils.Options;
15 import org.apache.commons.logging.Log;
16 import org.apache.log4j.Logger;
17
18 import javax.xml.namespace.QName;
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.InputStream;
22 import java.util.Calendar;
23
24 public class ExtensibilityQueryTestCase extends junit.framework.TestCase {
25 protected static Log log =
26 LogFactory.getLog(ExtensibilityQueryTestCase.class.getName());
27
28 public ExtensibilityQueryTestCase(String name) {
29 super(name);
30 }
31
32 public void testExtensibilityQueryPortWSDL() throws Exception {
33 javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
34 java.net.URL url = new java.net.URL(new test.wsdl.extensibility.ExtensibilityQueryLocator().getExtensibilityQueryPortAddress() + "?WSDL");
35 javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.extensibility.ExtensibilityQueryLocator().getServiceName());
36 assertTrue(service != null);
37 }
38
39 public void testQuery() {
40 ExtensibilityQueryPortType binding;
41 try {
42 ExtensibilityQueryLocator locator = new ExtensibilityQueryLocator();
43 binding = locator.getExtensibilityQueryPort();
44 deployServer();
45 }
46 catch (javax.xml.rpc.ServiceException jre) {
47 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
48 }
49 catch (Exception e) {
50 throw new junit.framework.AssertionFailedError("Binding initialization Exception caught: " + e);
51 }
52 assertTrue("binding is null", binding != null);
53
54 try {
55 ExtensibilityType expression = new ExtensibilityType();
56 BookType book = new BookType();
57 book.setSubject("all");
58 QName elementName = FindBooksQueryExpressionElement.getTypeDesc().getFields()[0].getXmlName();
59 MessageElement el = new MessageElement(elementName.getNamespaceURI(), elementName.getLocalPart(), book);
60 expression.set_any(new MessageElement [] { el });
61 // call the operation
62 ExtensibilityType any = binding.query(expression);
63 // validate results
64 MessageElement [] anyContent = any.get_any();
65 assertEquals(1, anyContent.length);
66 ResultListType result = (ResultListType)anyContent[0].getObjectValue(ResultListType.class);
67 log.debug("Message " + result + ": " + anyContent[0].toString());
68 assertNotNull("ResultListType back from getResultList() is null", result);
69 QueryResultType[] queryResult = result.getResult();
70 assertTrue(queryResult.length == 2);
71 isValid(queryResult[0], "Computer Science", "The Grid");
72 isValid(queryResult[1], "English", "The Oxford Dictionary");
73 }
74 catch (Exception e) {
75 e.printStackTrace();
76 throw new junit.framework.AssertionFailedError("Exception caught: " + e);
77 }
78 }
79
80 public void testMixedQuery() {
81 ExtensibilityQueryPortType binding;
82 try {
83 ExtensibilityQueryLocator locator = new ExtensibilityQueryLocator();
84 binding = locator.getExtensibilityQueryPort();
85 deployServer();
86 }
87 catch (javax.xml.rpc.ServiceException jre) {
88 throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
89 }
90 catch (Exception e) {
91 throw new junit.framework.AssertionFailedError("Binding initialization Exception caught: " + e);
92 }
93 assertTrue("binding is null", binding != null);
94
95 try {
96 ExtensibilityType expression = new ExtensibilityType();
97
98 MessageElement [] elements = new MessageElement[4];
99
100 elements[0] = new MessageElement(new Text("123"));
101 elements[1] = new MessageElement(new Text(" 456"));
102
103 BookType book = new BookType();
104 book.setSubject("all");
105 QName elementName = FindBooksQueryExpressionElement.getTypeDesc().getFields()[0].getXmlName();
106 elements[2] = new MessageElement(elementName.getNamespaceURI(), elementName.getLocalPart(), book);
107
108 elements[3] = new MessageElement(new Text("789"));
109
110 expression.set_any(elements);
111
112 // call the operation
113 ExtensibilityType any = binding.mixedQuery(expression);
114
115 if (any == null) {
116 throw new Exception("No output returned");
117 }
118
119 // validate results
120 MessageElement [] anyContent = any.get_any();
121
122 if (anyContent == null) {
123 throw new Exception("No any");
124 }
125 if (anyContent.length != 2) {
126 throw new Exception("Expected: 2 got: " +
127 anyContent.length + " element");
128 }
129
130 Object obj = anyContent[0].getObjectValue(BookType.class);
131 BookType bookQuery = (BookType)obj;
132 String subject = bookQuery.getSubject();
133 if (!"gotAll".equals(subject)) {
134 throw new Exception("Book subject query reply should be gotAll, instead was " + subject);
135 }
136
137 String expected = "ABCD";
138 String received = anyContent[1].toString();
139
140 if (!expected.equals(received)) {
141 throw new Exception("Expected: " + expected +
142 " received: " + received);
143 }
144
145 }
146 catch (Exception e) {
147 e.printStackTrace();
148 throw new junit.framework.AssertionFailedError("Exception caught: " + e);
149 }
150 }
151
152 private void isValid(QueryResultType result, String name, String value) {
153 Logger root = Logger.getRootLogger();
154 root.debug("Name: " + result.getName());
155 root.debug("Value: " + result.getValue());
156 assertTrue(result.getName().equals(name));
157 assertTrue(result.getValue().equals(value));
158 assertTrue(result.getStatus().equals(StatusType.MORE));
159 Calendar now = Calendar.getInstance();
160 Calendar then = result.getTime();
161 assertTrue("Time check failed. Result time = " + then + ", current time = " + now, then.before(now));
162 assertTrue(result.getQueryType().getNamespaceURI().equals("urn:QueryType"));
163 assertTrue(result.getQueryType().getLocalPart().equals("BookQuery"));
164 }
165
166 private void deployServer() {
167 final String INPUT_FILE = "server-deploy.wsdd";
168
169 InputStream is = getClass().getResourceAsStream(INPUT_FILE);
170 if (is == null) {
171 // try current directory
172 try {
173 is = new FileInputStream(INPUT_FILE);
174 } catch (FileNotFoundException e) {
175 is = null;
176 }
177 }
178 assertNotNull("Unable to find " + INPUT_FILE + ". Make sure it is on the classpath or in the current directory.", is);
179 AdminClient admin = new AdminClient();
180 try {
181 Options opts = new Options( null );
182 opts.setDefaultURL("http://localhost:8080/axis/services/AdminService");
183 admin.process(opts, is);
184 } catch (Exception e) {
185 assertTrue("Unable to deploy " + INPUT_FILE + ". ERROR: " + e, false);
186 }
187 }
188
189 public void testMixedType() {
190 MixedType1 t1 = new MixedType1();
191 assertTrue(t1 instanceof org.apache.axis.encoding.MixedContentType);
192 // restriction cases
193 MixedType2 t2 = new MixedType2();
194 assertFalse(t2 instanceof org.apache.axis.encoding.MixedContentType);
195 MixedType3 t3 = new MixedType3();
196 assertFalse(t3 instanceof org.apache.axis.encoding.MixedContentType);
197 }
198
199 public void testAnyAttribute() {
200 // if everything is right the AttributedURI class should be generated
201 AttributedURI uri = new AttributedURI();
202 assertTrue(uri instanceof org.apache.axis.encoding.SimpleType);
203 }
204
205 }
206