KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.tools.verifier.tests.web.runtime;
25
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.WebBundleDescriptor;
30 import com.sun.enterprise.tools.verifier.tests.web.*;
31 import com.sun.enterprise.deployment.runtime.web.*;
32
33 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
34
/* Changed the result messages to reflect consistency between the result messages generated
35  * for the EJB test cases for SunONE specific deployment descriptors*/

36 //</addition>
37

38 public class ASWebProperty extends WebTest implements WebCheck{
39
40
41 public Result check(WebBundleDescriptor descriptor) {
42
43     Result result = getInitializedResult();
44
45     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
46
47         boolean oneFailed = false;
48         boolean notApp = false;
49         
50         try{
51             WebProperty[] webProps = (descriptor.getSunDescriptor()).getWebProperty();
52             if (webProps.length > 0){
53                 oneFailed=checkWebProperties(webProps,result ,descriptor, this ) ;
54             }else{
55             notApp = true;
56             addNaDetails(result, compName);
57         result.notApplicable(smh.getLocalString
58                                  (getClass().getName() + ".notApplicable",
59                                   "NOT APPLICABLE [AS-WEB sun-web-app] web property element not defined within the web archive [ {0} ].",
60                                   new Object JavaDoc[] {descriptor.getName()}));
61         }
62         if (oneFailed) {
63             result.setStatus(Result.FAILED);
64         } else if(notApp) {
65             result.setStatus(Result.NOT_APPLICABLE);
66         }else {
67             result.setStatus(Result.PASSED);
68         }
69
70         }catch(Exception JavaDoc ex){
71             oneFailed = true;
72             addErrorDetails(result, compName);
73             result.failed(smh.getLocalString
74                 (getClass().getName() + ".failed",
75                     "FAILED [AS-WEB sun-web-app] could not create the web-property object"));
76         }
77
78     return result;
79     }
80    public static boolean checkWebProperties(WebProperty[] webProps, Result result ,WebBundleDescriptor descriptor, Object JavaDoc obj ) {
81        String JavaDoc compName = result.getComponentName();
82        String JavaDoc name;
83        String JavaDoc value;
84        boolean oneFailed = false;
85        String JavaDoc[] names=null;
86        if (webProps.length > 0){
87            names=new String JavaDoc[webProps.length];
88            for (int rep=0; rep<webProps.length; rep++ ){
89                name = webProps[rep].getAttributeValue(WebProperty.NAME); //*************needs verification from ko]umar Sg
90
value = webProps[rep].getAttributeValue(WebProperty.VALUE);
91                names[rep]=name;
92                if (name !=null && value !=null && name.length() != 0 && value.length() != 0){
93                    //check if the name already exist in this web-prop
94
boolean isDuplicate=false;
95                    for(int rep1=0;rep1<rep;rep1++)
96                    {
97                        if(name.equals(names[rep1])){
98                            isDuplicate=true;
99                             break;
100                        }
101
102                     }
103
104                     if(!isDuplicate){
105                         result.addGoodDetails(smh.getLocalString
106                                                 ("tests.componentNameConstructor",
107                                                  "For [ {0} ]",
108                                                  new Object JavaDoc[] {compName}));
109                         result.passed(smh.getLocalString
110                       (obj.getClass().getName() + ".passed",
111                        "PASSED [AS-WEB property] Proper web property with name [ {0} ] and value [ {1} ] defined.",
112                        new Object JavaDoc[] {name, value}));
113                     }else{
114                     if (!oneFailed)
115                         oneFailed = true;
116                     result.addErrorDetails(smh.getLocalString
117                                             ("tests.componentNameConstructor",
118                                              "For [ {0} ]",
119                                              new Object JavaDoc[] {compName}));
120                     result.failed(smh.getLocalString
121                                       (obj.getClass().getName() + ".failed2",
122                                       "FAILED [AS-WEB property] name [ {0} ] and value [ {1} ], the name must be unique in the entire list of web property.",
123                                       new Object JavaDoc[] {name, value}));
124                     }
125
126                }else{
127                    if (!oneFailed)
128                         oneFailed = true;
129                    result.addErrorDetails(smh.getLocalString
130                                             ("tests.componentNameConstructor",
131                                              "For [ {0} ]",
132                                              new Object JavaDoc[] {compName}));
133                    result.failed(smh.getLocalString
134                                       (obj.getClass().getName() + ".failed1",
135                                       "FAILED [AS-WEB property] name [ {0} ] and value [ {1} ], attributes must be of finite length.",
136                                       new Object JavaDoc[] {name, value}));
137                }
138             }
139
140         }
141
142         return oneFailed;
143
144    }
145
146 }
147
148
Popular Tags