KickJava   Java API By Example, From Geeks To Geeks.

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


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 which validates the Mail Resource Fields
35  * Author : srini@sun.com
36  **/

37
38 import java.net.*;
39
40 // 8.0 XML Verifier
41
//import com.sun.enterprise.tools.verifier.Result;
42
import com.sun.enterprise.config.serverbeans.Server;
43 import com.sun.enterprise.config.serverbeans.*;
44 import com.sun.enterprise.config.serverbeans.Resources;
45 import com.sun.enterprise.config.serverbeans.Applications;
46 import com.sun.enterprise.config.ConfigContext;
47 import com.sun.enterprise.config.ConfigContextEvent;
48 import com.sun.enterprise.config.ConfigException;
49 import com.sun.enterprise.config.serverbeans.*;
50
51 import com.sun.enterprise.admin.verifier.*;
52 // Logging
53
import java.util.logging.Logger JavaDoc;
54 import java.util.logging.Level JavaDoc;
55 import com.sun.logging.LogDomains;
56
57
58
59 public class MailResourceTest extends ServerXmlTest implements ServerCheck {
60     // Logging
61
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
62     
63     public MailResourceTest() {
64     }
65
66     // check method called by command line verifier
67
public Result check(ConfigContext context)
68     {
69         Result result;
70         result = super.getInitializedResult();
71         // 8.0 XML Verifier
72
/*try {
73             Server server = (Server)context.getRootConfigBean();
74             Resources res = server.getResources();
75             MailResource[] mailResource = res.getMailResource();
76             for(int i=0;i < mailResource.length;i++) {
77                 String ip = mailResource[i].getHost();
78                 // Bug 4711404
79                 if(ip != null && ip.equals(""))
80                     result.failed("Mail Resource Host Cannot be null String");
81                 try{
82                    InetAddress.getByName(ip).getHostName();
83                    result.passed("Valid IIOP Listener IP " + ip);
84                 }catch(UnknownHostException e){
85                     result.failed("Host name not resolvable - " + ip);
86                 }
87             }
88         }
89         catch(Exception ex) {
90             //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
91             /*ex.printStackTrace();
92             result.failed("Exception : " + ex.getMessage());*/

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

97         return result;
98     }
99     
100      // check method called by iasadmin and admin GUI
101
public Result check(ConfigContextEvent ccce) {
102         Result result = new Result();
103         Object JavaDoc value = ccce.getObject();
104         String JavaDoc beanName = ccce.getBeanName();
105         if(beanName!=null) {
106             String JavaDoc name = ccce.getName();
107             return testSave(name,(String JavaDoc)value);
108         }
109         
110         MailResource res = (MailResource)value;
111         String JavaDoc ip = res.getHost();
112         
113         // check if jndi-name is valid object name Bug : 4698687 : start
114
String JavaDoc id = res.getJndiName();
115         
116         if(StaticTest.checkObjectName(id, result))
117             result.passed("Valid Object Name");
118         else {
119             result.failed("Mail Resource Jndi-Name Invalid ");
120             return result;
121         }
122         // End Bug : 4698687
123
try{
124             InetAddress.getByName(ip).getHostName();
125             result.passed("Valid Mail Resource IP");
126         }catch(UnknownHostException e){
127             result.failed("Host name not resolvable - " + ip);
128             return result;
129         }
130         return result;
131     }
132      
133      public Result testSave(String JavaDoc name, String JavaDoc value) {
134          Result result = new Result();
135          result.passed("Passed **");
136          if(name.equals(ServerTags.HOST)){
137             try{
138                 InetAddress.getByName(value).getHostName();
139                 result.passed("Valid Mail Resource IP");
140             }catch(UnknownHostException e){
141                 result.failed("Host name not resolvable - " + value);
142             }
143          }
144      return result;
145      }
146     
147 }
148
Popular Tags