1 19 package org.netbeans.test.j2ee.refactoring.move; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import org.netbeans.jmi.javamodel.Resource; 25 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 26 import org.netbeans.modules.refactoring.api.MoveClassRefactoring; 27 import org.netbeans.modules.refactoring.api.RefactoringSession; 28 import org.netbeans.test.j2ee.refactoring.RefactoringTestCase; 29 import org.netbeans.test.j2ee.refactoring.Utility; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.FileUtil; 32 33 37 public class MoveTestCase extends RefactoringTestCase { 38 39 protected static final String DESTINATION_PACKAGE_1 = "org.netbeans.test.examples.movetest"; 40 41 protected static final String DESTINATION_PACKAGE_2 = "org.netbeans.test.examples.movetest.subpkg"; 42 43 44 public MoveTestCase(String name) { 45 super(name); 46 } 47 48 protected void moveClass(String name, String newPackage, boolean undo) { 49 setJavaClass(name); 50 ref("Move class "+name+" to "+newPackage); 51 52 HashMap files=null; 53 RefactoringSession result = RefactoringSession.create("Move Class"); 54 boolean finish=false; 55 Utility.prepareTest(); 56 try { 57 Resource resource = (Resource) jc.refImmediateComposite(); 58 FileObject classPathWorkDirFO = FileUtil.toFileObject(classPathWorkDir); 59 Collection list = new ArrayList (1); 60 list.add(resource); 61 MoveClassRefactoring refactoring = new MoveClassRefactoring(list); 62 if (refProblems( refactoring.preCheck() )) throw new Exception ("Fatal problem"); 63 refactoring.setTargetClassPathRoot(classPathWorkDirFO); 64 refactoring.setTargetPackageName(newPackage); 65 if (refProblems(refactoring.checkParameters())) throw new Exception ("Fatal problem"); 66 if (refProblems(refactoring.prepare(result) )) throw new Exception ("Fatal problem"); 67 files=getResources(result); 68 if (refProblems( result.doRefactoring(true) )) throw new Exception ("Fatal problem"); 69 finish=true; 70 } catch (Throwable t) { 71 if (t.getMessage() == null || !t.getMessage().equals("Fatal problem")) { 72 t.printStackTrace(getLogStream()); 73 assertTrue(t.getMessage(), false); 74 } 75 } finally { 76 Utility.finishTest(); 77 } 78 if (finish) { 79 try { 80 Thread.sleep(5000); 81 if (undo) { 82 JavaMetamodel.getUndoManager().undo(); 83 Thread.sleep(10000); 84 } 85 compareResources(files, result, name, newPackage+"."+((name.indexOf('.') > -1) ? name.substring(name.lastIndexOf('.')+1):name)); 86 } catch (Exception ex) { 87 ex.printStackTrace(getLogStream()); 88 assertTrue(ex.getMessage(), false); 89 } 90 } 91 } 92 } 93 | Popular Tags |