KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > wsclients > 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.wsclients;
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_56;
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription: Handler Port Names are valid
41  */

42
43 // portnames : verify that all the portnames exist in the WebService
44
public class HandlerPortNameCheck extends WSClientTest implements WSClientCheck {
45
46     /**
47      * @param descriptor the WebServices descriptor
48      * @return <code>Result</code> the results for this assertion
49      */

50     public Result check (ServiceReferenceDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54
55         if (descriptor.hasHandlers()) {
56            Collection allPortNames = getAllPortNamesInService(descriptor);
57            List handlerChain = descriptor.getHandlerChain();
58            for (Iterator it = handlerChain.iterator(); it.hasNext();) {
59                Collection c = ((WebServiceHandler)it.next()).getPortNames();
60                Collection invalid = getInvalidHandlerPortNames(c,allPortNames);
61                if (invalid.size() > 0) {
62                   //result.fail
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                      "The Port Name(s) in the Handler Chain are invalid."));
68                }
69                else {
70                   //result.pass
71
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
72                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
73                   result.passed(smh.getLocalString (getClass().getName()+ ".passed",
74                   "Port Name(s) in the Handler-Chain are valid."));
75
76                }
77            }
78         }
79         else {
80          // result.NotApplicable
81
result.addNaDetails(smh.getLocalString
82             ("tests.componentNameConstructor", "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
83          result.notApplicable(smh.getLocalString (getClass().getName() + ".notapp",
84            "Not Applicable since No handlers defined in this WebService."));
85         }
86
87         return result;
88     }
89
90    private Collection getAllPortNamesInService(ServiceReferenceDescriptor descriptor) {
91
92        Collection endPoints = descriptor.getPortsInfo();
93        Vector<String JavaDoc> ret = new Vector<String JavaDoc>();
94        for (Iterator it = endPoints.iterator(); it.hasNext();) {
95            ret.add(((ServiceRefPortInfo)it.next()).getPortComponentLinkName());
96        }
97     return ret;
98    }
99
100    private Collection getInvalidHandlerPortNames(Collection hpNames, Collection allPortNames) {
101        
102       Vector<String JavaDoc> ret = new Vector<String JavaDoc>();
103       for (Iterator it = hpNames.iterator(); it.hasNext();) {
104           String JavaDoc currName = (String JavaDoc)it.next();
105           if (!allPortNames.contains(currName))
106               ret.add(currName);
107       }
108     return ret;
109    }
110  }
111
112
Popular Tags