KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.tools.verifier.tests.web;
24
25 import java.util.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
30 import com.sun.enterprise.deployment.WebBundleDescriptor;
31
32
33 /**
34  * Must check for the correct authorization.
35  * @author Arun Jain
36  */

37 public class ResourceAuth extends WebTest implements WebCheck{
38     
39
40      /**
41      * Resource authority exists test. Must be Container or Servlet.
42      *
43      * @param descriptor the Web deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(WebBundleDescriptor descriptor) {
48
49         Set resourceRefs;
50         ResourceReferenceDescriptor resrefDes;
51         Iterator itr;
52         String JavaDoc resAuth;
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55         boolean oneFailed = false;
56         
57     if (!descriptor.getResourceReferenceDescriptors().isEmpty()) {
58             
59         // get the Resource Reference Descriptors set
60
resourceRefs = descriptor.getResourceReferenceDescriptors();
61         itr = resourceRefs.iterator();
62         // test the Resource Reference Descriptor
63
while (itr.hasNext()) {
64         resrefDes = (ResourceReferenceDescriptor)itr.next();
65         resAuth = resrefDes.getAuthorization();
66                 if (resAuth.equals("Application") || resAuth.equals("Container")) {
67             result.addGoodDetails(smh.getLocalString
68                        ("tests.componentNameConstructor",
69                     "For [ {0} ]",
70                     new Object JavaDoc[] {compName.toString()}));
71         result.addGoodDetails(smh.getLocalString
72                                        (getClass().getName() + ".passed",
73                                     "Resource reference has valid authorization."));
74                 }
75
76                 else {
77                     oneFailed = true;
78             result.addErrorDetails(smh.getLocalString
79                        ("tests.componentNameConstructor",
80                     "For [ {0} ]",
81                     new Object JavaDoc[] {compName.toString()}));
82             result.addErrorDetails(smh.getLocalString
83                                        (getClass().getName() + ".failed",
84                                     "Error: Resource reference auth has to be either Container or Application."));
85
86                 }
87             }
88             
89         } else {
90         result.addNaDetails(smh.getLocalString
91                        ("tests.componentNameConstructor",
92                     "For [ {0} ]",
93                     new Object JavaDoc[] {compName.toString()}));
94         result.notApplicable(smh.getLocalString
95                                  (getClass().getName() + ".notApplicable",
96                                   "There are no resource references defined within the web archive [ {0} ]",
97                                   new Object JavaDoc[] {descriptor.getName()}));
98         }
99         if (oneFailed) {
100             result.setStatus(Result.FAILED);
101         } else {
102             result.setStatus(Result.PASSED);
103         }
104     return result;
105     }
106 }
107
Popular Tags