Debian Codegraph @

test/httpunit/ServicesTest.java

raw
1 /*
2 * Copyright 2002-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package test.httpunit;
19
20 import com.meterware.httpunit.WebRequest;
21 import com.meterware.httpunit.GetMethodWebRequest;
22 import com.meterware.httpunit.WebResponse;
23
24 /**
25 * test the services
26 * @author Steve Loughran
27 * @created Jul 10, 2002 12:09:06 AM
28 */
29
30 public class ServicesTest extends HttpUnitTestBase {
31
32 private String services;
33
34 private String invalid_service;
35
36
37 public ServicesTest(String name) {
38 super(name);
39 }
40
41 /**
42 * The JUnit setup method
43 *
44 */
45 public void setUp() throws Exception {
46 super.setUp();
47 services=url+"/services/";
48 invalid_service=services+"invalid-name";
49 }
50
51 /**
52 * what string do we take as meaning services are present.
53 */
54 private final static String services_text="Some Services";
55
56 private final static String hi_there="Hi there, this is an AXIS service!";
57 /**
58 * verify the /servlet url is there
59 * @throws Exception
60 */
61 public void testServlet() throws Exception {
62 WebRequest request = new GetMethodWebRequest(url+"/servlet/AxisServlet");
63 assertStringInBody(request,services_text);
64 }
65
66 /**
67 * verify the services url works
68 */
69 public void testServices() throws Exception {
70 WebRequest request = new GetMethodWebRequest(services);
71 expectErrorCode(request,404, null);
72 }
73
74 /**
75 * @todo decide on the exception to throw in the servlet, write the
76 * test then fix the servlet
77 * @throws Exception
78 */
79 public void testInvalidServiceRaisesError() throws Exception {
80 WebRequest request = new GetMethodWebRequest(invalid_service);
81 expectErrorCode(request,404, null);
82 }
83
84 /**
85 * A missing wsdl page should be a 404 error;
86 * @throws Exception
87 */
88 public void testInvalidServiceWsdlRaisesError() throws Exception {
89 WebRequest request = new GetMethodWebRequest(invalid_service+"?wsdl");
90 // "The AXIS engine could not find a target service to invoke!");
91 expectErrorCode(request,404, null);
92 }
93
94 /**
95 * test version call
96 * @throws Exception
97 */
98 public void testVersionWSDL() throws Exception {
99 WebRequest request = new GetMethodWebRequest(services
100 +"Version?wsdl");
101 assertStringInBody(request,"<wsdl:definitions");
102 }
103
104 /**
105 * test version call
106 * @throws Exception
107 */
108 public void testVersionMethod() throws Exception {
109 WebRequest request = new GetMethodWebRequest(services
110 + "Version?method=getVersion");
111 WebResponse response=makeRequest(request);
112 String body = response.getText();
113 assertTrue(body.indexOf("<?xml") ==0);
114 assertTrue(body.indexOf("<getVersionReturn")>0);
115 }
116
117 /**
118 * test a get without any method
119 * @throws Exception
120 */
121 public void testVersionNoMethod() throws Exception {
122 WebRequest request = new GetMethodWebRequest(services
123 + "Version?arg1=foo&arg2=bar");
124 expectErrorCode(request, 400, null);
125 }
126
127
128 }