KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 /*
36  * @testName: check
37  * @assertion_ids: JSR109_WS_51;
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription: The developer must specify the jaxrpc-mapping-file if the wsdl-file is
41  * specified. jaxrpc-mapping-file The file name is a relative path within the module.
42  */

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

49     public Result check (ServiceReferenceDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         if (descriptor.hasWsdlFile()) {
55
56            if(descriptor.hasMappingFile()) {
57              //result.pass
58
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
59                                     "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
60              result.passed(smh.getLocalString (getClass().getName() + ".passed1",
61                            "Mapping file specified because WSDL file is also specified."));
62
63            }
64            else {
65              //result.fail, has wsdl but no mapping
66
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
67                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
68              result.failed(smh.getLocalString (getClass().getName() + ".failed1",
69                 "The webservice client [{0}] has a WSDL file specified but no Mapping File.",
70                  new Object JavaDoc[] {compName.toString()}));
71            }
72          }
73          else {
74            if(descriptor.hasMappingFile()) {
75              //result.fail, mapping without WSDL
76
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
77                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
78              result.failed(smh.getLocalString (getClass().getName() + ".failed1",
79                 "The webservice client [{0}] has a Mapping file specified but no WSDL File.",
80                  new Object JavaDoc[] {compName.toString()}));
81            }
82            else {
83              //result.pass, neither WSDL nor Mapping
84
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
85                                     "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
86               result.passed(smh.getLocalString (getClass().getName() + ".passed2",
87                            "Mapping file found at location [{0}] in archive.",
88                            new Object JavaDoc[] {descriptor.getMappingFileUri()}));
89            }
90         }
91
92         if (descriptor.hasMappingFile()) {
93            // maybe we should not depend on DOL to get the location of Mapping file
94
String JavaDoc mappingFile = descriptor.getMappingFileUri();
95
96 // File f = Verifier.getArchiveFile(descriptor.getBundleDescriptor().
97
// getModuleDescriptor().getArchiveUri());
98
// JarFile jarFile = null;
99
InputStream deploymentEntry=null;
100
101            try {
102           
103 // if (f == null) {
104
String JavaDoc uri = getAbstractArchiveUri(descriptor);
105 // try {
106
FileArchive arch = new FileArchive();
107                     arch.open(uri);
108                     deploymentEntry = arch.getEntry(mappingFile);
109 // }catch (IOException e) { throw e;}
110
// }
111
// else {
112
//
113
// jarFile = new JarFile(f);
114
// ZipEntry deploymentEntry1 =
115
// jarFile.getEntry(mappingFile);
116
// deploymentEntry = jarFile.getInputStream(deploymentEntry1);
117
// }
118
if (deploymentEntry == null) {
119                   //result.fail, mapping file does not exist at that location
120
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
121                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
122                    result.failed(smh.getLocalString (getClass().getName() + ".failed",
123                     "The mapping file does not exist at the specified location [{0}] in the archive.",
124                    new Object JavaDoc[] {mappingFile}));
125                }
126                else {
127
128                     result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
129                                     "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
130                     result.passed(smh.getLocalString (getClass().getName() + ".passed",
131                            "Mapping file found at location [{0}] in archive.",
132                            new Object JavaDoc[] {mappingFile}));
133                }
134            }catch (Exception JavaDoc e) {
135              // result.fail, mapping file does not exist at that location
136
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
137                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
138              result.failed(smh.getLocalString (getClass().getName() + ".failed",
139               "The mapping file does not exist at the specified location [{0}] in the archive.",
140                new Object JavaDoc[] {mappingFile}));
141
142            }
143            finally {
144               try {
145               if (deploymentEntry != null)
146                   deploymentEntry.close();
147               }catch(IOException e) {}
148            }
149         }
150         else {
151            //result.notapplicable. Mapping file exists check not applicable
152
result.addNaDetails(smh.getLocalString
153                      ("tests.componentNameConstructor", "For [ {0} ]",
154                       new Object JavaDoc[] {compName.toString()}));
155             result.notApplicable(smh.getLocalString
156                  ( getClass().getName() + ".notapp",
157                  "This webservice client does not have a Mapping File."));
158         }
159
160         return result;
161     }
162  }
163
164
Popular Tags