KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.WebComponentDescriptor;
30
31
32 /**
33  *
34  * @author Arun Jain
35  */

36 public class ServletParamValue extends WebTest implements WebCheck {
37     
38
39      /**
40      * Param Value exists 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         Set servlets;
49         Iterator itr;
50         String JavaDoc epValue;
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53         WebComponentDescriptor servlet;
54         Enumeration en;
55         EnvironmentProperty ep = null;
56         boolean oneFailed = false;
57         boolean status = false;
58         boolean notApp = false;
59         
60     if (!descriptor.getServletDescriptors().isEmpty()) {
61             
62         // get the servlets in this .war
63
servlets = descriptor.getServletDescriptors();
64         itr = servlets.iterator();
65         // test the servlets in this .war
66
while (itr.hasNext()) {
67         servlet = (WebComponentDescriptor)itr.next();
68                 en = servlet.getInitializationParameters();
69                 if (en.hasMoreElements()) {
70                     ep = (EnvironmentProperty)en.nextElement();
71                     epValue = ep.getValue();
72                     if (epValue.length() != 0) {
73             result.addGoodDetails(smh.getLocalString
74                        ("tests.componentNameConstructor",
75                     "For [ {0} ]",
76                     new Object JavaDoc[] {compName.toString()}));
77                         result.addGoodDetails(smh.getLocalString
78                                               (getClass().getName() + ".passed",
79                                                "Param named/value exists for in the servlet [ {0} ].",
80                                                new Object JavaDoc[] {servlet.getName()}));
81                     } else {
82                         // failed
83
oneFailed = true;
84                result.addErrorDetails(smh.getLocalString
85                        ("tests.componentNameConstructor",
86                     "For [ {0} ]",
87                     new Object JavaDoc[] {compName.toString()}));
88                         result.addErrorDetails(smh.getLocalString
89                                                (getClass().getName() + ".failed",
90                                                 "Error: Param name/value entry should of finite length."));
91                     }
92                 }
93             }
94             
95         } else {
96             notApp = true;
97         result.addNaDetails(smh.getLocalString
98                        ("tests.componentNameConstructor",
99                     "For [ {0} ]",
100                     new Object JavaDoc[] {compName.toString()}));
101         result.notApplicable(smh.getLocalString
102                                  (getClass().getName() + ".notApplicable",
103                                   "There are no initialization parameters for the servlet within the web archive [ {0} ]",
104                                   new Object JavaDoc[] {descriptor.getName()}));
105         }
106        if (oneFailed) {
107             result.setStatus(Result.FAILED);
108         } else if (notApp){
109             result.setStatus(Result.NOT_APPLICABLE);
110         } else {
111             result.setStatus(Result.PASSED);
112         }
113     return result;
114     }
115 }
116
Popular Tags