KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > dd > web > unit > WebIntegrationUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.dd.web.unit;
23
24 import java.net.URL JavaDoc;
25
26 import junit.framework.Test;
27
28 import org.jboss.test.JBossTestCase;
29 import org.jboss.ejb3.test.dd.web.util.HttpUtils;
30
31 /** Tests of servlet container integration into the JBoss server. This test
32  requires than a web container be integrated into the JBoss server. The tests
33  currently do NOT use the java.net.HttpURLConnection and associated http client
34  and these do not return valid HTTP error codes so if a failure occurs it
35  is best to connect the webserver using a browser to look for additional error
36  info.
37
38  The secure access tests require a user named 'jduke' with a password of 'theduke'
39  with a role of 'AuthorizedUser' in the servlet container.
40  
41  @author Scott.Stark@jboss.org
42  @version $Revision: 56407 $
43  */

44 public class WebIntegrationUnitTestCase extends JBossTestCase
45 {
46    private static String JavaDoc REALM = "JBossTest Servlets";
47    private String JavaDoc baseURL = HttpUtils.getBaseURL();
48    private String JavaDoc baseURLNoAuth = HttpUtils.getBaseURLNoAuth();
49    
50    public WebIntegrationUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54    
55    public void testEJBServlet() throws Exception JavaDoc
56    {
57       try {
58          URL JavaDoc url = new URL JavaDoc(baseURL+"dd/EJBServlet");
59          HttpUtils.accessURL(url);
60       } catch (Exception JavaDoc e){
61          e.printStackTrace();
62          throw e;
63       }
64    }
65
66
67    /*
68    public void testInjectionJsp() throws Exception
69    {
70       try {
71          URL url = new URL(baseURL+"dd/InjectionTest.jsp");
72          HttpUtils.accessURL(url);
73       } catch (Exception e){
74          e.printStackTrace();
75          throw e;
76       }
77    }
78    */

79
80 /*
81    public void testRealPath() throws Exception
82    {
83       URL url = new URL(baseURL+"dd/APIServlet?op=testGetRealPath");
84       HttpUtils.accessURL(url);
85    }
86
87    public void testHttpSessionListener() throws Exception
88    {
89       URL url = new URL(baseURL+"dd/APIServlet?op=testSessionListener");
90       HttpUtils.accessURL(url);
91    }
92
93    public void testEJBOnStartupServlet() throws Exception
94    {
95       URL url = new URL(baseURL+"dd/EJBOnStartupServlet");
96       HttpUtils.accessURL(url);
97    }
98    
99    public void testStatefulSessionServlet() throws Exception
100    {
101       URL url = new URL(baseURL+"dd/StatefulSessionServlet");
102       HttpUtils.accessURL(url);
103       // Need a mechanism to force passivation...
104       HttpUtils.accessURL(url);
105    }
106    
107    public void testSnoopJSP() throws Exception
108    {
109       URL url = new URL(baseURL+"dd/snoop.jsp");
110       HttpUtils.accessURL(url);
111    }
112   
113    public void testSpeedServlet() throws Exception
114    {
115       URL url = new URL(baseURL+"dd/SpeedServlet");
116       HttpUtils.accessURL(url);
117    }
118
119    public void testSnoopJSPByPattern() throws Exception
120    {
121       URL url = new URL(baseURL+"dd/test-snoop.snp");
122       HttpUtils.accessURL(url);
123    }
124   
125    public void testSnoopJSPByMapping() throws Exception
126    {
127       URL url = new URL(baseURL+"dd/test-jsp-mapping");
128       HttpUtils.accessURL(url);
129    }
130   
131    public void testJSPClasspath() throws Exception
132    {
133       URL url = new URL(baseURL+"dd/classpath.jsp");
134       HttpUtils.accessURL(url);
135    }
136
137    public void testClientLoginServlet() throws Exception
138    {
139       URL url = new URL(baseURL+"dd/ClientLoginServlet");
140       HttpUtils.accessURL(url);
141    }
142   
143    public void testUserInRoleServlet() throws Exception
144    {
145       URL url = new URL(baseURL+"dd/restricted/UserInRoleServlet");
146       HttpMethodBase request = HttpUtils.accessURL(url);
147       Header errors = request.getResponseHeader("X-ExpectedUserRoles-Errors");
148       log.info("X-ExpectedUserRoles-Errors: "+errors);
149       assertTrue("X-ExpectedUserRoles-Errors("+errors+") is null", errors == null);
150       errors = request.getResponseHeader("X-UnexpectedUserRoles-Errors");
151       log.info("X-UnexpectedUserRoles-Errors: "+errors);
152       assertTrue("X-UnexpectedUserRoles-Errors("+errors+") is null", errors == null);
153    }
154   
155    public void testSecureServlet() throws Exception
156    {
157       URL url = new URL(baseURL+"dd/restricted/SecureServlet");
158       HttpUtils.accessURL(url);
159    }
160  
161    public void testSecureServlet2() throws Exception
162    {
163       URL url = new URL(baseURL+"dd/restricted2/SecureServlet");
164       HttpUtils.accessURL(url);
165    }
166  
167    public void testSubjectServlet() throws Exception
168    {
169       URL url = new URL(baseURL+"dd/restricted/SubjectServlet");
170       HttpMethodBase request = HttpUtils.accessURL(url);
171       Header hdr = request.getResponseHeader("X-SubjectServlet");
172       log.info("X-SubjectServlet: "+hdr);
173       assertTrue("X-SubjectServlet("+hdr+") is NOT null", hdr != null);
174       hdr = request.getResponseHeader("X-SubjectFilter-ENC");
175       log.info("X-SubjectFilter-ENC: "+hdr);
176       assertTrue("X-SubjectFilter-ENC("+hdr+") is NOT null", hdr != null);
177       hdr = request.getResponseHeader("X-SubjectFilter-SubjectSecurityManager");
178       log.info("X-SubjectFilter-SubjectSecurityManager: "+hdr);
179       assertTrue("X-SubjectFilter-SubjectSecurityManager("+hdr+") is NOT null", hdr != null);
180    }
181   
182    public void testSecureServletAndUnsecureAccess() throws Exception
183    {
184       getLog().info("+++ testSecureServletAndUnsecureAccess");
185       URL url = new URL(baseURL+"dd/restricted/SecureServlet");
186       getLog().info("Accessing SecureServlet with valid login");
187       HttpUtils.accessURL(url);
188       String baseURL2 = "http://localhost:" + Integer.getInteger("web.port", 8080) + '/';
189       URL url2 = new URL(baseURL2+"dd/restricted/UnsecureEJBServlet");
190       getLog().info("Accessing SecureServlet with no login");
191       HttpUtils.accessURL(url2, REALM, HttpURLConnection.HTTP_UNAUTHORIZED);
192    }
193   
194    public void testSecureServletWithBadPass() throws Exception
195    {
196       String baseURL = "http://jduke:badpass@localhost:" + Integer.getInteger("web.port", 8080) + '/';
197       URL url = new URL(baseURL+"dd/restricted/SecureServlet");
198       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_UNAUTHORIZED);
199    }
200  
201    public void testSecureServletWithNoLogin() throws Exception
202    {
203       String baseURL = "http://localhost:" + Integer.getInteger("web.port", 8080) + '/';
204       URL url = new URL(baseURL+"dd/restricted/SecureServlet");
205       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_UNAUTHORIZED);
206    }
207   
208    public void testNotJbosstest() throws Exception
209    {
210       String baseURL = "http://localhost:" + Integer.getInteger("web.port", 8080) + '/';
211       URL url = new URL(baseURL+"jbosstest-not/unrestricted/SecureServlet");
212       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
213    }
214   
215    public void testSecureEJBAccess() throws Exception
216    {
217       URL url = new URL(baseURL+"dd/restricted/SecureEJBAccess");
218       HttpUtils.accessURL(url);
219    }
220   
221    public void testIncludeEJB() throws Exception
222    {
223       URL url = new URL(baseURL+"dd/restricted/include_ejb.jsp");
224       HttpUtils.accessURL(url);
225    }
226  
227    public void testUnsecureEJBAccess() throws Exception
228    {
229       URL url = new URL(baseURLNoAuth+"dd/UnsecureEJBAccess?method=echo");
230       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_INTERNAL_ERROR);
231    }
232  
233    public void testUnsecureAnonEJBAccess() throws Exception
234    {
235       URL url = new URL(baseURLNoAuth+"dd/UnsecureEJBAccess?method=unchecked");
236       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
237    }
238
239    public void testUnsecureRunAsServlet() throws Exception
240    {
241       URL url = new URL(baseURLNoAuth+"dd/UnsecureRunAsServlet?method=checkRunAs");
242       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
243    }
244
245    public void testUnsecureRunAsServletWithPrincipalName() throws Exception
246    {
247       URL url = new URL(baseURLNoAuth+"dd/UnsecureRunAsServletWithPrincipalName?ejbName=ejb/UnsecureRunAsServletWithPrincipalNameTarget");
248       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
249    }
250
251    public void testUnsecureRunAsServletWithPrincipalNameAndRoles() throws Exception
252    {
253       URL url = new URL(baseURLNoAuth+"dd/UnsecureRunAsServletWithPrincipalNameAndRoles?ejbName=ejb/UnsecureRunAsServletWithPrincipalNameAndRolesTarget");
254       HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
255    }
256    */

257    
258    /**
259     * Setup the test suite.
260     */

261    public static Test suite() throws Exception JavaDoc
262    {
263       return getDeploySetup(WebIntegrationUnitTestCase.class, "dd-web.ear");
264    }
265
266
267 }
268
Popular Tags