KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 /*
31  * @class.setup_props: ;
32  */

33
34 /*
35  * @testName: check
36  * @assertion_ids: JSR109_WS_26;
37  * @test_Strategy:
38  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
39  * @testDescription: No more than one servlet mapping may be specified for a servlet that is
40  * linked to by a port-component.
41  */

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

49     public Result check (WebServiceEndpoint desc) {
50
51     Result result = getInitializedResult();
52         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         if (desc.implementedByWebComponent()) {
55             WebBundleDescriptor webBundle = (WebBundleDescriptor)desc.getBundleDescriptor();
56             WebComponentDescriptor webComponent =
57                 (WebComponentDescriptor) webBundle.
58                 getWebComponentByCanonicalName(desc.getWebComponentLink());
59             if(webComponent != null && webComponent.isServlet()) {
60                int sz = getSize(webComponent.getUrlPatternsSet());
61                if (sz == 0) {
62                   //result.fail , no servlet-mapping for servlet linked to port-component
63
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
64                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
65                   result.failed(smh.getLocalString
66                        (getClass().getName() + ".failed",
67                        "Found [{0}] servlet mappings for the servlet linked to by this port-component.",
68                        new Object JavaDoc[] {"0"}));
69                }
70                if (sz > 1) {
71                   //result.fail , more than one servlet-mapping for servlet linked to port-component
72
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
73                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
74                   result.failed(smh.getLocalString
75                        (getClass().getName() + ".failed",
76                        "Found [{0}] servlet mappings for the servlet linked to by this port-component.",
77                        new Object JavaDoc[] {Integer.toString(sz)}));
78                 }
79                 else {
80                   //result.pass , one servlet-mapping for servlet linked to port-component
81
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
82                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
83                    result.passed(smh.getLocalString (getClass().getName() + ".passed",
84                    "Found only one servlet mapping for the servlet linked to by this port-component."));
85
86                 }
87             }
88          }
89          else {
90
91             result.addNaDetails(smh.getLocalString
92                      ("tests.componentNameConstructor", "For [ {0} ]",
93                       new Object JavaDoc[] {compName.toString()}));
94             result.notApplicable(smh.getLocalString(getClass().getName() + ".notapp",
95                  " Not applicable since this is Not a JAX-RPC Service Endpoint."));
96
97          }
98
99         return result;
100     }
101
102     /**
103      * This is a hack, since descriptors from backend contain
104      * an extra url pattern.
105      * @param urlPatterns
106      * @return
107      */

108     private int getSize(Set urlPatterns) {
109         int size = urlPatterns.size();
110         if (getVerifierContext().isAppserverMode()) //only if backend
111
for (Object JavaDoc url : urlPatterns) {
112                 String JavaDoc urlPattern = (String JavaDoc)url;
113                 if(urlPattern.indexOf("__container") != -1)
114                     size--;
115             }
116         return size;
117     }
118  }
119
120
Popular Tags