KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > TransactionTypeNullForContainerTX


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.ejb.session;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * Session Bean Transaction demarcation type test.
33  * For bean managed session beans, it doesn't make sense to have
34  * container transactions.
35  */

36 public class TransactionTypeNullForContainerTX extends EjbTest implements EjbCheck {
37
38
39     /**
40      * Session Bean Transaction demarcation type test.
41      * For bean managed session beans, it doesn't make sense to have
42      * container transactions.
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(EjbDescriptor descriptor) {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53     if (descriptor instanceof EjbSessionDescriptor) {
54         String JavaDoc transactionType = descriptor.getTransactionType();
55         if (EjbDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
56         // taken from DOL - remember that for bean managed session beans,
57
// it doesn't make sense to have container transactions
58
// you'll have to enforce this in the object model somewhere,
59
// and in the UI
60
try {
61             if (descriptor.getMethodContainerTransactions().size() > 0) {
62                 // shouldn't have container transaction for bean managed session
63
// since container transaction is not null, it's defined, we fail
64
// test
65
result.addErrorDetails(smh.getLocalString
66                            ("tests.componentNameConstructor",
67                         "For [ {0} ]",
68                         new Object JavaDoc[] {compName.toString()}));
69             result.failed(smh.getLocalString
70                       (getClass().getName() + ".failed",
71                        "Error: Session Beans [ {0} ] with [ {1} ] managed \n" +
72                        "transaction demarcation should not have container \n" +
73                        "transactions defined.",
74                        new Object JavaDoc[] {descriptor.getName(),transactionType}));
75             } else {
76                 // container transaction is null, not defined, which is correct
77
// shouldn't have container transaction for bean managed session
78
result.addGoodDetails(smh.getLocalString
79                           ("tests.componentNameConstructor",
80                            "For [ {0} ]",
81                            new Object JavaDoc[] {compName.toString()}));
82             result.passed(smh.getLocalString
83                       (getClass().getName() + ".passed",
84                        "This session bean [ {0} ] is [ {1} ] managed and correctly declares no container transactions.",
85                        new Object JavaDoc[] {descriptor.getName(),transactionType}));
86             }
87             return result;
88                 } catch (NullPointerException JavaDoc e) {
89             // container transaction is null, not defined, which is correct
90
// shouldn't have container transaction for bean managed session
91
result.addGoodDetails(smh.getLocalString
92                       ("tests.componentNameConstructor",
93                        "For [ {0} ]",
94                        new Object JavaDoc[] {compName.toString()}));
95             result.passed(smh.getLocalString
96                   (getClass().getName() + ".passed",
97                    "This session bean [ {0} ] is [ {1} ] managed and correctly declares no container transactions.",
98                    new Object JavaDoc[] {descriptor.getName(),transactionType}));
99             return result;
100         }
101         
102         } else {
103         // not bean/container managed, but is a session/entity bean
104
// (i.e it's CONTAINER_TRANSACTION_TYPE)
105
result.addNaDetails(smh.getLocalString
106                     ("tests.componentNameConstructor",
107                      "For [ {0} ]",
108                      new Object JavaDoc[] {compName.toString()}));
109         result.notApplicable(smh.getLocalString
110                      (getClass().getName() + ".notApplicable1",
111                       "Session bean [ {0} ], expected [ {1} ] managed, but called with [ {2} ] managed.",
112                       new Object JavaDoc[] {descriptor.getName(),EjbDescriptor.BEAN_TRANSACTION_TYPE, EjbDescriptor.CONTAINER_TRANSACTION_TYPE}));
113         return result;
114         }
115     } else {
116         result.addNaDetails(smh.getLocalString
117                 ("tests.componentNameConstructor",
118                  "For [ {0} ]",
119                  new Object JavaDoc[] {compName.toString()}));
120         result.notApplicable(smh.getLocalString
121                  (getClass().getName() + ".notApplicable",
122                   "[ {0} ] expected {1} \n bean, but called with {2} bean.",
123                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
124         return result;
125     }
126     }
127 }
128
Popular Tags