KickJava   Java API By Example, From Geeks To Geeks.

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


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 // portnames : verify that all the portnames exist in the WebService
32
/*
33  * @class.setup_props: ;
34  */

35
36 /*
37  * @testName: check
38  * @assertion_ids: JSR109_WS_45;
39  * @test_Strategy:
40  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
41  * @testDescription: Handler Port Name is a valid portname
42  */

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

49     public Result check (WebServiceEndpoint descriptor) {
50
51     Result result = getInitializedResult();
52         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         boolean pass = true;
55
56         if (descriptor.hasHandlers()) {
57            Collection allPortNames = getAllPortNamesInService(descriptor);
58            List handlerChain = descriptor.getHandlerChain();
59            for (Iterator it = handlerChain.iterator(); it.hasNext();) {
60                Collection c = ((WebServiceHandler)it.next()).getPortNames();
61                Collection invalid = getInvalidHandlerPortNames(c,allPortNames);
62                if (invalid.size() > 0) {
63                   //result.fail
64
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
65                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
66                  result.failed(smh.getLocalString
67                   ("com.sun.enterprise.tools.verifier.tests.webservices.failed",
68                    "[{0}]", new Object JavaDoc[] {"The Port Name(s) in the Handler Chain are invalid"}));
69
70                   pass = false;
71                }
72                else {
73                   //result.pass
74
result.addGoodDetails(smh.getLocalString
75                                   ("tests.componentNameConstructor",
76                                    "For [ {0} ]",
77                                    new Object JavaDoc[] {compName.toString()}));
78                   result.passed(smh.getLocalString (
79                   "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
80                   new Object JavaDoc[] {"Port Name(s) in the Handler-Chain are valid"}));
81
82                }
83            }
84         }
85         else {
86          // result.NotApplicable
87
result.addNaDetails(smh.getLocalString
88             ("tests.componentNameConstructor", "For [ {0} ]",
89              new Object JavaDoc[] {compName.toString()}));
90          result.notApplicable(smh.getLocalString
91           ("com.sun.enterprise.tools.verifier.tests.webservices.notapp",
92            "[{0}]", new Object JavaDoc[] {"Not Applicable since No handlers defined in this WebService"}));
93
94         }
95
96         return result;
97     }
98
99    private Collection getAllPortNamesInService(WebServiceEndpoint descriptor) {
100
101        Collection endPoints = descriptor.getWebService().getEndpoints();
102        Vector<String JavaDoc> ret = new Vector<String JavaDoc>();
103        for (Iterator it = endPoints.iterator(); it.hasNext();) {
104            ret.add(((WebServiceEndpoint)it.next()).getEndpointName());
105        }
106     return ret;
107    }
108
109    private Collection getInvalidHandlerPortNames(Collection hpNames, Collection allPortNames) {
110        
111       Vector<String JavaDoc> ret = new Vector<String JavaDoc>();
112       for (Iterator it = hpNames.iterator(); it.hasNext();) {
113           String JavaDoc currName = (String JavaDoc)it.next();
114           if (!allPortNames.contains(currName))
115               ret.add(currName);
116       }
117     return ret;
118    }
119  }
120
121
Popular Tags