KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > webservices > SEIEJBTxAttrChk


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.webservices;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.*;
27 import java.util.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import java.lang.reflect.*;
30
31 /*
32  * @class.setup_props: ;
33  */

34
35 /*
36  * @testName: check
37  * @assertion_ids: JSR109_WS_1
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription :If the Service Implementation Bean is an EJB,
41  * the transaction attributes for the methods defined by the SEI do not include Mandatory.
42  */

43 public class SEIEJBTxAttrChk extends WSTest implements WSCheck {
44
45     /**
46      * @param descriptor the WebService deployment descriptor
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check (WebServiceEndpoint wsdescriptor) {
50
51     Result result = getInitializedResult();
52         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         boolean pass = true;
55
56         if (wsdescriptor.implementedByEjbComponent()) {
57
58           EjbDescriptor descriptor = wsdescriptor.getEjbComponentImpl();
59
60       try {
61              ContainerTransaction ctx = descriptor.getContainerTransaction();
62
63              if ((ctx != null) &&
64                  (ContainerTransaction.MANDATORY.equals(ctx.getTransactionAttribute()))) {
65                  // Call result.failed here : All methods are having Mandatory TX
66
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
67                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
68                   result.failed(smh.getLocalString (getClass().getName() + ".failed",
69                   "[{0}] of this WebService [{1}] have Mandatory Transaction Attribute.",
70                   new Object JavaDoc[] {"All the methods", compName.toString()}));
71
72                  return result;
73              }
74
75              Collection txMethDescs = descriptor.getTransactionMethodDescriptors();
76
77              // get hold of the SEI Class
78
String JavaDoc s = descriptor.getWebServiceEndpointInterfaceName();
79
80              if (s == null) {
81                // internal error, should never happen
82
result.addErrorDetails(smh.getLocalString
83                ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
84                 "Error: Unexpected error occurred [ {0} ]",
85                 new Object JavaDoc[] {"Service Endpoint Interface Class Name Null"}));
86                 pass = false;
87              }
88              ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
89              Class JavaDoc sei = null;
90
91              try {
92                 sei = Class.forName(s, false, cl);
93              }catch(ClassNotFoundException JavaDoc e) {
94                result.addErrorDetails(smh.getLocalString
95                ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
96                 "Error: Unexpected error occurred [ {0} ]",
97                 new Object JavaDoc[] {"Could not Load Service Endpoint Interface Class"}));
98                 pass = false;
99              }
100
101              Iterator it = txMethDescs.iterator();
102              while (it.hasNext()) {
103                // need to check if this method is part of SEI
104
MethodDescriptor methdesc =(MethodDescriptor)it.next();
105               if (isSEIMethod(methdesc, descriptor, sei, cl)) {
106                   ctx = descriptor.getContainerTransactionFor(methdesc);
107                   if ((ctx != null) &&
108                      (ContainerTransaction.MANDATORY.equals(ctx.getTransactionAttribute()))) {
109                      // Call result.failed here with Method details here
110
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
111                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
112                      result.failed(smh.getLocalString (getClass().getName() + ".failed",
113                      "[{0}] of this WebService [{1}] have Mandatory Transaction Attribute.",
114                      new Object JavaDoc[] {methdesc.getName(), compName.toString()}));
115                      pass = false;
116                    }
117                }
118              }
119            } catch (Exception JavaDoc e) {
120              // Call result.addErrorDetails here with exception details
121
result.addErrorDetails(smh.getLocalString
122                ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
123                 "Error: Unexpected error occurred [ {0} ]",
124                 new Object JavaDoc[] {e.getMessage()}));
125                 pass = false;
126            }
127
128           if (pass) {
129
130            result.addGoodDetails(smh.getLocalString
131                                   ("tests.componentNameConstructor",
132                                    "For [ {0} ]",
133                                    new Object JavaDoc[] {compName.toString()}));
134            result.passed(smh.getLocalString (getClass().getName() + ".passed",
135                     "None of the methods of this WebService [{0}] have Mandatory Transaction Attribute.",
136                            new Object JavaDoc[] {compName.toString()}));
137
138           }
139           
140           return result;
141          }
142          else {
143           // call result.notapplicable
144
result.addNaDetails(smh.getLocalString
145                      ("tests.componentNameConstructor", "For [ {0} ]",
146                       new Object JavaDoc[] {compName.toString()}));
147           result.notApplicable(smh.getLocalString (getClass().getName() + ".notapp",
148                  "Not applicable since this is not an EJB Service Endpoint."));
149
150           return result;
151          }
152        }
153  }
154
155
Popular Tags