KickJava   Java API By Example, From Geeks To Geeks.

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


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  //public class ASCache extends WebTest implements WebCheck{
25

26 package com.sun.enterprise.tools.verifier.tests.web.ias;
27
28
29 import java.util.*;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
34 import com.sun.enterprise.deployment.WebBundleDescriptor;
35 import com.sun.enterprise.tools.verifier.tests.web.*;
36 import com.sun.enterprise.tools.common.dd.webapp.*;
37
38 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
39
/* Changed the result messages to reflect consistency between the result messages generated
40  * for the EJB test cases for SunONE specific deployment descriptors*/

41 //</addition>
42

43
44 public class ASCache extends WebTest implements WebCheck {
45
46
47     public Result check(WebBundleDescriptor descriptor) {
48
49
50     Result result = getInitializedResult();
51     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
52
53         boolean oneFailed = false;
54         boolean notApp = false;
55         String JavaDoc maxEntries=null;
56         String JavaDoc timeout=null;
57         int intMaxEntries;
58         //<addition author="irfan@sun.com" [bug/rfe]-id="4705988" >
59
//int intTimeout;
60
long longTimeout;
61         //</addition>
62

63         Cache cache = getCache(descriptor);
64
65     if (cache != null) {
66
67                 // <addition> srini@sun.com Bug : 4702284
68
//maxEntries = cache.getAttributeValue("MaxEntries");
69
//timeout = cache.getAttributeValue("Timeout");
70
maxEntries = cache.getAttributeValue("max-entries");
71                 timeout = cache.getAttributeValue("timeout-in-seconds");
72                 // </addition>
73
boolean validMaxEntriesValue=true;
74                 boolean validTimeOutValue=true;
75
76                 try{
77                       if(maxEntries !=null && maxEntries.length() != 0){ // check maxEntries.length() != 0 because is IMPLIED att
78
intMaxEntries=Integer.parseInt(maxEntries);
79
80                         if(intMaxEntries >0 && intMaxEntries < Integer.MAX_VALUE)
81                           validMaxEntriesValue=true;
82                         else
83                           validMaxEntriesValue=false;
84
85                       }
86
87                 } catch(NumberFormatException JavaDoc exception){
88                     validMaxEntriesValue=false;
89                     if (!oneFailed)
90                         oneFailed = true;
91
92                 }
93
94                 if(validMaxEntriesValue){
95                     result.passed(smh.getLocalString
96                       (getClass().getName() + ".passed",
97                        "PASSED [AS-WEB cache] max-entries [ {0} ] defined properly.",
98                        new Object JavaDoc[] {maxEntries}));
99                 }else{
100                     result.failed(smh.getLocalString
101                                       (getClass().getName() + ".failed",
102                                       "FAILED [AS-WEB cache] max-entries [ {0} ], attribute must be a proper integer value. "+
103                                       "Its range should be 1 to MAX_INT.",
104                                       new Object JavaDoc[] {maxEntries}));
105                     oneFailed = true;
106                 }
107
108                 try{
109                     //<addition author="irfan@sun.com" [bug/rfe]-id="4705988" >
110
/*if(timeout != null && timeout.length() != 0 ){ // check timeout.length() != 0 because is IMPLIED att
111                         intTimeout=Integer.parseInt(timeout);
112                         if(intTimeout > -1 && intTimeout < Integer.MAX_VALUE)
113                           validTimeOutValue=true;
114                         else
115                           validTimeOutValue=false;
116                       }*/

117                     if(timeout != null && timeout.length() != 0 ){ // check timeout.length() != 0 because is IMPLIED att
118
longTimeout=Long.parseLong(timeout);
119                         if(longTimeout >= -1 && longTimeout <= Long.MAX_VALUE)
120                           validTimeOutValue=true;
121                         else
122                           validTimeOutValue=false;
123                       }
124                     //</addition>
125

126                 } catch(NumberFormatException JavaDoc exception) {
127                      validTimeOutValue=false;
128                      oneFailed = true;
129
130
131                 }
132
133                 if(validTimeOutValue){
134                     result.passed(smh.getLocalString
135                       (getClass().getName() + ".passed1",
136                        "PASSED [AS-WEB cache] timeout-in-seconds [ {0} ] defined properly.",
137                        new Object JavaDoc[] {timeout}));
138                      
139                 }else{
140                     //<addition author="irfan@sun.com" [bug/rfe]-id="4705988" >
141
/*result.addErrorDetails(smh.getLocalString
142                                       (getClass().getName() + ".failed",
143                                       "Error: cache's timeout [ {0} ], attribute must be a proper inetger value. " +
144                                       "Its range should be between 0 to Integer.MAX_VALUE.",
145                                       new Object[] {timeout}));
146                      */

147                     result.failed(smh.getLocalString
148                                       (getClass().getName() + ".failed1",
149                                       "FAILED [AS-WEB cache] timeout-in-seconds value [ {0} ], attribute must be a proper long value. " +
150                                       "Its range should be between -1 and MAX_LONG.",
151                                       new Object JavaDoc[] {timeout}));
152                     oneFailed = true;
153                     //</addition>
154
}
155
156
157         } else {
158             notApp = true;
159         result.notApplicable(smh.getLocalString
160                                  (getClass().getName() + ".notApplicable",
161                                   "NOT APPLICABLE [AS-WEB cache] Element not defined for the web application.",
162                                   new Object JavaDoc[] {descriptor.getName()}));
163         }
164         if (oneFailed) {
165             result.setStatus(Result.FAILED);
166         } else if(notApp) {
167             result.setStatus(Result.NOT_APPLICABLE);
168         }else {
169             result.setStatus(Result.PASSED);
170         }
171     return result;
172     }
173
174     public Cache getCache(WebBundleDescriptor descriptor){
175
176          Cache c= descriptor.getIasWebApp().getCache();
177          return c;
178
179     }
180 }
181
Popular Tags