Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 131127 Details for
Bug 266812
[Tests] Add tests for creating/applying patches from UI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch_v01
266812_v01.txt (text/plain), 10.42 KB, created by
Pawel Pogorzelski
on 2009-04-07 10:09:07 EDT
(
hide
)
Description:
Patch_v01
Filename:
MIME Type:
Creator:
Pawel Pogorzelski
Created:
2009-04-07 10:09:07 EDT
Size:
10.42 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare.tests >Index: patchdata/patch_addition.txt >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare.tests/patchdata/patch_addition.txt,v >retrieving revision 1.1 >diff -u -r1.1 patch_addition.txt >--- patchdata/patch_addition.txt 8 Aug 2008 09:51:21 -0000 1.1 >+++ patchdata/patch_addition.txt 7 Apr 2009 14:07:25 -0000 >@@ -1,5 +1,11 @@ >---- addition.txt 2005-05-09 12:14:04.000000000 +0200 >-+++ exp_addition.txt 2005-05-09 13:15:34.000000000 +0200 >+### Eclipse Workspace Patch 1.0 >+#P ApplyPatchTest >+Index: exp_addition.txt >+=================================================================== >+RCS file: exp_addition.txt >+diff -N exp_addition.txt >+--- /dev/null 1 Jan 1970 00:00:00 -0000 >++++ exp_addition.txt 1 Jan 1970 00:00:00 -0000 > @@ -0,0 +1,9 @@ > +[1] > +[2] >Index: src/org/eclipse/compare/tests/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java,v >retrieving revision 1.17 >diff -u -r1.17 AllTests.java >--- src/org/eclipse/compare/tests/AllTests.java 17 Mar 2009 15:50:43 -0000 1.17 >+++ src/org/eclipse/compare/tests/AllTests.java 7 Apr 2009 14:07:25 -0000 >@@ -33,6 +33,7 @@ > suite.addTestSuite(FileDiffResultTest.class); > suite.addTestSuite(ContentMergeViewerTest.class); > suite.addTestSuite(PatchLinesTest.class); >+ suite.addTestSuite(UITest.class); > // $JUnit-END$ > return suite; > } >Index: src/org/eclipse/compare/tests/UITest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare.tests/src/org/eclipse/compare/tests/UITest.java,v >retrieving revision 1.4 >diff -u -r1.4 UITest.java >--- src/org/eclipse/compare/tests/UITest.java 16 Mar 2007 20:25:10 -0000 1.4 >+++ src/org/eclipse/compare/tests/UITest.java 7 Apr 2009 14:07:25 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 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 >@@ -10,15 +10,180 @@ > *******************************************************************************/ > package org.eclipse.compare.tests; > >+import java.io.IOException; >+import java.io.InputStream; >+import java.lang.reflect.InvocationTargetException; >+ > import junit.framework.TestCase; > >+import org.eclipse.compare.CompareConfiguration; >+import org.eclipse.compare.internal.patch.PatchWizard; >+import org.eclipse.compare.internal.patch.PatchWizardDialog; >+import org.eclipse.core.internal.resources.WorkspaceRoot; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.viewers.TreePath; >+import org.eclipse.jface.viewers.TreeSelection; >+import org.eclipse.jface.viewers.TreeViewer; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.internal.WorkbenchPlugin; >+ > public class UITest extends TestCase { > >+ private static final String TEST_PROJECT = "ApplyPatchTest"; >+ >+ private IWorkspaceRoot workspaceRoot = null; >+ private IProject testProject = null; >+ >+ private PatchWizardDialog wizardDialog = null; >+ private PatchWizard wizard = null; >+ > public UITest(String name) { > super(name); > } >- >- public void testUI() { >- // intentionally left empty >+ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); >+ testProject = workspaceRoot.getProject(TEST_PROJECT); >+ testProject.create(null); >+ testProject.open(null); >+ } >+ >+ protected void tearDown() throws Exception { >+ super.tearDown(); >+ testProject.delete(true, null); >+ } >+ >+ public void testApplyWorkspacePatch() throws CoreException { >+ copyIntoWorkspace("patch_addition.txt"); >+ >+ openPatchWizard(); >+ Assert.isTrue(wizard.getPageCount() == 3); >+ IWizardPage patchWizardPage = wizard.getPages()[0]; >+ >+ getButton(patchWizardPage, "fUseClipboardButton").setSelection(false); >+ getButton(patchWizardPage, "fUsePatchFileButton").setSelection(false); >+ getButton(patchWizardPage, "fUseWorkspaceButton").setSelection(true); >+ >+ TreeViewer tree = getTreeViewer(patchWizardPage, "fTreeViewer"); >+ treeSelect(tree, TEST_PROJECT + "/patch_addition.txt"); >+ Assert.isTrue(patchWizardPage.canFlipToNextPage()); >+ >+ callMethod(wizardDialog, "nextPressed", new Object[] {}); >+ >+ Assert.isTrue(wizard.canFinish()); >+ wizard.performFinish(); >+ >+ InputStream expected = PatchUtils.asInputStream("exp_addition.txt"); >+ InputStream actual = testProject.getFile("exp_addition.txt") >+ .getContents(); >+ compareStreams(expected, actual); >+ } >+ >+ private void openPatchWizard() { >+ ImageDescriptor patchWizardImage = null; >+ String patchWizardTitle = null; >+ >+ IStorage patch = null; >+ IResource target = null; >+ CompareConfiguration configuration = new CompareConfiguration(); >+ >+ wizard = new PatchWizard(patch, target, configuration); >+ if (patchWizardImage != null) >+ wizard.setDefaultPageImageDescriptor(patchWizardImage); >+ if (patchWizardTitle != null) >+ wizard.setWindowTitle(patchWizardTitle); >+ wizard.setNeedsProgressMonitor(true); >+ >+ wizardDialog = new PatchWizardDialog(getShell(), wizard); >+ wizard.setDialog(wizardDialog); >+ wizardDialog.setBlockOnOpen(false); >+ wizardDialog.open(); >+ } >+ >+ private void copyIntoWorkspace(String name) { >+ IFile file = testProject.getFile(name); >+ InputStream is = PatchUtils.asInputStream(name); >+ try { >+ file.create(is, true, null); >+ } catch (CoreException e) { >+ fail(e.getMessage()); >+ } >+ } >+ >+ private void compareStreams(InputStream expectedIS, InputStream actualIS) { >+ String expected = null; >+ String actual = null; >+ try { >+ expected = PatchUtils.asString(expectedIS); >+ actual = PatchUtils.asString(actualIS); >+ } catch (IOException e) { >+ fail(e.getMessage()); >+ } >+ assertEquals(expected, actual); >+ } >+ >+ private void treeSelect(TreeViewer tree, String path) { >+ WorkspaceRoot root = (WorkspaceRoot) tree.getInput(); >+ IFile file = root.getFile(path); >+ TreePath treePath = new TreePath(new Object[] { file }); >+ TreeSelection sel = new TreeSelection(treePath); >+ tree.setSelection(sel); >+ } >+ >+ private Button getButton(Object object, String name) { >+ return (Button) getField(object, name); > } >+ >+ private TreeViewer getTreeViewer(Object object, String name) { >+ return (TreeViewer) getField(object, name); >+ } >+ >+ private Object getField(Object object, String name) { >+ Object ret = null; >+ try { >+ ret = ReflectionUtils.getField(object, name); >+ } catch (IllegalArgumentException e) { >+ fail(e.getMessage()); >+ } catch (SecurityException e) { >+ fail(e.getMessage()); >+ } catch (IllegalAccessException e) { >+ fail(e.getMessage()); >+ } catch (NoSuchFieldException e) { >+ fail(e.getMessage()); >+ } >+ return ret; >+ } >+ >+ private Object callMethod(Object object, String name, Object args[]) { >+ Object ret = null; >+ try { >+ ret = ReflectionUtils.callMethod(object, name, args); >+ } catch (IllegalArgumentException e) { >+ fail(e.getMessage()); >+ } catch (IllegalAccessException e) { >+ fail(e.getMessage()); >+ } catch (InvocationTargetException e) { >+ fail(e.getMessage()); >+ } catch (NoSuchMethodException e) { >+ fail(e.getMessage()); >+ } >+ return ret; >+ } >+ >+ private Shell getShell() { >+ return WorkbenchPlugin.getDefault().getWorkbench() >+ .getActiveWorkbenchWindow().getShell(); >+ } >+ > } >Index: src/org/eclipse/compare/tests/ReflectionUtils.java >=================================================================== >RCS file: src/org/eclipse/compare/tests/ReflectionUtils.java >diff -N src/org/eclipse/compare/tests/ReflectionUtils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/compare/tests/ReflectionUtils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 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.compare.tests; >+ >+import java.lang.reflect.Field; >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+ >+public class ReflectionUtils { >+ >+ public static Object callMethod(Object object, String name, Object args[]) >+ throws IllegalArgumentException, IllegalAccessException, >+ InvocationTargetException, NoSuchMethodException { >+ Class types[] = new Class[args.length]; >+ for (int i = 0; i < args.length; i++) { >+ types[i] = args[i].getClass(); >+ } >+ Method method = null; >+ Class clazz = object.getClass(); >+ NoSuchMethodException ex = null; >+ while (method == null && clazz != null) { >+ try { >+ method = clazz.getDeclaredMethod(name, types); >+ } catch (NoSuchMethodException e) { >+ if (ex == null) { >+ ex = e; >+ } >+ clazz = clazz.getSuperclass(); >+ } >+ } >+ if (method == null) { >+ throw ex; >+ } >+ method.setAccessible(true); >+ Object ret = method.invoke(object, args); >+ return ret; >+ } >+ >+ public static Object getField(Object object, String name) >+ throws IllegalArgumentException, IllegalAccessException, >+ SecurityException, NoSuchFieldException { >+ Field field = object.getClass().getDeclaredField(name); >+ field.setAccessible(true); >+ Object ret = field.get(object); >+ return ret; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 266812
:
131127
|
131136
|
131383
|
131386
|
131388
|
131851