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 123617 Details for
Bug 220647
[native] Support for file manipulation actions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
JUnit tests for CopyAction - o.e.e.p2.tests project
TouchpointNativesTestPatch_Jan24.txt (text/plain), 16.46 KB, created by
Henrik Lindberg
on 2009-01-23 20:21:45 EST
(
hide
)
Description:
JUnit tests for CopyAction - o.e.e.p2.tests project
Filename:
MIME Type:
Creator:
Henrik Lindberg
Created:
2009-01-23 20:21:45 EST
Size:
16.46 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.tests >Index: src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java,v >retrieving revision 1.1 >diff -u -r1.1 AllTests.java >--- src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java 10 Nov 2008 19:27:21 -0000 1.1 >+++ src/org/eclipse/equinox/p2/tests/touchpoint/natives/AllTests.java 24 Jan 2009 01:20:26 -0000 >@@ -27,6 +27,7 @@ > suite.addTestSuite(NativeTouchpointTest.class); > suite.addTestSuite(RmdirActionTest.class); > suite.addTestSuite(UnzipActionTest.class); >+ suite.addTestSuite(CopyActionTest.class); > return suite; > } > } >Index: testData/nativeTouchpoint/aFolder/a.txt >=================================================================== >RCS file: testData/nativeTouchpoint/aFolder/a.txt >diff -N testData/nativeTouchpoint/aFolder/a.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testData/nativeTouchpoint/aFolder/a.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,2 @@ >+A >+// This a.txt should have the first line being a single A >Index: testData/nativeTouchpoint/aFolder/b.txt >=================================================================== >RCS file: testData/nativeTouchpoint/aFolder/b.txt >diff -N testData/nativeTouchpoint/aFolder/b.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testData/nativeTouchpoint/aFolder/b.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,3 @@ >+B >+// This b.txt should have the first line being a single B >+ >Index: testData/nativeTouchpoint/bcFolder/b.txt >=================================================================== >RCS file: testData/nativeTouchpoint/bcFolder/b.txt >diff -N testData/nativeTouchpoint/bcFolder/b.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testData/nativeTouchpoint/bcFolder/b.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,2 @@ >+C >+// This b.txt should have the first line being a single C >Index: file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677553623-0.836180750332067/DirectorApp Destination/artifacts.xml >=================================================================== >RCS file: file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677553623-0.836180750332067/DirectorApp Destination/artifacts.xml >diff -N file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677553623-0.836180750332067/DirectorApp Destination/artifacts.xml >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677553623-0.836180750332067/DirectorApp Destination/artifacts.xml 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<?artifactRepository class='org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository' version='1.0.0'?> >+<repository name='Bundle pool' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'> >+ <properties size='2'> >+ <property name='p2.system' value='true'/> >+ <property name='p2.timestamp' value='1232677553760'/> >+ </properties> >+ <mappings size='3'> >+ <rule filter='(& (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/> >+ <rule filter='(& (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/> >+ <rule filter='(& (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/> >+ </mappings> >+ <artifacts size='0'/> >+</repository> >Index: testData/nativeTouchpoint/xFolder/y.txt >=================================================================== >RCS file: testData/nativeTouchpoint/xFolder/y.txt >diff -N testData/nativeTouchpoint/xFolder/y.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testData/nativeTouchpoint/xFolder/y.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,2 @@ >+Y >+// This y.txt should have the first line being a single Y >Index: file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677557665-0.05949681923514438/DirectorApp Destination/artifacts.xml >=================================================================== >RCS file: file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677557665-0.05949681923514438/DirectorApp Destination/artifacts.xml >diff -N file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677557665-0.05949681923514438/DirectorApp Destination/artifacts.xml >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ file:/Users/henrik/Documents/Workspaces/junit-workspace/1232677557665-0.05949681923514438/DirectorApp Destination/artifacts.xml 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<?artifactRepository class='org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository' version='1.0.0'?> >+<repository name='Bundle pool' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'> >+ <properties size='2'> >+ <property name='p2.system' value='true'/> >+ <property name='p2.timestamp' value='1232677559232'/> >+ </properties> >+ <mappings size='3'> >+ <rule filter='(& (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/> >+ <rule filter='(& (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/> >+ <rule filter='(& (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/> >+ </mappings> >+ <artifacts size='0'/> >+</repository> >Index: src/org/eclipse/equinox/p2/tests/touchpoint/natives/CopyActionTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/touchpoint/natives/CopyActionTest.java >diff -N src/org/eclipse/equinox/p2/tests/touchpoint/natives/CopyActionTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/touchpoint/natives/CopyActionTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,244 @@ >+package org.eclipse.equinox.p2.tests.touchpoint.natives; >+ >+import java.io.*; >+import java.util.*; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.NativeTouchpoint; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.ActionConstants; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CopyAction; >+import org.eclipse.equinox.internal.provisional.p2.engine.*; >+import org.eclipse.equinox.internal.provisional.p2.metadata.*; >+import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription; >+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; >+import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; >+ >+public class CopyActionTest extends AbstractProvisioningTest { >+ >+ public CopyActionTest(String name) { >+ super(name); >+ } >+ >+ public CopyActionTest() { >+ super(""); >+ } >+ >+ public void testExecuteUndo() { >+ Map parameters = createParameters("/testData/nativeTouchpoint/aFolder/a.txt", "a.txt", false); >+ Map safeParameters = Collections.unmodifiableMap(parameters); >+ >+ CopyAction action = new CopyAction(); >+ action.execute(safeParameters); >+ >+ // Verify that the right file was copied >+ File target = new File((String) parameters.get(ActionConstants.PARM_COPY_TARGET)); >+ assertFileContent("copied content", target, "A"); >+ >+ // does nothing so should not alter parameters >+ action.undo(safeParameters); >+ assertFalse("Target should be removed after undo", target.exists()); >+ } >+ >+ public void testCopyDirectory() { >+ Map parameters = createParameters("/testData/nativeTouchpoint/aFolder/", "aFolder", false); >+ Map safeParameters = Collections.unmodifiableMap(parameters); >+ >+ CopyAction action = new CopyAction(); >+ action.execute(safeParameters); >+ >+ // Verify that the right files was copied >+ File target = new File((String) parameters.get(ActionConstants.PARM_COPY_TARGET)); >+ assertFileContent("copied content A", new File(target, "a.txt"), "A"); >+ assertFileContent("copied content B", new File(target, "b.txt"), "B"); >+ >+ // does nothing so should not alter parameters >+ action.undo(safeParameters); >+ assertFalse("Target should be removed after undo", target.exists()); >+ } >+ >+ public void testMergeDirectory() { >+ Map parameters1 = createParameters("/testData/nativeTouchpoint/xFolder/", "aFolder", true); >+ Map safeParameters1 = Collections.unmodifiableMap(parameters1); >+ >+ CopyAction action1 = new CopyAction(); >+ action1.execute(safeParameters1); >+ >+ // Verify that the right files was copied >+ File target = new File((String) parameters1.get(ActionConstants.PARM_COPY_TARGET)); >+ assertFileContent("copied content X", new File(target, "x.txt"), "X"); >+ assertFileContent("copied content Y", new File(target, "y.txt"), "Y"); >+ >+ Map parameters2 = new HashMap(); >+ parameters2.putAll(parameters1); >+ parameters2.put(ActionConstants.PARM_COPY_SOURCE, getTestData("get folder A", "/testData/nativeTouchpoint/aFolder/").getAbsolutePath()); >+ Map safeParameters2 = Collections.unmodifiableMap(parameters2); >+ >+ CopyAction action2 = new CopyAction(); >+ action2.execute(safeParameters2); >+ assertFileContent("copied content A", new File(target, "a.txt"), "A"); >+ assertFileContent("copied content B", new File(target, "b.txt"), "B"); >+ >+ // undo copy of x and y >+ action1.undo(safeParameters1); >+ assertTrue("Target should exist after undo", target.exists()); >+ File tmp = new File(target, "x.txt"); >+ assertFalse("File x should not exist", tmp.exists()); >+ tmp = new File(target, "y.txt"); >+ assertFalse("File y should not exist", tmp.exists()); >+ assertFileContent("copied content A", new File(target, "a.txt"), "A"); >+ assertFileContent("copied content B", new File(target, "b.txt"), "B"); >+ >+ // undo copy of a and b >+ action2.undo(safeParameters2); >+ assertFalse("Target should not exist after undo", target.exists()); >+ } >+ >+ public void testMergeOverwrite() { >+ Map parameters1 = createParameters("/testData/nativeTouchpoint/bcFolder/", "aFolder", true); >+ Map safeParameters1 = Collections.unmodifiableMap(parameters1); >+ >+ CopyAction action1 = new CopyAction(); >+ action1.execute(safeParameters1); >+ >+ // Verify that the right file was copied (a b.txt with a C in it [sic]) >+ File target = new File((String) parameters1.get(ActionConstants.PARM_COPY_TARGET)); >+ assertFileContent("copied content C", new File(target, "b.txt"), "C"); // [sic] >+ >+ Map parameters2 = new HashMap(); >+ parameters2.putAll(parameters1); >+ parameters2.put(ActionConstants.PARM_COPY_SOURCE, getTestData("get folder A", "/testData/nativeTouchpoint/aFolder/").getAbsolutePath()); >+ Map safeParameters2 = Collections.unmodifiableMap(parameters2); >+ >+ CopyAction action2 = new CopyAction(); >+ action2.execute(safeParameters2); >+ assertFileContent("copied content A", new File(target, "a.txt"), "A"); >+ assertFileContent("copied content B", new File(target, "b.txt"), "B"); >+ >+ // undo copy of a and b >+ action2.undo(safeParameters2); >+ assertFalse("Target should not exist after undo", target.exists()); >+ } >+ >+ public void testBlockedMergeOverwrite() { >+ Map parameters1 = createParameters("/testData/nativeTouchpoint/bcFolder/", "aFolder", false); >+ Map safeParameters1 = Collections.unmodifiableMap(parameters1); >+ >+ CopyAction action1 = new CopyAction(); >+ action1.execute(safeParameters1); >+ >+ // Verify that the right file was copied (a b.txt with a C in it [sic]) >+ File target = new File((String) parameters1.get(ActionConstants.PARM_COPY_TARGET)); >+ assertFileContent("copied content B", new File(target, "b.txt"), "C"); // [sic] >+ >+ Map parameters2 = new HashMap(); >+ parameters2.putAll(parameters1); >+ parameters2.put(ActionConstants.PARM_COPY_SOURCE, getTestData("get folder A", "/testData/nativeTouchpoint/aFolder/").getAbsolutePath()); >+ Map safeParameters2 = Collections.unmodifiableMap(parameters2); >+ >+ CopyAction action2 = new CopyAction(); >+ assertFalse("Overwrite of b.txt should not succeed", action2.execute(safeParameters2).isOK()); >+ assertFileContent("copied content B", new File(target, "b.txt"), "C"); // [sic] >+ >+ } >+ >+ public void testOverwrite() { >+ Map parameters = createParameters("/testData/nativeTouchpoint/aFolder/a.txt", "a.txt", true); >+ Map safeParameters = Collections.unmodifiableMap(parameters); >+ >+ File source = new File((String) parameters.get(ActionConstants.PARM_COPY_SOURCE)); >+ File target = new File((String) parameters.get(ActionConstants.PARM_COPY_TARGET)); >+ >+ // test an overwrite - by first copying the b file >+ copy("2.0", getTestData("1.0", "/testData/nativeTouchpoint/aFolder/b.txt"), target); >+ >+ CopyAction action = new CopyAction(); >+ action.execute(safeParameters); >+ // Verify that the right file was copied >+ assertFileContent("copied content", target, "A"); >+ // and that we did nothing bad to the source >+ assertFileContent("source content", source, "A"); >+ >+ assertTrue("copy action status", action.undo(safeParameters).isOK()); >+ assertFalse("Target should be removed after undo", target.exists()); >+ } >+ >+ public void testBlockedOverwrite() { >+ Map parameters = createParameters("/testData/nativeTouchpoint/aFolder/a.txt", "a.txt", false); >+ Map safeParameters = Collections.unmodifiableMap(parameters); >+ >+ File source = new File((String) parameters.get(ActionConstants.PARM_COPY_SOURCE)); >+ File target = new File((String) parameters.get(ActionConstants.PARM_COPY_TARGET)); >+ >+ // test an overwrite - by first copying the b file >+ copy("2.0", getTestData("1.0", "/testData/nativeTouchpoint/aFolder/b.txt"), target); >+ >+ CopyAction action = new CopyAction(); >+ assertFalse("copy action status", action.execute(safeParameters).isOK()); >+ >+ // Verify that nothing was copied >+ assertFileContent("original content", target, "B"); >+ // and that we did nothing bad to the source >+ assertFileContent("source content", source, "A"); >+ >+ // there is nothing to undo - the B file should still be there >+ action.undo(safeParameters); >+ assertTrue("Target should remain after undo", target.exists()); >+ assertFileContent("original content", target, "B"); >+ } >+ >+ /* >+ * TODO: testing of the following >+ * - copy of directory - check that it merges >+ * - copy of directory with overwrite false/true >+ */ >+ private Map createParameters(String sourceName, String targetName, boolean overwrite) { >+ Properties profileProperties = new Properties(); >+ File installFolder = getTempFolder(); >+ profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.toString()); >+ IProfile profile = createProfile("test", null, profileProperties); >+ >+ File source = getTestData("1.0", sourceName); >+ File target = new File(installFolder, targetName); >+ >+ InstallableUnitDescription iuDesc = new MetadataFactory.InstallableUnitDescription(); >+ iuDesc.setId("test"); >+ iuDesc.setVersion(DEFAULT_VERSION); >+ IArtifactKey key = PublisherHelper.createBinaryArtifactKey("test", DEFAULT_VERSION); >+ iuDesc.setArtifacts(new IArtifactKey[] {key}); >+ iuDesc.setTouchpointType(PublisherHelper.TOUCHPOINT_NATIVE); >+ IInstallableUnit iu = MetadataFactory.createInstallableUnit(iuDesc); >+ >+ Map parameters = new HashMap(); >+ parameters.put(ActionConstants.PARM_PROFILE, profile); >+ parameters.put(InstallableUnitPhase.PARM_ARTIFACT_REQUESTS, new ArrayList()); >+ InstallableUnitOperand operand = new InstallableUnitOperand(null, iu); >+ parameters.put("iu", operand.second()); >+ parameters.put(ActionConstants.PARM_OPERAND, operand); >+ parameters.put(ActionConstants.PARM_PROFILE, profile); >+ >+ NativeTouchpoint touchpoint = new NativeTouchpoint(); >+ touchpoint.initializePhase(null, profile, "test", parameters); >+ >+ parameters.put(ActionConstants.PARM_COPY_SOURCE, source.getAbsolutePath()); >+ parameters.put(ActionConstants.PARM_COPY_TARGET, target.getAbsolutePath()); >+ parameters.put(ActionConstants.PARM_COPY_OVERWRITE, Boolean.toString(overwrite)); >+ return parameters; >+ } >+ >+ /** >+ * Asserts that the first line of text in f equals the content. >+ * @param f >+ * @param content >+ */ >+ public static void assertFileContent(String message, File f, String content) { >+ //try{ >+ BufferedReader reader; >+ try { >+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(f))); >+ String line = reader.readLine(); >+ assertEquals(message, content, line); >+ } catch (FileNotFoundException e) { >+ fail("Getting copy target", e); >+ } catch (IOException e) { >+ fail("reading copy target", e); >+ } >+ } >+} >Index: testData/nativeTouchpoint/xFolder/x.txt >=================================================================== >RCS file: testData/nativeTouchpoint/xFolder/x.txt >diff -N testData/nativeTouchpoint/xFolder/x.txt >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ testData/nativeTouchpoint/xFolder/x.txt 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,2 @@ >+X >+// This x.txt should have the first line being a single X
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 220647
:
123614
| 123617 |
123618