KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > runtime > ASResourceRefName


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.common.*;
33
34 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
35
/* Changed the result messages to reflect consistency between the result messages generated
36  * for the EJB test cases for SunONE specific deployment descriptors*/

37 //</addition>
38

39
40 public class ASResourceRefName extends WebTest implements WebCheck {
41
42     public Result check(WebBundleDescriptor descriptor) {
43         String JavaDoc resrefName;
44         Result result = getInitializedResult();
45         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
46 //Start Bugid:4703107
47
DefaultResourcePrincipal defPrincipal;
48 //End Bugid:4703107
49
boolean oneFailed = false;
50         boolean notApp = false;
51         try{
52             ResourceRef[] resRefs = (descriptor.getSunDescriptor()).getResourceRef();
53             if (resRefs != null && resRefs.length > 0) {
54                 for (int rep=0; rep<resRefs.length; rep++ ) {
55                     resrefName = resRefs[rep].getResRefName();
56                     if (validResRefName(resrefName,descriptor)) {
57                         addGoodDetails(result, compName);
58                         result.passed(smh.getLocalString
59                                 (getClass().getName() + ".passed",
60                                         "PASSED [AS-WEB sun-web-app] resource-ref name [ {0} ] properly defined in the war file.",
61                                         new Object JavaDoc[] {resrefName}));
62
63                     }
64                     else {
65                         oneFailed = true;
66                         addErrorDetails(result, compName);
67                         result.failed(smh.getLocalString
68                                 (getClass().getName() + ".failed",
69                                         "FAILED [AS-WEB sun-web-app] resource-ref name [ {0} ] is not valid, either empty or not defined in web.xml.",
70                                         new Object JavaDoc[] {resrefName}));
71                     }
72                     //Start Bugid:4703107
73
defPrincipal = resRefs[rep].getDefaultResourcePrincipal();
74                     if(defPrincipal != null){
75                         boolean defResourcePrincipalValid = true;
76                         String JavaDoc defaultname = defPrincipal.getName();
77                         String JavaDoc defaultpassword = defPrincipal.getPassword();
78                         if((defaultname == null)||(defaultname.length() == 0)){
79                             oneFailed=true;
80                             defResourcePrincipalValid = false;
81                             addErrorDetails(result, compName);
82                             result.failed(smh.getLocalString
83                                     (getClass().getName() + ".failed2",
84                                             "FAILED [AS-WEB resource-ref] name field in DefaultResourcePrincipal of ResourceRef [ {0} ] is not specified or is an empty string.",
85                                             new Object JavaDoc[] {resrefName}));
86                         }
87                         if((defaultpassword == null)||(defaultpassword.length() == 0)){
88                             oneFailed=true;
89                             defResourcePrincipalValid = false;
90                             addErrorDetails(result, compName);
91                             result.failed(smh.getLocalString
92                                     (getClass().getName() + ".failed3",
93                                             "FAILED [AS-WEB resource-ref] password field in DefaultResourcePrincipal of ResourceRef [ {0} ] is not specified or is an empty string.",
94                                             new Object JavaDoc[] {resrefName}));
95                         }
96                         if(defResourcePrincipalValid){
97                             addGoodDetails(result, compName);
98                             result.passed(smh.getLocalString
99                                     (getClass().getName() + ".passed3",
100                                             "PASSED [AS-WEB resource-ref] DefaultResourcePrincipal of ResourceRef [ {0} ] properly defined",
101                                             new Object JavaDoc[] {resrefName}));
102                         }
103                     }
104                     //End Bugid:4703107
105
}
106             } else {
107                 notApp = true;
108                 addNaDetails(result, compName);
109                 result.notApplicable(smh.getLocalString
110                         (getClass().getName() + ".notApplicable",
111                                 "NOT APPLICABLE [AS-WEB sun-web-app] resource-ref element not defined in the web archive [ {0} ].",
112                                 new Object JavaDoc[] {descriptor.getName()}));
113             }
114             if (oneFailed) {
115                 result.setStatus(Result.FAILED);
116             } else if(notApp) {
117                 result.setStatus(Result.NOT_APPLICABLE);
118             }else {
119                 result.setStatus(Result.PASSED);
120                 addGoodDetails(result, compName);
121                 result.passed
122                         (smh.getLocalString
123                         (getClass().getName() + ".passed2",
124                                 "PASSED [AS-WEB sun-web-app] resource-ref element(s) are valid within the web archive [ {0} ] .",
125                                 new Object JavaDoc[] {descriptor.getName()} ));
126             }
127         }catch(Exception JavaDoc ex){
128             oneFailed=true;
129             addErrorDetails(result, compName);
130             result.failed(smh.getLocalString
131                     (getClass().getName() + ".failed4", "FAILED [AS-WEB resource-env-ref] Could not create the resource-ref"));
132
133         }
134         return result;
135     }
136
137     boolean validResRefName(String JavaDoc name,WebBundleDescriptor descriptor){
138         boolean valid =true;
139         if(name !=null && name.length()!=0) {
140             try{
141                 descriptor.getResourceReferenceByName(name);
142             }
143             catch(IllegalArgumentException JavaDoc e){
144                 valid=false;
145             }
146         } else{
147             valid=false;
148
149         }
150
151         return valid;
152     }
153 }
154
Popular Tags