Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2009-12-22 17:13:28 +0000
committerJohn Arthorne2009-12-22 17:13:28 +0000
commitca010afc13cb919ad766fdc5aaec721b3ed0b6c0 (patch)
treef5a75e04f7289bf91125738926461303ad5d090f
parent2b5dad14302a2cd44a0d96c65a7289c2c200b430 (diff)
downloadrt.equinox.p2-ca010afc13cb919ad766fdc5aaec721b3ed0b6c0.tar.gz
rt.equinox.p2-ca010afc13cb919ad766fdc5aaec721b3ed0b6c0.tar.xz
rt.equinox.p2-ca010afc13cb919ad766fdc5aaec721b3ed0b6c0.zip
Added helpers for setting up fake self profile
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java44
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstance.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstanceForCohostedMode.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInRunningInstance.java31
4 files changed, 46 insertions, 33 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
index 9328dc838..46435c82f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
@@ -79,6 +79,7 @@ public abstract class AbstractProvisioningTest extends TestCase {
protected List profilesToRemove = new ArrayList();
private File testFolder = null;
+ protected Object previousSelfValue = null;
public static void assertEmptyProfile(IProfile profile) {
assertNotNull("The profile should not be null", profile);
@@ -1446,4 +1447,47 @@ public abstract class AbstractProvisioningTest extends TestCase {
public int countPlanElements(IProvisioningPlan plan) {
return queryResultSize(new CompoundQueryable(new IQueryable[] {plan.getAdditions(), plan.getRemovals()}).query(InstallableUnitQuery.ANY, null));
}
+
+ /**
+ * This method is used by tests that require access to the "self" profile. It spoofs
+ * up a fake self profile is none is already available. Tests should invoke this method
+ * from their {@link #setUp()} method, and invoke {@link #tearDownSelfProfile()}
+ * from their {@link #tearDown()} method.
+ */
+ protected void setUpSelfProfile() {
+ if (System.getProperty("eclipse.p2.profile") == null) {
+ SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) getProfileRegistry();
+ try {
+ Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$
+ selfField.setAccessible(true);
+ previousSelfValue = selfField.get(profileRegistry);
+ if (previousSelfValue == null)
+ selfField.set(profileRegistry, "agent");
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+ createProfile("agent");
+ }
+
+ /**
+ * This method is used by tests that require access to the "self" profile. It cleans up
+ * a fake self profile is none is already available. Tests should invoke this method
+ * from their {@link #tearDown()} method, and invoke {@link #setUpSelfProfile()}
+ * from their {@link #setUp()} method.
+ */
+ protected void tearDownSelfProfile() {
+ if (System.getProperty("eclipse.p2.profile") == null) {
+ SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) getProfileRegistry();
+ try {
+ Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$
+ selfField.setAccessible(true);
+ Object self = selfField.get(profileRegistry);
+ if (self.equals("agent"))
+ selfField.set(profileRegistry, previousSelfValue);
+ } catch (Throwable t) {
+ // ignore as we still want to continue tidying up
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstance.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstance.java
index ee82c37f4..657021487 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstance.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstance.java
@@ -23,8 +23,6 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
public class AgentPlanTestInExternalInstance extends AbstractProvisioningTest {
- Object previousSelfValue;
-
public void setUp() throws Exception {
super.setUp();
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstanceForCohostedMode.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstanceForCohostedMode.java
index 8dfab3212..4170638a1 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstanceForCohostedMode.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInExternalInstanceForCohostedMode.java
@@ -23,8 +23,6 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
public class AgentPlanTestInExternalInstanceForCohostedMode extends AbstractProvisioningTest {
- Object previousSelfValue = null;
-
public void setUp() throws Exception {
super.setUp();
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInRunningInstance.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInRunningInstance.java
index 000fcc143..e3ed39091 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInRunningInstance.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AgentPlanTestInRunningInstance.java
@@ -8,10 +8,8 @@
******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;
-import java.lang.reflect.Field;
import java.net.URI;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.provisional.p2.director.*;
import org.eclipse.equinox.internal.provisional.p2.metadata.*;
@@ -22,8 +20,6 @@ import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
public class AgentPlanTestInRunningInstance extends AbstractProvisioningTest {
private IProfile initialProfile = null;
- private Object previousSelfValue = null;
-
public void setUp() throws Exception {
super.setUp();
@@ -31,35 +27,12 @@ public class AgentPlanTestInRunningInstance extends AbstractProvisioningTest {
if (initialProfile != null)
return;
- if (System.getProperty("eclipse.p2.profile") == null) {
- SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) getProfileRegistry();
- try {
- Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$
- selfField.setAccessible(true);
- previousSelfValue = selfField.get(profileRegistry);
- if (previousSelfValue == null)
- selfField.set(profileRegistry, "agent");
- } catch (Throwable t) {
- fail();
- }
- }
- createProfile("agent");
+ setUpSelfProfile();
}
public void tearDown() throws Exception {
if (initialProfile == null) {
- if (System.getProperty("eclipse.p2.profile") == null) {
- SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) getProfileRegistry();
- try {
- Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$
- selfField.setAccessible(true);
- Object self = selfField.get(profileRegistry);
- if (self.equals("agent"))
- selfField.set(profileRegistry, previousSelfValue);
- } catch (Throwable t) {
- // ignore as we still want to continue tidying up
- }
- }
+ tearDownSelfProfile();
} else {
//After the test we clean up the profile
IProfile profileAfterTestRun = getProfile(IProfileRegistry.SELF);

Back to the top