1 19 package org.netbeans.test.j2ee.refactoring.changesignature; 20 21 import java.io.File ; 22 import java.lang.reflect.Modifier ; 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 33 34 public class EjbModTest extends ChangeSignatureTestCase implements EjbModConstants { 36 37 private static boolean prjOpened = false; 38 39 private static final String METHOD_ACTIVATE = "ejbActivate"; 40 private static final String [] DUMMY_PARAMS = {}; 41 private static final String [][] CHANGE_PARAMS_TO 42 = new String [][] {{"ab", "java.lang.String", "\"\""}}; 43 private static final String METHOD_PASIVATE = "ejbPassivate"; 44 private static final String METHOD_CREATE = "ejbCreate"; 45 private static final String METHOD_REMOVE = "ejbRemove"; 46 private static final String METHOD_LOAD = "ejbLoad"; 47 private static final String METHOD_STORE = "ejbStore"; 48 private static final String METHOD_SET_SESSION_CONTEXT = "setSessionContext"; 49 private static final String [] METHOD_SET_SESSION_CONTEXT_PARAMS 50 = new String [] {"javax.ejb.SessionContext"}; 51 private static final String METHOD_SET_ENTITY_CONTEXT = "setEntityContext"; 52 private static final String [] METHOD_SET_ENTITY_CONTEXT_PARAMS 53 = new String [] {"javax.ejb.EntityContext"}; 54 private static final String METHOD_UNSET_ENTITY_CONTEXT = "unsetEntityContext"; 55 private static final String METHOD_POST_CREATE = "ejbPostCreate"; 56 private static final String [] METHOD_POST_CREATE_PARAMS 57 = new String [] {"java.lang.String"}; 58 private static final String METHOD_SET_MESSAGE_DRIVEN_CONTEXT 59 = "setMessageDrivenContext"; 60 private static final String [] METHOD_SET_MESSAGE_DRIVEN_CONTEXT_PARAMS 61 = new String [] {"javax.ejb.MessageDrivenContext"}; 62 private static final String METHOD_ON_MESSAGE = "onMessage"; 63 private static final String [] METHOD_ON_MESSAGE_PARAMS 64 = new String [] {"javax.jms.Message"}; 65 66 private static final String METHOD_FIND_BY_PRIMARY_KEY = "findByPrimaryKey"; 67 private static final String [] METHOD_FIND_BY_PRIMARY_KEY_PARAMS 68 = new String [] {"java.lang.String"}; 69 70 72 73 public EjbModTest(String 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 checkSessionLCMethods(CLASS_WS_1); 97 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 120 public static void main(String [] args) { 121 TestRunner.run(suite()); 122 } 123 124 public void prepareProject() { 125 if (prjOpened) { 126 return; 127 } 128 J2eeProjectSupport.openProject(new File (getDataDir(), "projects/League-util")); 129 J2eeProjectSupport.openProject(new File (getDataDir(), "projects/League-ejb")); 130 classPathWorkDir = new File (getDataDir(), "projects.League-ejb.src.java".replace('.', File.separatorChar)); 131 prjOpened = true; 132 } 133 134 private void checkSessionLCMethods(String 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 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 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 |