KickJava   Java API By Example, From Geeks To Geeks.

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


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 Web Module fields
35  * Author : srini@sun.com
36  */

37
38 import java.net.*;
39 import java.io.File JavaDoc;
40 import java.io.FileNotFoundException JavaDoc;
41
42 // 8.0 XML Verifier
43
//import com.sun.enterprise.tools.verifier.Result;
44
import com.sun.enterprise.config.serverbeans.Server;
45 import com.sun.enterprise.config.serverbeans.*;
46 import com.sun.enterprise.config.serverbeans.Resources;
47 import com.sun.enterprise.config.serverbeans.Applications;
48 import com.sun.enterprise.config.ConfigContext;
49 import com.sun.enterprise.config.ConfigException;
50 import com.sun.enterprise.config.serverbeans.*;
51 import com.sun.enterprise.config.ConfigContextEvent;
52
53 import com.sun.enterprise.admin.verifier.*;
54 // Logging
55
import java.util.logging.Logger JavaDoc;
56 import java.util.logging.Level JavaDoc;
57 import com.sun.logging.LogDomains;
58
59
60
61 public class WebModuleTest extends ServerXmlTest implements ServerCheck {
62     // Logging
63
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
64     
65     public WebModuleTest() {
66     }
67  
68     // check method invoked by the command line verifier
69
public Result check(ConfigContext context) {
70                 Result result;
71                 result = super.getInitializedResult();
72                 // 8.0 XML Verifier
73
/*try {
74                     Server server = (Server)context.getRootConfigBean();
75                     result.passed("Test Passed : ");
76                     Applications app = server.getApplications();
77                     WebModule[] web = app.getWebModule();
78                     File f;
79                     for(int i=0;i<web.length;i++) {
80                         f = new File(web[i].getLocation());
81                         try {
82                             if(f.exists())
83                                  result.passed("Test Passed ****");
84                             else
85                                  result.failed("Web Module location directory for " + web[i].getName() +" is not valid");
86                         }catch(SecurityException e) {
87                             result.failed("Security Manager Exists, not possible to access Web Module location");
88                         }
89                     }
90                 }
91                 catch(Exception ex){
92                     //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
93                     /*result.failed("Test Failed **** ");*/

94                     /*_logger.log(Level.FINE, "serverxmlverifier.exception", ex);
95                     result.failed("Exception : " + ex.getMessage());
96                     //</addition>
97                 }*/

98                 return result;
99     }
100     
101     // check method called from the admin GUI and iasadmin
102
public Result check(ConfigContextEvent ccce) {
103                 Object JavaDoc value = ccce.getObject();
104                 Result result = new Result();
105                 String JavaDoc beanName = ccce.getBeanName();
106                 if(beanName!=null) {
107                     String JavaDoc name = ccce.getName();
108                     return testSave(name,(String JavaDoc)value);
109                 }
110                 WebModule web = (WebModule)value;
111                 // check if jndi-name is valid object name Bug : 4698687 : start
112
String JavaDoc id = web.getName();
113                 if(StaticTest.checkObjectName(id, result))
114                     result.passed("Valid Object Name");
115                 else {
116                     result.failed("Web Module Name Invalid ");
117                     return result;
118                 }
119                 // End Bug : 4698687
120

121                 String JavaDoc location = web.getLocation();
122                 File JavaDoc f = new File JavaDoc(location);
123                 try {
124                     if(f.exists())
125                          result.passed("Test Passed ****");
126                     else
127                          result.failed("Web Module location directory is not valid");
128                 }catch(SecurityException JavaDoc e) {
129                     result.failed("Security Manager Exists, not possible to access Web Module location");
130                 }
131                 return result;
132     }
133
134     public Result testSave(String JavaDoc name,String JavaDoc value){
135           Result result = new Result();
136           result.passed("Passed **");
137       if(name.equals(ServerTags.LOCATION)) {
138               File JavaDoc f = new File JavaDoc(value);
139               try {
140                   if(f.exists())
141                        result.passed("Test Passed ****");
142                   else
143                        result.failed("Web Module location directory is not valid");
144               }catch(SecurityException JavaDoc e) {
145                   result.failed("Security Manager Exists, not possible to access Web Module location");
146               }
147               return result;
148          }
149          return result;
150     }
151
152 }
153
Popular Tags