KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > refactoring > changesignature > EjbModTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.j2ee.refactoring.changesignature;
20
21 import java.io.File JavaDoc;
22 import java.lang.reflect.Modifier JavaDoc;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
27 import org.netbeans.test.j2ee.refactoring.EjbModConstants;
28
29 /**
30  *
31  * @author jungi
32  */

33
34 //TODO: put ejbPostCreate somewhere...
35
public class EjbModTest extends ChangeSignatureTestCase implements EjbModConstants {
36     
37     private static boolean prjOpened = false;
38     
39     private static final String JavaDoc METHOD_ACTIVATE = "ejbActivate";
40     private static final String JavaDoc[] DUMMY_PARAMS = {};
41     private static final String JavaDoc[][] CHANGE_PARAMS_TO
42             = new String JavaDoc[][] {{"ab", "java.lang.String", "\"\""}};
43     private static final String JavaDoc METHOD_PASIVATE = "ejbPassivate";
44     private static final String JavaDoc METHOD_CREATE = "ejbCreate";
45     private static final String JavaDoc METHOD_REMOVE = "ejbRemove";
46     private static final String JavaDoc METHOD_LOAD = "ejbLoad";
47     private static final String JavaDoc METHOD_STORE = "ejbStore";
48     private static final String JavaDoc METHOD_SET_SESSION_CONTEXT = "setSessionContext";
49     private static final String JavaDoc[] METHOD_SET_SESSION_CONTEXT_PARAMS
50             = new String JavaDoc[] {"javax.ejb.SessionContext"};
51     private static final String JavaDoc METHOD_SET_ENTITY_CONTEXT = "setEntityContext";
52     private static final String JavaDoc[] METHOD_SET_ENTITY_CONTEXT_PARAMS
53             = new String JavaDoc[] {"javax.ejb.EntityContext"};
54     private static final String JavaDoc METHOD_UNSET_ENTITY_CONTEXT = "unsetEntityContext";
55     private static final String JavaDoc METHOD_POST_CREATE = "ejbPostCreate";
56     private static final String JavaDoc[] METHOD_POST_CREATE_PARAMS
57             = new String JavaDoc[] {"java.lang.String"};
58     private static final String JavaDoc METHOD_SET_MESSAGE_DRIVEN_CONTEXT
59             = "setMessageDrivenContext";
60     private static final String JavaDoc[] METHOD_SET_MESSAGE_DRIVEN_CONTEXT_PARAMS
61             = new String JavaDoc[] {"javax.ejb.MessageDrivenContext"};
62     private static final String JavaDoc METHOD_ON_MESSAGE = "onMessage";
63     private static final String JavaDoc[] METHOD_ON_MESSAGE_PARAMS
64             = new String JavaDoc[] {"javax.jms.Message"};
65             
66     private static final String JavaDoc METHOD_FIND_BY_PRIMARY_KEY = "findByPrimaryKey";
67     private static final String JavaDoc[] METHOD_FIND_BY_PRIMARY_KEY_PARAMS
68             = new String JavaDoc[] {"java.lang.String"};
69     
70     //_name_Bean, _name_Local, _name_LocalHome, _name_Remote, _name_RemoteHome, MDB
71

72     /** Creates a new instance of EjbModTest */
73     public EjbModTest(String JavaDoc name) {
74         super(name);
75     }
76     
77     public static TestSuite suite() {
78         NbTestSuite suite = new NbTestSuite();
79         suite.addTest(new EjbModTest("testWebSvcMethods"));
80         suite.addTest(new EjbModTest("testStatelessSessionBeanMethods"));
81         suite.addTest(new EjbModTest("testTopicMDBMethods"));
82         suite.addTest(new EjbModTest("testQueueMDBMethods"));
83         suite.addTest(new EjbModTest("testCMPEntityBeanMethods"));
84         return suite;
85     }
86     
87     public void testStatelessSessionBeanMethods() {
88         checkSessionLCMethods(CLASS_SESSION_1);
89         changeSignature(CLASS_SESSION_1, METHOD_CREATE,
90                 DUMMY_PARAMS, CHANGE_PARAMS_TO,
91                 Modifier.PUBLIC, false);
92     }
93     
94     public void testWebSvcMethods() {
95         //same as stateless session bean:
96
checkSessionLCMethods(CLASS_WS_1);
97         //user should not be able to change ejbCreate method in this case:
98
changeSignature(CLASS_WS_1, METHOD_CREATE,
99                 DUMMY_PARAMS, CHANGE_PARAMS_TO,
100                 Modifier.PUBLIC, false);
101     }
102     
103     public void testTopicMDBMethods() {
104         checkMdbLCMethods(MDB_TOPIC);
105     }
106     
107     public void testQueueMDBMethods() {
108         checkMdbLCMethods(MDB_QUEUE);
109     }
110
111     public void testCMPEntityBeanMethods() {
112         checkCMPEntityLCMethods(CLASS_CMP_ENTITY_4);
113     }
114     
115     /**
116      * Used for running test from inside the IDE by internal execution.
117      *
118      * @param args the command line arguments
119      */

120     public static void main(String JavaDoc[] args) {
121         TestRunner.run(suite());
122     }
123
124     public void prepareProject() {
125         if (prjOpened) {
126             return;
127         }
128         J2eeProjectSupport.openProject(new File JavaDoc(getDataDir(), "projects/League-util"));
129         J2eeProjectSupport.openProject(new File JavaDoc(getDataDir(), "projects/League-ejb"));
130         classPathWorkDir = new File JavaDoc(getDataDir(), "projects.League-ejb.src.java".replace('.', File.separatorChar));
131         prjOpened = true;
132     }
133     
134     private void checkSessionLCMethods(String JavaDoc ejbName) {
135         changeSignature(ejbName, METHOD_ACTIVATE, DUMMY_PARAMS,
136                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
137         changeSignature(ejbName, METHOD_PASIVATE, DUMMY_PARAMS,
138                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
139         changeSignature(ejbName, METHOD_REMOVE, DUMMY_PARAMS,
140                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
141         changeSignature(ejbName, METHOD_SET_SESSION_CONTEXT,
142                 METHOD_SET_SESSION_CONTEXT_PARAMS, CHANGE_PARAMS_TO,
143                 Modifier.PUBLIC, false);
144     }
145      
146     private void checkMdbLCMethods(String JavaDoc mdbName) {
147         changeSignature(mdbName, METHOD_REMOVE, DUMMY_PARAMS,
148                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
149         changeSignature(mdbName, METHOD_SET_MESSAGE_DRIVEN_CONTEXT,
150                 METHOD_SET_MESSAGE_DRIVEN_CONTEXT_PARAMS, CHANGE_PARAMS_TO,
151                 Modifier.PUBLIC, false);
152         changeSignature(mdbName, METHOD_ON_MESSAGE, METHOD_ON_MESSAGE_PARAMS,
153                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
154         changeSignature(mdbName, METHOD_CREATE, DUMMY_PARAMS,
155                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
156     }
157     
158     private void checkCMPEntityLCMethods(String JavaDoc cmpName) {
159         changeSignature(cmpName, METHOD_ACTIVATE, DUMMY_PARAMS,
160                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
161         changeSignature(cmpName, METHOD_PASIVATE, DUMMY_PARAMS,
162                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
163         changeSignature(cmpName, METHOD_REMOVE, DUMMY_PARAMS,
164                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
165         changeSignature(cmpName, METHOD_SET_ENTITY_CONTEXT,
166                 METHOD_SET_ENTITY_CONTEXT_PARAMS, CHANGE_PARAMS_TO,
167                 Modifier.PUBLIC, false);
168         changeSignature(cmpName, METHOD_UNSET_ENTITY_CONTEXT, DUMMY_PARAMS,
169                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
170         changeSignature(cmpName, METHOD_LOAD, DUMMY_PARAMS,
171                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
172         changeSignature(cmpName, METHOD_STORE, DUMMY_PARAMS,
173                 CHANGE_PARAMS_TO, Modifier.PUBLIC, false);
174     }
175 }
176
Popular Tags