KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > webservices > ServletUrlPatternExactCheck


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier.tests.webservices;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.*;
27 import java.util.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import java.lang.reflect.*;
30
31 /*
32  * @class.setup_props: ;
33  */

34
35 /*
36  * @testName: check
37  * @assertion_ids: JSR109_WS_27;
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription: The urlpattern of the servlet-mapping must be an exact match pattern
41  * (i.e. it must not contain an asterisk (?*?)).
42  */

43
44 public class ServletUrlPatternExactCheck extends WSTest implements WSCheck {
45
46     /**
47      * @param descriptor the WebServices descriptor
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check (WebServiceEndpoint desc) {
51
52     Result result = getInitializedResult();
53         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55         boolean pass = true;
56
57         if (desc.implementedByWebComponent()) {
58             WebBundleDescriptor webBundle = (WebBundleDescriptor)desc.getBundleDescriptor();
59             WebComponentDescriptor webComponent =
60                 (WebComponentDescriptor) webBundle.
61                 getWebComponentByCanonicalName(desc.getWebComponentLink());
62             if(webComponent != null && webComponent.isServlet()) {
63                 Enumeration en = webComponent.getUrlPatterns();
64                 while(en.hasMoreElements()) {
65                   String JavaDoc pattern =(String JavaDoc) en.nextElement();
66                   if (pattern.indexOf("*") == -1) {
67                      // result.pass
68
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
69                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
70                       result.passed(smh.getLocalString (getClass().getName() + ".passed",
71                       "The urlpattern for this servlet-mapping [{0}] is exact.",
72                       new Object JavaDoc[] {pattern}));
73                      
74                   }
75                   else {
76                      // result.fail
77
result.addErrorDetails(smh.getLocalString
78                                   ("tests.componentNameConstructor", "For [ {0} ]",
79                                    new Object JavaDoc[] {compName.toString()}));
80                      result.failed(smh.getLocalString (getClass().getName() + ".failed",
81                      "The urlpattern for this servlet-mapping [{0}] contains '*' and is not exact.",
82                      new Object JavaDoc[] {pattern}));
83
84                      pass = false;
85                   }
86                   // we assume there is one servlet-mapping specified,
87
// this check is done in another test
88
break;
89                 }
90             }
91          }
92          else {
93            //result.notapp
94
result.addNaDetails(smh.getLocalString
95                      ("tests.componentNameConstructor", "For [ {0} ]",
96                       new Object JavaDoc[] {compName.toString()}));
97             result.notApplicable(smh.getLocalString
98                  (getClass().getName() + ".notapp",
99                  "Not Applicable since this not a JAX-RPC Service Endpoint."));
100          }
101
102         return result;
103     }
104  }
105
106
Popular Tags