diff options
author | Stephan Herrmann | 2010-04-01 23:26:59 +0000 |
---|---|---|
committer | Stephan Herrmann | 2010-04-01 23:26:59 +0000 |
commit | 1bdfa7212104a5b97e6df46653802e9d19acb664 (patch) | |
tree | 8877dca7329f73b8e73d045c229bf021c011ccde /testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring | |
parent | b1427fd4a32812eaa29b7c9204ce2c6af2dc9508 (diff) | |
download | org.eclipse.objectteams-1bdfa7212104a5b97e6df46653802e9d19acb664.tar.gz org.eclipse.objectteams-1bdfa7212104a5b97e6df46653802e9d19acb664.tar.xz org.eclipse.objectteams-1bdfa7212104a5b97e6df46653802e9d19acb664.zip |
initial commit in accordance with CQ 3784
Diffstat (limited to 'testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring')
42 files changed, 9277 insertions, 0 deletions
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/AllTests.java new file mode 100644 index 000000000..75062084a --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/AllTests.java @@ -0,0 +1,78 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All Refactoring Tests");
+
+ // OTDT refactoring tests
+ // rename
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameMethodInInterfaceTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenamePrivateMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameStaticMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameVirtualMethodInClassTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenamePrivateFieldTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameTypeTests.suite());
+
+ // move
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.move.MoveInstanceMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.move.MoveStaticMethodTests.suite());
+
+ //extract
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractMethodRefactoringUtilTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractTempTests.suite());
+
+ //copy & paste, delete (cut)
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTCopyToClipboardTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTDeleteTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTPasteActionTest.suite());
+
+ // pull & push
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.pullup.PullUpTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.pushdown.PushDownTests.suite());
+
+ // ot refactorings
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.inlinecallin.InlineCallinTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractcallin.ExtractCallinTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/FileBasedRefactoringTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/FileBasedRefactoringTest.java new file mode 100644 index 000000000..e17c59b10 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/FileBasedRefactoringTest.java @@ -0,0 +1,37 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring;
+
+import org.eclipse.objectteams.otdt.tests.FileBasedTest;
+
+/**
+ * @author svacina
+ */
+public class FileBasedRefactoringTest extends FileBasedTest {
+
+ public FileBasedRefactoringTest(String name) {
+ super(name);
+ }
+
+ protected String getPluginID() {
+ return "org.eclipse.objectteams.otdt.ui.tests.refactoring";
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/MySetup.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/MySetup.java new file mode 100644 index 000000000..a7af2761b --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/MySetup.java @@ -0,0 +1,122 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.refactoring;
+
+import java.util.Hashtable;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper;
+import org.eclipse.objectteams.otdt.ui.tests.util.TestOptions;
+
+public class MySetup extends TestSetup
+{
+ private static IPackageFragmentRoot _root;
+ private static IPackageFragment _packageP;
+ private static IJavaProject _javaTestProject;
+
+ public static final String CONTAINER = "src";
+
+
+ public MySetup(Test test)
+ {
+ super(test);
+ }
+
+ public static IPackageFragmentRoot getDefaultSourceFolder() throws Exception
+ {
+ if (_root != null)
+ {
+ return _root;
+ }
+ throw new Exception("MySetup not initialized");
+ }
+
+ public static IJavaProject getProject() throws Exception
+ {
+ if (_javaTestProject != null)
+ {
+ return _javaTestProject;
+ }
+ throw new Exception("MySetup not initialized");
+ }
+
+ public static IPackageFragment getPackageP() throws Exception
+ {
+ if (_packageP != null)
+ {
+ return _packageP;
+ }
+ throw new Exception("MySetup not initialized");
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ JavaProjectHelper.setAutoBuilding(false);
+ if (JavaPlugin.getActivePage() != null)
+ {
+ JavaPlugin.getActivePage().close();
+ }
+ _javaTestProject = JavaProjectHelper.createOTJavaProject("TestProject"
+ + System.currentTimeMillis(), "bin");
+ JavaProjectHelper.addRTJar(_javaTestProject);
+ _root = JavaProjectHelper.addSourceContainer(_javaTestProject,
+ CONTAINER);
+ _packageP = _root.createPackageFragment("p", true, null);
+
+ Hashtable options = TestOptions.getFormatterOptions();
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0");
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
+ JavaCore.setOptions(options);
+ TestOptions.initializeCodeGenerationOptions();
+ JavaPlugin.getDefault().getCodeTemplateStore().load();
+
+ StringBuffer comment = new StringBuffer();
+ comment.append("/**\n");
+ comment.append(" * ${tags}\n");
+ comment.append(" */");
+ StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORCOMMENT_ID, comment.toString(), null);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (_packageP.exists())
+ {
+ _packageP.delete(true, null);
+ }
+ JavaProjectHelper.removeSourceContainer(_javaTestProject, CONTAINER);
+ JavaProjectHelper.delete(_javaTestProject);
+ super.tearDown();
+ }
+
+}
+
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestPlugin.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestPlugin.java new file mode 100644 index 000000000..ba5484a6b --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestPlugin.java @@ -0,0 +1,83 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class OTRefactoringTestPlugin extends Plugin
+{
+ //The shared instance.
+ private static OTRefactoringTestPlugin plugin;
+
+ public OTRefactoringTestPlugin()
+ {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static OTRefactoringTestPlugin getDefault()
+ {
+ return plugin;
+ }
+
+ public static IWorkspace getWorkspace()
+ {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ public File getFileInPlugin(IPath path)
+ {
+ try
+ {
+ URL installURL = new URL(getDefault().getBundle().getEntry("/"), path.toString());
+ URL localURL = Platform.asLocalURL(installURL);
+ return new File(localURL.getFile());
+ }
+ catch (IOException ex)
+ {
+ return null;
+ }
+ }
+
+ public InputStream getTestResourceStream(String fileName)
+ throws IOException
+ {
+ IPath path = new Path("testdata").append(fileName);
+ URL url = new URL(getDefault().getBundle().getEntry("/"), path.toString());
+ return url.openStream();
+ }
+}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestSetup.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestSetup.java new file mode 100644 index 000000000..98436ac2c --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/OTRefactoringTestSetup.java @@ -0,0 +1,42 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring; + +import junit.framework.Test; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.ui.tests.refactoring.RefactoringTestSetup; +import org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper; + +@SuppressWarnings("restriction") +public class OTRefactoringTestSetup extends RefactoringTestSetup { + + public OTRefactoringTestSetup(Test test) { + super(test); + } + +//{ObjectTeams: changed project creation: + protected IJavaProject createJavaProject(String string, String string2) throws CoreException { + return JavaProjectHelper.createOTJavaProject("TestProject"+System.currentTimeMillis(), "bin"); +// SH} + } +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java new file mode 100644 index 000000000..1e169f339 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/RefactoringTest.java @@ -0,0 +1,667 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.refactoring;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringBufferInputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.ISourceManipulation;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.ITypeNameRequestor;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.corext.util.Strings;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
+import org.eclipse.ltk.core.refactoring.CreateChangeOperation;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+public abstract class RefactoringTest extends TestCase
+{
+ private IPackageFragmentRoot _root;
+ private IPackageFragment _packageP;
+
+ public boolean _isVerbose = false;
+
+ public static final String TEST_PATH_PREFIX = "";
+
+ protected static final String TEST_INPUT_INFIX = "/in/";
+ protected static final String TEST_OUTPUT_INFIX = "/out/";
+ protected static final String CONTAINER = "src";
+
+ public RefactoringTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ _root = MySetup.getDefaultSourceFolder();
+ _packageP = MySetup.getPackageP();
+
+ if (_isVerbose)
+ {
+ System.out
+ .println("\n---------------------------------------------");
+ System.out.println("\nTest:" + getClass() + "." + getName());
+ }
+ RefactoringCore.getUndoManager().flush();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ refreshFromLocal();
+ performDummySearch();
+
+ if (getPackageP().exists())
+ {
+ tryDeletingAllJavaChildren(getPackageP());
+ tryDeletingAllNonJavaChildResources(getPackageP());
+ }
+
+ if (getRoot().exists())
+ {
+ IJavaElement[] packages = getRoot().getChildren();
+ for (int i = 0; i < packages.length; i++)
+ {
+ try
+ {
+ IPackageFragment pack = (IPackageFragment)packages[i];
+ if (!pack.equals(getPackageP()) && pack.exists()
+ && !pack.isReadOnly())
+ pack.delete(true, null);
+ }
+ catch (JavaModelException ex)
+ {
+ //try to delete'em all
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void refreshFromLocal() throws CoreException
+ {
+ if (getRoot().exists())
+ {
+ getRoot().getResource().
+ refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ else if (getPackageP().exists())//don't refresh package if root already refreshed
+ {
+ getPackageP().getResource().
+ refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ }
+
+ private static void tryDeletingAllNonJavaChildResources(
+ IPackageFragment pack) throws JavaModelException
+ {
+ Object[] nonJavaKids = pack.getNonJavaResources();
+ for (int i = 0; i < nonJavaKids.length; i++)
+ {
+ if (nonJavaKids[i] instanceof IResource)
+ {
+ IResource resource = (IResource)nonJavaKids[i];
+ try
+ {
+ resource.delete(true, null);
+ }
+ catch (CoreException ex)
+ {
+ //try to delete'em all
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private static void tryDeletingAllJavaChildren(IPackageFragment pack)
+ throws JavaModelException
+ {
+ IJavaElement[] kids = pack.getChildren();
+ for (int i = 0; i < kids.length; i++)
+ {
+ if (kids[i] instanceof ISourceManipulation)
+ {
+ try
+ {
+ if (kids[i].exists() && !kids[i].isReadOnly())
+ ((ISourceManipulation)kids[i]).delete(true, null);
+ }
+ catch (JavaModelException ex)
+ {
+ //try to delete'em all
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ protected IPackageFragmentRoot getRoot()
+ {
+ return _root;
+ }
+
+ protected IPackageFragment getPackageP()
+ {
+ return _packageP;
+ }
+
+ protected final RefactoringStatus performRefactoring(Refactoring ref)
+ throws Exception
+ {
+ return performRefactoring(ref, true);
+ }
+
+ protected final RefactoringStatus performRefactoring(Refactoring ref,
+ boolean providesUndo) throws Exception
+ {
+ performDummySearch();
+ IUndoManager undoManager = getUndoManager();
+ CreateChangeOperation create = new CreateChangeOperation(
+ new CheckConditionsOperation(ref,
+ CheckConditionsOperation.ALL_CONDITIONS),
+ RefactoringStatus.FATAL);
+ PerformChangeOperation perform = new PerformChangeOperation(create);
+ perform.setUndoManager(undoManager, ref.getName());
+ ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
+ RefactoringStatus status = create.getConditionCheckingStatus();
+ if (!status.isOK())
+ {
+ return status;
+ }
+ assertTrue("Change wasn't executed", perform.changeExecuted());
+ Change undo = perform.getUndoChange();
+ if (providesUndo)
+ {
+ assertNotNull("Undo doesn't exist", undo);
+ assertTrue("Undo manager is empty", undoManager.anythingToUndo());
+ }
+ else
+ {
+ assertNull("Undo manager contains undo but shouldn't", undo);
+ }
+ return null;
+ }
+
+ protected final RefactoringStatus performRefactoringWithStatus(
+ Refactoring ref) throws Exception
+ {
+ performDummySearch();
+ CreateChangeOperation create = new CreateChangeOperation(
+ new CheckConditionsOperation(ref,
+ CheckConditionsOperation.ALL_CONDITIONS),
+ RefactoringStatus.FATAL);
+ PerformChangeOperation perform = new PerformChangeOperation(create);
+ perform.setUndoManager(RefactoringCore.getUndoManager(), ref.getName());
+ ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
+ RefactoringStatus status = create.getConditionCheckingStatus();
+ if (status.hasFatalError())
+ {
+ return status;
+ }
+ assertTrue("Change wasn't executed", perform.changeExecuted());
+ return status;
+ }
+
+ protected void performDummySearch() throws Exception
+ {
+ performDummySearch(getPackageP());
+ }
+
+ protected final Change performChange(final Refactoring refactoring,
+ boolean storeUndo) throws Exception
+ {
+ CreateChangeOperation create = new CreateChangeOperation(refactoring);
+ PerformChangeOperation perform = new PerformChangeOperation(create);
+ if (storeUndo)
+ {
+ perform.setUndoManager(getUndoManager(), refactoring.getName());
+ }
+ ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
+ assertTrue("Change wasn't executed", perform.changeExecuted());
+ return perform.getUndoChange();
+ }
+
+ protected final Change performChange(final Change change) throws Exception
+ {
+ PerformChangeOperation perform = new PerformChangeOperation(change);
+ ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
+ assertTrue("Change wasn't executed", perform.changeExecuted());
+ return perform.getUndoChange();
+ }
+
+ protected IUndoManager getUndoManager()
+ {
+ IUndoManager undoManager = RefactoringCore.getUndoManager();
+ undoManager.flush();
+ return undoManager;
+ }
+
+ /** ************** helpers ***************** */
+ /** ** mostly not general, just shortcuts **** */
+
+ protected IType getType(ICompilationUnit cu, String name)
+ throws JavaModelException
+ {
+ IType[] types = cu.getAllTypes();
+ for (int i = 0; i < types.length; i++)
+ {
+ if (types[i].getFullyQualifiedName().equals(name)
+ || types[i].getElementName().equals(name))
+ {
+ return types[i];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * subclasses override to inform about the location of their test cases
+ */
+ protected String getRefactoringPath()
+ {
+ return "";
+ }
+
+ /**
+ * example "RenameType/"
+ */
+ protected String getTestPath()
+ {
+ return TEST_PATH_PREFIX + getRefactoringPath();
+ }
+
+ /**
+ * @param cuName
+ * @param infix
+ * example "RenameTest/test0 + infix + cuName.java"
+ */
+ protected String createTestFileName(String cuName, String infix)
+ {
+ return getTestPath() + getName() + infix + cuName + ".java";
+ }
+
+ protected String getInputTestFileName(String cuName)
+ {
+ return createTestFileName(cuName, TEST_INPUT_INFIX);
+ }
+
+ /**
+ * @param subDirName
+ * example "p/" or "org/eclipse/jdt/"
+ */
+ protected String getInputTestFileName(String cuName, String subDirName)
+ {
+ return createTestFileName(cuName, TEST_INPUT_INFIX + subDirName);
+ }
+
+ protected String getOutputTestFileName(String cuName)
+ {
+ return createTestFileName(cuName, TEST_OUTPUT_INFIX);
+ }
+
+ /**
+ * @param subDirName
+ * example "p/" or "org/eclipse/jdt/"
+ */
+ protected String getOutputTestFileName(String cuName, String subDirName)
+ {
+ return createTestFileName(cuName, TEST_OUTPUT_INFIX + subDirName);
+ }
+
+ protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
+ String cuName) throws Exception
+ {
+ return createCUfromTestFile(pack, cuName, true);
+ }
+
+ protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
+ String cuName, String subDirName) throws Exception
+ {
+ return createCUfromTestFile(pack, cuName, subDirName, true);
+ }
+
+ protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
+ String cuName, boolean input) throws Exception
+ {
+ String contents = input ? getFileContents(getInputTestFileName(cuName))
+ : getFileContents(getOutputTestFileName(cuName));
+ return createCU(pack, cuName + ".java", contents);
+ }
+
+ protected ICompilationUnit createCUfromTestFile(IPackageFragment pack,
+ String cuName, String subDirName, boolean input) throws Exception
+ {
+ String contents = input ? getFileContents(getInputTestFileName(cuName,
+ subDirName)) : getFileContents(getOutputTestFileName(cuName,
+ subDirName));
+
+ return createCU(pack, cuName + ".java", contents);
+ }
+
+ protected void printTestDisabledMessage(String explanation)
+ {
+ System.out.println("\n" + getClass().getName() + "::" + getName()
+ + " disabled (" + explanation + ")");
+ }
+
+ //-----------------------
+ public static InputStream getStream(String content)
+ {
+ return new StringBufferInputStream(content);
+ }
+
+ public static IPackageFragmentRoot getSourceFolder(
+ IJavaProject javaProject, String name) throws JavaModelException
+ {
+ IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
+ for (int i = 0; i < roots.length; i++)
+ {
+ if (!roots[i].isArchive() && roots[i].getElementName().equals(name))
+ return roots[i];
+ }
+ return null;
+ }
+
+ public static String getFileContents(String fileName) throws IOException
+ {
+ return getContents(getFileInputStream(fileName));
+ }
+
+ public static String getContents(IFile file) throws IOException,
+ CoreException
+ {
+ return getContents(file.getContents());
+ }
+
+ public static ICompilationUnit createCU(IPackageFragment pack, String name,
+ String contents) throws Exception
+ {
+ if (pack.getCompilationUnit(name).exists())
+ {
+ return pack.getCompilationUnit(name);
+ }
+ ICompilationUnit cu = pack.createCompilationUnit(name, contents, true,
+ null);
+ cu.save(null, true);
+ return cu;
+ }
+
+ public static String getContents(InputStream in) throws IOException
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ StringBuffer sb = new StringBuffer(300);
+ try
+ {
+ int read = 0;
+ while ((read = br.read()) != -1)
+ {
+ sb.append((char)read);
+ }
+ }
+ finally
+ {
+ br.close();
+ }
+ return sb.toString();
+ }
+
+ public static InputStream getFileInputStream(String fileName)
+ throws IOException
+ {
+ return OTRefactoringTestPlugin.getDefault().getTestResourceStream(
+ fileName);
+ }
+
+ public static String removeExtension(String fileName)
+ {
+ return fileName.substring(0, fileName.lastIndexOf('.'));
+ }
+
+ public static void performDummySearch(IJavaElement element)
+ throws Exception
+ {
+ new SearchEngine().searchAllTypeNames(ResourcesPlugin.getWorkspace(),
+ null, null, SearchPattern.R_EXACT_MATCH, true,
+ IJavaSearchConstants.CLASS, SearchEngine
+ .createJavaSearchScope(new IJavaElement[] { element }),
+ new Requestor(),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ }
+
+ public static IMember[] merge(IMember[] a1, IMember[] a2, IMember[] a3)
+ {
+ return JavaElementUtil.merge(JavaElementUtil.merge(a1, a2), a3);
+ }
+
+ public static IMember[] merge(IMember[] a1, IMember[] a2)
+ {
+ return JavaElementUtil.merge(a1, a2);
+ }
+
+ public static IField[] getFields(IType type, String[] names)
+ throws JavaModelException
+ {
+ if (names == null)
+ {
+ return new IField[0];
+ }
+ Set fields = new HashSet();
+ for (int i = 0; i < names.length; i++)
+ {
+ IField field = type.getField(names[i]);
+ assertTrue("field " + field.getElementName() + " does not exist",
+ field.exists());
+ fields.add(field);
+ }
+ return (IField[])fields.toArray(new IField[fields.size()]);
+ }
+
+ public static IType[] getMemberTypes(IType type, String[] names)
+ throws JavaModelException
+ {
+ if (names == null)
+ {
+ return new IType[0];
+ }
+ Set memberTypes = new HashSet();
+ for (int i = 0; i < names.length; i++)
+ {
+ IType memberType = type.getType(names[i]);
+ assertTrue("member type " + memberType.getElementName()
+ + " does not exist", memberType.exists());
+ memberTypes.add(memberType);
+ }
+ return (IType[])memberTypes.toArray(new IType[memberTypes.size()]);
+ }
+
+ public static IMethod[] getMethods(IType type, String[] names,
+ String[][] signatures) throws JavaModelException
+ {
+ if (names == null || signatures == null)
+ {
+ return new IMethod[0];
+ }
+ List methods = new ArrayList(names.length);
+ for (int i = 0; i < names.length; i++)
+ {
+ IMethod method = type.getMethod(names[i], signatures[i]);
+ assertTrue("method " + method.getElementName() + " does not exist",
+ method.exists());
+ if (!methods.contains(method))
+ {
+ methods.add(method);
+ }
+ }
+ return (IMethod[])methods.toArray(new IMethod[methods.size()]);
+ }
+
+ public static IType[] findTypes(IType[] types, String[] namesOfTypesToPullUp)
+ {
+ List found = new ArrayList(types.length);
+ for (int i = 0; i < types.length; i++)
+ {
+ IType type = types[i];
+ for (int j = 0; j < namesOfTypesToPullUp.length; j++)
+ {
+ String name = namesOfTypesToPullUp[j];
+ if (type.getElementName().equals(name))
+ {
+ found.add(type);
+ }
+ }
+ }
+ return (IType[])found.toArray(new IType[found.size()]);
+ }
+
+ public static IField[] findFields(IField[] fields,
+ String[] namesOfFieldsToPullUp)
+ {
+ List found = new ArrayList(fields.length);
+ for (int i = 0; i < fields.length; i++)
+ {
+ IField field = fields[i];
+ for (int j = 0; j < namesOfFieldsToPullUp.length; j++)
+ {
+ String name = namesOfFieldsToPullUp[j];
+ if (field.getElementName().equals(name))
+ {
+ found.add(field);
+ }
+ }
+ }
+ return (IField[])found.toArray(new IField[found.size()]);
+ }
+
+ public static IMethod[] findMethods(IMethod[] selectedMethods,
+ String[] namesOfMethods, String[][] signaturesOfMethods)
+ {
+ List found = new ArrayList(selectedMethods.length);
+ for (int i = 0; i < selectedMethods.length; i++)
+ {
+ IMethod method = selectedMethods[i];
+ String[] paramTypes = method.getParameterTypes();
+ for (int j = 0; j < namesOfMethods.length; j++)
+ {
+ String methodName = namesOfMethods[j];
+ if (!methodName.equals(method.getElementName()))
+ {
+ continue;
+ }
+ String[] methodSig = signaturesOfMethods[j];
+ if (!areSameSignatures(paramTypes, methodSig))
+ {
+ continue;
+ }
+ found.add(method);
+ }
+ }
+ return (IMethod[])found.toArray(new IMethod[found.size()]);
+ }
+
+ private static boolean areSameSignatures(String[] s1, String[] s2)
+ {
+ if (s1.length != s2.length)
+ {
+ return false;
+ }
+ for (int i = 0; i < s1.length; i++)
+ {
+ if (!s1[i].equals(s2[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Line-based version of junit.framework.Assert.assertEquals(String, String)
+ * without considering line delimiters.
+ */
+ public static void assertEqualLines(String expected, String actual)
+ {
+ assertEqualLines("", expected, actual);
+ }
+
+ /**
+ * Line-based version of junit.framework.Assert.assertEquals(String, String, String)
+ * without considering line delimiters.
+ */
+ public static void assertEqualLines(String message, String expected,
+ String actual)
+ {
+ String[] expectedLines = Strings.convertIntoLines(expected);
+ String[] actualLines = Strings.convertIntoLines(actual);
+
+ String expected2 = (expectedLines == null ? null : Strings.concatenate(
+ expectedLines, "\n"));
+ String actual2 = (actualLines == null ? null : Strings.concatenate(
+ actualLines, "\n"));
+ assertEquals(message, expected2, actual2);
+ }
+
+ private static class Requestor implements ITypeNameRequestor
+ {
+
+ public void acceptClass(char[] packageName, char[] simpleTypeName,
+ char[][] enclosingTypeNames, String path)
+ {
+ }
+
+ public void acceptInterface(char[] packageName, char[] simpleTypeName,
+ char[][] enclosingTypeNames, String path)
+ {
+ }
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/AllTests.java new file mode 100644 index 000000000..182a5d0a0 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/AllTests.java @@ -0,0 +1,44 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractcallin;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-ExtractCallin-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractcallin.ExtractCallinTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/ExtractCallinTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/ExtractCallinTests.java new file mode 100644 index 000000000..084eeb7c5 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractcallin/ExtractCallinTests.java @@ -0,0 +1,140 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractcallin; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.objectteams.otdt.internal.core.CallinMapping; +import org.eclipse.objectteams.otdt.internal.refactoring.otrefactorings.extractcallin.ExtractCallinRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * @author Johannes Gebauer + * + */ +@SuppressWarnings("restriction") +public class ExtractCallinTests extends RefactoringTest { + private static final String REFACTORING_PATH = "ExtractCallin/"; + + public ExtractCallinTests(String name) { + super(name); + } + + public static Test suite() { + return new MySetup(new TestSuite(ExtractCallinTests.class)); + } + + public static Test setUpTest(Test test) { + return new MySetup(test); + } + + protected String getRefactoringPath() { + return REFACTORING_PATH; + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + private ExtractCallinRefactoring createExtractCallinRefactoring(IMethod baseMethod, IType role, int mappingKind) { + ExtractCallinRefactoring refactoring = new ExtractCallinRefactoring(baseMethod, role, mappingKind); + return refactoring; + } + + private void performPullUp_pass(String[] cuNames, String baseMethodName, String[] baseMethodSignature, int mappingKind, boolean deleteRoleMethod, + String baseName, String roleName, boolean copyBaseMethod) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType baseType = getType(cus[0], baseName); + IType roleType = getType(cus[1], roleName); + + IMethod baseMethod = baseType.getMethod(baseMethodName, baseMethodSignature); + assertTrue("base method " + baseMethod.getElementName() + " does not exist", baseMethod.exists()); + + ExtractCallinRefactoring ref = createExtractCallinRefactoring(baseMethod, roleType, mappingKind); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + ref.setDeleteBaseMethod(deleteRoleMethod); + + ref.setCopyBaseMethod(copyBaseMethod); + + RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor()); + assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); + performChange(ref, false); + + for (int i = 0; i < cus.length; i++) { + String expected = getFileContents(getOutputTestFileName(cuNames[i])); + String actual = cus[i].getSource(); + assertEqualLines(expected, actual); + } + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + /******* tests ******************/ + + /* Extract Callin Tests */ + + public void testExtractSimpleBeforeCallin() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[0], CallinMapping.KIND_BEFORE, false, "B", "R", false); + } + + public void testExtractSimpleReplaceCallin1() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[0], CallinMapping.KIND_REPLACE, false, "B", "R", true); + } + + public void testExtractSimpleAfterCallin() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[0], CallinMapping.KIND_AFTER, false, "B", "R", false); + } + + public void testExtractSimpleReplaceCallin2() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[0], CallinMapping.KIND_REPLACE, false, "B", "R", false); + } + + public void testExtractCallinWithParameter() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[] { "I" }, CallinMapping.KIND_BEFORE, false, "B", "R", false); + } + + public void testExtractCallinWithParameterMapping() throws Exception { + performPullUp_pass(new String[] { "B", "T" }, "m", new String[] { "I", "I" }, CallinMapping.KIND_BEFORE, false, "B", "R", false); + } +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AbstractSelectionTestCase.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AbstractSelectionTestCase.java new file mode 100644 index 000000000..91aaa55a7 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AbstractSelectionTestCase.java @@ -0,0 +1,200 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod;
+
+/**
+ * @author brcan
+ *
+ */
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.tests.refactoring.infra.AbstractCUTestCase;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.OTRefactoringTestPlugin;
+
+@SuppressWarnings({ "nls", "restriction" })
+public abstract class AbstractSelectionTestCase extends AbstractCUTestCase
+{
+ public static final String SQUARE_BRACKET_OPEN = "/*[*/";
+ public static final int SQUARE_BRACKET_OPEN_LENGTH = SQUARE_BRACKET_OPEN.length();
+ public static final String SQUARE_BRACKET_CLOSE = "/*]*/";
+ public static final int SQUARE_BRACKET_CLOSE_LENGTH = SQUARE_BRACKET_CLOSE.length();
+
+ protected static final int VALID_SELECTION = 1;
+ protected static final int INVALID_SELECTION = 2;
+ protected static final int COMPARE_WITH_OUTPUT = 3;
+
+ public AbstractSelectionTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected int[] getSelection(String source)
+ {
+ int start = -1;
+ int end = -1;
+ int includingStart = source.indexOf(SQUARE_BRACKET_OPEN);
+ int excludingStart = source.indexOf(SQUARE_BRACKET_CLOSE);
+ int includingEnd = source.lastIndexOf(SQUARE_BRACKET_CLOSE);
+ int excludingEnd = source.lastIndexOf(SQUARE_BRACKET_OPEN);
+
+ if (includingStart > excludingStart && excludingStart != -1)
+ {
+ includingStart = -1;
+ }
+ else if (excludingStart > includingStart && includingStart != -1)
+ {
+ excludingStart = -1;
+ }
+
+ if (includingEnd < excludingEnd)
+ {
+ includingEnd = -1;
+ }
+ else if (excludingEnd < includingEnd)
+ {
+ excludingEnd = -1;
+ }
+
+ if (includingStart != -1)
+ {
+ start = includingStart;
+ }
+ else
+ {
+ start = excludingStart + SQUARE_BRACKET_CLOSE_LENGTH;
+ }
+
+ if (excludingEnd != -1)
+ {
+ end = excludingEnd;
+ }
+ else
+ {
+ end = includingEnd + SQUARE_BRACKET_CLOSE_LENGTH;
+ }
+
+ assertTrue("Selection invalid", start >= 0 && end >= 0 && end >= start);
+
+ int[] result = new int[] { start, end - start };
+ // System.out.println("|"+ source.substring(result[0], result[0] + result[1]) + "|");
+ return result;
+ }
+
+ protected ITextSelection getTextSelection(String source)
+ {
+ int[] s = getSelection(source);
+ return new TextSelection(s[0], s[1]);
+ }
+
+ protected InputStream getFileInputStream(String fileName) throws IOException
+ {
+ return OTRefactoringTestPlugin.getDefault().getTestResourceStream(fileName);
+ }
+
+//{ObjectTeams: fixing a JDT-problem: couldn't cope with package paths > 1
+ protected ICompilationUnit createCU(IPackageFragment pack, String name) throws Exception {
+ name= adaptName(name);
+ return createCU(pack, name, getFileInputStream(myGetFilePath(pack, name)));
+ }
+
+ protected String myGetFilePath(String path, String name) {
+ return getResourceLocation() + path + "/" + name;
+ }
+
+ protected String myGetFilePath(IPackageFragment pack, String name) {
+ return myGetFilePath(pack.getElementName().replace('.','/'), name); // <-- the patch: force the package path to use '/'
+ }
+// SH}
+
+ protected void performTest(
+ final ICompilationUnit unit,
+ final Refactoring refactoring,
+ int mode,
+ final String out,
+ boolean doUndo) throws Exception
+ {
+ IProgressMonitor pm = new NullProgressMonitor();
+ switch (mode)
+ {
+ case VALID_SELECTION:
+ assertTrue(checkPreconditions(refactoring, pm).isOK());
+ break;
+ case INVALID_SELECTION:
+ assertTrue(!checkPreconditions(refactoring, pm).isOK());
+ break;
+ case COMPARE_WITH_OUTPUT:
+ IUndoManager undoManager = RefactoringCore.getUndoManager();
+ undoManager.flush();
+ String original = unit.getSource();
+
+ PerformRefactoringOperation op = new PerformRefactoringOperation(
+ refactoring, getCheckingStyle());
+ JavaCore.run(op, new NullProgressMonitor());
+ assertTrue("Precondition check failed", !op.getConditionStatus().hasFatalError());
+ assertTrue("Validation check failed", !op.getValidationStatus().hasFatalError());
+ assertNotNull("No Undo", op.getUndoChange());
+ compareSource(unit.getSource(), out);
+ Change undo = op.getUndoChange();
+ assertNotNull("Undo doesn't exist", undo);
+ assertTrue("Undo manager is empty", undoManager.anythingToUndo());
+
+ if (doUndo)
+ {
+ undoManager.performUndo(null, new NullProgressMonitor());
+ assertTrue("Undo manager still has undo", !undoManager.anythingToUndo());
+ assertTrue("Undo manager is empty", undoManager.anythingToRedo());
+ compareSource(original, unit.getSource());
+ }
+ break;
+ }
+ }
+
+ protected RefactoringStatus checkPreconditions(
+ Refactoring refactoring,
+ IProgressMonitor pm) throws CoreException
+ {
+ CheckConditionsOperation op =
+ new CheckConditionsOperation(refactoring, getCheckingStyle());
+ op.run(new NullProgressMonitor());
+ return op.getStatus();
+ }
+
+ protected int getCheckingStyle()
+ {
+ return CheckConditionsOperation.ALL_CONDITIONS;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AllTests.java new file mode 100644 index 000000000..44ac71b4e --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/AllTests.java @@ -0,0 +1,50 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-Extract-Method-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractMethodRefactoringUtilTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractTempTests.suite());
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodRefactoringUtilTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodRefactoringUtilTests.java new file mode 100644 index 000000000..720083b16 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodRefactoringUtilTests.java @@ -0,0 +1,388 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.corext.Corext;
+import org.eclipse.jdt.internal.corext.refactoring.ParameterInfo;
+import org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.TypeHelper;
+import org.eclipse.objectteams.otdt.internal.refactoring.adaptor.extractmethod.ExtractMethodAmbuguityMsgCreator;
+import org.eclipse.objectteams.otdt.internal.refactoring.adaptor.extractmethod.ExtractMethodOverloadingMsgCreator;
+import org.eclipse.objectteams.otdt.internal.refactoring.corext.base.OTRefactoringStatusCodes;
+import org.eclipse.objectteams.otdt.internal.refactoring.util.RefactoringUtil;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.FileBasedRefactoringTest;
+
+/**
+ * @author brcan
+ *
+ */
+@SuppressWarnings( { "restriction", "nls" })
+public class ExtractMethodRefactoringUtilTests extends FileBasedRefactoringTest {
+ public static final String SQUARE_BRACKET_OPEN = "/*[*/";
+ public static final int SQUARE_BRACKET_OPEN_LENGTH = SQUARE_BRACKET_OPEN.length();
+ public static final String SQUARE_BRACKET_CLOSE = "/*]*/";
+ public static final int SQUARE_BRACKET_CLOSE_LENGTH = SQUARE_BRACKET_CLOSE.length();
+
+ // Regular classes
+ private IType _a;
+ private IType _b;
+ private IType _c;
+ private IType _q;
+ private IType _s;
+
+ // Team class
+ private IType _t1;
+
+ // Role classes
+ private IRoleType _t2r1;
+ private IRoleType _t3r1;
+ private IRoleType _t3r2;
+
+ private ExtractMethodRefactoring _refactoring;
+
+ public ExtractMethodRefactoringUtilTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new Suite(ExtractMethodRefactoringUtilTests.class);
+ }
+
+ public void setUpSuite() throws Exception {
+ setTestProjectDir("ExtractMethodRefactoringUtil");
+ super.setUpSuite();
+
+ _a = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "A");
+
+ _b = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "B");
+
+ _c = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "C");
+
+ _q = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "Q");
+
+ _s = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "S");
+
+ _t1 = getType(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "T1");
+
+ _t2r1 = getRole(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "T2", "R1");
+
+ _t3r1 = getRole(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "T3", "R1");
+
+ _t3r2 = getRole(getTestProjectDir(), "src", "roleAndBaseHierarchy1", "T3", "R2");
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private int[] getSelection(String source) {
+ int start = -1;
+ int end = -1;
+ int includingStart = source.indexOf(SQUARE_BRACKET_OPEN);
+ int excludingStart = source.indexOf(SQUARE_BRACKET_CLOSE);
+ int includingEnd = source.lastIndexOf(SQUARE_BRACKET_CLOSE);
+ int excludingEnd = source.lastIndexOf(SQUARE_BRACKET_OPEN);
+
+ if (includingStart > excludingStart && excludingStart != -1) {
+ includingStart = -1;
+ } else if (excludingStart > includingStart && includingStart != -1) {
+ excludingStart = -1;
+ }
+
+ if (includingEnd < excludingEnd) {
+ includingEnd = -1;
+ } else if (excludingEnd < includingEnd) {
+ excludingEnd = -1;
+ }
+
+ if (includingStart != -1) {
+ start = includingStart;
+ } else {
+ start = excludingStart + SQUARE_BRACKET_CLOSE_LENGTH;
+ }
+
+ if (excludingEnd != -1) {
+ end = excludingEnd;
+ } else {
+ end = includingEnd + SQUARE_BRACKET_CLOSE_LENGTH;
+ }
+
+ assertTrue("Selection invalid", start >= 0 && end >= 0 && end >= start);
+
+ int[] result = new int[] { start, end - start };
+ // System.out.println("|"+ source.substring(result[0], result[0] +
+ // result[1]) + "|");
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ // raw List from ExtractMethodRefactoring.
+ private String[] fetchNewParameterTypes() {
+ List parameterInfos = _refactoring.getParameterInfos();
+ String[] parameterTypes = new String[parameterInfos.size()];
+ for (int i = 0; i < parameterTypes.length; i++)
+ parameterTypes[i] = ((ParameterInfo) parameterInfos.get(i)).getNewTypeName();
+ return parameterTypes;
+ }
+
+ /********** tests **********/
+ // =====================================================================================
+ // Testing overloading
+ // =====================================================================================
+ public void testCheckOverloading1() throws Exception {
+ // focus type -> A
+ ICompilationUnit cu = _a.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("f");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_a, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading2() throws Exception {
+ // focus type -> B
+ ICompilationUnit cu = _b.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("g");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_b, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading3() throws Exception {
+ // focus type -> C
+ ICompilationUnit cu = _c.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("g");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_c, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading4() throws Exception {
+ // focus type -> Q
+ ICompilationUnit cu = _q.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("m");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_q, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading5() throws Exception {
+ // focus type -> S
+ ICompilationUnit cu = _s.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("m");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_s, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading6() throws Exception {
+ // focus type -> T1
+ ICompilationUnit cu = _t1.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("m");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_t1, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading7() throws Exception {
+ // focus type -> T2.R1
+ ICompilationUnit cu = _t2r1.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("m");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_t2r1, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ public void testCheckOverloading8() throws Exception {
+ // focus type -> T3.R2
+ ICompilationUnit cu = _t3r2.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("rm");
+ _refactoring.setVisibility(Modifier.PROTECTED);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_t3r2, true, true, true, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ // checking overloading including hidden (private) methods, because method
+ // bindings can refer to otherwise hidden base methods (decapsulation)
+ /* test overloading of private base method */
+ public void testCheckOverloading9() throws Exception {
+ // focus type -> C
+ ICompilationUnit cu = _c.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("n");
+ _refactoring.setVisibility(Modifier.PRIVATE);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_c, true, true, false, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ /* test overloading of private role method */
+ public void testCheckOverloading10() throws Exception {
+ // focus type -> T3.R2
+ ICompilationUnit cu = _t3r2.getCompilationUnit();
+ int[] selection = getSelection(cu.getSource());
+ _refactoring = new ExtractMethodRefactoring(cu, selection[0], selection[1]);
+ _refactoring.setMethodName("k");
+ _refactoring.setVisibility(Modifier.PRIVATE);
+ _refactoring.checkInitialConditions(new NullProgressMonitor());
+ IMethod[] inheritedMethods = TypeHelper.getInheritedMethods(_t3r2, true, true, false, null);
+ RefactoringStatus expected = RefactoringUtil.addOverloadingWarning(new ExtractMethodOverloadingMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkOverloading(inheritedMethods, _refactoring.getMethodName(), fetchNewParameterTypes(),
+ new ExtractMethodOverloadingMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.OVERLOADING));
+ }
+
+ // =====================================================================================
+ // Testing ambiguity
+ // =====================================================================================
+
+ public void testCheckAmbiguityInRoleMethodSpec1() throws Exception {
+ // check ambiguous role method specifier in callin binding of T2.R1
+ RefactoringStatus expected = RefactoringUtil.addAmbiguityFatalError(null, new ExtractMethodAmbuguityMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkForAmbiguousRoleMethodSpecs(_t2r1, "m", new ExtractMethodAmbuguityMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ }
+
+ public void testCheckAmbiguityInRoleMethodSpec2() throws Exception {
+ // check ambiguous role method specifier in callin binding of T3.R1
+ RefactoringStatus expected = RefactoringUtil.addAmbiguityFatalError(null, new ExtractMethodAmbuguityMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkForAmbiguousRoleMethodSpecs(_t3r1, "m", new ExtractMethodAmbuguityMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ }
+
+ public void testCheckAmbiguityInRoleMethodSpec3() throws Exception {
+ // check ambiguous role method specifier in callout binding of T3.R2
+ RefactoringStatus expected = RefactoringUtil.addAmbiguityFatalError(null, new ExtractMethodAmbuguityMsgCreator());
+ RefactoringStatus actual = RefactoringUtil.checkForAmbiguousRoleMethodSpecs(_t3r2, "m", new ExtractMethodAmbuguityMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ }
+
+ public void testCheckAmbiguityInBaseMethodSpec1() throws Exception {
+ // check ambiguous base method specifier in callin binding of T2.R1
+ RefactoringStatus expected = RefactoringUtil.addAmbiguityFatalError(null, new ExtractMethodAmbuguityMsgCreator());
+ ArrayList<IRoleType> boundRole = new ArrayList<IRoleType>();
+ boundRole.add(_t2r1);
+ RefactoringStatus actual = RefactoringUtil.checkForAmbiguousBaseMethodSpecs(boundRole, "f", "", new ExtractMethodAmbuguityMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ }
+
+ public void testCheckAmbiguityInBaseMethodSpec2() throws Exception {
+ // check ambiguous base method specifier in callout binding of T3.R2
+ RefactoringStatus expected = RefactoringUtil.addAmbiguityFatalError(null, new ExtractMethodAmbuguityMsgCreator());
+ ArrayList<IRoleType> boundRole = new ArrayList<IRoleType>();
+ boundRole.add(_t3r2);
+ RefactoringStatus actual = RefactoringUtil.checkForAmbiguousBaseMethodSpecs(boundRole, "f", "", new ExtractMethodAmbuguityMsgCreator());
+ assertEquals(expected.getSeverity(), actual.getSeverity());
+ assertNotNull(expected.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ assertNotNull(actual.getEntryMatchingCode(Corext.getPluginId(), OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER));
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTestSetup.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTestSetup.java new file mode 100644 index 000000000..0c6e9e3a6 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTestSetup.java @@ -0,0 +1,149 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod;
+
+import java.util.Hashtable;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper;
+import org.eclipse.objectteams.otdt.ui.tests.util.TestOptions;
+
+/**
+ * @author brcan
+ */
+@SuppressWarnings({ "nls", "restriction" })
+public class ExtractMethodTestSetup extends TestSetup
+{
+ private IJavaProject _javaProject;
+ private IPackageFragmentRoot _root;
+ private static final String CONTAINER = "src";
+
+// private IPackageFragment _selectionPackage;
+
+ private IPackageFragment _teamClassPackage;
+ private IPackageFragment _roleClassPackage;
+ private IPackageFragment _nestedTeamPackage;
+ private IPackageFragment _rolefilePackage;
+ private IPackageFragment _rolefileParentPackage;
+ private IPackageFragment _focusTypePackage;
+ private IPackageFragment _overloadingPackage;
+
+ public ExtractMethodTestSetup(Test test)
+ {
+ super(test);
+ }
+
+ public IPackageFragmentRoot getRoot() {
+ return _root;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ Hashtable options = TestOptions.getFormatterOptions();
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0");
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
+ JavaCore.setOptions(options);
+ TestOptions.initializeCodeGenerationOptions();
+ JavaPlugin.getDefault().getCodeTemplateStore().load();
+
+ _javaProject = JavaProjectHelper.createOTJavaProject("TestProject", "bin");
+ JavaProjectHelper.addRTJar(_javaProject);
+ _root = JavaProjectHelper.addSourceContainer(_javaProject, CONTAINER);
+
+ RefactoringCore.getUndoManager().flush();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceDescription description = workspace.getDescription();
+ description.setAutoBuilding(false);
+ workspace.setDescription(description);
+
+ //new packages for OT/J tests
+ _teamClassPackage = getRoot().createPackageFragment("team_in", true, null);
+ _roleClassPackage = getRoot().createPackageFragment("role_in", true, null);
+ _rolefilePackage = getRoot().createPackageFragment("roleFile_in.TeamWithRoleFile", true, null);
+ _rolefileParentPackage = getRoot().createPackageFragment("roleFile_in", true, null);
+ _nestedTeamPackage = getRoot().createPackageFragment("nestedTeam_in", true, null);
+ _focusTypePackage = getRoot().createPackageFragment("focusType_in", true, null);
+ _overloadingPackage = getRoot().createPackageFragment("overloading_in", true, null);
+
+// _selectionPackage = getRoot().createPackageFragment("selection", true, null);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ RefactoringTest.performDummySearch(_javaProject);
+ JavaProjectHelper.delete(_javaProject);
+ }
+
+// public IPackageFragment getSelectionPackage()
+// {
+// return _selectionPackage;
+// }
+
+ public IPackageFragment getTeamClassPackage()
+ {
+ return _teamClassPackage;
+ }
+
+ public IPackageFragment getRoleClassPackage()
+ {
+ return _roleClassPackage;
+ }
+
+ public IPackageFragment getNestedTeamPackage()
+ {
+ return _nestedTeamPackage;
+ }
+
+ public IPackageFragment getRoleFilePackage()
+ {
+ return _rolefilePackage;
+ }
+
+ public IPackageFragment getRoleFileParentPackage()
+ {
+ return _rolefileParentPackage;
+ }
+
+ public IPackageFragment getFocusTypePackage()
+ {
+ return _focusTypePackage;
+ }
+
+ public IPackageFragment getOverloadingPackage()
+ {
+ return _overloadingPackage;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTests.java new file mode 100644 index 000000000..c0eb561ab --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractMethodTests.java @@ -0,0 +1,480 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod; + +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jdt.internal.corext.refactoring.ParameterInfo; +import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring; + +/** + * @author brcan + * + */ +@SuppressWarnings({ "nls", "restriction" }) +public class ExtractMethodTests extends AbstractSelectionTestCase +{ + private static ExtractMethodTestSetup _testSetup; + + public ExtractMethodTests(String name) + { + super(name); + } + + public static Test suite() + { + _testSetup = new ExtractMethodTestSetup(new TestSuite(ExtractMethodTests.class)); + return _testSetup; + } + + protected IPackageFragmentRoot getRoot() + { + return _testSetup.getRoot(); + } + + protected String getResourceLocation() + { + return "ExtractMethod/"; + } + + protected String adaptName(String name) + { + if (getName().startsWith("testFocusType")) + { + return super.adaptName(name); + } + return name + "_" + getName() + ".java"; + } + +// protected void selectionTest(int startLine, int startColumn, int endLine, int endColumn) +// throws Exception +// { +// ICompilationUnit unit = createCU(getSelectionPackage(), "A"); +// String source = unit.getSource(); +// int[] selection = getSelection(source); +// ISourceRange expected = +// TextRangeUtil.getSelection(unit, startLine, startColumn, endLine, endColumn); +// assertEquals(expected.getOffset(), selection[0]); +// assertEquals(expected.getLength(), selection[1]); +// } +// +// private IPackageFragment getSelectionPackage() throws JavaModelException +// { +// return _testSetup.getSelectionPackage(); +// } + + protected void performTest( + IPackageFragment packageFragment, + String[] ids, + int mode, + String outputFolder) throws Exception + { + performTest(packageFragment, ids, mode, outputFolder, null, null, 0); + } + + @SuppressWarnings("unchecked") + protected void performTest( + IPackageFragment packageFragment, + String[] ids, + int mode, + String outputFolder, + String[] newNames, + int[] newOrder, + int destination) throws Exception + { + ICompilationUnit[] compUnits = createCUs(packageFragment, ids); + String source = compUnits[0].getSource(); + int[] selection = getSelection(source); + ExtractMethodRefactoring refactoring = new ExtractMethodRefactoring( + compUnits[0], + selection[0], + selection[1]); + refactoring.setMethodName("extracted"); + refactoring.setVisibility(Modifier.PROTECTED); + RefactoringStatus status = + refactoring.checkInitialConditions(new NullProgressMonitor()); + switch (mode) + { + case VALID_SELECTION: + assertTrue(status.isOK()); + break; + case INVALID_SELECTION: + if (!status.isOK()) + return; + } + List parameters = refactoring.getParameterInfos(); + if (newNames != null && newNames.length > 0) + { + for (int idx= 0; idx < newNames.length; idx++) + { + if (newNames[idx] != null) + { + ((ParameterInfo)parameters.get(idx)).setNewName(newNames[idx]); + } + } + } + if (newOrder != null && newOrder.length > 0) + { + assertTrue(newOrder.length == parameters.size()); + List current = new ArrayList(parameters); + for (int idx= 0; idx < newOrder.length; idx++) + { + parameters.set(newOrder[idx], current.get(idx)); + } + } + refactoring.setDestination(destination); + + String out = null; + switch (mode) + { + case COMPARE_WITH_OUTPUT: + out = getProofedContent(outputFolder, ids[0]); + break; + } + performTest(compUnits[0], refactoring, mode, out, true); + } + + private ICompilationUnit[] createCUs( + IPackageFragment packageFragment, + String[] ids) + throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[ids.length]; + + for (int idx = 0; idx < ids.length; idx++) + { + Assert.isNotNull(ids[idx]); + cus[idx] = createCU(packageFragment, ids[idx]); + } + return cus; + } + + protected int getCheckingStyle() + { + return CheckConditionsOperation.FINAL_CONDITIONS; + } + + /********** tests **********/ + //===================================================================================== + // Testing team classes + //===================================================================================== + + //extract method invocation in team + public void testTeamclass1() throws Exception + { + performTest( + _testSetup.getTeamClassPackage(), + new String[]{"T"}, + COMPARE_WITH_OUTPUT, + "team_out"); + } + //extract expression in team + public void testTeamclass2() throws Exception + { + performTest( + _testSetup.getTeamClassPackage(), + new String[]{"T"}, + COMPARE_WITH_OUTPUT, + "team_out"); + } + + //===================================================================================== + // Testing role classes + //===================================================================================== + + //extract method invocation in unbound role + public void testRoleclass1() throws Exception + { + performTest( + _testSetup.getRoleClassPackage(), + new String[]{"T"}, + COMPARE_WITH_OUTPUT, + "role_out"); + } + //extract expression in unbound role + public void testRoleclass2() throws Exception + { + performTest( + _testSetup.getRoleClassPackage(), + new String[]{"T"}, + COMPARE_WITH_OUTPUT, + "role_out"); + } + + //===================================================================================== + // Testing nested teams + //===================================================================================== + + /* passing */ + //extract method invocation in unbound nested team + public void testNestedTeam1() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[]{"T1"}, + COMPARE_WITH_OUTPUT, + "nestedTeam_out"); + } + //extract method invocation in inner role of unbound nested team + public void testNestedTeam2() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[]{"T1"}, + COMPARE_WITH_OUTPUT, + "nestedTeam_out"); + } + + /* failing */ + //extract method invocation in bound nested team -> ambiguous base method spec + public void testNestedTeam3() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[] {"B", "T1"}, + INVALID_SELECTION, + "nestedTeam_out"); + } + //extract method invocation in bound nested team -> ambiguous role method spec + public void testNestedTeam4() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[] {"T1", "B"}, + INVALID_SELECTION, + "nestedTeam_out"); + } + //extract method invocation in bound inner role of nested team -> + //ambiguous base method spec + public void testNestedTeam5() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[] {"B", "T1"}, + INVALID_SELECTION, + "nestedTeam_out"); + } + //extract method invocation in bound inner role of nested team -> + //ambiguous role method spec + public void testNestedTeam6() throws Exception + { + performTest( + _testSetup.getNestedTeamPackage(), + new String[] {"T1", "B"}, + INVALID_SELECTION, + "nestedTeam_out"); + } + + //===================================================================================== + // Testing role files + //===================================================================================== + + //extract method invocation in role file (unbound role) + public void testRoleFile1() throws Exception + { + establishTeamCU("TeamWithRoleFile.java"); + performTest( + _testSetup.getRoleFilePackage(), + new String[]{"R"}, + COMPARE_WITH_OUTPUT, + "roleFile_out/TeamWithRoleFile"); + + } + + //extract expression in role file (unbound role) + public void testRoleFile2() throws Exception + { + establishTeamCU("TeamWithRoleFile.java"); + performTest( + _testSetup.getRoleFilePackage(), + new String[]{"R"}, + COMPARE_WITH_OUTPUT, + "roleFile_out/TeamWithRoleFile"); + } + + ICompilationUnit teamCU = null; + + private void establishTeamCU(String teamFileName) throws Exception, IOException { + if (teamCU != null) return; + IPackageFragment pack = _testSetup.getRoleFileParentPackage(); + teamCU = createCU(pack, teamFileName, getFileInputStream(myGetFilePath(pack, teamFileName))); + } + // ===================================================================================== + // Testing overloading and/or ambiguity for different focus types + // ===================================================================================== + + //focus implicit role hierarchy + public void testFocusTypeIsSuperroleInRoleHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"T1", "A", "B", "C"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsMiddleRoleInRoleHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"T2", "T1", "A", "B", "C"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsLowestRoleInRoleHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"T3", "T2", "T1", "A", "B", "C"}, + INVALID_SELECTION, + "focusType_out"); + } + + //focus base hierarchy + public void testFocusTypeIsSuperBasetypeInBaseHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"A", "B", "C", "T1", "T2", "T3"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsMiddleBasetypeInBaseHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"B", "A", "C", "T1", "T2", "T3"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsLowestBasetypeInBaseHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"C", "B", "A", "T1", "T2", "T3"}, + INVALID_SELECTION, + "focusType_out"); + } + + //focus team hierarchy + public void testFocusTypeIsSuperteamInTeamHierachy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"FocusTeam1"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsMiddleTeamInTeamHierachy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"FocusTeam2", "FocusTeam1"}, + INVALID_SELECTION, + "focusType_out"); + } + + public void testFocusTypeIsLowestTeamInTeamHierarchy() throws Exception + { + performTest( + _testSetup.getFocusTypePackage(), + new String[] {"FocusTeam3", "FocusTeam2", "FocusTeam1"}, + INVALID_SELECTION, + "focusType_out"); + } + + // role is a indirect subclass of target class, explicit inheritance only, short methodSpec + public void test20() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "B", "Base1", "Team1"}, + INVALID_SELECTION, + "overloading_out"); + } + + // role is a indirect subclass of target class, explicit + implicit inheritance, short methodSpec + public void test21() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "B", "Base1", "Team1", "Team2"}, + INVALID_SELECTION, + "overloading_out"); + } + + // role is a indirect subclass of target class, explicit + implicit inheritance, long methodSpec + public void test22() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "B", "Base1", "Team1", "Team2"}, + COMPARE_WITH_OUTPUT, + "overloading_out"); + } + + // bound base class is target class, short methodSpec + public void test23() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "Team1"}, + INVALID_SELECTION, + "overloading_out"); + } + + // bound base class is direct/indirect subclass of target class, short methodSpec + public void test24() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "Base1", "Team1"}, + INVALID_SELECTION, + "overloading_out"); + } + + // base class is subclass of target class, long methodSpec + public void test25() throws Exception + { + performTest( + _testSetup.getOverloadingPackage(), + new String[] {"A", "Base1", "Team1"}, + COMPARE_WITH_OUTPUT, + "overloading_out"); + } +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTestSetup.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTestSetup.java new file mode 100644 index 000000000..0fe22a0e3 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTestSetup.java @@ -0,0 +1,96 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod;
+
+import java.util.Hashtable;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper;
+import org.eclipse.objectteams.otdt.ui.tests.util.TestOptions;
+
+/**
+ * @author stephan
+ */
+public class ExtractTempTestSetup extends TestSetup
+{
+ private IJavaProject _javaProject;
+ private IPackageFragmentRoot _root;
+ private static final String CONTAINER = "src";
+
+ private IPackageFragment _statementsPackage;
+
+ public ExtractTempTestSetup(Test test)
+ {
+ super(test);
+ }
+
+ public IPackageFragmentRoot getRoot() {
+ return _root;
+ }
+
+ protected void setUp() throws Exception
+ {
+ Hashtable options = TestOptions.getFormatterOptions();
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0");
+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
+ JavaCore.setOptions(options);
+ TestOptions.initializeCodeGenerationOptions();
+ JavaPlugin.getDefault().getCodeTemplateStore().load();
+
+ _javaProject = JavaProjectHelper.createOTJavaProject("TestProject", "bin");
+ JavaProjectHelper.addRTJar(_javaProject);
+ _root = JavaProjectHelper.addSourceContainer(_javaProject, CONTAINER);
+
+ RefactoringCore.getUndoManager().flush();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceDescription description = workspace.getDescription();
+ description.setAutoBuilding(false);
+ workspace.setDescription(description);
+
+ //new packages for OT/J tests
+ _statementsPackage = getRoot().createPackageFragment("statements_in", true, null);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ RefactoringTest.performDummySearch(_javaProject);
+ JavaProjectHelper.delete(_javaProject);
+ }
+
+ public IPackageFragment getStatementsPackage()
+ {
+ return _statementsPackage;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTests.java new file mode 100644 index 000000000..596ecb383 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/extractmethod/ExtractTempTests.java @@ -0,0 +1,209 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.ISourceRange; +import org.eclipse.jdt.internal.corext.refactoring.code.ExtractTempRefactoring; +import org.eclipse.jdt.ui.tests.refactoring.infra.TextRangeUtil; +import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; + +/** + * @author stephan + * + */ +@SuppressWarnings("restriction") +public class ExtractTempTests extends AbstractSelectionTestCase +{ + private static ExtractTempTestSetup _testSetup; + + public ExtractTempTests(String name) + { + super(name); + } + + public static Test suite() + { + _testSetup = new ExtractTempTestSetup(new TestSuite(ExtractTempTests.class)); + return _testSetup; + } + + protected IPackageFragmentRoot getRoot() + { + return _testSetup.getRoot(); + } + + protected String getResourceLocation() + { + return "ExtractTemp/"; + } + + protected String adaptName(String name) + { + if (getName().startsWith("testFocusType")) + { + return super.adaptName(name); + } + return name + "_" + getName() + ".java"; + } + + protected void performTest( + int startLine, + int startColumn, + int endLine, + int endColumn, + boolean declareFinal, + String outputFolder) throws Exception + { + performTest(_testSetup.getStatementsPackage(), + new String[]{"T"}, + startLine, + startColumn, endLine, endColumn, + COMPARE_WITH_OUTPUT, declareFinal, + outputFolder); + } + + protected void performTest( + IPackageFragment packageFragment, + String[] ids, + int startLine, + int startColumn, + int endLine, + int endColumn, + int mode, + String outputFolder) throws Exception + { + performTest(packageFragment, ids, startLine, startColumn, endLine, endColumn, mode, false, outputFolder); + } + + protected void performTest( + IPackageFragment packageFragment, + String[] ids, + int startLine, + int startColumn, + int endLine, + int endColumn, + int mode, + boolean declareFinal, + String outputFolder) throws Exception + { + ICompilationUnit[] compUnits = createCUs(packageFragment, ids); + ISourceRange selection= TextRangeUtil.getSelection(compUnits[0], startLine, startColumn, endLine, endColumn); + ExtractTempRefactoring refactoring = new ExtractTempRefactoring( + compUnits[0], + selection.getOffset(), + selection.getLength()); + refactoring.setTempName("extracted"); + refactoring.setDeclareFinal(declareFinal); + RefactoringStatus status = + refactoring.checkInitialConditions(new NullProgressMonitor()); + switch (mode) + { + case VALID_SELECTION: + assertTrue(status.isOK()); + break; + case INVALID_SELECTION: + if (!status.isOK()) + return; + } + + String out = null; + switch (mode) + { + case COMPARE_WITH_OUTPUT: + out = getProofedContent(outputFolder, ids[0]); + break; + } + performTest(compUnits[0], refactoring, mode, out, true); + } + + private ICompilationUnit[] createCUs( + IPackageFragment packageFragment, + String[] ids) + throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[ids.length]; + + for (int idx = 0; idx < ids.length; idx++) + { + Assert.isNotNull(ids[idx]); + cus[idx] = createCU(packageFragment, ids[idx]); + } + return cus; + } + + protected int getCheckingStyle() + { + return CheckConditionsOperation.FINAL_CONDITIONS; + } + + /********** tests **********/ + //===================================================================================== + // Testing within statement + //===================================================================================== + + //extract team instantiation expression "new T_x()"Â from within.team_expression + public void testWithin1() throws Exception + { + performTest(9, 16, 9, 35, + false, + "statements_out"); + } + // body is single statement instead of block + public void testWithin2() throws Exception + { + performTest(9, 16, 9, 35, + false, + "statements_out"); + } + + // two element path, extracted is a dependent type + public void testTypeAnchor1() throws Exception + { + performTest(15,13,15,18, + true, + "statements_out"); + } + + // three element path, extracted is not a dependent type + public void testTypeAnchor2() throws Exception + { + performTest(21,13,21,20, + true, + "statements_out"); + } + + // three element path, extracted is a dependent type + public void testTypeAnchor3() throws Exception + { + performTest(19,13,19,20, + true, + "statements_out"); + } +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/AllTests.java new file mode 100644 index 000000000..b7e071e8b --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/AllTests.java @@ -0,0 +1,44 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.inlinecallin;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-InlineCallin-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.inlinecallin.InlineCallinTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/InlineCallinTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/InlineCallinTests.java new file mode 100644 index 000000000..7507f3512 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/inlinecallin/InlineCallinTests.java @@ -0,0 +1,345 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.inlinecallin; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.objectteams.otdt.core.ICallinMapping; +import org.eclipse.objectteams.otdt.core.IMethodMapping; +import org.eclipse.objectteams.otdt.core.IRoleType; +import org.eclipse.objectteams.otdt.core.OTModelManager; +import org.eclipse.objectteams.otdt.internal.core.CallinMapping; +import org.eclipse.objectteams.otdt.internal.refactoring.otrefactorings.inlinecallin.InlineCallinRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * + * @author Johannes Gebauer + */ +@SuppressWarnings("restriction") +public class InlineCallinTests extends RefactoringTest { + private static final String REFACTORING_PATH = "InlineCallin/"; + + public InlineCallinTests(String name) { + super(name); + } + + public static Test suite() { + return new MySetup(new TestSuite(InlineCallinTests.class)); + } + + public static Test setUpTest(Test test) { + return new MySetup(test); + } + + protected String getRefactoringPath() { + return REFACTORING_PATH; + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + private static InlineCallinRefactoring createInlineCallinRefactoring(IMethod roleMethod, ICallinMapping[] callinMappings, IMethod[] baseMethods) + throws JavaModelException { + IJavaProject project = null; + if (callinMappings[0] != null) { + project = callinMappings[0].getJavaProject(); + InlineCallinRefactoring refactoring = new InlineCallinRefactoring(roleMethod, callinMappings, baseMethods); + return refactoring; + } + return null; + } + + /** + * The <code>ICompilationUnit</code> containing the role that defines the + * <code>ICallinMapping</code> at position 0 and its base at position 1. + * + */ + private void performInlineCallin_pass(String[] cuNames, String roleMethodName, String[] roleMethodSignature, String[] baseMethodNames, String[][] baseMethodSignatures, + int[] mappingKinds, boolean deleteRoleMethod, String roleName, String baseName) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType roleType = getType(cus[0], roleName); + IType baseType = getType(cus[1], baseName); + + IMethod roleMethod = roleType.getMethod(roleMethodName, roleMethodSignature); + assertTrue("role method " + roleMethod.getElementName() + " does not exist", roleMethod.exists()); + + IMethod[] baseMethods = new IMethod[baseMethodNames.length]; + for (int i = 0; i < baseMethods.length; i++) { + baseMethods[i] = baseType.getMethod(baseMethodNames[i], baseMethodSignatures[i]); + assertTrue("base method " + baseMethods[i].getElementName() + " does not exist", baseMethods[i].exists()); + + } + + ICallinMapping[] mappings = new ICallinMapping[baseMethodNames.length]; + for (int i = 0; i < mappings.length; i++) { + mappings[i] = getCallinMethodMapping(roleType, roleMethod, baseMethods[i], mappingKinds[i]); + assertNotNull("the described callin method mapping does not exist", mappings[i]); + } + + InlineCallinRefactoring ref = createInlineCallinRefactoring(roleMethod, mappings, baseMethods); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + ref.setDeleteRoleMethod(deleteRoleMethod); + + RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor()); + assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); + performChange(ref, false); + + for (int i = 0; i < cus.length; i++) { + String expected = getFileContents(getOutputTestFileName(cuNames[i])); + String actual = cus[i].getSource(); + assertEqualLines(expected, actual); + } + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + /** + * The <code>ICompilationUnit</code> containing the role that defines the + * <code>ICallinMapping</code> at position 0 and its base at position 1. + * + */ + private void performInlineCallin_failing(String[] cuNames, String roleMethodName, String[] roleMethodSignature, String[] baseMethodNames, + String[][] baseMethodSignatures, int[] mappingKinds, boolean deleteRoleMethod, String roleName, String baseName) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType roleType = getType(cus[0], roleName); + IType baseType = getType(cus[1], baseName); + + IMethod roleMethod = roleType.getMethod(roleMethodName, roleMethodSignature); + assertTrue("role method " + roleMethod.getElementName() + " does not exist", roleMethod.exists()); + + IMethod[] baseMethods = new IMethod[baseMethodNames.length]; + for (int i = 0; i < baseMethods.length; i++) { + baseMethods[i] = baseType.getMethod(baseMethodNames[i], baseMethodSignatures[i]); + assertTrue("base method " + baseMethods[i].getElementName() + " does not exist", baseMethods[i].exists()); + + } + + ICallinMapping[] mappings = new ICallinMapping[baseMethodNames.length]; + for (int i = 0; i < mappings.length; i++) { + mappings[i] = getCallinMethodMapping(roleType, roleMethod, baseMethods[i], mappingKinds[i]); + assertNotNull("the described callin method mapping does not exist", mappings[i]); + } + + InlineCallinRefactoring ref = createInlineCallinRefactoring(roleMethod, mappings, baseMethods); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + ref.setDeleteRoleMethod(deleteRoleMethod); + + RefactoringStatus result = performRefactoring(ref); + assertNotNull("precondition was supposed to fail.", result); + assertTrue("precondition was supposed to fail.", !result.isOK()); + assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR)); + + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + private ICallinMapping getCallinMethodMapping(IType roleType, IMethod roleMethod, IMethod baseMethod, int mappingKind) throws JavaModelException { + IRoleType role = (IRoleType) OTModelManager.getOTElement(roleType); + assertNotNull("type " + roleType.getElementName() + " is not a role", role); + + IMethodMapping[] mappings = role.getMethodMappings(); + + for (int i = 0; i < mappings.length; i++) { + if (mappings[i] instanceof ICallinMapping) { + ICallinMapping mapping = (ICallinMapping) mappings[i]; + + for (int j = 0; j < mapping.getBoundBaseMethods().length; j++) { + IMethod roleMethod2 = mapping.getRoleMethod(); + IMethod baseMethod2 = mapping.getBoundBaseMethods()[j]; + if (roleMethod2.equals(roleMethod) && baseMethod2.equals(baseMethod) && mapping.getCallinKind() == mappingKind) { + return mapping; + } + } + } + } + return null; + } + + + /******* tests ******************/ + + /* Inline Callin Tests */ + + public void testSimpleBeforeCallin() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, new int[] { CallinMapping.KIND_BEFORE }, false, "R", "B"); + } + + public void testSimpleAfterCallin() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testSimpleReplaceCallin() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testAfterCallinWithReturn() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testReplaceCallinResultTunneling1() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testReplaceCallinResultTunneling2() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testReplaceCallinWithReturn() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testDifferentParamNames() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[] { "I" }, new String[] { "m" }, new String[][] { new String[] { "I" } }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testDifferentParamLength() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[] { "I" }, new String[] { "m" }, new String[][] { new String[] { "I", "QString;" } }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", + "B"); + } + + public void testSimpleParameterMapping() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[] { "I" }, new String[] { "m" }, new String[][] { new String[] { "I", "I" } }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testReplaceWithParameterMapping() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[] { "I" }, new String[] { "m" }, new String[][] { new String[] { "I", "I" } }, + new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testReplaceCallinWithMultipleReturns() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testReplaceCallinWithParameter() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[] { "I", "QString;" }, new String[] { "m" }, new String[][] { new String[] { "I", "QString;" } }, new int[] { CallinMapping.KIND_REPLACE }, + false, "R", "B"); + } + + public void testCallinMappingWithSignature() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testMultipleBaseMethodCallin() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testRoleMethodReferencesCallout() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testRoleMethodReferencesCalloutToFieldGet() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testRoleMethodReferencesCalloutToFieldSet() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testParameterTunneling1() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[] { "I" } }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testParameterTunneling2() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[] { "I" } }, new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testInlineMultipleCallins() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m1", "m2" }, new String[][] { new String[0], new String[0] }, + new int[] { CallinMapping.KIND_AFTER, CallinMapping.KIND_AFTER }, false, "R", "B"); + } + + public void testDeleteRoleMethod() throws Exception { + performInlineCallin_pass(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_REPLACE }, true, "R", "B"); + } + + public void testDeleteReferencedRoleMethod() throws Exception { + performInlineCallin_failing(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_BEFORE }, true, "R", "B"); + } + + public void testInlineBoundCallin1() throws Exception { + performInlineCallin_failing(new String[] { "T1", "B", "T2" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testInlineBoundCallin2() throws Exception { + performInlineCallin_failing(new String[] { "T1", "B", "T2" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_REPLACE }, false, "R", "B"); + } + + public void testDependencyToRole1() throws Exception { + performInlineCallin_failing(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_BEFORE }, false, "R", "B"); + } + + public void testDependencyToRole2() throws Exception { + performInlineCallin_failing(new String[] { "T", "B" }, "n", new String[0], new String[] { "m" }, new String[][] { new String[0] }, + new int[] { CallinMapping.KIND_BEFORE }, false, "R", "B"); + } + +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/AllTests.java new file mode 100644 index 000000000..f99b76be5 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/AllTests.java @@ -0,0 +1,50 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.move;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-Move-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.move.MoveInstanceMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.move.MoveStaticMethodTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java new file mode 100644 index 000000000..70b68428c --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java @@ -0,0 +1,696 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.move;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.internal.corext.refactoring.structure.MoveInstanceMethodProcessor;
+import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
+import org.eclipse.jdt.ui.tests.refactoring.infra.TextRangeUtil;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring;
+import org.eclipse.objectteams.otdt.internal.refactoring.corext.base.OTRefactoringStatusCodes;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest;
+
+/**
+ * @author brcan
+ *
+ */
+@SuppressWarnings({ "restriction", "nls" })
+public class MoveInstanceMethodTests extends RefactoringTest
+{
+ private static final String REFACTORING_PATH = "MoveInstanceMethod/";
+
+ private static final int PARAMETER = 0;
+ private static final int FIELD = 1;
+
+ private boolean toSucceed;
+
+ public MoveInstanceMethodTests(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ if (false)
+ {
+ TestSuite suite = new TestSuite(MoveInstanceMethodTests.class.getName());
+ suite.addTest(new MoveInstanceMethodTests("testRoleclass1"));
+ return new MySetup(suite);
+ }
+ return new MySetup(new TestSuite(MoveInstanceMethodTests.class));
+ }
+
+ protected String getRefactoringPath()
+ {
+ return REFACTORING_PATH + successPath();
+ }
+
+ private String successPath()
+ {
+ return toSucceed ? "/canMove/" : "/cannotMove/";
+ }
+
+ private void performAndCheckSelectedCU_passing(
+ String[] cuQNames, String selectionCuQName,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName,
+ boolean inlineDelegator, boolean removeDelegator, boolean expectWarning)
+ throws Exception
+ {
+ int selectionCuIndex = firstIndexOf(selectionCuQName, cuQNames);
+ Assert.isTrue(selectionCuIndex != -1,
+ "parameter selectionCuQName must match some String in cuQNames.");
+ performRefactoring_passing(cuQNames, selectionCuIndex, startLine, startColumn, endLine,
+ endColumn, newReceiverType, newReceiverName, null,
+ inlineDelegator, removeDelegator, expectWarning);
+ }
+
+ private int firstIndexOf(String one, String[] others)
+ {
+ for (int idx = 0; idx < others.length; idx++)
+ {
+ if (one == null && others[idx] == null || one.equals(others[idx]))
+ {
+ return idx;
+ }
+ }
+ return -1;
+ }
+
+ private void performRefactoring_passing(
+ String[] cuQNames, int selectionCuIndex,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName, String newMethodName,
+ boolean inlineDelegator, boolean removeDelegator, boolean expectWarning)
+ throws Exception
+ {
+ Assert.isTrue(0 <= selectionCuIndex
+ && selectionCuIndex < cuQNames.length);
+
+ toSucceed = true;
+
+ ICompilationUnit[] cus = createCUs(cuQNames);
+ ICompilationUnit selectionCu = cus[selectionCuIndex];
+
+ ISourceRange selection = TextRangeUtil.getSelection(selectionCu,
+ startLine, startColumn, endLine, endColumn);
+ IMethod method = getMethod(selectionCu, selection);
+ assertNotNull(method);
+ MoveInstanceMethodProcessor refProc = new MoveInstanceMethodProcessor(
+ method,
+ JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
+ Refactoring ref= new MoveRefactoring(refProc);
+
+ assertNotNull("refactoring should be created", ref);
+ RefactoringStatus preconditionResult= ref
+ .checkInitialConditions(new NullProgressMonitor());
+
+ assertTrue("activation was supposed to be successful",
+ preconditionResult.isOK());
+
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ {
+ refProc.setMethodName(newMethodName);
+ }
+ preconditionResult.merge(ref.checkFinalConditions(new NullProgressMonitor()));
+ if (!expectWarning) {
+ assertTrue("precondition was supposed to pass", preconditionResult
+ .isOK());
+
+ assertFalse("no warnings expected", preconditionResult.hasWarning());
+ } else {
+ assertTrue("warning expected", preconditionResult.hasWarning());
+ }
+
+ performChange(ref, false);
+ for (int idx = 0; idx < cus.length; idx++)
+ {
+ String outputTestFileName = getOutputTestFileName(getSimpleName(cuQNames[idx]));
+ assertEqualLines("Incorrect inline in " + outputTestFileName,
+ getFileContents(outputTestFileName), cus[idx].getSource());
+ }
+ }
+
+ private void performAndCheckSelectedCU_failing(
+ String[] cuQNames, String selectionCuQName,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName,
+ boolean inlineDelegator, boolean removeDelegator, int errorCode)
+ throws Exception
+ {
+ int selectionCuIndex = firstIndexOf(selectionCuQName, cuQNames);
+ Assert.isTrue(selectionCuIndex != -1,
+ "parameter selectionCuQName must match some String in cuQNames.");
+ performRefactoring_failing(cuQNames, selectionCuIndex, startLine, startColumn,
+ endLine, endColumn, newReceiverType, newReceiverName,
+ null, inlineDelegator, removeDelegator, errorCode);
+ }
+
+ private void performRefactoring_failing(
+ String[] cuQNames, int selectionCuIndex,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName, String newMethodName,
+ boolean inlineDelegator, boolean removeDelegator, int errorCode)
+ throws Exception
+ {
+ Assert.isTrue(0 <= selectionCuIndex
+ && selectionCuIndex < cuQNames.length);
+
+ toSucceed = false;
+
+ ICompilationUnit[] cus = createCUs(cuQNames);
+ ICompilationUnit selectionCu = cus[selectionCuIndex];
+
+ ISourceRange selection = TextRangeUtil.getSelection(selectionCu,
+ startLine, startColumn, endLine, endColumn);
+ IMethod method = getMethod(selectionCu, selection);
+ assertNotNull(method);
+ MoveInstanceMethodProcessor refProc = new MoveInstanceMethodProcessor(
+ method,
+ JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
+ Refactoring ref= new MoveRefactoring(refProc);
+ if (ref == null)
+ {
+ assertTrue(errorCode != 0);
+ }
+ else
+ {
+ RefactoringStatus result= ref.checkInitialConditions(
+ new NullProgressMonitor());
+
+ if (!result.isOK())
+ {
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ return;
+ }
+ else
+ {
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ refProc.setMethodName(newMethodName);
+
+ result.merge(ref
+ .checkFinalConditions(new NullProgressMonitor()));
+
+ assertTrue("precondition checking is expected to fail.", !result.isOK());
+ assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR));
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ }
+ }
+ }
+
+ private void performConditionChecking_warnings(
+ String[] cuQNames, String selectionCuQName,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName, String newMethodName,
+ boolean inlineDelegator, boolean removeDelegator, int errorCode)
+ throws Exception
+ {
+ int selectionCuIndex = firstIndexOf(selectionCuQName, cuQNames);
+ Assert.isTrue(selectionCuIndex != -1,
+ "parameter selectionCuQName must match some String in cuQNames.");
+ Assert.isTrue(0 <= selectionCuIndex
+ && selectionCuIndex < cuQNames.length);
+
+ toSucceed = true;
+
+ ICompilationUnit[] cus = createCUs(cuQNames);
+ ICompilationUnit selectionCu = cus[selectionCuIndex];
+
+ ISourceRange selection = TextRangeUtil.getSelection(selectionCu,
+ startLine, startColumn, endLine, endColumn);
+ IMethod method = getMethod(selectionCu, selection);
+ assertNotNull(method);
+ MoveInstanceMethodProcessor refProc= new MoveInstanceMethodProcessor(
+ method,
+ JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
+ Refactoring ref = new MoveRefactoring(refProc);
+ if (ref == null)
+ {
+ assertTrue(errorCode != 0);
+ }
+ else
+ {
+ RefactoringStatus result = ref.checkInitialConditions(
+ new NullProgressMonitor());
+ if (!result.isOK())
+ {
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ return;
+ }
+ else
+ {
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ refProc.setMethodName(newMethodName);
+
+ result.merge(ref
+ .checkFinalConditions(new NullProgressMonitor()));
+
+ assertTrue("warnings expected", result.hasWarning());
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.WARNING).getCode());
+ }
+ }
+ }
+
+ private ICompilationUnit[] createCUs(String[] qualifiedNames)
+ throws Exception
+ {
+ ICompilationUnit[] cus = new ICompilationUnit[qualifiedNames.length];
+
+ for (int idx = 0; idx < qualifiedNames.length; idx++)
+ {
+ Assert.isNotNull(qualifiedNames[idx]);
+ cus[idx] = createCUfromTestFile(getRoot().createPackageFragment(
+ getQualifier(qualifiedNames[idx]), true, null),
+ getSimpleName(qualifiedNames[idx]));
+ }
+ return cus;
+ }
+
+ private String getQualifier(String qualifiedName)
+ {
+ int dot = qualifiedName.lastIndexOf('.');
+ return qualifiedName.substring(0, dot != -1 ? dot : 0);
+ }
+
+ private String getSimpleName(String qualifiedName)
+ {
+ return qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
+ }
+
+ private static IMethod getMethod(ICompilationUnit cu,
+ ISourceRange sourceRange) throws JavaModelException
+ {
+ IJavaElement[] jes = cu.codeSelect(sourceRange.getOffset(), sourceRange
+ .getLength());
+ if (jes.length != 1 || !(jes[0] instanceof IMethod))
+ return null;
+ return (IMethod)jes[0];
+ }
+
+ private static void chooseNewReceiver(
+ MoveInstanceMethodProcessor refProc, int newReceiverType,
+ String newReceiverName)
+ {
+ IVariableBinding chosen = null;
+ IVariableBinding[] possibleNewReceivers = refProc.getPossibleTargets();
+ for (int i = 0; i < possibleNewReceivers.length; i++)
+ {
+ IVariableBinding candidate = possibleNewReceivers[i];
+ if (candidate.getName().equals(newReceiverName)
+ && typeMatches(newReceiverType, candidate))
+ {
+ assertNull(chosen);
+ chosen = candidate;
+ }
+ }
+ assertNotNull("Expected new receiver not available.", chosen);
+ refProc.setTarget(chosen);
+ }
+
+ private static boolean typeMatches(int newReceiverType,
+ IVariableBinding newReceiver)
+ {
+ return newReceiverType == PARAMETER && newReceiver.isParameter()
+ || newReceiverType == FIELD && newReceiver.isField();
+ }
+
+ /********** tests *********/
+// test method template
+// public void test0() throws Exception
+// {
+// helper1(new String[] { "p1.A", "p2.B", "p3.C" }, "p1.A", 7, 17, 7, 20,
+// PARAMETER, "b", false, false);
+// }
+// public void testFail0() throws Exception
+// {
+// failHelper1("p1.IA", 5, 17, 5, 20, PARAMETER, "b", true, true, RefactoringStatusCodes.SELECT_METHOD_IMPLEMENTATION);
+// }
+
+ // TODO(SH): more tests for combinations of inline,removeDelegate!
+
+ /* Testing receiver types */
+ // TODO: commented passing tests
+ // public void testFieldNewReceiver() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.A", "p.B"}, "p.A",
+ // 7, 17, 7, 19, FIELD, "b", true, true, true);// warn:
+ // change-field-to-default-vis
+ // }
+ //
+ // public void testParameterNewReceiver() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.A", "p.B"}, "p.A",
+ // 5, 17, 5, 19, PARAMETER, "b", true, true, false);
+ // }
+ //
+ // /* Testing team classes */
+ // public void testTeamclass1() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 7, 17, 7, 20, FIELD, "_t", true, true, true);// warn:
+ // change-field-to-default-vis
+ // }
+ //
+ // public void testTeamclass2() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 5, 17, 5, 20, PARAMETER, "t", false, false, false);
+ // }
+ //
+ // /* Testing role classes */
+ // public void testRoleclass1() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 8, 17, 8, 20, FIELD, "_r", true, false, false);
+ // }
+ //
+ // public void testRoleclass2() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 7, 17, 7, 20, PARAMETER, "r", true, false, false);
+ // }
+ //
+ // /* Testing nested teams */
+ // public void testNestedTeam1() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 8, 17, 8, 20, FIELD, "_nT", true, false, false);
+ // }
+ //
+ // public void testNestedTeam2() throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.T", "p.O"}, "p.O",
+ // 7, 17, 7, 20, PARAMETER, "nT", true, false, false);
+ // }
+ //
+ // /* Testing role files */
+ // //TODO(gbr) implement tests for role files
+ // // public void testRoleFile1() throws Exception
+ // // {
+ // // }
+ // //
+ // // public void testRoleFile2() throws Exception
+ // // {
+ // // }
+ //
+ // public void testRoleClassWithLongMethodSpecsInCallinBinding()
+ // throws Exception
+ // {
+ // performConditionChecking_warnings(
+ // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
+ // 8, 17, 8, 18, FIELD, "_s", null, true, true,
+ // // FIXME(SH):
+ // //OTRefactoringStatusCodes.OVERLOADING
+ // -1
+ // );
+ // }
+ //
+ // public void testRoleClassWithLongMethodSpecsInCalloutBinding()
+ // throws Exception
+ // {
+ // performConditionChecking_warnings(
+ // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
+ // 8, 17, 8, 18, FIELD, "_s", null, true, true,
+ // // FIXME(SH):
+ // //OTRefactoringStatusCodes.OVERLOADING
+ // -1
+ // );
+ // }
+ //
+ // public void testExplicitlyInheritedRoleClassWithLongMethodSpecs()
+ // throws Exception
+ // {
+ // performConditionChecking_warnings(
+ // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
+ // 8, 17, 8, 18, FIELD, "_s", null, true, true,
+ // //FIXME(SH):
+ // //OTRefactoringStatusCodes.OVERLOADING
+ // -1
+ // );
+ // }
+ // public void testImplicitlyInheritedRoleClassWithLongMethodSpecs()
+ // throws Exception
+ // {
+ // performConditionChecking_warnings(
+ // new String[] {"p.O", "p.S", "p.B", "p.T1", "p.T2"}, "p.O",
+ // 8, 17, 8, 18, FIELD, "_s", null, true, true,
+ // // FIXME(SH):
+ // //OTRefactoringStatusCodes.OVERLOADING
+ // -1
+ // );
+ // }
+ // public void testTargetMethodAccessesPrivateFeatureOfEnclosingType1()
+ // throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.A", "p.B", "p.C"},
+ // "p.A", 8, 17, 8, 19, FIELD, "_c",
+ // true, true, true);//warn: move needs to open visibility of field
+ // }
+ // public void testTargetMethodAccessesPrivateFeatureOfEnclosingType2()
+ // throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p.A", "p.B", "p.C"},
+ // "p.A", 7, 17, 7, 19, PARAMETER, "c",
+ // true, true, true);//warn: move needs to open visibility of field
+ // }
+ // public void testTargetMethodAccessesProtectedFeatureOfEnclosingType1()
+ // throws Exception
+// {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p1.A", "p1.B", "p2.C"},
+ // "p1.A", 10, 17, 10, 19, FIELD, "_c",
+ // true, true, true);//warn: move needs to open visibility of field
+// }
+ // public void testTargetMethodAccessesProtectedFeatureOfEnclosingType2()
+ // throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p1.A", "p1.B", "p2.C"},
+ // "p1.A", 9, 17, 9, 19, PARAMETER, "c",
+ // true, true, true);//warn: move needs to open visibility of field
+ // }
+//
+ // public void
+ // testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType1()
+ // throws Exception
+// {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p1.A", "p1.B", "p2.C"},
+ // "p1.A", 10, 17, 10, 19, FIELD, "_c",
+ // true, true, true);//warn: move needs to open visibility of field
+ // }
+ // public void
+ // testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType2()
+ // throws Exception
+ // {
+ // performAndCheckSelectedCU_passing(
+ // new String[] {"p1.A", "p1.B", "p2.C"},
+ // "p1.A", 9, 17, 9, 19, PARAMETER, "c",
+ // true, true, true);//warn: move needs to open visibility of field
+ // }
+ //tests for ambiguity in method specs
+ public void testAmbiguousRoleMethodSpecifierInCallinBinding1()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.B", "p.T"},
+ "p.O", 8, 17, 8, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void testAmbiguousRoleMethodSpecifierInCallinBinding2()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 5, 17, 5, 18, PARAMETER, "s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void _testAmbiguousBaseMethodSpecifierInCallinBinding1()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.B", "p.T"},
+ "p.O", 8, 17, 8, 18, FIELD, "_s",
+ false, false,
+ OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void testAmbiguousBaseMethodSpecifierInCallinBinding2()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 5, 17, 5, 18, PARAMETER, "s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void testAmbiguousRoleMethodSpecifierInCalloutBinding1()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.B", "p.T"},
+ "p.O", 8, 17, 8, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void testAmbiguousRoleMethodSpecifierInCalloutBinding2()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 5, 17, 5, 18, PARAMETER, "s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void _testAmbiguousBaseMethodSpecifierInCalloutBinding1()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.B", "p.T"},
+ "p.O", 8, 17, 8, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ public void testAmbiguousBaseMethodSpecifierInCalloutBinding2()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 5, 17, 5, 18, PARAMETER, "s",
+ false, false,
+ OTRefactoringStatusCodes.AMBIGUOUS_METHOD_SPECIFIER);
+ }
+ //tests for overriding
+ public void _testMovedMethodIsOverriddenInBaseClass()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 7, 17, 7, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.BASE_METHOD_OVERRIDES_MOVED_METHOD);
+ }
+ public void _testMovedMethodIsOverriddenInRoleClass()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 7, 17, 7, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.ROLE_METHOD_OVERRIDES_MOVED_METHOD);
+ }
+ public void _testMovedMethodIsOverriddenInExplicitlyInheritedRoleClass()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 7, 17, 7, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.ROLE_METHOD_OVERRIDES_MOVED_METHOD);
+ }
+ public void _testMovedMethodIsOverriddenInImplicitlyInheritedRoleClass()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T1", "p.T2"},
+ "p.O", 7, 17, 7, 18, FIELD, "_s",
+ true, true, OTRefactoringStatusCodes.ROLE_METHOD_OVERRIDES_MOVED_METHOD);
+ }
+ //tests for duplication
+ public void testDuplicateMethodInNewReceiver()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S"},
+ "p.O", 7, 17, 7, 17, FIELD, "_s",
+ true, true, -1);
+ }
+ public void testDuplicateMethodInBaseClassReceiver()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.O", "p.S", "p.T"},
+ "p.O", 7, 17, 7, 17, FIELD, "_s",
+ true, true, -1);
+ }
+
+ public void _testDuplicateMethodInNewParameterReceiver1()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.A", "p.B"},
+ "p.A", 6, 17, 6, 18, PARAMETER, "b",
+ true, true, OTRefactoringStatusCodes.DUPLICATE_METHOD_IN_NEW_RECEIVER);
+ }
+
+ public void _testDuplicateMethodInNewParameterReceiver2()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.A", "p.B"},
+ "p.A", 8, 17, 8, 18, PARAMETER, "b",
+ true, true, OTRefactoringStatusCodes.DUPLICATE_METHOD_IN_NEW_RECEIVER);
+ }
+
+ public void _testTargetMethodIsPrivate()
+ throws Exception
+ {
+ performAndCheckSelectedCU_failing(
+ new String[] {"p.A", "p.B"},
+ "p.A", 6, 18, 6, 20, PARAMETER, "b",
+ true, true, OTRefactoringStatusCodes.CANNOT_MOVE_PRIVATE);
+ }
+
+}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveMethodTests.java new file mode 100644 index 000000000..849a56532 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveMethodTests.java @@ -0,0 +1,41 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.move;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ */
+public class MoveMethodTests
+{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(MoveMethodTests.class.getName());
+
+ suite.addTest(MoveInstanceMethodTests.suite());
+ suite.addTest(MoveStaticMethodTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveStaticMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveStaticMethodTests.java new file mode 100644 index 000000000..d648a1802 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveStaticMethodTests.java @@ -0,0 +1,563 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.move;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.refactoring.structure.MoveStaticMembersProcessor;
+import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest;
+
+/**
+ * Part of the tests in this class have been copied from the original class
+ * <code>MoveMembersTests</code> in the test suite
+ *<code>org.eclipse.jdt.ui.tests.refactoring</code> provided by Eclipse.
+ *
+ * @author brcan
+ *
+ */
+public class MoveStaticMethodTests extends RefactoringTest
+{
+ private static final String REFACTORING_PATH = "MoveStaticMethod/";
+
+ public MoveStaticMethodTests(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new MySetup(new TestSuite(MoveStaticMethodTests.class));
+ }
+
+ public static Test setUpTest(Test someTest)
+ {
+ return new MySetup(someTest);
+ }
+
+ protected String getRefactoringPath()
+ {
+ return REFACTORING_PATH;
+ }
+
+ private static MoveRefactoring createRefactoring(IMember[] members, IType destination)
+ throws JavaModelException
+ {
+ return createRefactoring(destination.getJavaProject(), members, destination.getFullyQualifiedName('.'));
+ }
+
+ private static MoveRefactoring createRefactoring(IJavaProject project, IMember[] members, String destination)
+ throws JavaModelException
+ {
+ MoveStaticMembersProcessor processor = new MoveStaticMembersProcessor(
+ members, JavaPreferencesSettings.getCodeGenerationSettings(project));
+ if (processor == null)
+ {
+ return null;
+ }
+ processor.setDestinationTypeFullyQualifiedName(destination);
+
+ return new MoveRefactoring(processor);
+ }
+
+ //helper methods for passing tests
+ private void methodHelper_passing(
+ String[] methodNames,
+ String[][] signatures,
+ String srcCuName,
+ String destCuName) throws Exception
+ {
+ fieldMethodTypeHelper_passing(
+ new String[0], methodNames, signatures, new String[0], srcCuName, destCuName);
+ }
+
+ private void fieldMethodTypeHelper_passing(
+ String[] fieldNames,
+ String[] methodNames,
+ String[][] signatures,
+ String[] typeNames,
+ String srcCuName,
+ String destCuName) throws Exception
+ {
+ IPackageFragment packForSrc = getPackageP();
+ IPackageFragment packForDest = getPackageP();
+ fieldMethodTypePackageHelper_passing(
+ fieldNames, methodNames, signatures, typeNames, packForSrc, packForDest, srcCuName, destCuName);
+ }
+
+ private void fieldMethodTypePackageHelper_passing(
+ String[] fieldNames,
+ String[] methodNames,
+ String[][] signatures,
+ String[] typeNames,
+ IPackageFragment packForSrc,
+ IPackageFragment packForDest,
+ String srcCuName,
+ String destTypeName) throws Exception
+ {
+ String[] destNames= destTypeName.split("[$]");
+ String destCUName = destNames[0];
+ //ParticipantTesting.reset();
+ ICompilationUnit srcCU = createCUfromTestFile(packForSrc, srcCuName);
+ ICompilationUnit destCU = createCUfromTestFile(packForDest, destCUName);
+ IType srcType = getType(srcCU, srcCuName);
+ IType destType = getType(destCU, destCUName);
+ for (int i=1; i<destNames.length; i++)
+ destType= destType.getType(destNames[i]);
+ IField[] fields = getFields(srcType, fieldNames);
+ IMethod[] methods = getMethods(srcType, methodNames, signatures);
+ IType[] types = getMemberTypes(srcType, typeNames);
+
+ IType destinationType = destType;
+ IMember[] members = merge(methods, fields, types);
+ // FIXME(SH): is this needed (was doubly commented)?
+ //String[] handles= ParticipantTesting.createHandles(members);
+ //MoveArguments[] args= new MoveArguments[handles.length];
+ //for (int i = 0; i < args.length; i++) {
+ // args[i]= new MoveArguments(destinationType, true);
+ //}
+ MoveRefactoring ref = createRefactoring(members, destinationType);
+
+ RefactoringStatus result = performRefactoringWithStatus(ref);
+ assertTrue("precondition was supposed to pass",
+ result.getSeverity() <= RefactoringStatus.WARNING);
+ //ParticipantTesting.testMove(handles, args);
+
+ String expected;
+ String actual;
+
+ expected = getFileContents(getOutputTestFileName(srcCuName));
+ actual = srcCU.getSource();
+ assertEqualLines("incorrect modification of " + srcCuName, expected, actual);
+
+ expected = getFileContents(getOutputTestFileName(destCUName));
+ actual = destCU.getSource();
+ assertEqualLines("incorrect modification of " + destTypeName, expected, actual);
+ }
+
+ //helper methods for failing tests
+ private void fieldMethodTypeHelper_failing(
+ String[] fieldNames,
+ String[] methodNames,
+ String[][] signatures,
+ String[] typeNames,
+ int errorLevel,
+ String destinationTypeName) throws Exception
+ {
+ IPackageFragment packForA = getPackageP();
+ IPackageFragment packForB = getPackageP();
+ fieldMethodTypePackageHelper_failing(
+ fieldNames, methodNames, signatures, typeNames, errorLevel, destinationTypeName, packForA, packForB);
+ }
+
+ private void fieldMethodTypePackageHelper_failing(
+ String[] fieldNames,
+ String[] methodNames,
+ String[][] signatures,
+ String[] typeNames,
+ int errorLevel,
+ String destinationTypeName,
+ IPackageFragment packForA,
+ IPackageFragment packForB) throws Exception
+ {
+ ICompilationUnit cuA = createCUfromTestFile(packForA, "A");
+ ICompilationUnit cuB = createCUfromTestFile(packForB, "B");
+ try
+ {
+ IType typeA = getType(cuA, "A");
+ IField[] fields = getFields(typeA, fieldNames);
+ IMethod[] methods = getMethods(typeA, methodNames, signatures);
+ IType[] types = getMemberTypes(typeA, typeNames);
+
+ MoveRefactoring ref = createRefactoring(
+ typeA.getJavaProject(), merge(methods, fields, types), destinationTypeName);
+ if (ref == null)
+ {
+ assertEquals(errorLevel, RefactoringStatus.FATAL);
+ return;
+ }
+ RefactoringStatus result = performRefactoring(ref);
+ assertNotNull("precondition was supposed to fail", result);
+ assertEquals("precondition was supposed to fail", errorLevel,
+ result.getSeverity());
+ }
+ finally
+ {
+ performDummySearch();
+ cuA.delete(false, null);
+ cuB.delete(false, null);
+ }
+ }
+
+ /********** tests *********/
+ public void test0() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test1() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test2() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test3() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test4() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test9() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test10() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test11() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test12() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test13() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test14() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test15() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test16() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test17() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test18() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test19() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test20() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test28() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m", "n" },
+ new String[][] { new String[0], new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test29() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void test41() throws Exception
+ {
+ methodHelper_passing(
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ "A",
+ "B");
+ }
+
+ public void testFail0() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.FATAL,
+ "p.B");
+ }
+
+ public void testFail1() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.ERROR,
+ "p.B.X");
+ }
+
+ public void testFail2() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.ERROR,
+ "p.B");
+ }
+
+ public void testFail3() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[] { "I", "I" } },
+ new String[0],
+ RefactoringStatus.ERROR,
+ "p.B");
+ }
+
+ public void testFail4() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[] { "I", "I" } },
+ new String[0],
+ RefactoringStatus.WARNING,
+ "p.B");
+ }
+
+ public void testFail5() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[] { "I", "I" } },
+ new String[0],
+ RefactoringStatus.WARNING,
+ "p.B");
+ }
+
+ public void testFail9() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.WARNING, // visibility adjustment
+ "p.B");
+ }
+
+ public void testFail10() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.WARNING, // visibility adjustment
+ "p.B");
+ }
+
+ public void testFail13() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.WARNING, // visibility adjustment
+ "p.B");
+ }
+
+ public void testFail15() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.WARNING,
+ "p.B");
+ }
+
+ public void testFail17() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.FATAL,
+ "java.lang.Object");
+ }
+
+ public void testFail18() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.FATAL,
+ "p.DontExist");
+ }
+
+ public void testFail19() throws Exception
+ {
+ fieldMethodTypeHelper_failing(
+ new String[0],
+ new String[] { "m" },
+ new String[][] { new String[0] },
+ new String[0],
+ RefactoringStatus.ERROR,
+ "p.B");
+ }
+
+ public void testMoveToTeamclass() throws Exception
+ {
+ methodHelper_passing(new String[] { "m" }, new String[][] { new String[0] }, "B", "T");
+ }
+
+ public void testMoveToNestedTeamclass1() throws Exception
+ {
+ methodHelper_passing(new String[] { "m" }, new String[][] { new String[0] }, "B", "T");
+ }
+ public void testMoveToNestedTeamclass2() throws Exception
+ {
+ methodHelper_passing(new String[] { "m" }, new String[][] { new String[0] }, "B", "T$TR");
+ }
+ public void testMoveToRoleclass() throws Exception
+ {
+ methodHelper_passing(new String[] { "m" }, new String[][] { new String[0] }, "B", "T$R");
+ }
+}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/AllTests.java new file mode 100644 index 000000000..f594bee82 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/AllTests.java @@ -0,0 +1,50 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.pullup;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author jogeb
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse
+ * refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-PullUp-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.pullup.PullUpTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java new file mode 100644 index 000000000..ff621e282 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java @@ -0,0 +1,330 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.pullup; + +import java.util.Arrays; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMember; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; +import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor; +import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; +import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; +import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * Example TestCase to practice testing for the diploma thesis. + * + * @author Johannes Gebauer + */ +public class PullUpTests extends RefactoringTest { + private static final String REFACTORING_PATH = "PullUp/"; + + public PullUpTests(String name) { + super(name); + } + + public static Test suite() { + return new MySetup(new TestSuite(PullUpTests.class)); + } + + public static Test setUpTest(Test test) { + return new MySetup(test); + } + + protected String getRefactoringPath() { + return REFACTORING_PATH; + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + private String createInputTestFileName(ICompilationUnit[] cus, int idx) { + return getInputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String createOutputTestFileName(ICompilationUnit[] cus, int idx) { + return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String getSimpleNameOfCu(String compUnit) { + int dot = compUnit.lastIndexOf('.'); + return compUnit.substring(0, dot); + } + + private void setTargetClass(PullUpRefactoringProcessor processor, int targetClassIndex) throws JavaModelException { + IType[] possibleClasses = getPossibleTargetClasses(processor); + processor.setDestinationType(getPossibleTargetClasses(processor)[possibleClasses.length - 1 - targetClassIndex]); + } + + private IType[] getPossibleTargetClasses(PullUpRefactoringProcessor processor) throws JavaModelException { + return processor.getCandidateTypes(new RefactoringStatus(), new NullProgressMonitor()); + } + + private static IMethod[] getMethods(IMember[] members) { + List l = Arrays.asList(JavaElementUtil.getElementsOfType(members, IJavaElement.METHOD)); + return (IMethod[]) l.toArray(new IMethod[l.size()]); + } + + private static PullUpRefactoringProcessor createRefactoringProcessor(IMember[] methods) throws JavaModelException { + IJavaProject project = null; + if (methods != null && methods.length > 0) + project = methods[0].getJavaProject(); + if (RefactoringAvailabilityTester.isPullUpAvailable(methods)) { + PullUpRefactoringProcessor processor = new PullUpRefactoringProcessor(methods, JavaPreferencesSettings.getCodeGenerationSettings(project)); + new ProcessorBasedRefactoring(processor); + return processor; + } + return null; + } + + /** + * The <code>ICompilationUnit</code> containing the declaring type must be + * at position 0. + * + * @param fieldNames + * TODO + */ + private void performPullUp_pass(String[] cuNames, String[] methodNames, String[][] signatures, String[] fieldNames, boolean deleteAllInSourceType, + boolean deleteAllMatchingMethods, int targetClassIndex, String nameOfDeclaringType) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType declaringType = getType(cus[0], nameOfDeclaringType); + IMethod[] methods = getMethods(declaringType, methodNames, signatures); + IField[] fields = getFields(declaringType, fieldNames); + IMember[] members = merge(methods, fields); + + PullUpRefactoringProcessor processor = createRefactoringProcessor(members); + Refactoring ref = processor.getRefactoring(); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + setTargetClass(processor, targetClassIndex); + + if (deleteAllInSourceType) + processor.setDeletedMethods(methods); + if (deleteAllMatchingMethods) + processor.setDeletedMethods(getMethods(processor.getMatchingElements(new NullProgressMonitor(), false))); + + RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor()); + assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); + performChange(ref, false); + + for (int i = 0; i < cus.length; i++) { + String expected = getFileContents(getOutputTestFileName(cuNames[i])); + String actual = cus[i].getSource(); + assertEqualLines(expected, actual); + } + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + /** + * The <code>ICompilationUnit</code> containing the declaring type must be + * at position 0. + */ + private void performPullUp_warning(String[] cuNames, String[] methodNames, String[][] signatures, boolean deleteAllInSourceType, + boolean deleteAllMatchingMethods, int targetClassIndex, String nameOfDeclaringType) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType declaringType = getType(cus[0], nameOfDeclaringType); + IMethod[] methods = getMethods(declaringType, methodNames, signatures); + + PullUpRefactoringProcessor processor = createRefactoringProcessor(methods); + Refactoring ref = processor.getRefactoring(); + + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + setTargetClass(processor, targetClassIndex); + + if (deleteAllInSourceType) + processor.setDeletedMethods(methods); + if (deleteAllMatchingMethods) + processor.setDeletedMethods(getMethods(processor.getMatchingElements(new NullProgressMonitor(), false))); + + RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor()); + RefactoringStatusEntry[] initialConditionStatus = checkInputResult.getEntries(); + assertEquals("precondition was supposed to give a warning", RefactoringStatus.WARNING, initialConditionStatus[0].getSeverity()); + assertEquals("precondition was supposed to give only one warning", initialConditionStatus.length, 1); + + performChange(ref, false); + + for (int i = 0; i < cus.length; i++) { + String expected = getFileContents(getOutputTestFileName(cuNames[i])); + String actual = cus[i].getSource(); + assertEqualLines(expected, actual); + } + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + private void performPullUp_failing(String[] cuNames, String[] methodNames, String[][] signatures, String[] fieldNames, boolean deleteAllInSourceType, + boolean deleteAllMatchingMethods, int targetClassIndex, String nameOfDeclaringType) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType declaringType = getType(cus[0], nameOfDeclaringType); + IMethod[] methods = getMethods(declaringType, methodNames, signatures); + IField[] fields = getFields(declaringType, fieldNames); + IMember[] members = merge(methods, fields); + + PullUpRefactoringProcessor processor = createRefactoringProcessor(members); + Refactoring ref = processor.getRefactoring(); + + setTargetClass(processor, targetClassIndex); + + if (deleteAllInSourceType) + processor.setDeletedMethods(methods); + if (deleteAllMatchingMethods) + processor.setDeletedMethods(getMethods(processor.getMatchingElements(new NullProgressMonitor(), false))); + + RefactoringStatus result = performRefactoring(ref); + assertNotNull("precondition was supposed to fail.", result); + assertTrue("precondition was supposed to fail.", !result.isOK()); + assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR)); + + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + /******* tests ******************/ + + /* Pull up Method Tests */ + + public void testPullUpBoundMethod() throws Exception { + performPullUp_warning(new String[] { "B", "BSuper", "T" }, new String[] { "bm" }, new String[][] { new String[0] }, true, false, 0, "B"); + } + + public void testPullUpCallinMethod() throws Exception { + performPullUp_pass(new String[] { "T", "TSuper", "B" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "R"); + } + + public void testPullUpMethodToImplicitSuperclass() throws Exception { + performPullUp_pass(new String[] { "T", "TSuper", "B" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "R"); + } + + public void testDeletionOfMatchingMethods() throws Exception { + performPullUp_pass(new String[] { "T", "T2", "TSuper", "B" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, true, true, 0, + "R"); + } + + public void testReferencingRoleInDeclaredLifting() throws Exception { + performPullUp_failing(new String[] { "T", "TSuper", "B" }, new String[] { "m" }, new String[][] { new String[] { "QB;" } }, new String[] {}, true, + false, 0, "T"); + } + + public void testPulledUpMethodIsOverriddenInImplicitSubRole() throws Exception { + performPullUp_failing(new String[] { "T1", "T2", "TSuper", }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, + "R"); + } + + public void testAmbiguityInExplicitRelatedRole1() throws Exception { + performPullUp_failing(new String[] { "T", "B" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "R1"); + } + + public void testAmbiguityInExplicitRelatedRole2() throws Exception { + performPullUp_failing(new String[] { "T", "B" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "R1"); + } + + public void testAmbiguityInImplicitRelatedRole1() throws Exception { + performPullUp_failing(new String[] { "T1", "T2", "TSuper", "B" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, + 0, "R"); + } + + public void testAmbiguityInImplicitRelatedRole2() throws Exception { + performPullUp_failing(new String[] { "T1", "T2", "TSuper", "B" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, + 0, "R"); + } + + public void testAmbiguityInBase1() throws Exception { + performPullUp_failing(new String[] { "B2", "B1", "T" }, new String[] { "bm" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "B2"); + } + + public void testAmbiguityInBase2() throws Exception { + performPullUp_failing(new String[] { "B2", "B1", "T" }, new String[] { "bm" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "B2"); + } + + public void testPullUpCallinIntoRegularClass() throws Exception { + performPullUp_failing(new String[] { "T", "C" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, true, false, 0, "R"); + } + + /* Pull up Field Tests */ + + public void testPullUpAnchoredTypeField() throws Exception { + performPullUp_failing(new String[] { "T2", "T1", "T3" }, new String[] {}, new String[][] { new String[0] }, new String[] { "extern" }, true, false, 0, + "T2"); + } + + public void testPulledUpFieldWillBeShadowed() throws Exception { + performPullUp_failing(new String[] { "T2", "T1", "T3" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, true, false, 0, + "Role"); + } + + public void testPullUpCalloutFieldInBase() throws Exception { + performPullUp_pass(new String[] { "B1", "B2", "T" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, true, false, 0, "B1"); + } + + public void testPullUpFieldToImplicitSuperclass() throws Exception { + performPullUp_pass(new String[] { "T", "TSuper" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, true, false, 0, "R"); + } +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/AllTests.java new file mode 100644 index 000000000..59dea9145 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/AllTests.java @@ -0,0 +1,46 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.pushdown;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author jogeb
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse
+ * refactoring tests
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All OT-PushDown-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.pushdown.PushDownTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/PushDownTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/PushDownTests.java new file mode 100644 index 000000000..ff7ab3e2f --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pushdown/PushDownTests.java @@ -0,0 +1,265 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.pushdown; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMember; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; +import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * Copy of {@link org.eclipse.jdt.ui.tests.refactoring.PushDownTests}. + * + * @author Johannes Gebauer + * + */ +public class PushDownTests extends RefactoringTest { + + private static final Class clazz= PushDownTests.class; + + private static final String REFACTORING_PATH= "PushDown/"; + + public PushDownTests(String name) { + super(name); + } + + protected String getRefactoringPath() { + return REFACTORING_PATH; + } + + + public static Test suite() { + return new MySetup(new TestSuite(PushDownTests.class)); + } + + private void performPullUp_pass(String[] cuNames, String[] methodNames, String[][] signatures, String[] fieldNames, String nameOfDeclaringType) + throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType declaringType = getType(cus[0], nameOfDeclaringType); + IMethod[] methods = getMethods(declaringType, methodNames, signatures); + IField[] fields = getFields(declaringType, fieldNames); + IMember[] members = merge(methods, fields); + + PushDownRefactoringProcessor processor = createRefactoringProcessor(members); + Refactoring ref = processor.getRefactoring(); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor()); + assertTrue("precondition was supposed to pass", !checkInputResult.hasError()); + performChange(ref, false); + + for (int i = 0; i < cus.length; i++) { + String expected = getFileContents(getOutputTestFileName(cuNames[i])); + String actual = cus[i].getSource(); + assertEqualLines(expected, actual); + } + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + private void performPullUp_fail(String[] cuNames, String[] methodNames, String[][] signatures, String[] fieldNames, String nameOfDeclaringType) + throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + try { + + IType declaringType = getType(cus[0], nameOfDeclaringType); + IMethod[] methods = getMethods(declaringType, methodNames, signatures); + IField[] fields = getFields(declaringType, fieldNames); + IMember[] members = merge(methods, fields); + + PushDownRefactoringProcessor processor = createRefactoringProcessor(members); + Refactoring ref = processor.getRefactoring(); + + assertTrue("activation", ref.checkInitialConditions(new NullProgressMonitor()).isOK()); + + RefactoringStatus result = performRefactoring(ref); + assertNotNull("precondition was supposed to fail.", result); + assertTrue("precondition was supposed to fail.", !result.isOK()); + assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR)); + + } finally { + performDummySearch(); + for (int i = 0; i < cus.length; i++) { + cus[i].delete(false, null); + } + + } + } + + private static PushDownRefactoringProcessor createRefactoringProcessor(IMember[] methods) throws JavaModelException { + IJavaProject project = null; + if (methods != null && methods.length > 0) + project = methods[0].getJavaProject(); + if (RefactoringAvailabilityTester.isPullUpAvailable(methods)) { + PushDownRefactoringProcessor processor = new PushDownRefactoringProcessor(methods); + new ProcessorBasedRefactoring(processor); + return processor; + } + return null; + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + + //-------------------------------------------------------- + public void testPushDownMethodToImplicitSubclass() throws Exception { + performPullUp_pass(new String[] { "TSuper", "T", "B" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, "R"); + } + + public void testDeclaringTypeHasADirectPhantomSubRole() throws Exception { + performPullUp_fail(new String[] { "TSuper", "T1", "T2" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, "R"); + } + + public void testPushedDownMethodReferencedInMethodBinding1() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] { "bm" }, new String[][] { new String[0] }, new String[] {}, "B1"); + } + + public void testPushedDownMethodReferencedInMethodBinding2() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] { "bm" }, new String[][] { new String[0] }, new String[] {}, "B1"); + } + + public void testPushedDownMethodReferencedInMethodBinding3() throws Exception { + performPullUp_fail(new String[] { "T1", "T2", "B" }, new String[] { "rm" }, new String[][] { new String[0] }, new String[] {}, "Role"); + } + + public void testPushedDownMethodIsReferencedInRegularGuard1() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] { "b" }, new String[][] { new String[0] }, new String[] {}, "R1"); + } + + public void testPushedDownMethodIsReferencedInRegularGuard2() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] { "b" }, new String[][] { new String[0] }, new String[] {}, "R1"); + } + + public void testPushedDownMethodIsReferencedInBaseGuard1() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] { "b" }, new String[][] { new String[0] }, new String[] {}, "B1"); + } + + public void testPushedDownMethodIsReferencedInBaseGuard2() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] { "b" }, new String[][] { new String[0] }, new String[] {}, "B1"); + } + + public void testPushedDownMethodIsReferencedInBaseGuard3() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] { "b" }, new String[][] { new String[0] }, new String[] {}, "B1"); + } + + public void testPushedDownMethodIsReferencedInParameterMapping1() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] { "f" }, new String[][] { new String[0] }, new String[] {}, "R1"); + } + + public void testPushedDownMethodIsReferencedInParameterMapping2() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] { "f" }, new String[][] { new String[0] }, new String[] {}, "R1"); + } + + // See Ticket #286 + public void _testPushedDownMethodIsReferencedInParameterMapping3() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] { "f" }, new String[][] { new String[0] }, new String[] {}, "R1"); + } + + /* Push Down Field Tests */ + public void testPushDownFieldToImplicitSubclass() throws Exception { + performPullUp_pass(new String[] { "TSuper", "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "R"); + } + + public void testPushedDownFieldReferencedInCalloutToField() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "B1"); + } + + public void testPushDownTypeAnchorInstance() throws Exception { + performPullUp_fail(new String[] { "T1", "T2", "T3" }, new String[] {}, new String[][] { new String[0] }, new String[] { "anchor" }, "T1"); + } + + public void testPushedDownFieldWouldShadowAnInheritedField() throws Exception { + performPullUp_fail(new String[] { "B", "T1", "T2" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "B"); + } + + public void testPushedDownFieldIsReferencedInRegularGuard1() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "b" }, "R1"); + } + + public void testPushedDownFieldIsReferencedInRegularGuard2() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "b" }, "R1"); + } + + public void testPushedDownFieldIsReferencedInBaseGuard1() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] {}, new String[][] { new String[0] }, new String[] { "b" }, "B1"); + } + + public void testPushedDownFieldIsReferencedInBaseGuard2() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] {}, new String[][] { new String[0] }, new String[] { "b" }, "B1"); + } + + public void testPushedDownFieldIsReferencedInBaseGuard3() throws Exception { + performPullUp_fail(new String[] { "B1", "B2", "T" }, new String[] {}, new String[][] { new String[0] }, new String[] { "b" }, "B1"); + } + + public void testPushedDownFieldIsReferencedInParameterMapping1() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "R1"); + } + + public void testPushedDownFieldIsReferencedInParameterMapping2() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "R1"); + } + + public void testOverrideImplicitInheritedMethod() throws Exception { + performPullUp_fail(new String[] { "A", "T1", "T2" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, "A"); + } + + public void testOverrideExplicitInheritedMethod() throws Exception { + performPullUp_pass(new String[] { "T2", "T1", "A" }, new String[] { "m" }, new String[][] { new String[0] }, new String[] {}, "R"); + } + + // See Ticket #286 + public void _testPushedDownFieldIsReferencedInParameterMapping3() throws Exception { + performPullUp_fail(new String[] { "T", "B" }, new String[] {}, new String[][] { new String[0] }, new String[] { "f" }, "R1"); + } + +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/AllTests.java new file mode 100644 index 000000000..74bc24974 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/AllTests.java @@ -0,0 +1,54 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-Rename-Refactoring Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameMethodInInterfaceTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenamePrivateMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameStaticMethodTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameVirtualMethodInClassTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenamePrivateFieldTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.rename.RenameTypeTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodInInterfaceTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodInInterfaceTests.java new file mode 100644 index 000000000..43074bb37 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodInInterfaceTests.java @@ -0,0 +1,257 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * @author brcan + * + */ +public class RenameMethodInInterfaceTests extends RefactoringTest +{ + private static final String REFACTORING_PATH = "RenameMethodInInterface/"; + + public RenameMethodInInterfaceTests(String name) + { + super(name); + } + + public static Test suite() + { + return new MySetup(new TestSuite(RenameMethodInInterfaceTests.class)); + } + + public static Test setUpTest(Test test) + { + return new MySetup(test); + } + + protected String getRefactoringPath() + { + return REFACTORING_PATH; + } + + private RenameRefactoring createRefactoring(RenameMethodProcessor processor) + { + return new RenameRefactoring(processor); + } + + private RenameMethodProcessor createProcessor(IMethod method) + { + return new RenameVirtualMethodProcessor(method); + } + + private void performRenamingMtoK_failing(String[] cuQNames) + throws Exception + { + performRenameRefactoring_failing(cuQNames, "m", "k", new String[0]); + } + + private void performRenameRefactoring_failing( + String[] cuQNames, + String methodName, + String newMethodName, + String[] signatures) + throws Exception + { + ICompilationUnit[] cus = createCUs(cuQNames); + IType interfaceI = null; + for (int idx = 0; idx < cus.length; idx++) + { + if (cus[idx].getElementName().equals("I.java")) + { + interfaceI = getType(cus[idx], "I"); + } + } + RenameMethodProcessor processor = createProcessor( + interfaceI.getMethod(methodName, signatures)); + RenameRefactoring ref = createRefactoring(processor); + processor.setNewElementName(newMethodName); + RefactoringStatus result = performRefactoring(ref); + assertNotNull("precondition was supposed to fail", result); + } + + private void performRenaming_passing(String [] cuQNames) + throws Exception + { + performRenamingMtoK_passing(cuQNames, true); + } + + /** + * Rename method m to k and update all references. + */ + private void performRenamingMtoK_passing( + String [] cuQNames, + boolean updateReferences) + throws Exception + { + performRenameRefactoring_passing( + cuQNames, "m", "k", new String[0], true, updateReferences); + } + + + private void performRenameRefactoring_passing( + String[] cuQNames, + String methodName, + String newMethodName, + String[] signatures, + boolean shouldPass, + boolean updateReferences) + throws Exception + { + ICompilationUnit[] cus = createCUs(cuQNames); + IType interfaceI = null; + for (int idx = 0; idx < cus.length; idx++) + { + if (cus[idx].getElementName().equals("I.java")) + { + interfaceI = getType(cus[idx], "I"); + } + } + RenameMethodProcessor processor = createProcessor( + interfaceI.getMethod(methodName, signatures)); + RenameRefactoring ref = createRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setNewElementName(newMethodName); + assertEquals("was supposed to pass", null, performRefactoring(ref)); + if (!shouldPass) + { + for (int idx = 0; idx < cus.length; idx++) + { + assertTrue("incorrect renaming because of a java model bug", + !getFileContents( + getOutputTestFileName(getSimpleName(cuQNames[idx]))). + equals(cus[idx].getSource())); + } + return; + } + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("incorrect renaming", + getFileContents( + getOutputTestFileName( + getSimpleName(cuQNames[idx]))), cus[idx].getSource()); + } + assertTrue("anythingToUndo", RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager() + .anythingToRedo()); + //assertEquals("1 to undo", 1, + // Refactoring.getUndoManager().getRefactoringLog().size()); + + RefactoringCore.getUndoManager().performUndo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid undo", + getFileContents( + getInputTestFileName( + getSimpleName(cuQNames[idx]))), cus[idx].getSource()); + } + assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("anythingToRedo", RefactoringCore.getUndoManager() + .anythingToRedo()); + RefactoringCore.getUndoManager().performRedo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid redo", + getFileContents( + getOutputTestFileName( + getSimpleName(cuQNames[idx]))), cus[idx].getSource()); + } + } + + private ICompilationUnit[] createCUs(String[] qualifiedNames) + throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[qualifiedNames.length]; + + for (int idx = 0; idx < qualifiedNames.length; idx++) + { + Assert.isNotNull(qualifiedNames[idx]); + cus[idx] = createCUfromTestFile(getRoot().createPackageFragment( + getQualifier(qualifiedNames[idx]), true, null), + getSimpleName(qualifiedNames[idx])); + } + return cus; + } + + private String getQualifier(String qualifiedName) + { + int dot = qualifiedName.lastIndexOf('.'); + return qualifiedName.substring(0, dot != -1 ? dot : 0); + } + + private String getSimpleName(String qualifiedName) + { + return qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); + } + + /********** tests **********/ + //passing + public void testUpdateImplementationInRoleClass() throws Exception + { + performRenaming_passing(new String[] {"p.I", "p.T"}); + } + public void testUpdateImplementationInExplicitlyInheritedRoleClass() + throws Exception + { + performRenaming_passing(new String[] {"p.I", "p.T"}); + } + public void testUpdateImplementationInImplicitlyInheritedRoleClass() + throws Exception + { + performRenaming_passing(new String[] {"p.I", "p.T1", "p.T2"}); + } + //failing + public void testMethodAlreadyExistsInRoleClass() throws Exception + { + performRenamingMtoK_failing(new String[] {"p.I", "p.T"}); + } + public void testMethodAlreadyExistsInExplicitlyInheritedRoleClass() + throws Exception + { + performRenamingMtoK_failing(new String[] {"p.I", "p.T"}); + } + public void testMethodAlreadyExistsInImplicitlyInheritedRoleClass() + throws Exception + { + performRenamingMtoK_failing(new String[] {"p.I", "p.T1", "p.T2"}); + } + +}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodTests.java new file mode 100644 index 000000000..8dc8c680c --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameMethodTests.java @@ -0,0 +1,43 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ */
+public class RenameMethodTests
+{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(RenameMethodTests.class.getName());
+
+ suite.addTest(RenameVirtualMethodInClassTests.suite());
+ suite.addTest(RenameMethodInInterfaceTests.suite());
+ suite.addTest(RenamePrivateMethodTests.suite());
+ suite.addTest(RenameStaticMethodTests.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateFieldTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateFieldTests.java new file mode 100644 index 000000000..42f2c8890 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateFieldTests.java @@ -0,0 +1,418 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameArguments; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor; + +/** + * @author jwl + * + */ +public class RenamePrivateFieldTests extends RefactoringTest +{ + private static final Class clazz = RenamePrivateFieldTests.class; + private static final String REFACTORING_PATH = "RenamePrivateField/"; + + private Object _prefixPref; + + public RenamePrivateFieldTests(String name) + { + super(name); + } + + public static Test suite() + { + return new MySetup(new TestSuite(clazz)); + } + + public static Test setUpTest(Test someTest) + { + return new MySetup(someTest); + } + + protected String getRefactoringPath() + { + return REFACTORING_PATH; + } + + protected void setUp() throws Exception + { + super.setUp(); + Hashtable options = JavaCore.getOptions(); + _prefixPref = options.get(JavaCore.CODEASSIST_FIELD_PREFIXES); + options.put(JavaCore.CODEASSIST_FIELD_PREFIXES, getPrefixes()); + JavaCore.setOptions(options); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CODEASSIST_FIELD_PREFIXES, _prefixPref); + JavaCore.setOptions(options); + } + + private String getPrefixes() + { + return "_"; + } + + private void performRenamingFtoG_failing( + String[] cuNames, + String selectionCuName, + String declaringTypeName) + throws Exception + { + performRenaming_failing(cuNames, selectionCuName, declaringTypeName, "f", "g"); + } + + private void performRenaming_failing( + String[] cuNames, + String selectionCuName, + String declaringTypeName, + String fieldName, + String newFieldName) + throws Exception + { + performRenameRefactoring_failing( + cuNames, selectionCuName, declaringTypeName, fieldName, newFieldName, false, false); + } + + + private void performRenameRefactoring_failing( + String[] cuNames, + String selectionCuName, + String declaringTypeName, + String fieldName, + String newFieldName, + boolean renameGetter, + boolean renameSetter) throws Exception + { + int selectionCuIndex = firstIndexOf(selectionCuName, cuNames); + Assert.isTrue(selectionCuIndex != -1, + "parameter selectionCuQName must match some String in cuQNames."); + Assert.isTrue(0 <= selectionCuIndex + && selectionCuIndex < cuNames.length); + + ICompilationUnit[] cus = createCUs(cuNames); + ICompilationUnit declaringCu = cus[selectionCuIndex]; + IType declaringType = getType(declaringCu, declaringTypeName); + IField field = declaringType.getField(fieldName); + RenameFieldProcessor processor = new RenameFieldProcessor(field); + RenameRefactoring refactoring = new RenameRefactoring(processor); + processor.setNewElementName(newFieldName); + processor.setRenameGetter(renameGetter); + processor.setRenameSetter(renameSetter); + RefactoringStatus result = performRefactoring(refactoring); + assertNotNull("precondition was supposed to fail", result); + } + + private void performRenamingFtoG_passing( + String[] cuNames, + String declaringTypeName, + boolean updateReferences) throws Exception + { + performRenameRefactoring_passing( + cuNames, declaringTypeName, "f", "g", + updateReferences, false, false, false, false, false); + } + + private void performRenameRefactoring_passing( + String[] cuNames, + String declaringTypeName, + String fieldName, + String newFieldName, + boolean updateReferences, + boolean updateTextualMatches, + boolean renameGetter, + boolean renameSetter, + boolean expectedGetterRenameEnabled, + boolean expectedSetterRenameEnabled) throws Exception + { +// ParticipantTesting.reset(); + ICompilationUnit[] cus = createCUs(cuNames); + IType declaringType = getType(cus[0], declaringTypeName); + IField field = declaringType.getField(fieldName); + RenameFieldProcessor processor = new RenameFieldProcessor(field); + RenameRefactoring refactoring = new RenameRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setUpdateTextualMatches(updateTextualMatches); +// assertEquals("getter rename enabled", expectedGetterRenameEnabled, +// processor.canEnableGetterRenaming() == null); +// assertEquals("setter rename enabled", expectedSetterRenameEnabled, +// processor.canEnableSetterRenaming() == null); + processor.setRenameGetter(renameGetter); + processor.setRenameSetter(renameSetter); + processor.setNewElementName(newFieldName); + String newGetterName = processor.getNewGetterName(); + String newSetterName = processor.getNewSetterName(); + + int numbers = 1; + List elements = new ArrayList(); + elements.add(field); + List args = new ArrayList(); + args.add(new RenameArguments(newFieldName, updateReferences)); + if (renameGetter && expectedGetterRenameEnabled) + { + elements.add(processor.getGetter()); + args.add(new RenameArguments(newGetterName, updateReferences)); + numbers++; + } + if (renameSetter && expectedSetterRenameEnabled) + { + elements.add(processor.getSetter()); + args.add(new RenameArguments(newSetterName, updateReferences)); + numbers++; + } +// String[] renameHandles = ParticipantTesting.createHandles(elements +// .toArray()); + + RefactoringStatus result = performRefactoring(refactoring); + assertEquals("was supposed to pass", null, result); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid renaming!", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + +// ParticipantTesting.testRename(renameHandles, (RenameArguments[])args +// .toArray(new RenameArguments[args.size()])); + + assertTrue("anythingToUndo", RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performUndo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid undo", + getFileContents(createInputTestFileName(cus, idx)), cus[idx].getSource()); + } + + assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("anythingToRedo", RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performRedo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid redo", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + } + + private int firstIndexOf(String one, String[] others) + { + for (int idx = 0; idx < others.length; idx++) + { + if (one == null && others[idx] == null || one.equals(others[idx])) + { + return idx; + } + } + return -1; + } + + private String createInputTestFileName(ICompilationUnit[] cus, int idx) + { + return getInputTestFileName(getSimpleNameOfCu( + cus[idx].getElementName())); + } + + private String createOutputTestFileName(ICompilationUnit[] cus, + int idx) + { + return getOutputTestFileName(getSimpleNameOfCu(cus[idx]. + getElementName())); + } + + private String getSimpleNameOfCu(String compUnit) + { + int dot = compUnit.lastIndexOf('.'); + return compUnit.substring(0, dot); + } + + private String getUnqualifiedMemberTypeName(String qualifiedMemberType) + { + int dot = qualifiedMemberType.indexOf('.'); + if (dot != -1) + { + return qualifiedMemberType.substring(dot+1); + } + return qualifiedMemberType; + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) + { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + //--------- tests ---------- + public void testRenameFieldInTeamclass() throws Exception + { + performRenamingFtoG_passing(new String[]{"T"}, "T", true); + } + + public void testUpdateFieldReferenceInTeamMethod() throws Exception + { + performRenamingFtoG_passing(new String[]{"T"}, "T", true); + } + + public void testUpdateFieldReferenceInLiftingMethod() throws Exception + { + performRenamingFtoG_passing(new String[]{"T"}, "T", true); + } + + public void testUpdateTeamFieldReferenceInRoleclass1() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "T", "number", "amount", + true, false, false, false, false, false); + } + + public void testUpdateTeamFieldReferenceInRoleclass2() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "T", "number", "amount", + true, false, false, false, false, false); + } + + public void testUpdateTeamFieldReferenceInNestedTeam1() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "T", "number", "amount", + true, false, false, false, false, false); + } + + public void testUpdateTeamFieldReferenceInNestedTeam2() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "T", "number", "amount", + true, false, false, false, false, false); + } + + public void testRenameFieldInRoleclass() throws Exception + { + performRenamingFtoG_passing(new String[]{"T"}, "R", true); + } + + public void testUpdateFieldReferenceInRoleclass1() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "R", "name", "newName", + true, false, true, false, true, false); + } + + public void testUpdateFieldReferenceInRoleclass2() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "R", "name", "newName", + true, true, true, true, true, true); + } + + public void testUpdateFieldReferenceInRoleclass3() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "R", "name", "newName", + true, false, false, true, false, true); + } + + public void testUpdateReferenceInCalloutToField1() throws Exception + { + performRenamingFtoG_passing(new String[]{"B", "T"}, "B", true); + } + //private field from super base class visible in bound base class + public void testUpdateReferenceInCalloutToField2() throws Exception + { + performRenamingFtoG_passing(new String[]{"B1", "B2", "T"}, "B1", true); + } + //shorthand definition: callout to field access method without + //prior abstract declaration + method names only + public void testUpdateReferenceInCalloutToField3() throws Exception + { + performRenameRefactoring_passing( + new String[]{"B", "T"}, "B", "name", "surname", + true, false, false, false, false, false); + } + //shorthand definition: callout to field access method without + //prior abstract declaration + complete signatures + public void testUpdateReferenceInCalloutToField4() throws Exception + { + performRenameRefactoring_passing( + new String[]{"B", "T"}, "B", "name", "surname", + true, false, false, false, false, false); + } + + //passing + public void testRenameGetterAndSetter1() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "T", "number", "index", + true, false, true, true, true, true); + } + public void testRenameGetterAndSetter2() throws Exception + { + performRenameRefactoring_passing( + new String[]{"T"}, "R", "number", "index", + true, false, true, true, true, true); + } + //failing + public void testRenameGetterAndSetter3() throws Exception + { + performRenameRefactoring_failing( + new String[]{"T1", "T2"}, "T2", "T2", "number", "index", true, true); + } + public void testRenameGetterAndSetter4() throws Exception + { + performRenameRefactoring_failing( + new String[]{"T1", "T2"}, "T2", "R", "number", "index", true, true); + } +}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateMethodTests.java new file mode 100644 index 000000000..8fa6f0a9e --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenamePrivateMethodTests.java @@ -0,0 +1,234 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.core.runtime.Assert; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor; + +/** + * The tests in this class have been inspired by the test class + * <code>RenamePrivateMethodTests</code> in the test suite + *<code>org.eclipse.jdt.ui.tests.refactoring</code> provided by Eclipse JDT. + * + * @author brcan + */ +public class RenamePrivateMethodTests extends RefactoringTest +{ + private static final String REFACTORING_PATH = "RenamePrivateMethod/"; + + public RenamePrivateMethodTests(String name) + { + super(name); + } + + public static Test suite() + { + return new MySetup(new TestSuite(RenamePrivateMethodTests.class)); + } + + public static Test setUpTest(Test test) + { + return new MySetup(test); + } + + protected String getRefactoringPath() + { + return REFACTORING_PATH; + } + + private RenameRefactoring createRefactoring(RenameMethodProcessor processor) + { + return new RenameRefactoring(processor); + } + + private RenameMethodProcessor createProcessor(IMethod method) + { + return new RenameNonVirtualMethodProcessor(method); + } + + private void performRenameRefactoring_failing( + String methodName, + String newMethodName, + String[] signatures) + throws Exception + { + IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A"); + RenameMethodProcessor processor = + createProcessor(classA.getMethod(methodName, signatures)); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setNewElementName(newMethodName); + RefactoringStatus result= performRefactoring(refactoring); + assertNotNull("precondition was supposed to fail", result); + } + + private void performRenaming_failing() throws Exception + { + performRenameRefactoring_failing("m", "k", new String[0]); + } + + private void performRenaming_passing( + String cuNames[], + String declaringTypeName) throws Exception + { + performRenamingMtoK_passing(cuNames, declaringTypeName, true); + } + + private void performRenamingMtoK_passing( + String cuNames[], + String declaringTypeName, + boolean updateReferences) + throws Exception + { + performRenameRefactoring_passing( + cuNames, declaringTypeName, "m", "k", new String[0], updateReferences); + } + + private void performRenameRefactoring_passing( + String[] cuNames, + String declaringTypeName, + String methodName, + String newMethodName, + String[] signatures, + boolean updateReferences) + throws Exception + { + ICompilationUnit[] cus = createCUs(cuNames); + IType declaringType = getType(cus[0], declaringTypeName); + IMethod method = declaringType.getMethod(methodName, signatures); + RenameMethodProcessor processor = createProcessor(method); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setNewElementName(newMethodName); + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid renaming!", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + + assertTrue("anythingToUndo", RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performUndo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid undo", + getFileContents(createInputTestFileName(cus, idx)), cus[idx].getSource()); + } + + assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("anythingToRedo", RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performRedo(null, + new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid redo", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) + { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + private String createInputTestFileName(ICompilationUnit[] cus, int idx) + { + return getInputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String createOutputTestFileName(ICompilationUnit[] cus, int idx) + { + return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String getSimpleNameOfCu(String compUnit) + { + int dot = compUnit.lastIndexOf('.'); + return compUnit.substring(0, dot); + } + + /******* tests ******************/ + + public void testUpdateReferenceInCalloutBinding1() throws Exception + { + performRenaming_passing(new String[]{"B", "T"}, "B"); + } + + public void testUpdateReferenceInCalloutBinding2() throws Exception + { + performRenameRefactoring_passing( + new String[]{"B", "T"}, "B", "getAmount", "getQuantity", null, true); + } + + public void testUpdateReferenceInCallinBinding1() throws Exception + { + performRenaming_passing(new String[]{"B", "T"}, "B"); + } + + public void testUpdateReferenceInCallinBinding2() throws Exception + { + performRenaming_passing(new String[]{"B", "T"}, "B"); + } + + //renaming of private role method + public void testPrivateMethodInTeamclass() throws Exception + { + performRenaming_passing(new String[]{"T"}, "T"); + } + + public void testUpdatePrivateTeamMethodInvocation1() throws Exception + { + performRenaming_passing(new String[]{"T"}, "T"); + } + + public void testUpdatePrivateTeamMethodInvocation2() throws Exception + { + performRenameRefactoring_passing(new String[]{"T", "B1"}, "T", "m1", "k1", null, true); + } + +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameStaticMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameStaticMethodTests.java new file mode 100644 index 000000000..9fa880e61 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameStaticMethodTests.java @@ -0,0 +1,296 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.Signature; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor; + +/** + * The tests in this class have initially been copied from the original class + * <code>RenameStaticMethodTests</code> in the test suite + *<code>org.eclipse.jdt.ui.tests.refactoring</code> provided by Eclipse. + * + * @author brcan + */ +public class RenameStaticMethodTests extends RefactoringTest +{ + private static final String REFACTORING_PATH = "RenameStaticMethod/"; + + public RenameStaticMethodTests(String name) + { + super(name); + } + + public static Test suite() + { + return new MySetup(new TestSuite(RenameStaticMethodTests.class)); + } + + protected String getRefactoringPath() + { + return REFACTORING_PATH; + } + + private RenameRefactoring createRefactoring(RenameMethodProcessor processor) + { + return new RenameRefactoring(processor); + } + + private RenameMethodProcessor createProcessor(IMethod method) + { + return new RenameNonVirtualMethodProcessor(method); + } + + private void performRenamingMtoK_failing() throws Exception + { + performRenameRefactoring_failing("m", "k", new String[0]); + } + + private void performRenameRefactoring_failing( + String methodName, + String newMethodName, + String[] signatures) + throws Exception + { + IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A"); + try + { + RenameMethodProcessor processor = + createProcessor(classA.getMethod(methodName, signatures)); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setNewElementName(newMethodName); + RefactoringStatus result = performRefactoring(refactoring); + assertNotNull("precondition was supposed to fail", result); + } + finally + { + performDummySearch(); + classA.getCompilationUnit().delete(true, null); + } + } + + private void performRenaming_passing() throws Exception + { + performRenamingMtoK_passing(true); + } + + /** + * Rename method m to k and update all references. + */ + private void performRenamingMtoK_passing(boolean updateReferences) + throws Exception + { + performRenameRefactoring_passing1("m", "k", new String[0], updateReferences); + } + + private void performRenameRefactoring_passing2( + String methodName, + String newMethodName, + String[] signatures) + throws Exception + { + performRenameRefactoring_passing1(methodName, newMethodName, signatures, true); + } + + private void performRenameRefactoring_passing1( + String methodName, + String newMethodName, + String[] signatures, + boolean updateReferences) + throws Exception + { + ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A"); + try + { + IType classA = getType(cu, "A"); + RenameMethodProcessor processor = + createProcessor(classA.getMethod(methodName, signatures)); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setNewElementName(newMethodName); + assertEquals("was supposed to pass", null, + performRefactoring(refactoring)); + assertEqualLines("invalid renaming", + getFileContents(getOutputTestFileName("A")), cu.getSource()); + + assertTrue("anythingToUndo", RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performUndo(null, + new NullProgressMonitor()); + assertEqualLines("invalid undo", + getFileContents(getInputTestFileName("A")), cu.getSource()); + + assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager() + .anythingToUndo()); + assertTrue("anythingToRedo", RefactoringCore.getUndoManager() + .anythingToRedo()); + + RefactoringCore.getUndoManager().performRedo(null, + new NullProgressMonitor()); + assertEqualLines("invalid redo", + getFileContents(getOutputTestFileName("A")), cu.getSource()); + } + finally + { + performDummySearch(); + cu.delete(true, null); + } + } + + /********** tests **********/ +// test method template +// public void test0() throws Exception +// { +// helper0_passing(); +// } + + public void testFail0() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail1() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail2() throws Exception{ + performRenamingMtoK_failing(); + } + + //testFail3 deleted + + public void testFail4() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail5() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail6() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail7() throws Exception{ + performRenamingMtoK_failing(); + } + + public void testFail8() throws Exception{ + performRenamingMtoK_failing(); + } + + public void test0() throws Exception{ + performRenaming_passing(); + } + + public void test1() throws Exception{ + performRenaming_passing(); + } + + public void test2() throws Exception{ + performRenaming_passing(); + } + + public void test3() throws Exception{ + performRenaming_passing(); + } + + public void test4() throws Exception{ + performRenaming_passing(); + } + + public void test5() throws Exception{ + performRenaming_passing(); + } + + public void test6() throws Exception{ + performRenaming_passing(); + } + + public void test7() throws Exception{ + performRenameRefactoring_passing2("m", "k", new String[]{Signature.SIG_INT}); + } + + public void test8() throws Exception{ + performRenameRefactoring_passing2("m", "k", new String[]{Signature.SIG_INT}); + } + + public void test9() throws Exception{ + performRenameRefactoring_passing1("m", "k", new String[]{Signature.SIG_INT}, false); + } + + public void test10() throws Exception + { + ICompilationUnit cuA = createCUfromTestFile(getPackageP(), "A"); + ICompilationUnit cuB = createCUfromTestFile(getPackageP(), "B"); + + IType classB = getType(cuB, "B"); + RenameMethodProcessor processor = + createProcessor(classB.getMethod("method", new String[0])); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setUpdateReferences(true); + processor.setNewElementName("newmethod"); + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + assertEqualLines("invalid renaming in A", getFileContents( + getOutputTestFileName("A")), cuA.getSource()); + assertEqualLines("invalid renaming in B", getFileContents( + getOutputTestFileName("B")), cuB.getSource()); + } + + public void test11() throws Exception + { + IPackageFragment packageA = + getRoot().createPackageFragment("a", false, new NullProgressMonitor()); + IPackageFragment packageB = + getRoot().createPackageFragment("b", false, new NullProgressMonitor()); + try + { + ICompilationUnit cuA = createCUfromTestFile(packageA, "A"); + ICompilationUnit cuB = createCUfromTestFile(packageB, "B"); + + IType classA = getType(cuA, "A"); + RenameMethodProcessor processor = + createProcessor(classA.getMethod("method2", new String[0])); + RenameRefactoring refactoring = createRefactoring(processor); + processor.setUpdateReferences(true); + processor.setNewElementName("fred"); + assertEquals("was supposed to pass", null, performRefactoring(refactoring)); + assertEqualLines("invalid renaming in A", getFileContents( + getOutputTestFileName("A")), cuA.getSource()); + assertEqualLines("invalid renaming in B", getFileContents( + getOutputTestFileName("B")), cuB.getSource()); + } + finally + { + packageA.delete(true, new NullProgressMonitor()); + packageB.delete(true, new NullProgressMonitor()); + } + } +}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameTypeTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameTypeTests.java new file mode 100644 index 000000000..a1958828d --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameTypeTests.java @@ -0,0 +1,463 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * FIXME(SH): + * Once this test class is reactivated, also check the following conditions which are + * known not to work currently (e.g., OTDT 1.1.6): + * + Rename role type: + * - inline (not dialog-based) refactoring links all references of a role type but not: + * - its declaration + * - class literals + * (linked-mode in the Editor). + * - class literals in a predicate are not renamed + * + * @author brcan + * + */ +@SuppressWarnings({"restriction", "nls"}) +public class RenameTypeTests extends RefactoringTest +{ + private static final String REFACTORING_PATH = "RenameType/"; + + private static IPackageFragment _teamPkg; + + private RenameProcessor _processor = null; + + + public RenameTypeTests(String name) + { + super(name); + } + + public static Test suite() + { + return new MySetup(new TestSuite(RenameTypeTests.class)); + } + + public static Test setUpTest(Test someTest) + { + return new MySetup(someTest); + } + + protected String getRefactoringPath() + { + return REFACTORING_PATH; + } + +// MIGRATE + private RenameRefactoring createRefactoring(IType type, String newName) + throws CoreException + { + _processor = new RenameTypeProcessor(type); + RenameTypeProcessor renameTypeProcessor = (RenameTypeProcessor)_processor; + renameTypeProcessor.setNewElementName(newName); + RenameRefactoring ref = new RenameRefactoring(renameTypeProcessor); + return ref; + } + + private void createTeamPackageFragment() throws Exception + { + _teamPkg = getRoot().createPackageFragment("p.T1", true, null); + } + + private IPackageFragment getUpdatedTeamPackageFragment() throws Exception + { + return getRoot().getPackageFragment("p.T2"); + } + + private IPackageFragment getTeamPackage() + { + return _teamPkg; + } + + private void performRenameRefactoring_failing( + String[] cuNames, + String targetTypeName, + String newName, + boolean roleFilesExist) throws Exception + { + if (roleFilesExist) { + createTeamPackageFragment(); + } + ICompilationUnit[] cus = createCUs(cuNames); + IType targetType = getType(cus[0], targetTypeName); + Refactoring ref = createRefactoring(targetType, newName); + RefactoringStatus result = performRefactoring(ref); + assertNotNull("precondition was supposed to fail", result); + } + +// MIGRATE +// private String[] performRenameRefactoringOneCU_passing( +// String oldCuName, +// String oldName, +// String newName, +// String newCUName, +// boolean updateReferences, +// boolean updateTextualMatches) throws Exception +// { +// ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName); +// IType classA = getType(cu, oldName); +// +// IPackageFragment pack = (IPackageFragment) cu.getParent(); +// String[] renameHandles = null; +// if (classA.getDeclaringType() == null && +// cu.getElementName().startsWith(classA.getElementName())) +// { +// renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource()); +// } +// else +// { +// renameHandles = ParticipantTesting.createHandles(classA); +// } +// RenameRefactoring ref = createRefactoring(classA, newName); +// RenameTypeProcessor processor = (RenameTypeProcessor) ref.getProcessor(); +// processor.setUpdateReferences(updateReferences); +// processor.setUpdateTextualMatches(updateTextualMatches); +// assertEquals("was supposed to pass", null, performRefactoring(ref)); +// ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java"); +// assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists()); +// assertEqualLines( +// "invalid renaming!", +// getFileContents(getOutputTestFileName(newCUName)), +// newcu.getSource()); +// return renameHandles; +// } + + private void performRenameRefactoring_passing( + String[] cuNames, + String targetTypeName, + String newName, + boolean roleFilesExist, + boolean updateReferences, + boolean updateTextualMatches) throws Exception + { +// MIGRATE + if (roleFilesExist) + { + createTeamPackageFragment(); + } + ICompilationUnit[] cus = createCUs(cuNames); + IType targetType = getType(cus[0], targetTypeName); + IPackageFragment pack = (IPackageFragment) cus[0].getParent(); + RenameRefactoring refactoring = createRefactoring(targetType, newName); + RenameTypeProcessor renameTypeProcessor = (RenameTypeProcessor)_processor; + renameTypeProcessor.setUpdateReferences(updateReferences); + renameTypeProcessor.setUpdateTextualMatches(updateTextualMatches); + RefactoringStatus result = performRefactoring(refactoring); + assertEquals("was supposed to pass", null, result); + //if a top-level type is renamed, its compilation unit is also renamed + if (targetType.getDeclaringType() == null && + cus[0].getElementName().startsWith(targetType.getElementName())) + { + ICompilationUnit newCu = pack.getCompilationUnit(newName + ".java"); + assertTrue("cu " + newCu.getElementName() + " does not exist", newCu.exists()); + assertEqualLines("invalid renaming!", + getFileContents(getOutputTestFileName(newName)), newCu.getSource()); + if (roleFilesExist) + { + IPackageFragment updatedTeamPackage = getUpdatedTeamPackageFragment(); + for (int idx = 0; idx < cus.length; idx++) + { + if (cus[idx].getElementName().startsWith("R") || + cus[idx].getElementName().startsWith("TR")) + + { + cus[idx] = updatedTeamPackage.getCompilationUnit(cus[idx].getElementName()); + assertEqualLines("invalid renaming!", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + } + } + } + else + { + for (int idx = 0; idx < cus.length; idx++) + { + assertEqualLines("invalid renaming!", + getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + + } + } + + private String getSimpleNameOfCu(String compUnit) + { + int dot = compUnit.lastIndexOf('.'); + return compUnit.substring(0, dot); + } + + private String createOutputTestFileName(ICompilationUnit[] cus, int idx) + { + return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception + { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) + { + Assert.isNotNull(cuNames[idx]); + if (cuNames[idx].startsWith("R") || cuNames[idx].startsWith("TR")) + { + cus[idx] = createCUfromTestFile(getTeamPackage(), cuNames[idx]); + } + else + { + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + } + return cus; + } + + /*********** tests ***********/ + //passing + public void testRenameTeamclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T1" }, "T1", "T2", false, true, false); + } + + public void testRenameNestedTeamclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "TR1", "TR2", false, true, false); + } + + public void testUpdateReferencesToTeamclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T1" }, "T1", "T2", false, true, false); + } + + public void testUpdateReferencesToNestedTeamclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "TR1", "TR2", false, true, false); + } + + public void testRenameRoleclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "R1", "R2", false, true, false); + } + + public void testRenameRoleclassPrecedence() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "R2", "ROut", false, true, false); + } + + public void testRenameRoleclassLiteralInPredicate() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "R1", "ROut", false, true, false); + } + + public void testRenameInnermostRole() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "IR1", "IR2", false, true, false); + } + + public void testUpdateReferencesToRoleclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "R1", "R2", false, true, false); + } + + public void testUpdateReferencesToInnermostRole() throws Exception { + performRenameRefactoring_passing(new String[] { "T" }, "IR1", "IR2", false, true, false); + } + + // see https://svn.objectteams.org/trac/ot/ticket/80 + public void testUpdateImplicitSuperRoles() throws Exception { + performRenameRefactoring_passing(new String[] { "T2", "T1" }, "R1", "R3", false, true, false); + } + + public void testUpdateImplicitSubRoles() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testRenameImplicitSuperRoles1() throws Exception { + performRenameRefactoring_passing(new String[] { "T8", "T2", "T3", "T4", "T5", "T6", "T7", "T1" }, "R2", "R_New", false, true, false); + } + + public void testRenameImplicitSuperRoles2() throws Exception { + performRenameRefactoring_passing(new String[] { "T2", "T1" }, "R1", "R4", false, true, false); + } + + public void testRenameImplicitSubRoles1() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8" }, "R2", "R_New", false, true, false); + } + + public void testRenameImplicitSubRoles2() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R4", false, true, false); + } + + // see https://svn.objectteams.org/trac/ot/ticket/79 + public void testUpdateReferenceInTeamPackage1() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "R1" }, "T1", "T2", true, true, false); + + } + + public void testUpdateReferenceInTeamPackage2() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "R1", "R2" }, "T1", "T2", true, true, false); + + } + + public void testUpdateReferenceUsingTypeAnchor1() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testUpdateReferenceUsingTypeAnchor2() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testUpdateReferenceUsingTypeAnchor3() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testUpdateReferenceUsingTypeAnchor4() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testUpdateReferenceUsingTypeAnchor5() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2" }, "R1", "R3", false, true, false); + } + + public void testEnclosedNestedTeamHasNewName() throws Exception { + performRenameRefactoring_failing(new String[] { "B" }, "B", "A", false); + } + + public void testEnclosedRoleHasNewName() throws Exception { + performRenameRefactoring_failing(new String[] { "B" }, "B", "A", false); + } + + public void testEnclosedRoleInNestedTeamHasNewName() throws Exception { + performRenameRefactoring_failing(new String[] { "B" }, "B", "A", false); + } + + public void testEnclosingNestedTeamHasNewName() throws Exception { + performRenameRefactoring_failing(new String[] { "B" }, "A", "C", false); + } + + public void testEnclosingTeamHasNewName() throws Exception { + performRenameRefactoring_failing(new String[] { "B" }, "A", "B", false); + } + + public void testUpdatePhantomTypeReference() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2", "T3" }, "R1", "R3", false, true, false); + } + + public void testNameConflictInSubclass() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void testNameConflictInSuperclass() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void testNameConflictWithRegularClass1() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2", "A" }, "R1", "A", false); + } + + public void testNameConflictWithRegularClass2() throws Exception { + performRenameRefactoring_failing(new String[] { "A", "T1" }, "A", "R1", false); + } + + public void testImplicitOverridingInSuperTeam() throws Exception { + performRenameRefactoring_failing(new String[] { "T", "TSuper" }, "R", "R1", false); + } + + public void testImplicitOverridingInSubTeam() throws Exception { + performRenameRefactoring_failing(new String[] { "T", "TSub" }, "R", "R1", false); + } + + public void testNameClashInSameTeam() throws Exception { + performRenameRefactoring_failing(new String[] { "T" }, "R1", "R2", false); + } + + public void testShadowedName1() throws Exception { + performRenameRefactoring_failing(new String[] { "T" }, "R1", "R2", false); + } + + public void testShadowedName2() throws Exception { + performRenameRefactoring_failing(new String[] { "T" }, "R1", "R2", false); + } + + public void testShadowedNameOfSuperType1() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void testShadowedNameOfSuperType2() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void testShadowedNameOfSubType1() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void testNameClashWithRoleFile() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "R2" }, "R1", "R2", true); + } + + public void testShadowedNameRoleFile1() throws Exception { + performRenameRefactoring_failing(new String[] { "R1", "T1" }, "R1", "R2", true); + } + + public void testShadowedNameRoleFile2() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "R2" }, "R1", "R2", true); + } + + public void testShadowedNameRoleFile3() throws Exception { + performRenameRefactoring_failing(new String[] { "R1", "T1", "T2" }, "R1", "R2", true); + } + + public void testShadowedNameRoleFile5() throws Exception { + performRenameRefactoring_failing(new String[] { "T2", "T1", "RT" }, "R1", "R2", true); + } + + public void testShadowedNameRoleFile6() throws Exception { + performRenameRefactoring_failing(new String[] { "T2", "T1", "R2" }, "R1", "R2", true); + } + + public void testImplicitOverridingWithRoleFile1() throws Exception { + performRenameRefactoring_failing(new String[] { "T2", "T1", "R1" }, "R", "R1", true); + } + + public void testImplicitOverridingWithRoleFile2() throws Exception { + performRenameRefactoring_failing(new String[] { "T", "R1", "T1" }, "R", "R1", true); + } + + // failing + + // FIXME(jogeb): phantom roles within phantom roles wont be found by the + // OTTypeHierarchy or change strategy in RenameTypeAdapter + public void _testShadowedNameOfSubType2() throws Exception { + performRenameRefactoring_failing(new String[] { "T1", "T2" }, "R1", "R2", false); + } + + public void _testShadowedNameRoleFile4() throws Exception { + performRenameRefactoring_failing(new String[] { "RT", "T1", "T2" }, "R1", "R2", true); + } + +} diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameVirtualMethodInClassTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameVirtualMethodInClassTests.java new file mode 100644 index 000000000..1fb7482ea --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/rename/RenameVirtualMethodInClassTests.java @@ -0,0 +1,283 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.rename; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor; +import org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest; + +/** + * @author brcan + * + */ +public class RenameVirtualMethodInClassTests extends RefactoringTest { + private static final String REFACTORING_PATH = "RenameVirtualMethodInClass/"; + + public RenameVirtualMethodInClassTests(String name) { + super(name); + } + + public static Test suite() { + return new MySetup(new TestSuite(RenameVirtualMethodInClassTests.class)); + } + + public static Test setUpTest(Test test) { + return new MySetup(test); + } + + protected String getRefactoringPath() { + return REFACTORING_PATH; + } + + private RenameRefactoring createRefactoring(RenameMethodProcessor processor) { + return new RenameRefactoring(processor); + } + + private RenameMethodProcessor createProcessor(IMethod method) { + return new RenameVirtualMethodProcessor(method); + } + + private void performRenaming_failing(String[] cuNames, String declaringTypeName, String[] signature, boolean updateReferences) throws Exception { + performRenameRefactoring_failing(cuNames, declaringTypeName, "m", "k", signature, updateReferences); + } + + private void performRenameRefactoring_failing(String[] cuNames, String declaringTypeName, String methodName, String newMethodName, String[] signatures, + boolean updateReferences) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + IType declaringType = getType(cus[0], declaringTypeName); + IMethod method = declaringType.getMethod(methodName, signatures); + RenameMethodProcessor processor = createProcessor(method); + RenameRefactoring ref = createRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setNewElementName(newMethodName); + RefactoringStatus result = performRefactoring(ref); + + assertNotNull("precondition was supposed to fail!", result); + } + + private void performRenaming_passing(String[] cuNames, String declaringTypeName) throws Exception { + performRenamingMtoK_passing(cuNames, declaringTypeName, true); + } + + private void performRenamingMtoK_passing(String[] cuNames, String declaringTypeName, boolean updateReferences) throws Exception { + performRenameRefactoring_passing(cuNames, declaringTypeName, "m", "k", new String[0], true, updateReferences); + } + + private void performRenameRefactoring_passing(String[] cuNames, String declaringTypeName, String methodName, String newMethodName, String[] signatures, + boolean shouldPass, boolean updateReferences) throws Exception { + ICompilationUnit[] cus = createCUs(cuNames); + IType declaringType = getType(cus[0], declaringTypeName); + IMethod method = declaringType.getMethod(methodName, signatures); + RenameMethodProcessor processor = createProcessor(method); + RenameRefactoring ref = createRefactoring(processor); + processor.setUpdateReferences(updateReferences); + processor.setNewElementName(newMethodName); + RefactoringStatus status = performRefactoring(ref); + + assertEquals("was supposed to pass!", null, status); + if (!shouldPass) { + for (int idx = 0; idx < cus.length; idx++) { + assertTrue("incorrect renaming because of java model!", !getFileContents(createOutputTestFileName(cus, idx)).equals(cus[idx].getSource())); + } + return; + } + + for (int idx = 0; idx < cus.length; idx++) { + String expectedRenaming = getFileContents(createOutputTestFileName(cus, idx)); + String actualRenaming = cus[idx].getSource(); + assertEqualLines("incorrect renaming!", expectedRenaming, actualRenaming); + } + assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo()); + assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo()); + + RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor()); + + for (int idx = 0; idx < cus.length; idx++) { + assertEqualLines("invalid undo!", getFileContents(createInputTestFileName(cus, idx)), cus[idx].getSource()); + } + assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo()); + assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo()); + + RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor()); + for (int idx = 0; idx < cus.length; idx++) { + assertEqualLines("invalid redo", getFileContents(createOutputTestFileName(cus, idx)), cus[idx].getSource()); + } + } + + private String createInputTestFileName(ICompilationUnit[] cus, int idx) { + return getInputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String createOutputTestFileName(ICompilationUnit[] cus, int idx) { + return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName())); + } + + private String getSimpleNameOfCu(String compUnit) { + int dot = compUnit.lastIndexOf('.'); + return compUnit.substring(0, dot); + } + + private ICompilationUnit[] createCUs(String[] cuNames) throws Exception { + ICompilationUnit[] cus = new ICompilationUnit[cuNames.length]; + + for (int idx = 0; idx < cuNames.length; idx++) { + Assert.isNotNull(cuNames[idx]); + cus[idx] = createCUfromTestFile(getPackageP(), cuNames[idx]); + } + return cus; + } + + /********** tests **********/ + + public void testUpdateDeclarationOfOverridingRoleMethod() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInCallinBinding() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInCallinBindings1() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInCallinBindings2() throws Exception { + performRenaming_passing(new String[] { "B", "T1", "T2" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInCalloutBinding1() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInCalloutBinding2() throws Exception { + performRenameRefactoring_passing(new String[] { "B", "T" }, "B", "getAmount", "getQuantity", new String[0], true, true); + } + + public void testUpdateReferenceToBaseMethodInExplicitlyOverriddenCalloutBinding() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceInFieldInitializationInRole() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceInFieldInitializationInTeam() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToBaseMethodInImplicitlyOverriddenCalloutBinding() throws Exception { + performRenaming_passing(new String[] { "B", "T1", "T2" }, "B"); + } + + public void testUpdateReferenceInRoleMethod() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceInTeamMethod() throws Exception { + performRenaming_passing(new String[] { "B", "T" }, "B"); + } + + public void testUpdateReferenceToOverridingRoleMethod() throws Exception { + performRenaming_passing(new String[] { "S", "T" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInCallinBinding() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInCallinBindings1() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInCallinBindings2() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T1", "T2" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInExplicitlyOverriddenCalloutBinding() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInImplicitlyOverriddenCalloutBinding() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T1", "T2" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInCallinBindingOfImplicitSubrole() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T1", "T2" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInCalloutBindingOfImplicitSubrole() throws Exception { + performRenaming_passing(new String[] { "S", "B", "T1", "T2" }, "S"); + } + + public void testUpdateReferenceToOverridingRoleMethodInTsuperCall() throws Exception { + performRenaming_passing(new String[] { "S", "T1", "T2" }, "S"); + } + + public void testRenamePrivateMethodInRoleclass() throws Exception { + performRenaming_passing(new String[] { "T" }, "R"); + } + + public void testRenamePrivateAbstractMethodInRoleclass() throws Exception { + performRenameRefactoring_passing(new String[] { "T", "B" }, "R", "m1", "m3", new String[0], true, true); + } + + public void testRenamePrivateMethodInNestedTeam() throws Exception { + performRenaming_passing(new String[] { "T" }, "TR"); + } + + public void testUpdateImplicitlyInheritedAndOverridingPrivateMethod1() throws Exception { + performRenaming_passing(new String[] { "T1", "T2" }, "R1"); + } + + public void testUpdateImplicitlyInheritedAndOverridingPrivateMethod2() throws Exception { + performRenaming_passing(new String[] { "T1", "T2" }, "TR1"); + } + + public void testUpdateReferenceToPrivateRoleMethodInCalloutBinding() throws Exception { + performRenameRefactoring_passing(new String[] { "T1", "T2", "B" }, "R", "m1", "m3", new String[0], true, true); + } + + public void testUpdateReferenceToPrivateRoleMethodInCallinBinding() throws Exception { + performRenameRefactoring_passing(new String[] { "T", "B" }, "R", "m1", "m3", new String[0], true, true); + } + + public void testUpdateMethodToCauseAmbiguousCallinBinding1() throws Exception { + // performRenaming_passing(new String[] { "B", "T" }, "B"); + performRenaming_failing(new String[] { "B", "T" }, "B", new String[0], true); + } + + public void testUpdateMethodToCauseAmbiguousCallinBinding2() throws Exception { + performRenaming_failing(new String[] { "B", "T" }, "B", new String[0], true); + } + +}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/AllTests.java new file mode 100644 index 000000000..e49650a82 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/AllTests.java @@ -0,0 +1,53 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-Reorg Refactoring Tests");
+
+ //copy & paste, delete (cut)
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTCopyToClipboardTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTDeleteTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.PasteActionTest.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTPasteActionTest.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/MockReorgQueries.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/MockReorgQueries.java new file mode 100644 index 000000000..135ba8a84 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/MockReorgQueries.java @@ -0,0 +1,70 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IConfirmQuery;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgQueries;
+
+/**
+ * @author brcan
+ */
+public class MockReorgQueries implements IReorgQueries
+{
+ private final List fQueriesRun= new ArrayList();
+
+ public IConfirmQuery createYesNoQuery(String queryTitle, boolean allowCancel, int queryID) {
+ run(queryID);
+ return yesQuery;
+ }
+
+ public IConfirmQuery createYesYesToAllNoNoToAllQuery(String queryTitle, boolean allowCancel, int queryID) {
+ run(queryID);
+ return yesQuery;
+ }
+
+ private void run(int queryID) {
+ fQueriesRun.add(new Integer(queryID));
+ }
+
+ //List<Integer>
+ public List getRunQueryIDs() {
+ return fQueriesRun;
+ }
+
+ private final IConfirmQuery yesQuery= new IConfirmQuery() {
+ public boolean confirm(String question) throws OperationCanceledException {
+ return true;
+ }
+
+ public boolean confirm(String question, Object[] elements) throws OperationCanceledException {
+ return true;
+ }
+ };
+
+ public IConfirmQuery createSkipQuery(String queryTitle, int queryID) {
+ run(queryID);
+ return yesQuery;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTCopyToClipboardTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTCopyToClipboardTests.java new file mode 100644 index 000000000..2aa845f66 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTCopyToClipboardTests.java @@ -0,0 +1,573 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceManipulation;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.refactoring.TypedSource;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaElementTransfer;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils;
+import org.eclipse.jdt.internal.corext.util.Strings;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.CopyToClipboardAction;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.TypedSourceTransfer;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTestSetup;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockClipboard;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockWorkbenchSite;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.part.ResourceTransfer;
+import org.eclipse.objectteams.otdt.core.ICallinMapping;
+import org.eclipse.objectteams.otdt.core.ICalloutMapping;
+import org.eclipse.objectteams.otdt.core.ICalloutToFieldMapping;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IOTJavaElement;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.OTRefactoringTestSetup;
+
+//{OT_COPY_PASTE: Copy of class org.eclipse.jdt.ui.tests.reorg.CopyToClipboardActionTest
+//Reason: adapt tests for the OTCopyToClipboardAction, add additional tests for OT elements
+// remove tests which won't work with the given OT type declarations
+// test enumeration is kept, new OT tests are testEnabledOT0 - testEnabledOT6
+@SuppressWarnings("restriction")
+public class OTCopyToClipboardTests extends RefactoringTest
+{
+ private static final String CU_T1_NAME = "T1";
+ private static final String CU_B1_NAME = "B1";
+
+ private ILabelProvider _labelProvider;
+ private Clipboard _clipboard;
+ private ICompilationUnit _cuT1;
+ private ICompilationUnit _cuB1;
+
+ public OTCopyToClipboardTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new OTRefactoringTestSetup(new TestSuite(OTCopyToClipboardTests.class));
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _clipboard = new MockClipboard(Display.getDefault());
+
+ _cuT1 = createCU(getPackageP(), CU_T1_NAME + ".java",
+ "package p;" + "\n" +
+ "import java.util.List;" + "\n" +
+ "public team class T1" + "\n" +
+ "{" + "\n" +
+ "int x;" + "\n" +
+ "public void t1m(){}" + "\n" +
+ "public team class TR1" + "\n" +
+ "{" + "\n" +
+ "public void tr1m(){}" + "\n" +
+ "public class R1 extends S1 playedBy B1" + "\n" +
+ "{" + "\n" +
+ "public abstract int rm();" + "\n" +
+ "rm -> bm;" + "\n" +
+ "sm <- after bm;" + "\n" +
+ "rm => get x;" + "\n" +
+ "}" + "\n" +
+ "}" + "\n" +
+ "}");
+
+ _cuB1 = createCU(getPackageP(), CU_B1_NAME + ".java",
+ "package p;" + "\n" +
+ "public class B1" + "\n" +
+ "{" + "\n" +
+ "private int x;" + "\n" +
+ "public int bm(){}" + "\n" +
+ "}");
+
+ _labelProvider = new JavaElementLabelProvider(
+ JavaElementLabelProvider.SHOW_VARIABLE +
+ JavaElementLabelProvider.SHOW_PARAMETERS +
+ JavaElementLabelProvider.SHOW_TYPE);
+
+ assertTrue("T1.java does not exist", _cuT1.exists());
+ assertTrue("B1.java does not exist", _cuB1.exists());
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ performDummySearch();
+ _clipboard.dispose();
+ _labelProvider.dispose();
+ delete(_cuT1);
+ delete(_cuB1);
+ }
+
+ private static void delete(ISourceManipulation element) {
+ try {
+ if (element != null && ((IJavaElement)element).exists())
+ element.delete(true, null);
+ } catch(JavaModelException e) {
+ //ignore, we must keep going
+ }
+ }
+
+ private void checkDisabled(Object[] elements){
+ CopyToClipboardAction copyAction= new CopyToClipboardAction(new MockWorkbenchSite(elements), _clipboard);
+ copyAction.setAutoRepeatOnFailure(true);
+ copyAction.update(copyAction.getSelection());
+ assertTrue("action should be disabled", ! copyAction.isEnabled());
+ }
+
+ private void checkEnabled(Object[] elements) throws Exception{
+ CopyToClipboardAction copyAction= new CopyToClipboardAction(new MockWorkbenchSite(elements), _clipboard);
+ copyAction.setAutoRepeatOnFailure(true);
+ copyAction.update(copyAction.getSelection());
+ assertTrue("action should be enabled", copyAction.isEnabled());
+ copyAction.run();
+ checkClipboard(elements);
+ }
+
+ private void checkClipboard(Object[] elementsCopied) throws Exception {
+ IResource[] resourcesCopied= getResources(elementsCopied);
+ IJavaElement[] javaElementsCopied= getJavaElements(elementsCopied);
+ IType[] mainTypesCopied= ReorgUtils.getMainTypes(javaElementsCopied);
+
+ IResource[] resourcesExpected= computeResourcesExpectedInClipboard(resourcesCopied, mainTypesCopied, javaElementsCopied);
+ IJavaElement[] javaElementsExpected= computeJavaElementsExpectedInClipboard(javaElementsCopied, mainTypesCopied);
+
+ String[] clipboardFiles= getClipboardFiles();
+ IResource[] clipboardResources= getClipboardResources();
+ String clipboardText= getClipboardText();
+ IJavaElement[] clipboardJavaElements= getClipboardJavaElements();
+ TypedSource[] clipboardTypedSources= getClipboardTypedSources();
+
+ checkNames(resourcesCopied, javaElementsCopied, clipboardText);
+ checkFiles(resourcesCopied, javaElementsCopied, mainTypesCopied, clipboardFiles);
+ checkTypedSources(javaElementsCopied, clipboardTypedSources);
+ checkElements(resourcesExpected, clipboardResources);
+ checkElements(javaElementsExpected, clipboardJavaElements);
+ }
+
+ private void checkTypedSources(IJavaElement[] javaElementsCopied, TypedSource[] clipboardTypedSources) throws Exception {
+ TypedSource[] typedSources= TypedSource.createTypedSources(javaElementsCopied);
+ assertEquals("different number", typedSources.length, clipboardTypedSources.length);
+ TypedSource.sortByType(typedSources);
+ TypedSource.sortByType(clipboardTypedSources);
+ for (int i= 0; i < typedSources.length; i++) {
+ assertEquals("different typed sources", typedSources[i], clipboardTypedSources[i]);
+ }
+ }
+
+ private IResource[] computeResourcesExpectedInClipboard(IResource[] resourcesCopied, IType[] mainTypesCopied, IJavaElement[] javaElementsCopied) throws JavaModelException {
+ IResource[] cuResources= ReorgUtils.getResources(getCompilationUnits(javaElementsCopied));
+ return ReorgUtils.union(cuResources, ReorgUtils.union(resourcesCopied, ReorgUtils.getResources(ReorgUtils.getCompilationUnits(mainTypesCopied))));
+ }
+
+ private static IJavaElement[] computeJavaElementsExpectedInClipboard(IJavaElement[] javaElementsExpected, IType[] mainTypesCopied) throws JavaModelException {
+ return ReorgUtils.union(javaElementsExpected, ReorgUtils.getCompilationUnits(mainTypesCopied));
+ }
+
+ private String getName(IResource resource){
+ return _labelProvider.getText(resource);
+ }
+ private String getName(IJavaElement javaElement){
+ return _labelProvider.getText(javaElement);
+ }
+
+ private static void checkElements(Object[] copied, Object[] retreivedFromClipboard) {
+ assertEquals("different number of elements", copied.length, retreivedFromClipboard.length);
+ sortByName(copied);
+ sortByName(retreivedFromClipboard);
+ for (int i= 0; i < retreivedFromClipboard.length; i++) {
+ Object retreived= retreivedFromClipboard[i];
+ assertTrue("element does not exist", exists(retreived));
+ assertTrue("different copied " + getName(copied[i]) + " retreived: " + getName(retreived) , copied[i].equals(retreivedFromClipboard[i]));
+ }
+ }
+
+ private static boolean exists(Object element) {
+ if (element instanceof IJavaElement)
+ return ((IJavaElement)element).exists();
+ if (element instanceof IResource)
+ return ((IResource)element).exists();
+ assertTrue(false);
+ return false;
+ }
+
+ private static String getName(Object object) {
+ if (object instanceof IJavaElement)
+ return ((IJavaElement)object).getElementName();
+ if (object instanceof IResource)
+ return ((IResource)object).getName();
+ return object == null ? null : object.toString();
+ }
+
+ private static void sortByName(Object[] copied) {
+ Arrays.sort(copied, new Comparator(){
+ public int compare(Object arg0, Object arg1) {
+ return getName(arg0).compareTo(getName(arg1));
+ }
+ });
+ }
+
+ private void checkNames(IResource[] resourcesCopied, IJavaElement[] javaElementsCopied, String clipboardText){
+ List stringLines= Arrays.asList(Strings.convertIntoLines(clipboardText));
+ assertEquals("different number of names", resourcesCopied.length + javaElementsCopied.length, stringLines.size());
+ for (int i= 0; i < resourcesCopied.length; i++) {
+ String name= getName(resourcesCopied[i]);
+ assertTrue("name not in set:" + name, stringLines.contains(name));
+ }
+ for (int i= 0; i < javaElementsCopied.length; i++) {
+ IJavaElement element= javaElementsCopied[i];
+ if (! ReorgUtils.isInsideCompilationUnit(element)){
+ String name= getName(element);
+ assertTrue("name not in set:" + name, stringLines.contains(name));
+ }
+ }
+ }
+
+ private static void checkFiles(IResource[] resourcesCopied, IJavaElement[] javaElementsCopied, IType[] mainTypes, String[] clipboardFiles) {
+ int expected= 0;
+ expected += resourcesCopied.length;
+ expected += countResources(javaElementsCopied);
+ expected += mainTypes.length;
+
+ //we cannot compare file names here because they're absolute and depend on the worspace location
+ assertEquals("different number of files in clipboard", expected, clipboardFiles.length);
+ }
+
+ private static int countResources(IJavaElement[] javaElementsCopied) {
+ int count= 0;
+ for (int i= 0; i < javaElementsCopied.length; i++) {
+ IJavaElement element= javaElementsCopied[i];
+ switch (element.getElementType()) {
+ case IJavaElement.JAVA_PROJECT :
+ case IJavaElement.PACKAGE_FRAGMENT_ROOT :
+ case IJavaElement.PACKAGE_FRAGMENT :
+ case IJavaElement.COMPILATION_UNIT :
+ case IJavaElement.CLASS_FILE :
+ count++;
+ }
+ }
+ return count;
+ }
+
+ private static IJavaElement[] getCompilationUnits(IJavaElement[] javaElements) {
+ List cus= ReorgUtils.getElementsOfType(javaElements, IJavaElement.COMPILATION_UNIT);
+ return (ICompilationUnit[]) cus.toArray(new ICompilationUnit[cus.size()]);
+ }
+
+ private static IResource[] getResources(Object[] elements) {
+ return ReorgUtils.getResources(Arrays.asList(elements));
+ }
+
+ private static IJavaElement[] getJavaElements(Object[] elements) {
+ return ReorgUtils.getJavaElements(Arrays.asList(elements));
+ }
+
+ private IJavaElement[] getClipboardJavaElements() {
+ IJavaElement[] elements= (IJavaElement[])_clipboard.getContents(JavaElementTransfer.getInstance());
+ return elements == null ? new IJavaElement[0]: elements;
+ }
+
+ private String[] getClipboardFiles() {
+ String[] files= (String[])_clipboard.getContents(FileTransfer.getInstance());
+ return files == null ? new String[0]: files;
+ }
+
+ private IResource[] getClipboardResources() {
+ IResource[] resources= (IResource[])_clipboard.getContents(ResourceTransfer.getInstance());
+ return resources == null ? new IResource[0]: resources;
+ }
+
+ private TypedSource[] getClipboardTypedSources() {
+ TypedSource[] typedSources= (TypedSource[])_clipboard.getContents(TypedSourceTransfer.getInstance());
+ return typedSources == null ? new TypedSource[0]: typedSources;
+ }
+
+ private String getClipboardText() {
+ return (String)_clipboard.getContents(TextTransfer.getInstance());
+ }
+
+ ///---------tests
+
+ public void testDisabled0() {
+ Object[] elements= {};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled1() throws Exception {
+ Object[] elements= {null};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled2() throws Exception {
+ Object[] elements= {this};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled3() throws Exception {
+ Object[] elements= {RefactoringTestSetup.getProject(), getPackageP()};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled4() throws Exception{
+ checkDisabled(new Object[]{getPackageP(), _cuT1});
+ }
+
+ public void testDisabled5() throws Exception{
+ checkDisabled(new Object[]{getRoot(), _cuT1});
+ }
+
+ public void testDisabled12() throws Exception{
+ checkDisabled(new Object[]{getRoot().getJavaProject(), _cuT1});
+ }
+
+ public void testDisabled15() throws Exception {
+ Object fieldF= _cuT1.getType("T1").getField("x");
+ Object classA= _cuT1.getType("T1");
+ Object[] elements= {fieldF, classA};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled16() throws Exception {
+ Object fieldF= _cuT1.getType("T1").getField("x");
+ Object[] elements= {fieldF, _cuT1};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled20() throws Exception {
+ Object fieldF= _cuT1.getType("T1").getField("x");
+ Object[] elements= {fieldF, getRoot()};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled21() throws Exception {
+ Object fieldF= _cuT1.getType("T1").getField("x");
+ Object[] elements= {fieldF, RefactoringTestSetup.getProject()};
+ checkDisabled(elements);
+ }
+
+ public void testDisabled22() throws Exception {
+ Object typeT1= _cuT1.getType("T1");
+ Object typeB1= _cuB1.getType("B1");
+ Object[] elements= {typeT1, typeB1};
+ checkDisabled(elements);
+ }
+
+ public void testEnabled0() throws Exception {
+ Object[] elements= {RefactoringTestSetup.getProject()};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled1() throws Exception {
+ Object[] elements= {getPackageP()};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled2() throws Exception {
+ Object[] elements= {getRoot()};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled3() throws Exception {
+ Object[] elements= {RefactoringTestSetup.getDefaultSourceFolder()};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled5() throws Exception{
+ checkEnabled(new Object[]{getRoot()});
+ }
+
+ public void testEnabled6() throws Exception{
+ checkEnabled(new Object[]{_cuT1});
+ }
+
+ public void testEnabled7() throws Exception{
+ checkEnabled(new Object[]{getRoot().getJavaProject()});
+ }
+
+ public void testEnabled8() throws Exception{
+ checkEnabled(new Object[]{getPackageP()});
+ }
+
+ public void testEnabled10() throws Exception{
+ Object packDecl= _cuT1.getPackageDeclarations()[0];
+ Object[] elements= {packDecl};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled11() throws Exception{
+ Object importD= _cuT1.getImports()[0];
+ Object[] elements= {importD};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled12() throws Exception{
+// printTestDisabledMessage("disabled due to bug 37750");
+// if (true)
+// return;
+ IJavaElement importContainer= _cuT1.getImportContainer();
+ Object[] elements= {importContainer};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled13() throws Exception{
+ Object classA= _cuT1.getType("T1");
+ Object[] elements= {classA};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled14() throws Exception{
+ Object methodT1m= _cuT1.getType("T1").getMethod("t1m", new String[0]);
+ Object[] elements= {methodT1m};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled15() throws Exception{
+ Object fieldX= _cuT1.getType("T1").getField("x");
+ Object[] elements= {fieldX};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled19() throws Exception{
+// printTestDisabledMessage("disabled due to bug 37750");
+// if (true)
+// return;
+
+ Object classA= _cuT1.getType("T1");
+ Object importContainer= _cuT1.getImportContainer();
+ Object packDecl= _cuT1.getPackageDeclarations()[0];
+ Object[] elements= {classA, importContainer, packDecl};
+ checkEnabled(elements);
+ }
+
+ public void testEnabled22() throws Exception{
+// printTestDisabledMessage("bug 39410");
+ Object classA= _cuT1.getType("T1");
+ Object packDecl= _cuT1.getPackageDeclarations()[0];
+ Object[] elements= {classA, packDecl};
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT0() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ IMethod methodTr1m = nestedTeamTR1.getMethod("tr1m", new String[0]);
+ Object[] elements = { methodTr1m };
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT1() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ Object elem = nestedTeamTR1.getType("R1");
+ if (elem instanceof IType)
+ {
+ IType type = (IType)elem;
+ IRoleType roleR1 = (IRoleType)OTModelManager.getOTElement(type);
+ Object[] elements = { roleR1 };
+ checkEnabled(elements);
+ }
+ }
+
+ public void testEnabledOT2() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ IType type = nestedTeamTR1.getType("R1");
+ IRoleType roleR1 = (IRoleType)OTModelManager.getOTElement(type);
+ IMethod methodRm = roleR1.getMethod("rm", new String[0]);
+ Object[] elements = { methodRm };
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT3() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ IType type = nestedTeamTR1.getType("R1");
+ IRoleType roleR1 = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mapping = roleR1.getMethodMappings(IRoleType.CALLOUTS);
+ ICalloutMapping callout = null;
+ for (int idx = 0; idx < mapping.length; idx++)
+ {
+ if (mapping[idx].getElementType() == IOTJavaElement.CALLOUT_MAPPING)
+ {
+ callout = (ICalloutMapping)mapping[idx];
+ }
+ }
+ Object[] elements = { callout };
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT4() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ IType type = nestedTeamTR1.getType("R1");
+ IRoleType roleR1 = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mapping = roleR1.getMethodMappings(IRoleType.CALLINS);
+ ICallinMapping callin = (ICallinMapping)mapping[0];
+ Object[] elements = { callin };
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT5() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ IType type = nestedTeamTR1.getType("R1");
+ IRoleType roleR1 = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mapping = roleR1.getMethodMappings(IRoleType.CALLOUTS);
+ ICalloutToFieldMapping calloutToField = null;
+ for (int idx = 0; idx < mapping.length; idx++)
+ {
+ if (mapping[idx].getElementType() == IOTJavaElement.CALLOUT_TO_FIELD_MAPPING)
+ {
+ calloutToField = (ICalloutToFieldMapping)mapping[idx];
+ }
+ }
+ Object[] elements = { calloutToField };
+ checkEnabled(elements);
+ }
+
+ public void testEnabledOT6() throws Exception
+ {
+ IType teamT1 = _cuT1.getType("T1");
+ IField fieldX = teamT1.getField("x");
+ IMethod methodT1m = teamT1.getMethod("t1m", new String[0]);
+ IType nestedTeamTR1 = teamT1.getType("TR1");
+ Object[] elements = { fieldX, methodT1m, nestedTeamTR1 };
+ checkEnabled(elements);
+ }
+
+
+}
+//sko}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTDeleteTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTDeleteTests.java new file mode 100644 index 000000000..8c0866ea7 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTDeleteTests.java @@ -0,0 +1,195 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgQueries;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaDeleteProcessor;
+import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.DeleteRefactoring;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest;
+
+/**
+ * @author brcan
+ */
+public class OTDeleteTests extends RefactoringTest
+{
+ private static final String REFACTORING_PATH = "Delete/";
+ private static final String CU_NAME = "T";
+ private ICompilationUnit _cuT;
+
+ public OTDeleteTests(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new MySetup(new TestSuite(OTDeleteTests.class));
+ }
+
+ public static Test setUpTest(Test someTest)
+ {
+ return new MySetup(someTest);
+ }
+
+ protected String getRefactoringPath()
+ {
+ return REFACTORING_PATH;
+ }
+
+ private void loadFileSetup() throws Exception
+ {
+ _cuT = createCUfromTestFile(getPackageP(), CU_NAME);
+ assertTrue("T.java does not exist", _cuT.exists());
+ }
+
+ private void checkDelete(IJavaElement[] elems, boolean deleteCu)
+ throws JavaModelException, Exception
+ {
+ ICompilationUnit newCuT = null;
+ try
+ {
+ DeleteRefactoring refactoring = createRefactoring(elems);
+ assertNotNull(refactoring);
+ RefactoringStatus status = performRefactoring(refactoring, true);
+ assertEquals("precondition was supposed to pass", null, status);
+
+ newCuT = getPackageP().getCompilationUnit(CU_NAME + ".java");
+ assertTrue("T.java does not exist", newCuT.exists() == !deleteCu);
+ if (!deleteCu)
+ {
+ assertEqualLines(
+ "incorrect content of T.java",
+ getFileContents(getOutputTestFileName(CU_NAME)),
+ newCuT.getSource());
+ }
+ }
+ finally
+ {
+ performDummySearch();
+ if (newCuT != null && newCuT.exists())
+ {
+ newCuT.delete(true, null);
+ }
+ if (_cuT != null && _cuT.exists())
+ {
+ _cuT.delete(true, null);
+ _cuT = null;
+ }
+ }
+ }
+
+ private DeleteRefactoring createRefactoring(Object[] elements)
+ throws CoreException
+ {
+ JavaDeleteProcessor processor = new JavaDeleteProcessor(elements);
+ DeleteRefactoring result = new DeleteRefactoring(processor);
+ processor.setQueries(createReorgQueries());
+ return result;
+ }
+
+ private IReorgQueries createReorgQueries()
+ {
+ return new MockReorgQueries();
+ }
+
+ //---- tests ----
+ public void testDeleteTeamclass() throws Exception
+ {
+// ParticipantTesting.reset();
+ loadFileSetup();
+ IJavaElement aTeam = _cuT.getType("T");
+ IJavaElement[] elems = new IJavaElement[] { aTeam };
+ checkDelete(elems, true);
+// String[] handles = ParticipantTesting.createHandles(elem0);
+// ParticipantTesting.testDelete(handles);
+ }
+
+ public void testDeleteNestedTeamclass() throws Exception
+ {
+ loadFileSetup();
+ IJavaElement nestedTeam = _cuT.getType("T").getType("TR");
+ IJavaElement[] elems = new IJavaElement[] { nestedTeam };
+ checkDelete(elems, false);
+ }
+
+ public void testDeleteRoleclass() throws Exception
+ {
+ loadFileSetup();
+ IType type = _cuT.getType("T").getType("R");
+ IRoleType role = (IRoleType)OTModelManager.getOTElement(type);
+ IJavaElement[] elems = new IJavaElement[] { role };
+ checkDelete(elems, false);
+ }
+
+ @SuppressWarnings("restriction")
+ public void testGetRoleclassName() throws Exception
+ {
+ loadFileSetup();
+ IType type = _cuT.getType("T").getType("R");
+ IRoleType role = (IRoleType)OTModelManager.getOTElement(type);
+ String message1= ReorgUtils.getName(role);
+ assertEquals("role 'R'", message1);
+ }
+
+ public void testDeleteCalloutMapping() throws Exception
+ {
+ loadFileSetup();
+ IType type = _cuT.getType("T").getType("R");
+ IRoleType role = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mappings = role.getMethodMappings();
+ IJavaElement[] elems = new IJavaElement[] { mappings[0] };
+ checkDelete(elems, false);
+ }
+
+ public void testDeleteCalloutToFieldMapping() throws Exception
+ {
+ loadFileSetup();
+ IType type = _cuT.getType("T").getType("R");
+ IRoleType role = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mappings = role.getMethodMappings();
+ IJavaElement[] elems = new IJavaElement[] { mappings[0] };
+ checkDelete(elems, false);
+ }
+
+ public void testDeleteCallinMapping() throws Exception
+ {
+ loadFileSetup();
+ IType type = _cuT.getType("T").getType("R");
+ IRoleType role = (IRoleType)OTModelManager.getOTElement(type);
+ IMethodMapping[] mappings = role.getMethodMappings();
+ IJavaElement[] elems = new IJavaElement[] { mappings[0] };
+ checkDelete(elems, false);
+ }
+}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTPasteActionTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTPasteActionTest.java new file mode 100644 index 000000000..982534650 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/OTPasteActionTest.java @@ -0,0 +1,372 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IImportDeclaration;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockClipboard;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockWorkbenchSite;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.objectteams.otdt.core.IMethodMapping;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.MySetup;
+import org.eclipse.objectteams.otdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.CopyToClipboardAction;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction;
+
+
+public class OTPasteActionTest extends RefactoringTest
+{
+
+ private Clipboard _clipboard;
+ private IPackageFragment _packageQ;
+ private static final String REFACTORING_PATH= "Paste/";
+
+ public OTPasteActionTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new MySetup(new TestSuite(OTPasteActionTest.class));
+ }
+
+ protected String getRefactoringPath() {
+ return REFACTORING_PATH;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _clipboard= new MockClipboard(Display.getDefault());
+ _packageQ = MySetup.getDefaultSourceFolder().createPackageFragment("q", true, null);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (_packageQ.exists())
+ {
+ _packageQ.delete(true, null);
+ }
+ _clipboard.dispose();
+ super.tearDown();
+ }
+
+ private static Object[] merge(Object[] array1, Object[] array2) {
+ Set elements= new HashSet(array1.length + array2.length);
+ elements.addAll(Arrays.asList(array1));
+ elements.addAll(Arrays.asList(array2));
+ return elements.toArray();
+ }
+
+ private PasteAction verifyEnabled(IResource[] copySelectedResources, IJavaElement[] copySelectedJavaElements, IResource[] pasteSelectedResources, IJavaElement[] pasteSelectedJavaElements) throws JavaModelException {
+ PasteAction pasteAction= new PasteAction(new MockWorkbenchSite(merge(pasteSelectedResources, pasteSelectedJavaElements)), _clipboard);
+ CopyToClipboardAction copyToClipboardAction= new CopyToClipboardAction(new MockWorkbenchSite(merge(copySelectedResources, copySelectedJavaElements)), _clipboard);
+ copyToClipboardAction.setAutoRepeatOnFailure(true);
+ copyToClipboardAction.update(copyToClipboardAction.getSelection());
+ assertTrue("copy not enabled", copyToClipboardAction.isEnabled());
+ copyToClipboardAction.run();
+
+ pasteAction.update(pasteAction.getSelection());
+ assertTrue("paste should be enabled", pasteAction.isEnabled());
+ return pasteAction;
+ }
+
+ private void compareContents(String cuName) throws JavaModelException, IOException {
+ assertEqualLines(cuName, getFileContents(getOutputTestFileName(cuName)), getPackageP().getCompilationUnit(cuName + ".java").getSource());
+ }
+
+ private void delete(ICompilationUnit cu) throws Exception {
+ try {
+ performDummySearch();
+ cu.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ //ingore and keep going
+ }
+ }
+
+ public void testPasteTeamclassIntoTeamclass() throws Exception
+ {
+ ICompilationUnit cuTSource = createCUfromTestFile(getPackageP(),
+ "TSource");
+ ICompilationUnit cuTDest = createCUfromTestFile(getPackageP(),
+ "TDest");
+
+ try
+ {
+ IType teamTSource = cuTSource.getType("TSource");
+ IType teamTDest = cuTDest.getType("TDest");
+
+ assertTrue("TSource does not exist", teamTSource.exists());
+ assertTrue("TDest does not exist", teamTDest.exists());
+
+ IJavaElement[] copyJavaElements = { teamTSource };
+ IResource[] copyResources = {};
+ IJavaElement[] pasteJavaElements = { teamTDest };
+ IResource[] pasteResources = {};
+ PasteAction paste = verifyEnabled(copyResources,
+ copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ }
+ }
+
+ public void testPasteNestedTeamclass() throws Exception
+ {
+ ICompilationUnit cuTSource = createCUfromTestFile(getPackageP(),
+ "TSource");
+ ICompilationUnit cuTDest = createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IType teamTDest_TN = cuTSource.getType("TSource").getType("TN");
+ IType teamTDest = cuTDest.getType("TDest");
+
+ assertTrue("TSource.TN does not exist", teamTDest_TN.exists());
+ assertTrue("TDest does not exist", teamTDest.exists());
+
+ IJavaElement[] copyJavaElements = { teamTDest_TN };
+ IResource[] copyResources = {};
+ IJavaElement[] pasteJavaElements = { teamTDest };
+ IResource[] pasteResources = {};
+ PasteAction paste = verifyEnabled(copyResources,
+ copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteRoleclass() throws Exception
+ {
+ ICompilationUnit cuTSource = createCUfromTestFile(getPackageP(),
+ "TSource");
+ ICompilationUnit cuTDest = createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IType roleR = cuTSource.getType("TSource").getType("R");
+ IType teamTDest = cuTDest.getType("TDest");
+
+ assertTrue("R does not exist", roleR.exists());
+ assertTrue("TDest does not exist", teamTDest.exists());
+
+ IJavaElement[] copyJavaElements = { roleR };
+ IResource[] copyResources = {};
+ IJavaElement[] pasteJavaElements = { teamTDest };
+ IResource[] pasteResources = {};
+ PasteAction paste = verifyEnabled(copyResources,
+ copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteCalloutMapping() throws Exception
+ {
+ ICompilationUnit cuTSource= createCUfromTestFile(getPackageP(), "TSource");
+ ICompilationUnit cuTDest= createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IRoleType roleSrc = (IRoleType)OTModelManager.getOTElement(cuTSource.getType("TSource").getType("R"));
+ IMethodMapping calloutMapping = roleSrc.getMethodMappings()[0];
+ IType roleTDest_R = cuTDest.getType("TDest").getType("R");
+
+ assertTrue("callout does not exist", calloutMapping.exists());
+ assertTrue("R does not exist", roleTDest_R.exists());
+
+ IJavaElement[] copyJavaElements= {calloutMapping};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {roleTDest_R};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteCalloutMappingParam() throws Exception
+ {
+ ICompilationUnit cuTSource= createCUfromTestFile(getPackageP(), "TSource");
+ ICompilationUnit cuTDest= createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IRoleType roleSrc = (IRoleType)OTModelManager.getOTElement(cuTSource.getType("TSource").getType("R"));
+ IMethodMapping calloutMapping = roleSrc.getMethodMappings()[0];
+ IType roleTDest_R = cuTDest.getType("TDest").getType("R");
+
+ assertTrue("callout does not exist", calloutMapping.exists());
+ assertTrue("R does not exist", roleTDest_R.exists());
+
+ IJavaElement[] copyJavaElements= {calloutMapping};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {roleTDest_R};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteCallinMappingParam() throws Exception
+ {
+ ICompilationUnit cuTSource= createCUfromTestFile(getPackageP(), "TSource");
+ ICompilationUnit cuTDest= createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IRoleType roleSrc = (IRoleType)OTModelManager.getOTElement(cuTSource.getType("TSource").getType("R"));
+ IMethodMapping calloutMapping = roleSrc.getMethodMappings()[0];
+ IType roleTDest_R = cuTDest.getType("TDest").getType("R");
+
+ assertTrue("callout does not exist", calloutMapping.exists());
+ assertTrue("R does not exist", roleTDest_R.exists());
+
+ IJavaElement[] copyJavaElements= {calloutMapping};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {roleTDest_R};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteCalloutToFieldMapping() throws Exception
+ {
+ ICompilationUnit cuTSource = createCUfromTestFile(getPackageP(),
+ "TSource");
+ ICompilationUnit cuTDest = createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IRoleType roleSrc = (IRoleType)OTModelManager
+ .getOTElement(cuTSource.getType("TSource").getType("R"));
+ IMethodMapping calloutToFieldMapping = roleSrc.getMethodMappings()[0];
+ IType roleTDest_R = cuTDest.getType("TDest").getType("R");
+
+ assertTrue("callout does not exist", calloutToFieldMapping.exists());
+ assertTrue("R does not exist", roleTDest_R.exists());
+
+ IJavaElement[] copyJavaElements = { calloutToFieldMapping };
+ IResource[] copyResources = {};
+ IJavaElement[] pasteJavaElements = { roleTDest_R };
+ IResource[] pasteResources = {};
+ PasteAction paste = verifyEnabled(copyResources,
+ copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+ public void testPasteCallinMapping() throws Exception
+ {
+ ICompilationUnit cuTSource = createCUfromTestFile(getPackageP(),
+ "TSource");
+ ICompilationUnit cuTDest = createCUfromTestFile(getPackageP(), "TDest");
+
+ try
+ {
+ IRoleType roleSrc = (IRoleType)OTModelManager
+ .getOTElement(cuTSource.getType("TSource").getType("R"));
+ IMethodMapping callinMapping = roleSrc.getMethodMappings()[0];
+ IType roleTDest_R = cuTDest.getType("TDest").getType("R");
+
+ assertTrue("callout does not exist", callinMapping.exists());
+ assertTrue("R does not exist", roleTDest_R.exists());
+
+ IJavaElement[] copyJavaElements = { callinMapping };
+ IResource[] copyResources = {};
+ IJavaElement[] pasteJavaElements = { roleTDest_R };
+ IResource[] pasteResources = {};
+ PasteAction paste = verifyEnabled(copyResources,
+ copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("TSource");
+ compareContents("TDest");
+ }
+ finally
+ {
+ delete(cuTSource);
+ delete(cuTDest);
+ }
+ }
+
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/PasteActionTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/PasteActionTest.java new file mode 100644 index 000000000..52c607c8d --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/reorg/PasteActionTest.java @@ -0,0 +1,454 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/
+package org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IImportContainer;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.refactoring.TypedSource;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.CopyToClipboardAction;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction;
+import org.eclipse.jdt.internal.ui.refactoring.reorg.TypedSourceTransfer;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.jdt.ui.tests.refactoring.RefactoringTestSetup;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockClipboard;
+import org.eclipse.jdt.ui.tests.refactoring.infra.MockWorkbenchSite;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+
+
+public class PasteActionTest extends RefactoringTest{
+
+ private Clipboard _clipboard;
+ private static final String REFACTORING_PATH= "Paste/";
+
+ public PasteActionTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new RefactoringTestSetup(new TestSuite(PasteActionTest.class));
+ }
+
+ protected String getRefactoringPath() {
+ return REFACTORING_PATH;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _clipboard= new MockClipboard(Display.getDefault());
+ }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _clipboard.dispose();
+ }
+
+ private static Object[] merge(Object[] array1, Object[] array2) {
+ Set elements= new HashSet(array1.length + array2.length);
+ elements.addAll(Arrays.asList(array1));
+ elements.addAll(Arrays.asList(array2));
+ return elements.toArray();
+ }
+
+ private PasteAction verifyEnabled(IResource[] copySelectedResources, IJavaElement[] copySelectedJavaElements, IResource[] pasteSelectedResources, IJavaElement[] pasteSelectedJavaElements) throws JavaModelException {
+ PasteAction pasteAction= new PasteAction(new MockWorkbenchSite(merge(pasteSelectedResources, pasteSelectedJavaElements)), _clipboard);
+ CopyToClipboardAction copyToClipboardAction= new CopyToClipboardAction(new MockWorkbenchSite(merge(copySelectedResources, copySelectedJavaElements)), _clipboard);
+ copyToClipboardAction.setAutoRepeatOnFailure(true);
+ copyToClipboardAction.update(copyToClipboardAction.getSelection());
+ assertTrue("copy not enabled", copyToClipboardAction.isEnabled());
+ copyToClipboardAction.run();
+
+ pasteAction.update(pasteAction.getSelection());
+ assertTrue("paste should be enabled", pasteAction.isEnabled());
+ return pasteAction;
+ }
+
+ private PasteAction verifyEnabled(IResource[] copySelectedResources, IJavaElement[] copySelectedJavaElements, IWorkingSet pasteSelectedWorkingSet) throws JavaModelException {
+ PasteAction pasteAction= new PasteAction(new MockWorkbenchSite(new Object[] {pasteSelectedWorkingSet}), _clipboard);
+ CopyToClipboardAction copyToClipboardAction= new CopyToClipboardAction(new MockWorkbenchSite(merge(copySelectedResources, copySelectedJavaElements)), _clipboard);
+ copyToClipboardAction.setAutoRepeatOnFailure(true);
+ copyToClipboardAction.update(copyToClipboardAction.getSelection());
+ assertTrue("copy not enabled", copyToClipboardAction.isEnabled());
+ copyToClipboardAction.run();
+
+ pasteAction.update(pasteAction.getSelection());
+ assertTrue("paste should be enabled", pasteAction.isEnabled());
+ return pasteAction;
+ }
+
+ public void testEnabled_javaProject() throws Exception {
+ IJavaElement[] javaElements= {RefactoringTestSetup.getProject()};
+ IResource[] resources= {};
+ verifyEnabled(resources, javaElements, new IResource[0], new IJavaElement[0]);
+ }
+
+ public void testEnabled_project() throws Exception {
+ IJavaElement[] javaElements= {};
+ IResource[] resources= {RefactoringTestSetup.getProject().getProject()};
+ verifyEnabled(resources, javaElements, new IResource[0], new IJavaElement[0]);
+ }
+
+ public void testEnabled_workingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test", new IAdaptable[] {});
+ try {
+ verifyEnabled(new IResource[0], new IJavaElement[] {RefactoringTestSetup.getProject()}, ws);
+ } finally {
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ private void compareContents(String cuName) throws JavaModelException, IOException {
+ assertEqualLines(cuName, getFileContents(getOutputTestFileName(cuName)), getPackageP().getCompilationUnit(cuName + ".java").getSource());
+ }
+
+ private void delete(ICompilationUnit cu) throws Exception {
+ try {
+ performDummySearch();
+ cu.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ //ingore and keep going
+ }
+ }
+
+ public void test0() throws Exception{
+ if (true) {
+ printTestDisabledMessage("not implemented yet");
+ return;
+ }
+
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ ICompilationUnit cuB= createCUfromTestFile(getPackageP(), "B");
+
+ try {
+ IType typeA= cuA.getType("A");
+ IType typeB= cuB.getType("B");
+
+ assertTrue("A does not exist", typeA.exists());
+ assertTrue("B does not exist", typeB.exists());
+
+ IJavaElement[] copyJavaElements= {typeA};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {typeB};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("A");
+ compareContents("B");
+ } finally{
+ delete(cuA);
+ delete(cuB);
+ }
+ }
+
+ public void test2() throws Exception{
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ ICompilationUnit cuB= createCUfromTestFile(getPackageP(), "B");
+
+ try {
+ IField fieldY= cuA.getType("A").getField("y");
+ IType typeB= cuB.getType("B");
+
+ assertTrue("y does not exist", fieldY.exists());
+ assertTrue("B does not exist", typeB.exists());
+
+ IJavaElement[] copyJavaElements= {fieldY};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {typeB};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("A");
+ compareContents("B");
+ } finally{
+ delete(cuA);
+ delete(cuB);
+ }
+ }
+
+ public void test3() throws Exception{
+// printTestDisabledMessage("test for bug#19007");
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ ICompilationUnit cuB= createCUfromTestFile(getPackageP(), "B");
+
+ try {
+ IJavaElement elem0= cuA.getImport("java.lang.*");
+ IImportContainer importContainer= cuB.getImportContainer();
+
+ assertTrue("y does not exist", elem0.exists());
+ assertTrue("B does not exist", importContainer.exists());
+
+ IJavaElement[] copyJavaElements= {elem0};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {importContainer};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("A");
+ compareContents("B");
+ } finally{
+ delete(cuA);
+ delete(cuB);
+ }
+ }
+
+ public void test4() throws Exception{
+// printTestDisabledMessage("test for bug 20151");
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ try {
+ IJavaElement elem0= cuA.getType("A").getMethod("f", new String[0]);
+ IMethod method= cuA.getType("A").getMethod("f1", new String[0]);
+
+ assertTrue("y does not exist", elem0.exists());
+ assertTrue("B does not exist", method.exists());
+
+ IJavaElement[] copyJavaElements= {elem0};
+ IResource[] copyResources= {};
+ IJavaElement[] pasteJavaElements= {method};
+ IResource[] pasteResources= {};
+ PasteAction paste= verifyEnabled(copyResources, copyJavaElements, pasteResources, pasteJavaElements);
+ paste.run((IStructuredSelection)paste.getSelection());
+ compareContents("A");
+ } finally{
+ delete(cuA);
+ }
+ }
+
+ public void testPastingJavaElementIntoWorkingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test", new IAdaptable[] {});
+ try {
+ IResource[] resources= {};
+ IJavaElement[] jElements= {RefactoringTestSetup.getProject()};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(RefactoringTestSetup.getProject(), ws.getElements()[0]);
+ } finally {
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ public void testPastingResourceIntoWorkingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test", new IAdaptable[] {});
+ IFolder folder= RefactoringTestSetup.getProject().getProject().getFolder("folder");
+ folder.create(true, true, null);
+ try {
+ IResource[] resources= {folder};
+ IJavaElement[] jElements= {};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(folder, ws.getElements()[0]);
+ } finally {
+ performDummySearch();
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ folder.delete(true, false, null);
+ }
+ }
+
+ public void testPastingJavaElementAsResourceIntoWorkingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test", new IAdaptable[] {});
+ try {
+ IResource[] resources= {RefactoringTestSetup.getProject().getProject()};
+ IJavaElement[] jElements= {};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(RefactoringTestSetup.getProject(), ws.getElements()[0]);
+ } finally {
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ public void testPastingExistingElementIntoWorkingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test",
+ new IAdaptable[] {RefactoringTestSetup.getProject()});
+ try {
+ IResource[] resources= {};
+ IJavaElement[] jElements= {RefactoringTestSetup.getProject()};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(RefactoringTestSetup.getProject(), ws.getElements()[0]);
+ } finally {
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ public void testPastingChildJavaElementIntoWorkingSet() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test",
+ new IAdaptable[] {RefactoringTestSetup.getProject()});
+ try {
+ IResource[] resources= {};
+ IJavaElement[] jElements= {getPackageP()};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(RefactoringTestSetup.getProject(), ws.getElements()[0]);
+ } finally {
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ public void testPastingChildResourceIntoWorkingSet() throws Exception {
+ IFolder folder= RefactoringTestSetup.getProject().getProject().getFolder("folder");
+ folder.create(true, true, null);
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test",
+ new IAdaptable[] {folder});
+ IFolder sub= folder.getFolder("sub");
+ sub.create(true, true, null);
+ try {
+ IResource[] resources= {sub};
+ IJavaElement[] jElements= {};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(folder, ws.getElements()[0]);
+ } finally {
+ performDummySearch();
+ folder.delete(true, false, null);
+ sub.delete(true, false, null);
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ public void testPastingChildResourceIntoWorkingSetContainingParent() throws Exception {
+ IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet("Test",
+ new IAdaptable[] {RefactoringTestSetup.getProject()});
+ IFolder folder= RefactoringTestSetup.getProject().getProject().getFolder("folder");
+ folder.create(true, true, null);
+ try {
+ IResource[] resources= {folder};
+ IJavaElement[] jElements= {};
+ PasteAction paste= verifyEnabled(resources , jElements, ws);
+ paste.run((IStructuredSelection)paste.getSelection());
+ assertEquals("Only one element", 1, ws.getElements().length);
+ assertEquals(RefactoringTestSetup.getProject(), ws.getElements()[0]);
+ } finally {
+ performDummySearch();
+ folder.delete(true, false, null);
+ PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(ws);
+ }
+ }
+
+ private void setClipboardContents(TypedSource[] typedSources, int repeat) {
+ final int maxRepeat= 10;
+ try {
+ _clipboard.setContents(new Object[] {typedSources}, new Transfer[] {TypedSourceTransfer.getInstance()});
+ } catch (SWTError e) {
+ if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD || repeat >= maxRepeat)
+ throw e;
+ setClipboardContents(typedSources, repeat+1);
+ }
+ }
+
+ private void copyAndPasteTypedSources(IJavaElement[] elemsForClipboard, IJavaElement[] pasteSelectedJavaElements, boolean pasteEnabled) throws CoreException {
+ setClipboardContents(TypedSource.createTypedSources(elemsForClipboard), 0);
+ PasteAction pasteAction= new PasteAction(new MockWorkbenchSite(pasteSelectedJavaElements), _clipboard);
+ pasteAction.update(pasteAction.getSelection());
+ assertEquals("action enablement", pasteEnabled, pasteAction.isEnabled());
+ if (pasteEnabled)
+ pasteAction.run((IStructuredSelection)pasteAction.getSelection());
+ }
+
+ public void testPastingTypedResources0() throws Exception {
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ try {
+ IJavaElement methodM= cuA.getType("A").getMethod("m", new String[0]);
+ IJavaElement[] elemsForClipboard= {methodM};
+ IJavaElement[] pasteSelectedJavaElements= {methodM};
+ boolean enabled= true;
+ copyAndPasteTypedSources(elemsForClipboard, pasteSelectedJavaElements, enabled);
+ compareContents("A");
+ } finally{
+ delete(cuA);
+ }
+ }
+
+ public void testPastingTypedResources1() throws Exception {
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ try {
+ IType typeA= cuA.getType("A");
+ IJavaElement fieldF= typeA.getField("f");
+ IJavaElement[] elemsForClipboard= {fieldF};
+ IJavaElement[] pasteSelectedJavaElements= {typeA};
+ boolean enabled= true;
+ copyAndPasteTypedSources(elemsForClipboard, pasteSelectedJavaElements, enabled);
+ compareContents("A");
+ } finally{
+ delete(cuA);
+ }
+ }
+
+ public void testPastingTypedResources2() throws Exception {
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ try {
+ IType typeA= cuA.getType("A");
+ IJavaElement fieldF= typeA.getField("f");
+ IJavaElement[] elemsForClipboard= {fieldF};
+ IJavaElement[] pasteSelectedJavaElements= {typeA};
+ boolean enabled= true;
+ copyAndPasteTypedSources(elemsForClipboard, pasteSelectedJavaElements, enabled);
+ compareContents("A");
+ } finally{
+ delete(cuA);
+ }
+ }
+
+ public void testPastingTypedResources3() throws Exception {
+ ICompilationUnit cuA= createCUfromTestFile(getPackageP(), "A");
+ try {
+ IType typeA= cuA.getType("A");
+ IJavaElement fieldF= typeA.getField("f");
+ IJavaElement fieldG= typeA.getField("g");
+ IJavaElement[] elemsForClipboard= {fieldF, fieldG};
+ IJavaElement[] pasteSelectedJavaElements= {typeA};
+ boolean enabled= true;
+ copyAndPasteTypedSources(elemsForClipboard, pasteSelectedJavaElements, enabled);
+ compareContents("A");
+ } finally{
+ delete(cuA);
+ }
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/requiredfeatures/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/requiredfeatures/AllTests.java new file mode 100644 index 000000000..394daa321 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/requiredfeatures/AllTests.java @@ -0,0 +1,56 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.requiredfeatures;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author svacina
+ *
+ * Runs all test cases which are needed for refactoring
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "Tests for required features");
+
+ //TODO(jsv) test only the usage of specific components used in Refactoring Processor
+
+ // Hierarchy
+ suite.addTest(org.eclipse.objectteams.otdt.tests.superhierarchy.AllTests.suite());
+ // TypeHelper.getInheritedMethods
+ suite.addTest(org.eclipse.objectteams.otdt.tests.otmodel.internal.TypeHelperGetInheritedMethodsTest.suite());
+ // SearchEngine
+ suite.addTest(org.eclipse.objectteams.otdt.tests.search.OTJavaMethodSearchTests.suite());
+ suite.addTest(org.eclipse.objectteams.otdt.tests.search.OTJavaTypeSearchTests.suite());
+ //TODO(jsv): add required selection tests
+ return suite;
+ }
+}
\ No newline at end of file diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/AllTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/AllTests.java new file mode 100644 index 000000000..2e3be0552 --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/AllTests.java @@ -0,0 +1,49 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.util;
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author brcan
+ *
+ * Runs all OT-specific refactoring tests and corresponding eclipse refactoring tests
+ */
+public class AllTests
+{
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "All OT-Refactoring-Util Tests");
+
+ suite.addTest(org.eclipse.objectteams.otdt.ui.tests.refactoring.util.RefactoringUtilTest.suite());
+
+ return suite;
+ }
+}
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/RefactoringUtilTest.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/RefactoringUtilTest.java new file mode 100644 index 000000000..0664a2e2f --- /dev/null +++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/util/RefactoringUtilTest.java @@ -0,0 +1,192 @@ +/********************************************************************** + * This file is part of "Object Teams Development Tooling"-Software + * + * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany, + * for its Fraunhofer Institute and Computer Architecture and Software + * Technology (FIRST), Berlin, Germany and Technical University Berlin, + * Germany. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * $Id$ + * + * Please visit http://www.eclipse.org/objectteams for updates and contact. + * + * Contributors: + * Fraunhofer FIRST - Initial API and implementation + * Technical University Berlin - Initial API and implementation + **********************************************************************/ +package org.eclipse.objectteams.otdt.ui.tests.refactoring.util; + +import junit.framework.Test; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.objectteams.otdt.core.IRoleType; +import org.eclipse.objectteams.otdt.ui.tests.refactoring.FileBasedRefactoringTest; + +/** + * @author svacina + * @version $Id: RefactoringUtilTest.java 6446 2005-08-02 10:49:59Z svacina $ + */ +public class RefactoringUtilTest extends FileBasedRefactoringTest +{ + + private IType _a; + private IType _aa; + private IType _b; + private IType _c; + private IType _itest1; + private IType _itest2; + + private IRoleType _team1role1; + private IRoleType _team2role1; + + private IRoleType _team3role2; + private IRoleType _team4role2; + + private IMethod _team2role1m1; + private IMethod _team2role1m2; + private IMethod _itest2m1; + + private IMethod _cm1; + private IMethod _cm2; + private IMethod _team4role2m1; + private IMethod _team4role2m2; + + + public RefactoringUtilTest(String name) + { + super(name); + } + + public static Test suite() + { + return new Suite(RefactoringUtilTest.class); + } + + /** + * Creates a team hierarchy with implicit role type inheritance. + */ + public void setUpSuite() throws Exception + { + setTestProjectDir("RefactoringUtil"); + super.setUpSuite(); + + _a = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "A"); + + _aa = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "AA"); + + _b = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "B"); + + _c = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "C"); + + _itest1 = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "ITest1"); + + _itest2 = getType(getTestProjectDir(), + "src", + "rolehierarchy1", + "ITest2"); + + _team1role1 = + getRole(getTestProjectDir(), + "src", + "rolehierarchy1", + "Team1", + "Role1"); + + _team2role1 = + getRole(getTestProjectDir(), + "src", + "rolehierarchy1", + "Team2", + "Role1"); + + _team3role2 = + getRole(getTestProjectDir(), + "src", + "rolehierarchy1", + "Team3", + "Role2"); + + _team4role2 = + getRole(getTestProjectDir(), + "src", + "rolehierarchy1", + "Team4", + "Role2"); + + _team2role1m1 = _team2role1.getMethods()[0]; + _team2role1m2 = _team2role1.getMethods()[1]; + + _itest2m1 = _itest2.getMethods()[0]; + + _cm1 = _c.getMethods()[0]; + _cm2 = _c.getMethods()[1]; + _team4role2m2 = _team4role2.getMethods()[1]; + _team4role2m1 = _team4role2.getMethods()[0]; + + + + } + + protected void setUp() throws Exception + { + super.setUp(); + } + + public void testIsDeclaredInInterface_yes() throws JavaModelException + { + fail("Not yet implemented"); +// MIGRATE +// IMethod expected = _itest2m1; +// IMethod actual = RefactoringUtil.isDeclaredInInterface(_team2role1m1, new NullProgressMonitor()); +// assertTrue(expected.equals(actual)); +// } +// +// public void testIsDeclaredInInterface_no1() throws JavaModelException +// { +// IMethod actual = RefactoringUtil.isDeclaredInInterface(_team2role1m2, new NullProgressMonitor()); +// assertNull(actual); +// } +// +// public void testIsDeclaredInInterface_no2() throws JavaModelException +// { +// IMethod actual = RefactoringUtil.isDeclaredInInterface(_team4role2m2, new NullProgressMonitor()); +// assertNull(actual); +// } +// +// public void testOverridesAnotherMethod_yes() throws JavaModelException +// { +// IMethod expected = _cm2; +// IMethod actual = RefactoringUtil.overridesAnotherMethod(_team4role2m2, new NullProgressMonitor()); +// assertTrue(expected.equals(actual)); +// } +// +// public void testOverridesAnotherMethod_no() throws JavaModelException +// { +// IMethod actual = RefactoringUtil.overridesAnotherMethod(_team2role1m2, new NullProgressMonitor()); +// assertNull(actual); + } + + //TODO(jsv) test with nested teams +}
\ No newline at end of file |