Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2002e85dd4f6a9d47c2de92a47ca9560dac2c2b0 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*******************************************************************************
 * Copyright (c) 2008 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
 ******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;

import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.provisional.p2.director.*;
import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class InclusionRuleTest extends AbstractProvisioningTest {
	IInstallableUnit a1;
	IInstallableUnit a2;
	IInstallableUnit b1;
	IProfile profile1;
	IProfile profile2;
	IProfile profile3;
	IProfile profile4;
	IPlanner planner;
	IEngine engine;

	protected void setUp() throws Exception {
		super.setUp();
		a1 = createIU("A", Version.create("1.0.0"), true);

		a2 = createIU("A", Version.create("2.0.0"), true);

		b1 = createIU("B", Version.create("1.0.0"), true);

		createTestMetdataRepository(new IInstallableUnit[] {a1, a2});

		planner = createPlanner();
		engine = createEngine();
	}

	public void testMultipleInstallations() {
		profile1 = createProfile("TestProfile." + getName());
		ProfileChangeRequest req = new ProfileChangeRequest(profile1);
		req.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
		assertEquals(IStatus.OK, plan.getStatus().getSeverity());
		engine.perform(plan, null);
		assertProfileContainsAll("A1 is missing", profile1, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile1.query(InstallableUnitQuery.ANY, null)), 1);

		//Make a1 optional.
		ProfileChangeRequest req2 = new ProfileChangeRequest(profile1);
		req2.setInstallableUnitInclusionRules(a1, PlannerHelper.createOptionalInclusionRule(a1));
		IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null);
		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
		engine.perform(plan2, null);
		assertProfileContainsAll("A1 is missing", profile1, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile1.query(InstallableUnitQuery.ANY, null)), 1);

		//Install b1 (this should not change anything for a1)
		ProfileChangeRequest req3 = new ProfileChangeRequest(profile1);
		req3.addInstallableUnits(new IInstallableUnit[] {b1});
		IProvisioningPlan plan3 = planner.getProvisioningPlan(req3, null, null);
		assertEquals(IStatus.OK, plan3.getStatus().getSeverity());
		engine.perform(plan3, null);
		assertProfileContainsAll("A1 or B1 is missing", profile1, new IInstallableUnit[] {a1, b1});
		assertEquals(queryResultSize(profile1.query(InstallableUnitQuery.ANY, null)), 2);

		//Add a2, this removes a1.
		ProfileChangeRequest req4 = new ProfileChangeRequest(profile1);
		req4.addInstallableUnits(new IInstallableUnit[] {a2});
		IProvisioningPlan plan4 = planner.getProvisioningPlan(req4, null, null);
		assertEquals(IStatus.OK, plan4.getStatus().getSeverity());
		engine.perform(plan4, null);
		assertProfileContainsAll("A2 is missing", profile1, new IInstallableUnit[] {a2});
		assertNotIUs(new IInstallableUnit[] {a1}, profile1.query(InstallableUnitQuery.ANY, null).iterator());
		assertEquals(queryResultSize(profile1.query(InstallableUnitQuery.ANY, null)), 2);

		//Try to add a1 again. This will fail because since a1 has been uninstalled in the previous step and we no longer know about its optional inclusion
		ProfileChangeRequest req5 = new ProfileChangeRequest(profile1);
		req5.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan5 = planner.getProvisioningPlan(req5, null, null);
		assertEquals(IStatus.ERROR, plan5.getStatus().getSeverity());
	}

	public void testRemoveInclusionRule() {
		profile2 = createProfile("TestProfile2." + getName());
		//Install a1
		ProfileChangeRequest req = new ProfileChangeRequest(profile2);
		req.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
		assertEquals(IStatus.OK, plan.getStatus().getSeverity());
		engine.perform(plan, null);
		assertProfileContainsAll("A1 is missing", profile2, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile2.query(InstallableUnitQuery.ANY, null)), 1);

		//Make a1 optional.
		ProfileChangeRequest req2 = new ProfileChangeRequest(profile2);
		req2.setInstallableUnitInclusionRules(a1, PlannerHelper.createOptionalInclusionRule(a1));
		IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null);
		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
		engine.perform(plan2, null);
		assertProfileContainsAll("A1 is missing", profile2, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile2.query(InstallableUnitQuery.ANY, null)), 1);

		//Install b1 (this should not change anything for a1)
		ProfileChangeRequest req3 = new ProfileChangeRequest(profile2);
		req3.addInstallableUnits(new IInstallableUnit[] {b1});
		IProvisioningPlan plan3 = planner.getProvisioningPlan(req3, null, null);
		assertEquals(IStatus.OK, plan3.getStatus().getSeverity());
		engine.perform(plan3, null);
		profile2 = getProfile(profile2.getProfileId());
		assertProfileContainsAll("A1 or B1 is missing", profile2, new IInstallableUnit[] {a1, b1});
		assertEquals(queryResultSize(profile2.query(InstallableUnitQuery.ANY, null)), 2);

		//Remove the optional inclusion rule from a1. a1 and b1 are still here 
		ProfileChangeRequest req5 = new ProfileChangeRequest(profile2);
		req5.removeInstallableUnitInclusionRules(a1);
		IProvisioningPlan plan5 = planner.getProvisioningPlan(req5, null, null);
		assertEquals(IStatus.OK, plan5.getStatus().getSeverity());
		engine.perform(plan5, null);
		profile2 = getProfile(profile2.getProfileId());
		assertProfileContainsAll("A1 or B1 is missing", profile2, new IInstallableUnit[] {a1, b1});
		assertEquals(queryResultSize(profile2.query(InstallableUnitQuery.ANY, null)), 2);
	}

	public void testRemoveIUandInclusionRule() {
		profile3 = createProfile("TestProfile3." + getName());
		ProfileChangeRequest req = new ProfileChangeRequest(profile3);
		req.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
		assertEquals(IStatus.OK, plan.getStatus().getSeverity());
		engine.perform(plan, null);
		assertProfileContainsAll("A1 is missing", profile3, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile3.query(InstallableUnitQuery.ANY, null)), 1);

		//Make a1 optional.
		ProfileChangeRequest req2 = new ProfileChangeRequest(profile3);
		req2.setInstallableUnitInclusionRules(a1, PlannerHelper.createOptionalInclusionRule(a1));
		IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null);
		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
		engine.perform(plan2, null);
		assertProfileContainsAll("A1 is missing", profile3, new IInstallableUnit[] {a1});
		assertEquals(queryResultSize(profile3.query(InstallableUnitQuery.ANY, null)), 1);

		//Install b1 (this should not change anything for a1)
		ProfileChangeRequest req3 = new ProfileChangeRequest(profile3);
		req3.addInstallableUnits(new IInstallableUnit[] {b1});
		IProvisioningPlan plan3 = planner.getProvisioningPlan(req3, null, null);
		assertEquals(IStatus.OK, plan3.getStatus().getSeverity());
		engine.perform(plan3, null);
		assertProfileContainsAll("A1 or B1 is missing", profile3, new IInstallableUnit[] {a1, b1});
		assertEquals(queryResultSize(profile3.query(InstallableUnitQuery.ANY, null)), 2);

		//Remove the a1 and its inclusion rule
		ProfileChangeRequest req5 = new ProfileChangeRequest(profile3);
		req5.removeInstallableUnits(new IInstallableUnit[] {a1});
		req5.removeInstallableUnitInclusionRules(a1);
		IProvisioningPlan plan5 = planner.getProvisioningPlan(req5, null, null);
		assertEquals(IStatus.OK, plan5.getStatus().getSeverity());
		engine.perform(plan5, null);
		assertProfileContainsAll("bB1 is missing", profile3, new IInstallableUnit[] {b1});
		assertEquals(queryResultSize(profile3.query(InstallableUnitQuery.ANY, null)), 1);
	}

	public void testAdditionWithInclusionRule() {
		profile4 = createProfile("TestProfile4." + getName());
		//Try to Install a1 and a2
		ProfileChangeRequest req5 = new ProfileChangeRequest(profile4);
		req5.addInstallableUnits(new IInstallableUnit[] {a1, a2});
		IProvisioningPlan plan5 = planner.getProvisioningPlan(req5, null, null);
		assertEquals(IStatus.ERROR, plan5.getStatus().getSeverity());

		//Install a1 and a2 marking a1 optional 
		ProfileChangeRequest req = new ProfileChangeRequest(profile4);
		req.addInstallableUnits(new IInstallableUnit[] {a1, a2});
		req.setInstallableUnitInclusionRules(a1, PlannerHelper.createOptionalInclusionRule(a1));
		IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
		assertEquals(IStatus.OK, plan.getStatus().getSeverity());
		engine.perform(plan, null);
		assertProfileContainsAll("A2 is missing", profile4, new IInstallableUnit[] {a2});
		assertEquals(queryResultSize(profile4.query(InstallableUnitQuery.ANY, null)), 1);

		//Make a1 optional, this is a no-op since a1 is not in the system
		ProfileChangeRequest req2 = new ProfileChangeRequest(profile4);
		req2.setInstallableUnitInclusionRules(a1, PlannerHelper.createOptionalInclusionRule(a1));
		IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null);
		assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
		engine.perform(plan2, null);
		assertProfileContainsAll("A2 is missing", profile4, new IInstallableUnit[] {a2});
		assertEquals(queryResultSize(profile4.query(InstallableUnitQuery.ANY, null)), 1);

		//Install a1, this is expected to fail
		ProfileChangeRequest req3 = new ProfileChangeRequest(profile4);
		req3.addInstallableUnits(new IInstallableUnit[] {a1});
		IProvisioningPlan plan3 = planner.getProvisioningPlan(req3, null, null);
		assertEquals(IStatus.ERROR, plan3.getStatus().getSeverity());
	}
}

Back to the top