summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault (Ericsson)2013-04-16 16:23:23 (EDT)
committerPascal Rapicault2013-04-16 16:23:23 (EDT)
commit7d3a43be3a4fbb04bf9a22453a46af1633d09c1a (patch)
tree27fc6b51f4b71c83be37391bcaecf2daba79b0ea
parentd330aa59060a33bd44ac2fa5a2148c7300fcd0ca (diff)
downloadrt.equinox.p2-7d3a43be3a4fbb04bf9a22453a46af1633d09c1a.zip
rt.equinox.p2-7d3a43be3a4fbb04bf9a22453a46af1633d09c1a.tar.gz
rt.equinox.p2-7d3a43be3a4fbb04bf9a22453a46af1633d09c1a.tar.bz2
Add test for migration from install to install
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AbstractSharedInstallTest.java74
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstall.java72
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstallRealTest.java38
4 files changed, 183 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
index abd7784..7d199e7 100644
--- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
@@ -55,8 +55,7 @@ Require-Bundle: org.eclipse.equinox.frameworkadmin,
org.eclipse.equinox.p2.operations;bundle-version="2.1.0",
org.eclipse.equinox.p2.ui.sdk.scheduler
Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository
-Bundle-RequiredExecutionEnvironment: J2SE-1.5,
- J2SE-1.4
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
Import-Package: javax.xml.parsers,
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AbstractSharedInstallTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AbstractSharedInstallTest.java
index c7cd662..f5bdec0 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AbstractSharedInstallTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AbstractSharedInstallTest.java
@@ -10,6 +10,9 @@
package org.eclipse.equinox.p2.tests.sharedinstall;
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.*;
import java.util.*;
import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry;
import org.eclipse.equinox.p2.tests.reconciler.dropins.AbstractReconcilerTest;
@@ -103,6 +106,10 @@ public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest {
runEclipse("user2", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature1.feature.group", "-repository", getTestRepo()});
}
+ protected void installFeature1InUserWithoutSpecifyingConfiguration() {
+ runEclipse("user2", output, new String[] {"-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature1.feature.group", "-repository", getTestRepo()});
+ }
+
protected void installFeature2InUser() {
runEclipse("user2", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature2.feature.group", "-repository", getTestRepo()});
}
@@ -149,14 +156,56 @@ public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest {
runEclipse("Running eclipse", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-listInstalledRoots"});
}
- protected void executeVerifier(Properties verificationProperties) {
+ protected void executeVerifierWithoutSpecifyingConfiguration(Properties verificationProperties) {
+ realExecuteVerifier(verificationProperties, false);
+ }
+
+ private void realExecuteVerifier(Properties verificationProperties, boolean withConfigFlag) {
File verifierConfig = new File(getTempFolder(), "verification.properties");
try {
writeProperties(verifierConfig, verificationProperties);
} catch (IOException e) {
fail("Failing to write out properties to configure verifier", e);
}
- assertEquals(0, runEclipse("Running verifier", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.tests.verifier.application", "-verifier.properties", verifierConfig.getAbsolutePath(), "-consoleLog"}));
+
+ String[] args = null;
+ if (withConfigFlag)
+ args = new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.tests.verifier.application", "-verifier.properties", verifierConfig.getAbsolutePath(), "-consoleLog"};
+ else
+ args = new String[] {"-application", "org.eclipse.equinox.p2.tests.verifier.application", "-verifier.properties", verifierConfig.getAbsolutePath(), "-consoleLog"};;
+
+ assertEquals(0, runEclipse("Running verifier", output, args));
+ }
+
+ protected void executeVerifier(Properties verificationProperties) {
+ realExecuteVerifier(verificationProperties, true);
+ }
+
+ protected void reallyReadOnly(File folder) {
+ try {
+ Path path = folder.toPath();
+ AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);
+ AclEntry newEntry = AclEntry.newBuilder().setFlags(AclEntryFlag.FILE_INHERIT, AclEntryFlag.DIRECTORY_INHERIT).setPermissions(AclEntryPermission.WRITE_DATA, AclEntryPermission.APPEND_DATA, AclEntryPermission.WRITE_NAMED_ATTRS, AclEntryPermission.WRITE_ATTRIBUTES).setPrincipal(view.getOwner()).setType(AclEntryType.DENY).build();
+
+ List<AclEntry> acl = view.getAcl();
+ acl.add(0, newEntry); // insert before any DENY entries
+ view.setAcl(acl);
+ } catch (IOException e) {
+ fail("oh shit");
+ }
+ }
+
+ protected void removeReallyReadOnly(File folder) {
+ try {
+ Path path = folder.toPath();
+ AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);
+
+ List<AclEntry> acl = view.getAcl();
+ acl.remove(0);
+ view.setAcl(acl);
+ } catch (IOException e) {
+ fail("oh shit");
+ }
}
public static Properties loadProperties(File inputFile) throws FileNotFoundException, IOException {
@@ -206,4 +255,25 @@ public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest {
super(name);
}
+ public void replaceDotEclipseProductFile(File base, String id, String version) {
+ File eclipseProductFile = new File(base, ".eclipseproduct");
+ eclipseProductFile.delete();
+
+ Properties newProps = new Properties();
+ newProps.put("id", id);
+ newProps.put("version", version);
+ OutputStream os = null;
+ try {
+ try {
+ os = new FileOutputStream(eclipseProductFile);
+ newProps.save(os, "file generated for tests " + getName());
+ } finally {
+ if (os != null)
+ os.close();
+ }
+ } catch (IOException e) {
+ fail("Failing setting up the .eclipseproduct file at:" + eclipseProductFile.getAbsolutePath());
+ }
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstall.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstall.java
new file mode 100644
index 0000000..527eeff
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstall.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson AB 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:
+ * Ericsson AB - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.p2.tests.sharedinstall;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite;
+
+//This test verifies that when eclipse runs for the first time and it has been run previously, then the migration wizard is presented.
+
+//This test is separated in two classes.
+//This class is responsible for setting up eclipse once
+//The second class (InitialSharedInstallReadTest) is responsible for carrying out the real test
+//The test is setup this way in order to reuse all the testing infrastructure without having the modify much of it.
+public class InitialSharedInstall extends AbstractSharedInstallTest {
+
+ public static Test suite() {
+ TestSuite suite = new ReconcilerTestSuite();
+ suite.setName(InitialSharedInstall.class.getName());
+ suite.addTest(new InitialSharedInstall("setupRun"));
+
+ TestSuite suite2 = new ReconcilerTestSuite();
+ suite2.addTest(new InitialSharedInstallRealTest("testImportFromPreviousInstall"));
+
+ suite.addTest(suite2);
+ return suite;
+ }
+
+ public InitialSharedInstall(String name) {
+ super(name);
+ }
+
+ public void setupRun() {
+ cleanupDotEclipseFolder();
+ assertInitialized();
+ replaceDotEclipseProductFile(new File(output, "eclipse"), "p2.automated.test", "1.0.0");
+ setupReadOnlyInstall();
+ reallyReadOnly(readOnlyBase);
+ System.out.println(readOnlyBase);
+ System.out.println(userBase);
+
+ {
+ //This causes an installation of Eclipse to be created in the default location (~/.eclipse/...)
+ installFeature1InUserWithoutSpecifyingConfiguration();
+ }
+ removeReallyReadOnly(readOnlyBase);
+ }
+
+ private void cleanupDotEclipseFolder() {
+ File userHome = new File(System.getProperty("user.home"));
+ File dotEclipse = new File(userHome, ".eclipse");
+ File[] toDelete = dotEclipse.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ if (name.startsWith("p2.automated.test"))
+ return true;
+ return false;
+ }
+ });
+ for (int i = 0; i < toDelete.length; i++) {
+ delete(toDelete[i]);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstallRealTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstallRealTest.java
new file mode 100644
index 0000000..c945b3b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InitialSharedInstallRealTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson AB 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:
+ * Ericsson AB - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.p2.tests.sharedinstall;
+
+import java.io.File;
+import java.util.Properties;
+
+//See InitialSharedInstall
+public class InitialSharedInstallRealTest extends AbstractSharedInstallTest {
+
+ public InitialSharedInstallRealTest(String name) {
+ super(name);
+ }
+
+ public void testImportFromPreviousInstall() {
+ assertInitialized();
+ replaceDotEclipseProductFile(new File(output, "eclipse"), "p2.automated.test", "1.0.1");
+ installVerifierInBase();
+ setupReadOnlyInstall();
+ reallyReadOnly(readOnlyBase);
+ System.out.println(readOnlyBase);
+ System.out.println(userBase);
+
+ //Run the verifier in read only mode to ensure that the wizard opens up
+ Properties verificationProperties = new Properties();
+ verificationProperties.setProperty("checkMigrationWizard", "true");
+ verificationProperties.setProperty("checkMigrationWizard.open", "true");
+ executeVerifierWithoutSpecifyingConfiguration(verificationProperties);
+ removeReallyReadOnly(readOnlyBase);
+ }
+}