1 19 20 package org.netbeans.modules.j2ee.refactoring.test; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import junit.textui.TestRunner; 25 import org.netbeans.junit.NbTestSuite; 26 import org.netbeans.modules.web.taglib.TLDDataObject; 27 import org.netbeans.modules.j2ee.refactoring.test.util.Helper; 28 import org.openide.cookies.EditorCookie; 29 import org.openide.cookies.OpenCookie; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileStateInvalidException; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.loaders.DataObject; 34 35 39 public class J2EERenameRefactoringTest extends J2EERefactoringTest { 40 private static final String PROJECT_EJBMOD1 = "ejbmod1"; 41 private static final String PROJECT_WEBAPP1 = "webapp1"; 42 43 public J2EERenameRefactoringTest(String testName) { 44 super(testName); 45 } 46 47 public static NbTestSuite suite() { 48 NbTestSuite suite = new NbTestSuite("J2EERenameRefactoringTest"); 49 suite.addTest(new J2EERenameRefactoringTest("testPrepare")); 50 suite.addTest(new J2EERenameRefactoringTest("testTldRenameClass")); 51 suite.addTest(new J2EERenameRefactoringTest("testWebRenameClass")); 52 suite.addTest(new J2EERenameRefactoringTest("testEjbRenameClass")); 53 suite.addTest(new J2EERenameRefactoringTest("testWSRenameClass")); 54 suite.addTest(new J2EERenameRefactoringTest("testCleanup")); 55 return suite; 56 } 57 58 61 public void testPrepare() { 62 openProject(PROJECT_WEBAPP1); 63 openProject(PROJECT_EJBMOD1); 64 } 65 66 70 public void testTldRenameClass() throws FileStateInvalidException, IOException { 71 File f = getProjectFile(PROJECT_WEBAPP1, "/web/WEB-INF/tlds/mytld.tld"); 72 FileObject fo = FileUtil.toFileObject(f); 73 74 TLDDataObject tdo = ((TLDDataObject)DataObject.find(fo)); 76 OpenCookie oc = (OpenCookie)tdo.getCookie(OpenCookie.class); 77 oc.open(); 78 80 doRenameRefactoring(PROJECT_WEBAPP1, "abc.NewTagHandler", "RenamedTagHandler", "rename tag handler"); 81 82 Helper.waitForAWTDispatchThread(); 83 84 EditorCookie ec = (EditorCookie)tdo.getCookie(EditorCookie.class); 86 try { 87 ec.getDocument().insertString(0, " ", null); 88 ec.saveDocument(); 89 ec.getDocument().remove(0, 1); 90 ec.saveDocument(); 91 } catch (Exception e) { 92 fail(e.toString()); 93 } 94 96 Helper.waitForAWTDispatchThread(); 97 try { 99 checkGoldenFile(PROJECT_WEBAPP1, "src/java/abc/RenamedTagHandler.java", "RenamedTagHandler.pass"); 100 101 checkFile(PROJECT_WEBAPP1, "web/WEB-INF/tlds/mytld.tld", new String []{">abc.RenamedTagHandler<"}, 103 new String []{">abc.NewTagHandler<"}); 104 105 } catch (FileStateInvalidException e) { 106 fail(e.getMessage()); 107 } catch (IOException e) { 108 fail(e.getMessage()); 109 } 110 } 111 112 118 public void testWebRenameClass() throws FileStateInvalidException, IOException { 119 120 doRenameRefactoring(PROJECT_WEBAPP1, "abc.NewServlet", "RenamedServlet", "rename servlet"); 121 doRenameRefactoring(PROJECT_WEBAPP1, "abc.NewSimpleFilter", "RenamedFilter", "rename filter"); 122 doRenameRefactoring(PROJECT_WEBAPP1, "abc.NewServletListener", "RenamedListener", "rename listener"); 123 124 Helper.waitForAWTDispatchThread(); 125 126 try { 128 checkGoldenFile(PROJECT_WEBAPP1, "src/java/abc/RenamedServlet.java", "RenamedServlet.pass"); 129 checkGoldenFile(PROJECT_WEBAPP1, "src/java/abc/RenamedFilter.java", "RenamedFilter.pass"); 130 checkGoldenFile(PROJECT_WEBAPP1, "src/java/abc/RenamedListener.java", "RenamedListener.pass"); 131 132 checkFile(PROJECT_WEBAPP1, "web/WEB-INF/web.xml", 134 new String []{">abc.RenamedServlet<", ">abc.RenamedFilter<", ">abc.RenamedListener<"}, 135 new String []{">abc.NewServlet<", ">abc.NewSimpleFilter<", ">abc.NewServletListener<"}); 136 137 } catch (FileStateInvalidException e) { 138 fail(e.getMessage()); 139 } catch (IOException e) { 140 fail(e.getMessage()); 141 } 142 } 143 144 160 public void testEjbRenameClass() throws FileStateInvalidException, IOException { 161 Helper.waitForAWTDispatchThread(); 162 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewSessionBean", "RenamedSessionBean", "rename session bean"); 163 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewSessionLocal", "RenamedSessionLocal", 164 "rename session bean's local interface"); 165 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewSessionLocalHome", "RenamedSessionLocalHome", 166 "rename session bean's local home interface"); 167 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewSessionRemote", "RenamedSessionRemote", 168 "rename session bean's remote interface"); 169 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewSessionRemoteHome", "RenamedSessionRemoteHome", 170 "rename session bean's remote home interface"); 171 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewMessageBean", "RenamedMessageBean", "rename queue message bean"); 172 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewMessageTopicBean", "RenamedMessageTopicBean", 173 "rename topic message bean"); 174 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityContainerBean", "RenamedEntityContainerBean", 175 "rename entity container bean"); 176 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityContainerLocal", "RenamedEntityContainerLocal", 177 "rename entity container bean's local interface"); 178 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityContainerLocalHome", "RenamedEntityContainerLocalHome", 179 "rename entity container bean's local home interface"); 180 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityBeanMPBean", "RenamedEntityBeanMPBean", 181 "rename entity bmp bean"); 182 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityBeanMPLocal", "RenamedEntityBeanMPLocal", 183 "rename entity bmp bean's local interface"); 184 doRenameRefactoring(PROJECT_EJBMOD1, "my.enterprise.beans.NewEntityBeanMPLocalHome", "RenamedEntityBeanMPLocalHome", 185 "rename entity bmp bean's local home interface"); 186 187 Helper.waitForAWTDispatchThread(); 188 189 try { 191 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedSessionBean.java", 192 "RenamedSessionBean.pass"); 193 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedSessionLocal.java", 194 "RenamedSessionLocal.pass"); 195 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedSessionLocalHome.java", 196 "RenamedSessionLocalHome.pass"); 197 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedSessionRemote.java", 198 "RenamedSessionRemote.pass"); 199 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedSessionRemoteHome.java", 200 "RenamedSessionRemoteHome.pass"); 201 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedMessageBean.java", 202 "RenamedMessageBean.pass"); 203 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedMessageTopicBean.java", 204 "RenamedMessageTopicBean.pass"); 205 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityContainerBean.java", 206 "RenamedEntityContainerBean.pass"); 207 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityContainerLocal.java", 208 "RenamedEntityContainerLocal.pass"); 209 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityContainerLocalHome.java", 210 "RenamedEntityContainerLocalHome.pass"); 211 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityBeanMPBean.java", 212 "RenamedEntityBeanMPBean.pass"); 213 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityBeanMPLocal.java", 214 "RenamedEntityBeanMPLocal.pass"); 215 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/enterprise/beans/RenamedEntityBeanMPLocalHome.java", 216 "RenamedEntityBeanMPLocalHome.pass"); 217 218 String [] mustContain = new String []{ 220 ">my.enterprise.beans.RenamedSessionBean<", 221 ">my.enterprise.beans.RenamedSessionLocal<", 222 ">my.enterprise.beans.RenamedSessionLocalHome<", 223 ">my.enterprise.beans.RenamedSessionRemote<", 224 ">my.enterprise.beans.RenamedSessionRemoteHome<", 225 ">my.enterprise.beans.RenamedMessageBean<", 226 ">my.enterprise.beans.RenamedMessageTopicBean<", 227 ">my.enterprise.beans.RenamedEntityContainerBean<", 228 ">my.enterprise.beans.RenamedEntityContainerLocal<", 229 ">my.enterprise.beans.RenamedEntityContainerLocalHome<", 230 ">my.enterprise.beans.RenamedEntityBeanMPBean<", 231 ">my.enterprise.beans.RenamedEntityBeanMPLocal<", 232 ">my.enterprise.beans.RenamedEntityBeanMPLocalHome<" 233 }; 234 String [] mustNotContain = new String []{ 235 ">my.enterprise.beans.NewSessionBean<", 236 ">my.enterprise.beans.NewSessionLocal<", 237 ">my.enterprise.beans.NewSessionLocalHome<", 238 ">my.enterprise.beans.NewSessionRemote<", 239 ">my.enterprise.beans.NewSessionRemoteHome<", 240 ">my.enterprise.beans.NewMessageBean<", 241 ">my.enterprise.beans.NewMessageTopicBean<", 242 ">my.enterprise.beans.NewEntityContainerBean<", 243 ">my.enterprise.beans.NewEntityContainerLocal<", 244 ">my.enterprise.beans.NewEntityContainerLocalHome<", 245 ">my.enterprise.beans.NewEntityBeanMPBean<", 246 ">my.enterprise.beans.NewEntityBeanMPLocal<", 247 ">my.enterprise.beans.NewEntityBeanMPLocalHome<" 248 }; 249 250 try { 252 Thread.sleep(2000); 253 } catch (InterruptedException e) { 254 } 256 257 checkFile(PROJECT_EJBMOD1, "src/conf/ejb-jar.xml", mustContain, mustNotContain); 258 259 } catch (FileStateInvalidException e) { 260 fail(e.getMessage()); 261 } catch (IOException e) { 262 fail(e.getMessage()); 263 } 264 } 265 266 271 public void testWSRenameClass() throws FileStateInvalidException, IOException { 272 273 doRenameRefactoring(PROJECT_EJBMOD1, "my.ws.server.NewWebServiceBean", "RenamedWebServiceBean", "rename ws server impl bean"); 274 doRenameRefactoring(PROJECT_EJBMOD1, "my.ws.server.NewWebServiceSEI", "RenamedWebServiceSEI", 275 "rename ws server servlet endpoint interface"); 276 277 Helper.waitForAWTDispatchThread(); 278 279 try { 281 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/ws/server/RenamedWebServiceBean.java", "RenamedWebServiceBean.pass"); 282 checkGoldenFile(PROJECT_EJBMOD1, "src/java/my/ws/server/RenamedWebServiceSEI.java", "RenamedWebServiceSEI.pass"); 283 284 checkFile(PROJECT_EJBMOD1, "src/java/my/ws/server/NewWebService-config.xml", 286 new String []{"my.ws.server.RenamedWebServiceSEI", "my.ws.server.RenamedWebServiceBean"}, 287 new String []{"my.ws.server.NewWebServiceSEI", "my.ws.server.NewWebServiceBean"}); 288 289 checkFile(PROJECT_EJBMOD1, "src/conf/ejb-jar.xml", new String []{">my.ws.server.RenamedWebServiceBean<"}, 291 new String []{">my.ws.server.NewWebServiceBean<"}); 292 293 checkFile(PROJECT_EJBMOD1, "src/conf/webservices.xml", new String []{">my.ws.server.RenamedWebServiceSEI<"}, 295 new String []{">my.ws.server.NewWebServiceSEI<"}); 296 297 checkFile(PROJECT_EJBMOD1, "src/conf/webservices.xml", new String []{">wsdl-port_ns:RenamedWebServiceSEIPort<"}, 299 new String []{">wsdl-port_ns:NewWebServiceSEIPort<"}); 300 301 } catch (FileStateInvalidException e) { 302 fail(e.getMessage()); 303 } catch (IOException e) { 304 fail(e.getMessage()); 305 } 306 } 307 308 311 public void testCleanup() { 312 closeProject(PROJECT_WEBAPP1); 313 closeProject(PROJECT_EJBMOD1); 314 } 315 316 321 public static void main(String [] args) { 322 TestRunner.run(suite()); 323 } 324 325 } 326 | Popular Tags |