Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 40b53d3e00000ee75bff9858e376c3e71b368fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.eclipse.equinox.p2.tests.planner;

import org.eclipse.equinox.internal.provisional.p2.director.IPlanner;
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

/*******************************************************************************
 * 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
 *******************************************************************************/
public class AbsolutePlanTest extends AbstractProvisioningTest {
	public void testAddAndRemoveIU() {
		IProfile profile = createProfile(getName());
		ProfileChangeRequest pcr = new ProfileChangeRequest(profile);
		pcr.setAbsoluteMode(true);
		IInstallableUnit iuA = createEclipseIU("A");
		pcr.addInstallableUnits(new IInstallableUnit[] {iuA, createEclipseIU("B"), createEclipseIU("C")});
		IPlanner planner = createPlanner();
		IProvisioningPlan plan = planner.getProvisioningPlan(pcr, new ProvisioningContext(), null);
		assertEquals(3, countPlanElements(plan));
		createEngine().perform(plan, null);

		ProfileChangeRequest removeRequest = new ProfileChangeRequest(profile);
		removeRequest.setAbsoluteMode(true);
		removeRequest.removeInstallableUnits(new IInstallableUnit[] {iuA});
		assertEquals(1, countPlanElements(planner.getProvisioningPlan(removeRequest, new ProvisioningContext(), null)));
	}

	public void testAddAndRemoveProperty() {
		IInstallableUnit iuA = createEclipseIU("A");
		IProfile profile = createProfile(getName());

		ProfileChangeRequest pcr = new ProfileChangeRequest(profile);
		pcr.setAbsoluteMode(true);
		pcr.addInstallableUnits(new IInstallableUnit[] {iuA});
		pcr.setInstallableUnitProfileProperty(iuA, "key", "value");

		IPlanner planner = createPlanner();
		IProvisioningPlan plan = planner.getProvisioningPlan(pcr, new ProvisioningContext(), null);
		assertEquals(1, countPlanElements(plan));
		createEngine().perform(plan, null);

		Operand[] ops = plan.getOperands();
		boolean found = false;
		for (int i = 0; i < ops.length; i++) {
			if (ops[i] instanceof InstallableUnitPropertyOperand)
				found = true;
		}
		assertTrue(found);

		ProfileChangeRequest removeRequest = new ProfileChangeRequest(profile);
		removeRequest.setAbsoluteMode(true);
		removeRequest.removeInstallableUnits(new IInstallableUnit[] {iuA});
		removeRequest.removeInstallableUnitProfileProperty(iuA, "key");

		assertEquals(1, countPlanElements(planner.getProvisioningPlan(removeRequest, new ProvisioningContext(), null)));
	}

	public void testAddProperty() {
		IProfile profile = createProfile(getName());

		ProfileChangeRequest pcr = new ProfileChangeRequest(profile);
		pcr.setAbsoluteMode(true);
		pcr.setProfileProperty("foo", "bar");

		IPlanner planner = createPlanner();
		IProvisioningPlan plan = planner.getProvisioningPlan(pcr, new ProvisioningContext(), null);
		createEngine().perform(plan, null);

		assertEquals("bar", getProfileRegistry().getProfile(getName()).getProperty("foo"));
	}
}

Back to the top