KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > ASEntBeanCmpResource


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import java.util.*;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar;
36 import com.sun.enterprise.tools.common.dd.ejb.EnterpriseBeans;
37 import com.sun.enterprise.tools.common.dd.ejb.CmpResource;
38 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal;
39
40 /** enterprise-bean
41  * cmp-resource ?
42  * jndi-name [String]
43  * default-resource-principal ?
44  * name [String]
45  * password [String]
46  *
47  * The cmp-resource contains the database to be used for storing the cmp beans
48  * in the ejb-jar.xml
49  * The jndi-name should not be null and should start with jdbc/
50  * @author Irfan Ahmed
51  */

52 public class ASEntBeanCmpResource extends EjbTest implements EjbCheck {
53
54     public Result check(EjbDescriptor descriptor) {
55
56     Result result = getInitializedResult();
57     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
58         //4698046
59
boolean oneFailed=false;
60         boolean oneWarning=false;
61
62         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
63         String JavaDoc ejbName = null;
64         
65         if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))
66         {
67             result.setStatus(Result.NOT_RUN);
68             result.addGoodDetails(smh.getLocalString(getClass().getName() + ".notRun",
69                 "NOT RUN [AS-EJB enterprise-beans] name test is a JAR Level Test. This test has already been run once"));
70             return result;
71         }
72         descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());
73         
74         if(ejbJar!=null)
75         {
76             EnterpriseBeans entBean = ejbJar.getEnterpriseBeans();
77             CmpResource cmpResource = entBean.getCmpResource();
78             if(cmpResource!=null)
79             {
80                 String JavaDoc jndiName = cmpResource.getJndiName();
81                 if(jndiName.length()==0)
82                 {
83                     result.failed(smh.getLocalString(getClass().getName()+".failed",
84                         "FAILED [AS-EJB cmp-resource] : jndi-name cannot be an empty string"));
85                     oneFailed=true;//4698046
86
}
87                 else
88                 {
89                     if(jndiName.startsWith("jdbc/")|| jndiName.startsWith("jdo/"))
90                         result.passed(smh.getLocalString(getClass().getName()+".passed",
91                             "PASSED [AS-EJB cmp-resource] : jndi-name is {0}",new Object JavaDoc[]{jndiName}));
92                     else{
93                         result.warning(smh.getLocalString(getClass().getName()+".warning",
94                             "WARNING [AS-EJB cmp-resource] : The jndi-name is {0}, the preferred jndi-name should start with jdbc/ or jdo/"
95                             , new Object JavaDoc[]{jndiName}));
96                             oneWarning=true;//4698046
97
}
98                 }
99                 
100                 DefaultResourcePrincipal defPrincipal = cmpResource.getDefaultResourcePrincipal();
101                 if(defPrincipal!=null)
102                 {
103                     String JavaDoc name = defPrincipal.getName();
104                     if(name.length()==0)
105                     {
106                         result.failed(smh.getLocalString(getClass().getName()+".failed2",
107                             "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
108                         oneFailed=true; //4698046
109
}
110                     else
111                     {
112                         result.passed(smh.getLocalString(getClass().getName()+".passed1",
113                             "PASSED [AS-EJB default-resource-principal] : name is {0}",new Object JavaDoc[]{name}));
114                     }
115
116                     String JavaDoc password = defPrincipal.getPassword();
117                     if(password.length()==0)
118                     {
119                         // <addition> srini@sun.com
120
//result.failed(smh.getLocalString(getClass().getName()+".failed3",
121
// "FAILED [AS-EJB default-resource-principal] : password cannot be an empty string"));
122
result.warning(smh.getLocalString(getClass().getName()+".warning1",
123                             "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
124                         // </addition>
125
oneWarning=true;//4698046
126
}
127                     else
128                     {
129                         result.passed(smh.getLocalString(getClass().getName()+".passed2",
130                             "PASSED [AS-EJB default-resource-principal] : password is {0}",new Object JavaDoc[]{password}));
131                     }
132                 }
133                 else
134                     result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
135                         "NOT APPLICABLE [AS-EJB cmp-resource] : default-resource-principal Element not defined"));
136             
137                 if(oneFailed)//4698046
138
result.setStatus(Result.FAILED);
139                 else if(oneWarning)
140                     result.setStatus(Result.WARNING);
141             
142             }
143             else
144                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
145                     "NOT APPLICABLE [AS-EJB enterprise-beans] : cmp-resource element is not defined"));
146         }
147         else
148         {
149             result.addErrorDetails(smh.getLocalString
150                                    ("tests.componentNameConstructor",
151                                     "For [ {0} ]",
152                                     new Object JavaDoc[] {compName.toString()}));
153             result.addErrorDetails(smh.getLocalString
154                  (getClass().getName() + ".notRun1",
155                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
156         }
157         return result;
158     }
159 }
160
161
Popular Tags