KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > EjbContainerTest


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  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 /* Test case to check the validity of Ejb Container fields
35  * Author : srini@sun.com
36  */

37
38 // 8.0 XML Verifier
39
//import com.sun.enterprise.tools.verifier.Result;
40
import com.sun.enterprise.config.serverbeans.Server;
41 import com.sun.enterprise.config.serverbeans.*;
42 import com.sun.enterprise.config.ConfigContext;
43 import com.sun.enterprise.config.ConfigException;
44 import com.sun.enterprise.config.serverbeans.*;
45 import com.sun.enterprise.config.ConfigContextEvent;
46
47 import com.sun.enterprise.admin.verifier.*;
48
49 // Logging
50
import java.util.logging.Logger JavaDoc;
51 import java.util.logging.Level JavaDoc;
52 import com.sun.logging.LogDomains;
53
54 public class EjbContainerTest extends ServerXmlTest implements ServerCheck {
55     
56      // Logging
57
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
58     // Bug 4675624
59
static int ejbSteadyQty = 0;
60     static int ejbMaxCacheSize = 0;
61     static int ejbResizeQty = 0;
62
63     public EjbContainerTest() {
64     }
65  
66     // check method invoked by the command line verifier
67
public Result check(ConfigContext context) {
68             Result result;
69             result = super.getInitializedResult();
70             // 8.0 XML Verifier
71
/*try {
72                 Server server = (Server)context.getRootConfigBean();
73                 EjbContainer ejb = server.getEjbContainer();
74                 try {
75                     String pool = ejb.getSteadyPoolSize();
76                     if(Integer.parseInt(pool) < 0)
77                         result.failed(smh.getLocalString(getClass().getName()+".steadyPoolNegative","Steady Pool size cannot be a negative number"));
78                     else
79                         result.passed("*** passed *****");
80                 } catch(NumberFormatException e) {
81                     result.failed(smh.getLocalString(getClass().getName()+".steadyPoolInvalid","Steady Pool Size : invalid number"));
82                 }
83                 try {
84                     String maxPool = ejb.getMaxPoolSize();
85                     if(Integer.parseInt(maxPool) < 0)
86                         result.failed(smh.getLocalString(getClass().getName()+".maxPoolNegative","Max Pool Size cannot be a negative number"));
87                     else
88                         result.passed("**** Passed *****");
89                 }
90                 catch(NumberFormatException e) {
91                     result.failed(smh.getLocalString(getClass().getName()+".maxPoolInvalid","Max. Pool Size : invalid number "));
92                 }
93                 try {
94                     String poolIdle = ejb.getPoolIdleTimeoutInSeconds();
95                     if(Integer.parseInt(poolIdle) < 0)
96                         result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutNegative","Pool Idle Timeout cannot be negative number"));
97                     else
98                         result.passed("**** Passed ****");
99                 }
100                 catch(NumberFormatException e) {
101                     result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutInvalid","Pool Idle timeout : invalid number"));
102                 }
103                 try {
104                     String resize = ejb.getPoolResizeQuantity();
105                     if(Integer.parseInt(resize) < 0)
106                         result.failed(smh.getLocalString(getClass().getName()+".resizeQtyNegative","Pool resize quantity cannot be negative number"));
107                     else
108                         result.passed("**** Passed ****");
109                 }
110                 catch(NumberFormatException e) {
111                     result.failed(smh.getLocalString(getClass().getName()+".resizeQtyInvalid","Pool Resize Quantity : invalid number "));
112                 }
113                 try {
114                     String maxCache = ejb.getMaxCacheSize();
115                     if(Integer.parseInt(maxCache) < 0)
116                         result.failed(smh.getLocalString(getClass().getName()+".maxCacheNegative","Max Cache Size cannot be negative number"));
117                     else
118                         result.passed("**** Passed ****");
119                         
120                 }
121                 catch(NumberFormatException e) {
122                     result.failed(smh.getLocalString(getClass().getName()+".maxCacheInvalid","Max Cache Size : invalid number "));
123                 }
124                 try {
125                     String resizeQty = ejb.getCacheResizeQuantity();
126                     if(Integer.parseInt(resizeQty) < 0)
127                         result.failed(smh.getLocalString(getClass().getName()+".cacheResizeNegative","Cache Resize Qty cannot be negative number"));
128                     else
129                         result.passed("**** Passed ****");
130                 }
131                 catch(NumberFormatException e) {
132                     result.failed(smh.getLocalString(getClass().getName()+".cacheResizeInvalid","Cache Resize Qty : invalid number "));
133                 }
134                 try {
135                     String cacheIdle = ejb.getCacheIdleTimeoutInSeconds();
136                     if(Integer.parseInt(cacheIdle) < 0)
137                         result.failed(smh.getLocalString(getClass().getName()+".cacheIdleTimeoutNegative","Cache Idle Timeout cannot be negative number"));
138                     else
139                         result.passed("**** Passed ****");
140                         
141                 }
142                 catch(NumberFormatException e) {
143                     result.failed(smh.getLocalString(getClass().getName()+".cacheIdleTimeoutInvalid","Cache Idle Timeout : invalid number "));
144                 }
145             }
146             catch(Exception ex) {
147                 // Logging
148                 _logger.log(Level.FINE, "serverxmlverifier.exception" , ex);
149                 result.failed("Exception : " + ex.getMessage());
150             }*/

151             return result;
152     }
153     
154     // check method called from the admin GUI and iasadmin
155
public Result check(ConfigContextEvent ccce) {
156                 Object JavaDoc value = ccce.getObject();
157                 ConfigContext context = ccce.getConfigContext();
158                 Result result = new Result();
159                 result.passed("Passed ** ");
160                 String JavaDoc beanName = ccce.getBeanName();
161                 if(beanName!=null) {
162                     String JavaDoc name = ccce.getName();
163                     if(name != null && value != null)
164                         result = validateAttribute(name, (String JavaDoc)value);
165                     return result;
166                 }
167                 
168                 return result;
169     }
170     
171     public Result validateAttribute(String JavaDoc name, String JavaDoc value) {
172             Result result = new Result();
173             boolean isFailed = false;
174             result.passed("Passed **");
175             if(name.equals(ServerTags.STEADY_POOL_SIZE)) {
176                 try {
177                     int steadyQty = Integer.parseInt(value);
178                     if(steadyQty < 0) {
179                         result.failed(smh.getLocalString(getClass().getName()+".steadyPoolNegative","Steady Pool size cannot be a negative number"));
180                         isFailed = true;
181                     }
182                     else { // Bug 4675624
183
result.passed("Passed ***");
184                         EjbContainerTest.ejbSteadyQty = steadyQty;
185                     }
186                 } catch(NumberFormatException JavaDoc e) {
187                     result.failed(smh.getLocalString(getClass().getName()+".steadyPoolInvalid","Steady Pool Size : invalid number"));
188                     isFailed = true;
189                 }
190             }
191             if(name.equals(ServerTags.MAX_POOL_SIZE)) {
192                 try {
193                     int maxQty = Integer.parseInt(value);
194                     if(maxQty < 0) {
195                         result.failed(smh.getLocalString(getClass().getName()+".maxPoolNegative","Max Pool Size cannot be a negative number"));
196                         isFailed = true;
197                     }
198                     // Bug 4675624
199
else if(maxQty < EjbContainerTest.ejbSteadyQty) {
200                         result.failed(smh.getLocalString(getClass().getName()+".steadyPoolMaxPoolError","Steady Pool Size should be less than or equal to Maximum Pool Size"));
201                         isFailed = true;
202                     }
203                     else if(maxQty < EjbContainerTest.ejbResizeQty) {
204                         result.failed(smh.getLocalString(getClass().getName()+".resizePoolMaxPoolError","Pool Resize Qty should be less than or equal to Maximum Pool Size"));
205                         isFailed = true;
206                     }
207                     else
208                         result.passed("Passed ***");
209                 } catch(NumberFormatException JavaDoc e) {
210                     result.failed(smh.getLocalString(getClass().getName()+".maxPoolInvalid","Max. Pool Size : invalid number "));
211                     isFailed = true;
212                 }
213             }
214             if(name.equals(ServerTags.POOL_RESIZE_QUANTITY)){
215                 try {
216                     int resizeQty = Integer.parseInt(value);
217                     if(resizeQty < 0) {
218                         result.failed(smh.getLocalString(getClass().getName()+".resizeQtyNegative","Pool resize quantity cannot be negative number"));
219                         isFailed = true;
220                     }
221                     else { // Bug 4675624
222
result.passed("Passed ***");
223                         EjbContainerTest.ejbResizeQty = resizeQty;
224                     }
225                 } catch(NumberFormatException JavaDoc e) {
226                     result.failed(smh.getLocalString(getClass().getName()+".resizeQtyInvalid","Pool Resize Quantity : invalid number "));
227                     isFailed = true;
228                 }
229                 
230             }
231             if(name.equals(ServerTags.POOL_IDLE_TIMEOUT_IN_SECONDS)) {
232                 try {
233                     if(Integer.parseInt(value) < 0) {
234                         result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutNegative","Pool Idle Timeout cannot be negative number"));
235                         isFailed = true;
236                     }
237                     else
238                         result.passed("Passed ***");
239                 } catch(NumberFormatException JavaDoc e) {
240                     result.failed(smh.getLocalString(getClass().getName()+".idleTimeoutInvalid","Pool Idle timeout : invalid number"));
241                     isFailed = true;
242                 }
243             }
244             if(name.equals(ServerTags.MAX_CACHE_SIZE)) {
245                 try {
246                     int maxCache = Integer.parseInt(value);
247                     if(maxCache < 0) {
248                         result.failed(smh.getLocalString(getClass().getName()+".maxCacheNegative","Max Cache Size cannot be negative number"));
249                         isFailed = true;
250                     }
251                     else {
252                         result.passed("Passed ***");
253                         EjbContainerTest.ejbMaxCacheSize = maxCache;
254                     }
255                 } catch(NumberFormatException JavaDoc e) {
256                     result.failed(smh.getLocalString(getClass().getName()+".maxCacheInvalid","Max Cache Size : invalid number "));
257                     isFailed = true;
258                 }
259             }
260             if(name.equals(ServerTags.CACHE_RESIZE_QUANTITY)) {
261                 try {
262                     int cacheResize = Integer.parseInt(value);
263                     if(Integer.parseInt(value) < 0) {
264                         result.failed(smh.getLocalString(getClass().getName()+".cacheResizeNegative","Cache Resize Qty cannot be negative number"));
265                         isFailed = true;
266                     }
267                     else if( cacheResize > EjbContainerTest.ejbMaxCacheSize) {
268                         result.failed(smh.getLocalString(getClass().getName()+".cacheResizeMaxCacheError","Cache Resize Quantity should be less than or equal to Maximum Cache Size"));
269                         isFailed = true;
270                     }
271                     else
272                         result.passed("Passed ***");
273                 } catch(NumberFormatException JavaDoc e) {
274                     result.failed(smh.getLocalString(getClass().getName()+".cacheResizeInvalid","Cache Resize Qty : invalid number "));
275                     isFailed = true;
276                 }
277             }
278             if(name.equals(ServerTags.REMOVAL_TIMEOUT_IN_SECONDS)) {
279                 try {
280                     if(Integer.parseInt(value) < 0) {
281                         result.failed(smh.getLocalString(getClass().getName()+".removalTimeNegative","Removal Timeout cannot be negative number"));
282                         isFailed = true;
283                     }
284                     else
285                         result.passed("Passed ***");
286                 } catch(NumberFormatException JavaDoc e) {
287                     result.failed(smh.getLocalString(getClass().getName()+".removalTimeInvalid","Removal Timeout : invalid number"));
288                     isFailed = true;
289                 }
290             }
291             if(name.equals(ServerTags.CACHE_IDLE_TIMEOUT_IN_SECONDS)) {
292                 try {
293                     if(Integer.parseInt(value) < 0) {
294                         result.failed(smh.getLocalString(getClass().getName()+".cacheIdleTimeoutNegative","Cache Idle Timeout cannot be negative number"));
295                         isFailed = true;
296                     }
297                     else
298                         result.passed("Passed ***");
299                 } catch(NumberFormatException JavaDoc e) {
300                     result.failed(smh.getLocalString(getClass().getName()+".cacheIdleTimeoutInvalid","Cache Idle Timeout : invalid number "));
301                     isFailed = true;
302                 }
303             }
304             if(isFailed)
305                 result.setStatus(Result.FAILED);
306             return result;
307     }
308     
309 }
310
Popular Tags