KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > wsclients > WSDLFileCheck


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.deployment.deploy.shared.FileArchive;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import java.io.*;
30 import java.net.URL JavaDoc;
31
32 /*
33  * @class.setup_props: ;
34  */

35
36 /*
37  * @testName: check
38  * @assertion_ids: JSR109_WS_50;
39  * @test_Strategy:
40  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
41  * @testDescription: The wsdl-file element specifies a location of the WSDL description of the
42  * service. The location is relative to the root of the module. The WSDL description may be a
43  * partial WSDL, but must at least include the portType and binding elements.
44  */

45
46 public class WSDLFileCheck extends WSClientTest implements WSClientCheck {
47
48     /**
49      * @param descriptor the WebServices descriptor
50      * @return <code>Result</code> the results for this assertion
51      */

52     public Result check (ServiceReferenceDescriptor descriptor) {
53
54         Result result = getInitializedResult();
55         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56
57         InputStream deploymentEntry=null;
58
59         // wsdl file
60
if (descriptor.hasWsdlFile()) {
61             String JavaDoc wsdlUri = descriptor.getWsdlFileUri();
62             URL JavaDoc url = null;
63             try {
64                 url = new URL JavaDoc(wsdlUri);
65             } catch(java.net.MalformedURLException JavaDoc e) {
66                 // don't care, will eventuall fail below
67
}
68             if (url != null) {
69                 if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol())) {
70                     return result;
71                 }
72             }
73             try {
74                 String JavaDoc uri = getAbstractArchiveUri(descriptor);
75                 FileArchive arch = new FileArchive();
76                 arch.open(uri);
77                 deploymentEntry = arch.getEntry(wsdlUri);
78
79                 if (deploymentEntry == null) {
80                     //result.fail,
81
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
82                             "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
83                     result.failed(smh.getLocalString (getClass().getName() + ".failed",
84                             "WSDL file does not exist in the archive at uri [{0}].",
85                             new Object JavaDoc[] {wsdlUri}));
86                 }
87                 else {
88                     //result.pass
89
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
90                             "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
91                     result.passed(smh.getLocalString (getClass().getName() + ".passed",
92                             "WSDL file exists in the archive at uri [{0}].",
93                             new Object JavaDoc[] {wsdlUri}));
94
95                 }
96             }catch (Exception JavaDoc e) {
97                 // result.fail
98
result.addErrorDetails(smh.getLocalString
99                         ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
100                                 "Error: Unexpected error occurred [ {0} ]",
101                                 new Object JavaDoc[] {e.getMessage()}));
102             }
103             finally {
104                 try {
105                     if (deploymentEntry != null)
106                         deploymentEntry.close();
107                 }catch (IOException e) {}
108             }
109
110         }
111         else {
112             //result.notapplicable since no wsdl specified
113
result.addNaDetails(smh.getLocalString
114                     ("tests.componentNameConstructor", "For [ {0} ]",
115                             new Object JavaDoc[] {compName.toString()}));
116             result.notApplicable(smh.getLocalString
117                     ( getClass().getName() + ".notapp",
118                             "Not applicable since Service Client does not have a WSDL file specified."));
119
120         }
121
122         return result;
123     }
124  }
125
126
Popular Tags