KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > LibDirExists


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.web;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.*;
27 import java.io.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Servlet lib directory resides in WEB-INF/lib directory test.
34  */

35 public class LibDirExists extends WebTest implements WebCheck {
36
37     final String JavaDoc servletLibDirPath = "WEB-INF/lib";
38       
39     /**
40      * Servlet lib directory resides in WEB-INF/lib directory test.
41      *
42      * @param descriptor the Web deployment descriptor
43      *
44      * @return <code>Result</code> the results for this assertion
45      */

46     public Result check(WebBundleDescriptor descriptor) {
47
48     Result result = getInitializedResult();
49     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
50
51     if (!descriptor.getServletDescriptors().isEmpty()) {
52         boolean oneFailed = false;
53         int na = 0;
54         boolean foundIt = false;
55         // get the servlets in this .war
56
Set servlets = descriptor.getServletDescriptors();
57         Iterator itr = servlets.iterator();
58         // test the servlets in this .war
59
while (itr.hasNext()) {
60         foundIt = false;
61         WebComponentDescriptor servlet = (WebComponentDescriptor)itr.next();
62 // try {
63
File warfile = new File(System.getProperty("java.io.tmpdir"));
64             warfile = new File(warfile, "wartmp");
65 // File f = Verifier.getArchiveFile(
66
// descriptor.getModuleDescriptor().getArchiveUri());
67
File warLibDir = null;
68
69 // if (f != null) {
70
// VerifierUtils.copyArchiveToDir(f, warfile);
71
// warLibDir = new File(warfile, servletLibDirPath);
72
// }
73
// else {
74
String JavaDoc uri = getAbstractArchiveUri(descriptor);
75               warLibDir = new File(uri, servletLibDirPath);
76 // }
77

78                     if (warLibDir.isDirectory()) {
79                 foundIt = true;
80                     }
81 /* } catch (IOException e) {
82             if (!oneFailed ) {
83             oneFailed = true;
84             }
85             Verifier.debug(e);
86             result.addErrorDetails(smh.getLocalString
87                        ("tests.componentNameConstructor",
88                         "For [ {0} ]",
89                         new Object[] {compName.toString()}));
90
91             result.addErrorDetails(smh.getLocalString
92                        (getClass().getName() + ".IOException",
93                         "Error: IOError trying to open [ {0} ], {1}",
94                         new Object[] {Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri()), e.getMessage()}));
95         }*/

96    
97         if (foundIt) {
98             result.addGoodDetails(smh.getLocalString
99                        ("tests.componentNameConstructor",
100                         "For [ {0} ]",
101                         new Object JavaDoc[] {compName.toString()}));
102             result.addGoodDetails(smh.getLocalString
103                       (getClass().getName() + ".passed",
104                        "Servlet lib dir [ {0} ] resides in WEB-INF/lib directory of [ {1} ].",
105                        new Object JavaDoc[] {servletLibDirPath,uri}));
106         } else {
107             na++;
108             result.addNaDetails(smh.getLocalString
109                     ("tests.componentNameConstructor",
110                      "For [ {0} ]",
111                      new Object JavaDoc[] {compName.toString()}));
112             result.addNaDetails(smh.getLocalString
113                        (getClass().getName() + ".notApplicable2",
114                         "Servlet lib dir [ {0} ] does not reside in [ {1} ].",
115                         new Object JavaDoc[] {servletLibDirPath,uri}));
116         }
117         }
118             File wartmp = new File(System.getProperty("java.io.tmpdir"));
119         wartmp = new File(wartmp, "wartmp");
120         deleteDirectory(wartmp.getAbsolutePath());
121         if (na == descriptor.getServletDescriptors().size()) {
122         result.setStatus(Result.NOT_APPLICABLE);
123         } else if (oneFailed) {
124         result.setStatus(Result.FAILED);
125         } else {
126         result.setStatus(Result.PASSED);
127         }
128     } else {
129         result.addNaDetails(smh.getLocalString
130                 ("tests.componentNameConstructor",
131                  "For [ {0} ]",
132                  new Object JavaDoc[] {compName.toString()}));
133         result.notApplicable(smh.getLocalString
134                  (getClass().getName() + ".notApplicable",
135                   "There are no servlet components within the web archive [ {0} ]",
136                   new Object JavaDoc[] {descriptor.getName()}));
137     }
138     return result;
139     }
140 }
141
Popular Tags