KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 package com.sun.enterprise.tools.verifier.tests.web.runtime;
26
27 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
28 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30 import com.sun.enterprise.tools.verifier.Result;
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32
33 /** constraint-field *
34  * Attribute: name, scope, cache-on-match, cache-on-match-failure
35  */

36
37 public class ASConstraintField extends WebTest implements WebCheck {
38
39     public Result check(WebBundleDescriptor descriptor) {
40
41     Result result = getInitializedResult();
42     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
43         String JavaDoc value = null;
44     int count = 0;
45         boolean oneFailed = false;
46         try{
47             count = getCountNodeSet("sun-web-app/cache/cache-mapping/constraint-field");
48             if (count>0){
49                 for(int i=1;i<=count;i++){
50                     //name attribute
51
value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field["+i+"]/@name");
52                     if (value==null || value.length()==0){
53                         oneFailed = true;
54                         result.addErrorDetails(smh.getLocalString
55                             ("tests.componentNameConstructor",
56                             "For [ {0} ]",
57                             new Object JavaDoc[] {compName.toString()}));
58                         result.failed(smh.getLocalString
59                             (getClass().getName() + ".failed",
60                             "FAILED [AS-WEB constraint-field] : name attribute is required",
61                             new Object JavaDoc[] {descriptor.getName()}));
62                     }else{
63                         result.addGoodDetails(smh.getLocalString
64                             ("tests.componentNameConstructor",
65                             "For [ {0} ]",
66                             new Object JavaDoc[] {compName.toString()}));
67                         result.passed(smh.getLocalString( getClass().getName() + ".passed",
68                               "PASSED [AS-WEB constraint-field] : name attribute is {1}",
69                               new Object JavaDoc[] {descriptor.getName(),value}));
70                     }
71
72                     //scope attribute
73
value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field["+i+"]/@scope");
74                     if (value==null || value.length()==0){
75                         result.addNaDetails(smh.getLocalString
76                         ("tests.componentNameConstructor",
77                             "For [ {0} ]",
78                             new Object JavaDoc[] {compName.toString()}));
79                         result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
80                             "NOT APPLICABLE [AS-WEB constraint-field] : scope attribute not defined"));
81                     }else{
82                         String JavaDoc scopeValue[] = {"context.attribute", "request.header", "request.parameter", "request.cookie", "request.attribute", "session.attribute" };
83                         boolean found = false;
84                         for (int j=0;j<scopeValue.length;j++){
85                             if (scopeValue[j].compareTo(value) ==0){
86                                 found = true;
87                             }
88                         }
89                         if (found){
90                             result.addGoodDetails(smh.getLocalString
91                                 ("tests.componentNameConstructor",
92                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
93                             result.passed(smh.getLocalString( getClass().getName() + ".passed1",
94                                 "PASSED [AS-WEB constraint-field] : scope attribute is {1}",
95                                 new Object JavaDoc[] {descriptor.getName(),value}));
96                         }else{
97                             oneFailed = true;
98                             result.addErrorDetails(smh.getLocalString
99                                 ("tests.componentNameConstructor",
100                                 "For [ {0} ]",
101                                 new Object JavaDoc[] {compName.toString()}));
102                             result.failed(smh.getLocalString
103                                 (getClass().getName() + ".failed1",
104                                 "FAILED [AS-WEB constraint-field] : scope attribute must be one of context.attribute, request.header, request.parameter, request.cookie, request.attribute, session.attribute",
105                                 new Object JavaDoc[] {descriptor.getName()}));
106                         }
107                     }
108                     //cache-on-match % boolean "(yes | no | on | off | 1 | 0 | true | false)">
109
value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field["+i+"]/@cache-on-match");
110                     if (value==null || value.length()==0){
111                         result.addNaDetails(smh.getLocalString
112                         ("tests.componentNameConstructor",
113                             "For [ {0} ]",
114                             new Object JavaDoc[] {compName.toString()}));
115                         result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
116                             "NOT APPLICABLE [AS-WEB constraint-field] : cache-on-match attribute not defined"));
117                     }else{
118                         String JavaDoc cacheOnMatchValue[] = {"yes", "no", "on", "off", "1", "0", "true", "false" };
119                         boolean foundCacheOnMatch = false;
120                         for (int j=0;j<cacheOnMatchValue.length;j++){
121                             if (cacheOnMatchValue[j].compareTo(value) ==0){
122                                 foundCacheOnMatch = true;
123                             }
124                         }
125                         if (foundCacheOnMatch){
126                             result.addGoodDetails(smh.getLocalString
127                                 ("tests.componentNameConstructor",
128                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
129                             result.passed(smh.getLocalString( getClass().getName() + ".passed2",
130                                 "PASSED [AS-WEB constraint-field] : cache-on-match attribute is {1}",
131                                 new Object JavaDoc[] {descriptor.getName(),value}));
132                         }else{
133                             oneFailed = true;
134                             result.addErrorDetails(smh.getLocalString
135                                 ("tests.componentNameConstructor",
136                                 "For [ {0} ]",
137                                 new Object JavaDoc[] {compName.toString()}));
138                             result.failed(smh.getLocalString
139                                 (getClass().getName() + ".failed2",
140                                 "FAILED [AS-WEB constraint-field] : cache-on-match attribute must be one of yes, no, on, off, 1, 0, true, false",
141                                 new Object JavaDoc[] {descriptor.getName()}));
142                         }
143                     }
144
145                     //cache-on-match-failure
146
value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field["+i+"]/@cache-on-match-failure");
147                     if (value==null || value.length()==0){
148                         result.addNaDetails(smh.getLocalString
149                         ("tests.componentNameConstructor",
150                             "For [ {0} ]",
151                             new Object JavaDoc[] {compName.toString()}));
152                         result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable2",
153                             "NOT APPLICABLE [AS-WEB constraint-field] : cache-on-match-failure attribute not defined"));
154                     }else{
155                         String JavaDoc cacheOnMatchFailureValue[] = {"yes", "no", "on", "off", "1", "0", "true", "false" };
156                         boolean found = false;
157                         for (int j=0;j<cacheOnMatchFailureValue.length;j++){
158                             if (cacheOnMatchFailureValue[j].compareTo(value) ==0){
159                                 found = true;
160                             }
161                         }
162                         if (found){
163                             result.addGoodDetails(smh.getLocalString
164                                 ("tests.componentNameConstructor",
165                                 "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
166                             result.passed(smh.getLocalString( getClass().getName() + ".passed3",
167                                 "PASSED [AS-WEB constraint-field] : cache-on-match-failure attribute is {1}",
168                                 new Object JavaDoc[] {descriptor.getName(),value}));
169                         }else{
170                             oneFailed = true;
171                             result.addErrorDetails(smh.getLocalString
172                                 ("tests.componentNameConstructor",
173                                 "For [ {0} ]",
174                                 new Object JavaDoc[] {compName.toString()}));
175                             result.failed(smh.getLocalString
176                                 (getClass().getName() + ".failed3",
177                                 "FAILED [AS-WEB constraint-field] : cache-on-match-failure attribute must be one of yes, no, on, off, 1, 0, true, false",
178                                 new Object JavaDoc[] {descriptor.getName()}));
179                         }
180                     }
181                 }
182             }else{
183                 result.addNaDetails(smh.getLocalString
184             ("tests.componentNameConstructor",
185             "For [ {0} ]",
186             new Object JavaDoc[] {compName.toString()}));
187                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable3",
188                     "NOT APPLICABLE [AS-WEB sun-web-app] : constraint-field Element not defined"));
189             }
190             if(oneFailed)
191                 result.setStatus(Result.FAILED);
192         }catch(Exception JavaDoc ex){
193             result.failed(smh.getLocalString
194                 (getClass().getName() + ".failed4",
195                     "FAILED [AS-WEB sun-web-app] could not create the constraint-field object"));
196         }
197     return result;
198     }
199
200 }
201
Popular Tags