diff options
author | Pascal Rapicault (Ericsson) | 2013-02-06 01:47:52 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-02-06 01:47:52 +0000 |
commit | 725d65da2ca10bacb503ca3a689f1582dece86c7 (patch) | |
tree | 3bd937cbe12bdaad6fd47d0f56a3ca7cfc6e7c2b | |
parent | daacdc430d00d136bc1eec1706275a07b8cc46be (diff) | |
download | rt.equinox.p2-725d65da2ca10bacb503ca3a689f1582dece86c7.tar.gz rt.equinox.p2-725d65da2ca10bacb503ca3a689f1582dece86c7.tar.xz rt.equinox.p2-725d65da2ca10bacb503ca3a689f1582dece86c7.zip |
Separate tests in different classes.v20130206-014752
23 files changed, 393 insertions, 233 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java b/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java index 0c53a5489..a6aeb9ac9 100644 --- a/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java +++ b/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2013 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 @@ -7,11 +7,13 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Ericsson AB - Ongoing development *******************************************************************************/ package org.eclipse.equinox.internal.p2.tests.verifier; import java.io.*; import java.util.*; +import java.util.Map.Entry; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.internal.adaptor.EclipseAdaptorMsg; import org.eclipse.core.runtime.internal.adaptor.MessageHelper; @@ -316,6 +318,35 @@ public class VerifierApplication implements IApplication { if (!temp.isOK()) result.merge(temp); + temp = checkSystemProperties(); + if (!temp.isOK()) + result.merge(temp); + + return result; + } + + private IStatus checkSystemProperties() { + final String ABSENT_SYS_PROPERTY = "not.sysprop."; + final String PRESENT_SYS_PROPERTY = "sysprop."; + MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "System properties validation", null); + + Set<Entry<Object, Object>> entries = properties.entrySet(); + for (Entry<Object, Object> entry : entries) { + String key = (String) entry.getKey(); + if (key.startsWith(ABSENT_SYS_PROPERTY)) { + String property = key.substring(ABSENT_SYS_PROPERTY.length()); + if (System.getProperty(property) != null) + result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Property " + property + " should not be set.")); + } + if (key.startsWith(PRESENT_SYS_PROPERTY)) { + String property = key.substring(PRESENT_SYS_PROPERTY.length()); + String foundValue = System.getProperty(property); + if (!entry.getValue().equals(foundValue)) + result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Property " + property + " should be set to " + entry.getValue() + " and is set to " + foundValue + ".")); + } + } + if (result.getChildren().length == 0) + return Status.OK_STATUS; return result; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java index bbc028190..8f530f008 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractReconcilerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 IBM Corporation and others. + * Copyright (c) 2008, 2013 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Ericsson AB - Ongoing development *******************************************************************************/ package org.eclipse.equinox.p2.tests.reconciler.dropins; @@ -43,6 +44,7 @@ public class AbstractReconcilerTest extends AbstractProvisioningTest { private static Properties archiveAndRepositoryProperties = null; private String propertyToPlatformArchive; + private boolean debug = false; static { loadPlatformZipPropertiesFromFile(); @@ -618,7 +620,8 @@ public class AbstractReconcilerTest extends AbstractProvisioningTest { Collections.addAll(command, args); Collections.addAll(command, new String[] {"-vmArgs", "-Dosgi.checkConfiguration=true"}); // command-line if you want to run and allow a remote debugger to connect - //Collections.addAll(command, new String[] {"-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787"}); + if (debug) + Collections.addAll(command, new String[] {"-Xdebug", "-Xnoagent", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787"}); int result = run(message, command.toArray(new String[command.size()])); // 13 means that we wrote something out in the log file. // so try and parse it and fail via that message if we can. @@ -627,6 +630,10 @@ public class AbstractReconcilerTest extends AbstractProvisioningTest { return result; } + protected void debugEclipse(boolean on) { + this.debug = on; + } + private void parseExitdata(String message) { // if the exit data contains a message telling us the location of the log file, then get it String data = TestActivator.getContext().getProperty("eclipse.exitdata"); 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 18cc8382c..5a5a5b792 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 @@ -5,14 +5,14 @@ * available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Ericsson AB - ongoing development + * Ericsson AB - initial API and implementation ******************************************************************************/ package org.eclipse.equinox.p2.tests.sharedinstall; -import org.eclipse.equinox.p2.tests.reconciler.dropins.AbstractReconcilerTest; - import java.io.*; -import java.util.Properties; +import java.util.*; +import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; +import org.eclipse.equinox.p2.tests.reconciler.dropins.AbstractReconcilerTest; public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest { static final boolean WINDOWS = java.io.File.separatorChar == '\\'; @@ -24,6 +24,118 @@ public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest { return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); } + protected String getTestRepo() { + return getTestData("repo for shared install tests", "testData/sharedInstall/repo").toURI().toString(); + } + + protected File getUserBundleInfoTimestamp() { + return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/.baseBundlesInfoTimestamp"); + } + + protected File getUserProfileRegistryFolder() { + return new File(userBase, "p2/org.eclipse.equinox.p2.engine/profileRegistry/"); + } + + protected File getUserProfileFolder() { + return new File(getUserProfileRegistryFolder(), profileId + ".profile"); + } + + protected File getBaseProfileRegistryFolder() { + return new File(output, "eclipse/p2/org.eclipse.equinox.p2.engine/profileRegistry/"); + } + + protected long[] getProfileTimestampsFromUser() { + return new SimpleProfileRegistry(getAgent(), getUserProfileRegistryFolder()).listProfileTimestamps(profileId); + } + + protected long getMostRecentProfileTimestamp(File profileFolder) { + long[] ts = new SimpleProfileRegistry(getAgent(), profileFolder).listProfileTimestamps(profileId); + return ts[ts.length - 1]; + } + + protected long getMostRecentProfileTimestampFromBase() { + return getMostRecentProfileTimestamp(getBaseProfileRegistryFolder()); + } + + protected void assertProfileStatePropertiesHasValue(File profileFolder, String value) { + try { + Properties p = loadProperties(new File(profileFolder, "state.properties")); + Collection<Object> values = p.values(); + for (Object v : values) { + if (((String) v).contains(value)) { + return; + } + } + fail("Value: " + value + " not found."); + } catch (IOException e) { + fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); + } + + } + + protected File getConfigIniTimestamp() { + return new File(userBase, "configuration/.baseConfigIniTimestamp"); + } + + protected void assertProfileStatePropertiesHasKey(File profileFolder, String key) { + try { + Properties p = loadProperties(new File(profileFolder, "state.properties")); + Set<Object> keys = p.keySet(); + for (Object k : keys) { + if (((String) k).contains(key)) { + return; + } + } + fail("Key: " + key + " not found."); + } catch (IOException e) { + fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); + } + + } + + protected void installInUser() { + //TODO Install something into eclipse - make sure that this can be done in an automated setup + runEclipse("Installing in user", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature1.feature.group,Verifier.feature.group", "-repository", getTestRepo()}); + } + + protected void installInUser2() { + 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()}); + } + + protected void installVerifierInBase() { + setReadOnly(readOnlyBase, false); + runEclipse("Running eclipse", output, new String[] {"-application", "org.eclipse.equinox.p2.director", "-installIU", "Verifier.feature.group", "-repository", getTestRepo()}); + setReadOnly(readOnlyBase, true); + } + + protected boolean isInUserBundlesInfo(String bundleId) { + try { + return isInBundlesInfo(getUserBundlesInfo(), bundleId, null, null); + } catch (IOException e) { + fail("Problem reading bundles.info"); + } + //should never be reached + return false; + } + + protected File getUserBundlesInfo() { + return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); + } + + protected void startEclipseAsUser() { + runEclipse("Running eclipse", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.garbagecollector.application", "-profile", "_SELF_"}); + } + + protected void executeVerifier(Properties verificationProperties) { + 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"})); + } + public static Properties loadProperties(File inputFile) throws FileNotFoundException, IOException { Properties props = new Properties(); InputStream is = null; diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AllTests.java index df6e1f847..a85e3a6f5 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/AllTests.java @@ -5,7 +5,7 @@ * available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Ericsson AB - ongoing development + * Ericsson AB - initial API and implementation ******************************************************************************/ package org.eclipse.equinox.p2.tests.sharedinstall; @@ -21,7 +21,10 @@ import junit.framework.*; public class AllTests extends TestCase { public static Test suite() { TestSuite suite = new TestSuite(AllTests.class.getName()); - suite.addTest(SharedInstallEnd2End.suite()); + suite.addTest(BaseChange.suite()); + suite.addTest(BaseChangeWithoutUserChange.suite()); + suite.addTest(InstallInUserSpace.suite()); + suite.addTest(TestInitialRun.suite()); return suite; } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChange.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChange.java new file mode 100644 index 000000000..826799c9c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChange.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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.util.Properties; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite; + +public class BaseChange extends AbstractSharedInstallTest { + + public static Test suite() { + TestSuite suite = new ReconcilerTestSuite(); + suite.setName(BaseChange.class.getName()); + suite.addTest(new BaseChange("testBaseChange")); + return suite; + } + + public BaseChange(String name) { + super(name); + } + + public void testBaseChange() { + assertInitialized(); + setupReadOnlyInstall(); + System.out.println(readOnlyBase); + System.out.println(userBase); + + { //install verifier and something else in user and checks there are there + installInUser(); + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("expectedBundleList", "p2TestBundle1,org.eclipse.equinox.p2.tests.verifier"); + verificationProperties.setProperty("checkProfileResetFlag", "false"); + verificationProperties.setProperty("not.sysprop.eclipse.ignoreUserConfiguration", ""); + executeVerifier(verificationProperties); + + assertTrue(isInUserBundlesInfo("p2TestBundle1")); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } + + { //Now change the base. Install the verifier and something else in the base, and run the verifier as a user + installVerifierInBase(); + + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("unexpectedBundleList", "p2TestBundle1"); + verificationProperties.setProperty("checkPresenceOfVerifier", "false"); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + verificationProperties.setProperty("checkProfileResetFlag", "true"); + verificationProperties.setProperty("sysprop.eclipse.ignoreUserConfiguration", "profileFlushed"); + executeVerifier(verificationProperties); + assertTrue(isInUserBundlesInfo("p2TestBundle1")); //Despite the reset, the bundles.info is still on-disk unmodified since no provisioning has been done + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + + verificationProperties = new Properties(); + //Execute the verifier another time, to check that the profile reset flag is not set + verificationProperties.setProperty("checkProfileResetFlag", "false"); + verificationProperties.setProperty("checkPresenceOfVerifier", "false"); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + executeVerifier(verificationProperties); + } + + { //Now add something into the user install again + installInUser2(); + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + executeVerifier(verificationProperties); + assertTrue(isInUserBundlesInfo("p2TestBundle2")); + assertTrue(isInUserBundlesInfo("org.eclipse.equinox.p2.tests.verifier")); //It is now coming from the base + assertFalse(isInUserBundlesInfo("p2TestBundle1")); + + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChangeWithoutUserChange.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChangeWithoutUserChange.java new file mode 100644 index 000000000..4260b0cad --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/BaseChangeWithoutUserChange.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.util.Properties; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite; + +public class BaseChangeWithoutUserChange extends AbstractSharedInstallTest { + + public static Test suite() { + TestSuite suite = new ReconcilerTestSuite(); + suite.setName(BaseChangeWithoutUserChange.class.getName()); + suite.addTest(new BaseChangeWithoutUserChange("testBaseChangeWithoutUserChange")); + return suite; + } + + public BaseChangeWithoutUserChange(String name) { + super(name); + } + + public void testBaseChangeWithoutUserChange() { + assertInitialized(); + setupReadOnlyInstall(); + System.out.println(readOnlyBase); + System.out.println(userBase); + + { + //Run Eclipse a first time to have the user profile created + startEclipseAsUser(); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } + + { //Change the base and then verify + installVerifierInBase(); + + assertFalse(getUserBundleInfo().exists()); + assertFalse(getUserBundleInfoTimestamp().exists()); + + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("unexpectedBundleList", "p2TestBundle1"); + verificationProperties.setProperty("checkPresenceOfVerifier", "false"); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + verificationProperties.setProperty("checkProfileResetFlag", "true"); + executeVerifier(verificationProperties); + + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InstallInUserSpace.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InstallInUserSpace.java new file mode 100644 index 000000000..37c442f96 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/InstallInUserSpace.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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 junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite; + +public class InstallInUserSpace extends AbstractSharedInstallTest { + + public static Test suite() { + TestSuite suite = new ReconcilerTestSuite(); + suite.setName(InstallInUserSpace.class.getName()); + suite.addTest(new InstallInUserSpace("testInstallInUserSpace")); + return suite; + } + + public InstallInUserSpace(String name) { + super(name); + } + + public void testInstallInUserSpace() { + assertInitialized(); + setupReadOnlyInstall(); + System.out.println(readOnlyBase); + System.out.println(userBase); + + installInUser(); + assertTrue(isInUserBundlesInfo("p2TestBundle1")); + assertTrue(isInUserBundlesInfo("org.eclipse.swt")); //this verifies that we have the bundles from the base installed in the user bundles.info + + assertTrue(getUserBundleInfoTimestamp().exists()); + assertTrue(getConfigIniTimestamp().exists()); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); + assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + assertEquals(3, getProfileTimestampsFromUser().length); + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/SharedInstallEnd2End.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/SharedInstallEnd2End.java deleted file mode 100644 index dba22dd18..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/SharedInstallEnd2End.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * 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 - ongoing development - ******************************************************************************/ -package org.eclipse.equinox.p2.tests.sharedinstall; - -import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; -import org.eclipse.equinox.p2.engine.IProfile; - -public class SharedInstallEnd2End extends AbstractSharedInstallTest { - public static Test suite() { - TestSuite suite = new ReconcilerTestSuite(); - suite.setName(SharedInstallEnd2End.class.getName()); - suite.addTest(new SharedInstallEnd2End("testInitialRun")); - suite.addTest(new SharedInstallEnd2End("testInstallInUserSpace")); - suite.addTest(new SharedInstallEnd2End("testBaseChange")); - return suite; - } - - public SharedInstallEnd2End(String name) { - super(name); - } - - private String getTestRepo() { - return getTestData("repo for shared install tests", "testData/sharedInstall/repo").toURI().toString(); - } - - private File getUserBundleInfoTimestamp() { - return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/.baseBundlesInfoTimestamp"); - } - - protected File getUserProfileRegistryFolder() { - return new File(userBase, "p2/org.eclipse.equinox.p2.engine/profileRegistry/"); - } - - private File getUserProfileFolder() { - return new File(getUserProfileRegistryFolder(), profileId + ".profile"); - } - - private File getBaseProfileRegistryFolder() { - return new File(output, "eclipse/p2/org.eclipse.equinox.p2.engine/profileRegistry/"); - } - - private long[] getProfileTimestampsFromUser() { - return new SimpleProfileRegistry(getAgent(), getUserProfileRegistryFolder()).listProfileTimestamps(profileId); - } - - private long getMostRecentProfileTimestamp(File profileFolder) { - long[] ts = new SimpleProfileRegistry(getAgent(), profileFolder).listProfileTimestamps(profileId); - return ts[ts.length - 1]; - } - - private long getMostRecentProfileTimestampFromBase() { - return getMostRecentProfileTimestamp(getBaseProfileRegistryFolder()); - } - - private void assertProfileStatePropertiesHasValue(File profileFolder, String value) { - try { - Properties p = loadProperties(new File(profileFolder, "state.properties")); - Collection<Object> values = p.values(); - for (Object v : values) { - if (((String) v).contains(value)) { - return; - } - } - fail("Value: " + value + " not found."); - } catch (IOException e) { - fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); - } - - } - - private File getConfigIniTimestamp() { - return new File(userBase, "configuration/.baseConfigIniTimestamp"); - } - - private void assertProfileStatePropertiesHasKey(File profileFolder, String key) { - try { - Properties p = loadProperties(new File(profileFolder, "state.properties")); - Set<Object> keys = p.keySet(); - for (Object k : keys) { - if (((String) k).contains(key)) { - return; - } - } - fail("Key: " + key + " not found."); - } catch (IOException e) { - fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); - } - - } - - private void installInUser() { - //TODO Install something into eclipse - make sure that this can be done in an automated setup - runEclipse("Installing in user", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature1.feature.group,Verifier.feature.group", "-repository", getTestRepo()}); - } - - private void installInUser2() { - 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()}); - } - - private void installVerifierInBase() { - setReadOnly(readOnlyBase, false); - runEclipse("Running eclipse", output, new String[] {"-application", "org.eclipse.equinox.p2.director", "-installIU", "Verifier.feature.group", "-repository", getTestRepo()}); - setReadOnly(readOnlyBase, true); - } - - private boolean isInUserBundlesInfo(String bundleId) { - try { - return isInBundlesInfo(getUserBundlesInfo(), bundleId, null, null); - } catch (IOException e) { - fail("Problem reading bundles.info"); - } - //should never be reached - return false; - } - - private File getUserBundlesInfo() { - return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); - } - - private void startEclipseAsUser() { - runEclipse("Running eclipse", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.garbagecollector.application", "-profile", "_SELF_"}); - } - - public void testInitialRun() { - assertInitialized(); - setupReadOnlyInstall(); - //Here we are invoking the GC to force the profile to be loaded. - startEclipseAsUser(); - assertFalse(getUserBundleInfo().exists()); - assertFalse(getUserBundleInfoTimestamp().exists()); - assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); - assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); - assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); - } - - public void testInstallInUserSpace() { - assertInitialized(); - setupReadOnlyInstall(); - - installInUser(); - assertTrue(isInUserBundlesInfo("p2TestBundle1")); - assertTrue(isInUserBundlesInfo("org.eclipse.swt")); //this verifies that we have the bundles from the base installed in the user bundles.info - - assertTrue(getUserBundleInfoTimestamp().exists()); - assertTrue(getConfigIniTimestamp().exists()); - assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); - assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); - assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); - assertEquals(3, getProfileTimestampsFromUser().length); - } - - public void testBaseChange() { - assertInitialized(); - setupReadOnlyInstall(); - System.out.println(readOnlyBase); - System.out.println(userBase); - - { //install verifier and something else in user and checks there are there - installInUser(); - Properties verificationProperties = new Properties(); - verificationProperties.setProperty("expectedBundleList", "p2TestBundle1,org.eclipse.equinox.p2.tests.verifier"); - verificationProperties.setProperty("checkProfileResetFlag", "false"); - executeVerifier(verificationProperties); - - assertTrue(isInUserBundlesInfo("p2TestBundle1")); - assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); - } - - { //Now change the base. Install the verifier and something else in the base, and run the verifier as a user - installVerifierInBase(); - - Properties verificationProperties = new Properties(); - verificationProperties.setProperty("unexpectedBundleList", "p2TestBundle1"); - verificationProperties.setProperty("checkPresenceOfVerifier", "false"); - verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); - verificationProperties.setProperty("checkProfileResetFlag", "true"); - executeVerifier(verificationProperties); - assertTrue(isInUserBundlesInfo("p2TestBundle1")); //Despite the reset, the bundles.info is still on-disk unmodified since no provisioning has been done - assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); - - verificationProperties = new Properties(); - //Execute the verifier another time, to check that the profile reset flag is not set - verificationProperties.setProperty("checkProfileResetFlag", "false"); - verificationProperties.setProperty("checkPresenceOfVerifier", "false"); - verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); - executeVerifier(verificationProperties); - } - - { //Now add something into the user install again - installInUser2(); - Properties verificationProperties = new Properties(); - verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); - executeVerifier(verificationProperties); - assertTrue(isInUserBundlesInfo("p2TestBundle2")); - assertTrue(isInUserBundlesInfo("org.eclipse.equinox.p2.tests.verifier")); //It is now coming from the base - assertFalse(isInUserBundlesInfo("p2TestBundle1")); - - } - } - - private void executeVerifier(Properties verificationProperties) { - 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"})); - } -} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/TestInitialRun.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/TestInitialRun.java new file mode 100644 index 000000000..cc381bb72 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/sharedinstall/TestInitialRun.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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 junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.tests.reconciler.dropins.ReconcilerTestSuite; + +public class TestInitialRun extends AbstractSharedInstallTest { + + public static Test suite() { + TestSuite suite = new ReconcilerTestSuite(); + suite.setName(TestInitialRun.class.getName()); + suite.addTest(new TestInitialRun("testInitialRun")); + return suite; + } + + public TestInitialRun(String name) { + super(name); + } + + public void testInitialRun() { + assertInitialized(); + setupReadOnlyInstall(); + System.out.println(readOnlyBase); + System.out.println(userBase); + + //Here we are invoking the GC to force the profile to be loaded. + startEclipseAsUser(); + assertFalse(getUserBundleInfo().exists()); + assertFalse(getUserBundleInfoTimestamp().exists()); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); + assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar Binary files differindex c19f0b317..644d1e9b8 100644 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar Binary files differindex 217ce912c..24f403c07 100644 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar Binary files differdeleted file mode 100644 index b60bf6b9a..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302052031.jar Binary files differnew file mode 100644 index 000000000..1b293696f --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302052031.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar Binary files differdeleted file mode 100644 index 427842b21..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302052031.jar Binary files differnew file mode 100644 index 000000000..4bea822fe --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302052031.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar Binary files differdeleted file mode 100644 index cf3aa866a..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302052031.jar Binary files differnew file mode 100644 index 000000000..a927cda31 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302052031.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar Binary files differdeleted file mode 100644 index ed56eac95..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302052031.jar Binary files differnew file mode 100644 index 000000000..b5054dad6 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302052031.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar Binary files differdeleted file mode 100644 index 51e68eddf..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302052031.jar Binary files differnew file mode 100644 index 000000000..54f26ea79 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302052031.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar Binary files differdeleted file mode 100644 index 3842472b3..000000000 --- a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar +++ /dev/null diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302052031.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302052031.jar Binary files differnew file mode 100644 index 000000000..9e7ea65de --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302052031.jar |