KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > runtime > 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 package com.sun.enterprise.tools.verifier.tests.web.runtime;
25
26
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31 import com.sun.enterprise.tools.verifier.tests.web.*;
32 import com.sun.enterprise.deployment.runtime.web.*;
33
34 //import com.sun.enterprise.tools.common.dd.webapp.*;
35

36 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
37
/* Changed the result messages to reflect consistency between the result messages generated
38  * for the EJB test cases for SunONE specific deployment descriptors*/

39 //</addition>
40

41
42 public class ASCache extends WebTest implements WebCheck{
43
44     public Result check(WebBundleDescriptor descriptor) {
45         
46     Result result = getInitializedResult();
47     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
48         boolean oneFailed = false;
49         boolean notApp = false;
50         String JavaDoc maxEntries=null;
51         String JavaDoc timeout=null;
52         int intMaxEntries;
53         long longTimeout;
54         String JavaDoc enabled=null;
55         
56         try{
57         Cache cache = (descriptor.getSunDescriptor()).getCache();
58     
59         if (cache != null)
60         {
61             maxEntries = cache.getAttributeValue(Cache.MAX_ENTRIES);
62             timeout = cache.getAttributeValue(Cache.TIMEOUT_IN_SECONDS);
63             enabled = cache.getAttributeValue(Cache.ENABLED);
64             if (!(enabled.equalsIgnoreCase("true")) && !(enabled.equalsIgnoreCase("false")))
65             {
66
67             addErrorDetails(result, compName);
68                 result.failed(smh.getLocalString
69                     (getClass().getName() + ".failed3",
70                     "FAILED [AS-WEB cache] enabled [ {0} ], attribute must be a proper boolean value. ",
71                     new Object JavaDoc[] {enabled}));
72                     oneFailed = true;
73             }
74             else
75             {
76             addGoodDetails(result, compName);
77                 result.passed(smh.getLocalString
78                     (getClass().getName() + ".passed3",
79                         "PASSED [AS-WEB cache] enabled [ {0} ] defined properly.",
80                          new Object JavaDoc[] {enabled}));
81             }
82               
83
84             boolean validMaxEntriesValue=true;
85             boolean validTimeOutValue=true;
86             try
87             {
88                 if(maxEntries !=null && maxEntries.length() != 0) // check maxEntries.length() != 0 because is IMPLIED att
89
{
90                     intMaxEntries=Integer.parseInt(maxEntries);
91                     if(intMaxEntries >0 && intMaxEntries < Integer.MAX_VALUE)
92                         validMaxEntriesValue=true;
93                     else
94                         validMaxEntriesValue=false;
95                 }
96             }
97             catch(NumberFormatException JavaDoc exception)
98             {
99                 validMaxEntriesValue=false;
100                 if (!oneFailed)
101                     oneFailed = true;
102             }
103             if(validMaxEntriesValue)
104             {
105                 addGoodDetails(result, compName);
106                 result.passed(smh.getLocalString
107                     (getClass().getName() + ".passed",
108                     "PASSED [AS-WEB cache] max-entries [ {0} ] defined properly.",
109                     new Object JavaDoc[] {maxEntries}));
110             }else
111             {
112                 addErrorDetails(result, compName);
113                 result.failed(smh.getLocalString
114                     (getClass().getName() + ".failed",
115                     "FAILED [AS-WEB cache] max-entries [ {0} ], attribute must be a proper integer value. "+
116                         "Its range should be 1 to MAX_INT.",
117                         new Object JavaDoc[] {maxEntries}));
118                      oneFailed = true;
119             }
120             try
121             {
122                 if(timeout != null && timeout.length() != 0 ) // check timeout.length() != 0 because is IMPLIED att
123
{
124                     longTimeout=Long.parseLong(timeout);
125                     if(longTimeout >= -1 && longTimeout <= Long.MAX_VALUE)
126                         validTimeOutValue=true;
127                     else
128                         validTimeOutValue=false;
129                 }
130
131             }catch(NumberFormatException JavaDoc exception)
132             {
133                 validTimeOutValue=false;
134                     oneFailed = true;
135             }
136             if(validTimeOutValue)
137             {
138                 addGoodDetails(result, compName);
139                 result.passed(smh.getLocalString
140                     (getClass().getName() + ".passed1",
141                         "PASSED [AS-WEB cache] timeout-in-seconds [ {0} ] defined properly.",
142                          new Object JavaDoc[] {timeout}));
143             }
144             else
145             {
146                 addErrorDetails(result, compName);
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             }
154             
155         }else
156         {
157             notApp = true;
158             addNaDetails(result, compName);
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         
165         if (oneFailed) {
166             result.setStatus(Result.FAILED);
167         } else if(notApp) {
168             result.setStatus(Result.NOT_APPLICABLE);
169         }else {
170             result.setStatus(Result.PASSED);
171         }
172         }catch(Exception JavaDoc ex){
173             oneFailed=true;
174             addErrorDetails(result, compName);
175             result.failed(smh.getLocalString
176                     (getClass().getName() + ".failed2",
177                     "FAILED [AS-WEB cache] Could not create the cache object"));
178         }
179     return result;
180     }
181 }
182
Popular Tags