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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
package org.eclipse.equinox.p2.tests.planner;
import org.eclipse.equinox.p2.planner.IPlanner;
import java.util.*;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.metadata.ProvidedCapability;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.internal.provisional.p2.director.*;
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
public class NegationTesting extends AbstractProvisioningTest {
private static final String NS = "theNamespace";
private static final String N = "theName";
// public void testNot1() {
// RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.2.0)"), null, 0, 0, false);
// ProvidedCapability prov = new ProvidedCapability(NS, N, Version.createOSGi(1, 5, 0));
// assertTrue(prov.satisfies(req1));
// }
//
// public void testNot2() {
// RequiredCapability req = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.2.0)"), null, 0, 0, false);
// ProvidedCapability prov = new ProvidedCapability(NS, N, Version.createOSGi(1, 1, 0));
// assertFalse(prov.satisfies(req));
// }
//
// public void testNot3() {
// RequiredCapability req = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.2.0)"), null, 0, 0, false);
// // RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.5.0, 2.0.0)"), null, false, false);
// ProvidedCapability prov = new ProvidedCapability("foo", "bar", Version.createOSGi(1, 5, 0));
// assertTrue(prov.satisfies(req));
// }
//Test the slicer and the resolver.
public void testNot4() {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection requirements = new ArrayList();
requirements.add(req1);
requirements.add(req2);
iud1.addRequiredCapabilities(requirements);
Collection capabilities = new ArrayList();
capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
MetadataFactory.InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("ProviderOf1");
iud2.setVersion(Version.create("1.0.0"));
Collection capabilities2 = new ArrayList();
capabilities2.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.0.0")));
iud2.addProvidedCapabilities(capabilities2);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
MetadataFactory.InstallableUnitDescription iud3 = new MetadataFactory.InstallableUnitDescription();
iud3.setId("ProviderOf1_1_1");
iud3.setVersion(Version.create("1.0.0"));
Collection capabilities3 = new ArrayList();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
IMetadataRepository repo = createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2, iu3});
// Verify that the slice includes iu3 because the requirement from iu1 is a range including the provided capability of iu3.
Slicer slicer = new Slicer(repo, new Properties(), false);
IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor());
assertEquals(3, queryResultSize(slice.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
//Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1
IProfile profile = createProfile("TestProfile." + getName());
IPlanner planner = createPlanner();
ProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
changeRequest.add(iu1);
ProvisioningPlan plan = (ProvisioningPlan) planner.getProvisioningPlan(changeRequest, null, null);
assertEquals(0, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(new InstallableUnitQuery("ProviderOf1_1_1"), null)));
assertEquals(2, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(InstallableUnitQuery.ANY, null)));
//Verify that the installing iu1 and iu3 will result in a conflict since iu3 is excluded by the requirement of iu1
ProfileChangeRequest changeRequest2 = new ProfileChangeRequest(profile);
Collection<IInstallableUnit> toAdd = new ArrayList<IInstallableUnit>();
toAdd.add(iu1);
toAdd.add(iu3);
changeRequest2.addAll(toAdd);
IProvisioningPlan plan2 = planner.getProvisioningPlan(changeRequest2, null, null);
assertNotOK("The resolution should be failing because of the negation requirement.", plan2.getStatus());
}
public void testNot5() {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
Collection requirements = new ArrayList();
requirements.add(req1);
requirements.add(req2);
iud1.addRequiredCapabilities(requirements);
Collection capabilities = new ArrayList();
capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
MetadataFactory.InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("ProviderOf1");
iud2.setVersion(Version.create("1.0.0"));
Collection capabilities2 = new ArrayList();
capabilities2.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.0.0")));
iud2.addProvidedCapabilities(capabilities2);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
MetadataFactory.InstallableUnitDescription iud3 = new MetadataFactory.InstallableUnitDescription();
iud3.setId("ProviderOf1_1_1");
iud3.setVersion(Version.create("1.0.0"));
Collection capabilities3 = new ArrayList();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
IMetadataRepository repo = createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2, iu3});
//Test the slicer. The slice will not contain iu3 because none of the range of iu1 cause it to be brought in.
Slicer slicer = new Slicer(repo, new Properties(), false);
IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor());
assertEquals(0, queryResultSize(slice.query(new InstallableUnitQuery("ProviderOf1_1_1"), new NullProgressMonitor())));
assertEquals(2, queryResultSize(slice.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
}
public void testNot6() {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 1.1.0)"), null, false, false);
Collection requirements = new ArrayList();
requirements.add(req1);
requirements.add(req2);
iud1.addRequiredCapabilities(requirements);
Collection capabilities = new ArrayList();
capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
MetadataFactory.InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("ProviderOf1");
iud2.setVersion(Version.create("1.0.0"));
Collection capabilities2 = new ArrayList();
capabilities2.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.0.0")));
iud2.addProvidedCapabilities(capabilities2);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
IMetadataRepository repo = createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2});
//Test the slicer. The slice will not contain iu3 because none of the range of iu1 cause it to be brought in.
Slicer slicer = new Slicer(repo, new Properties(), false);
IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor());
assertEquals(0, queryResultSize(slice.query(new InstallableUnitQuery("ProviderOf1_1_1"), new NullProgressMonitor())));
assertEquals(2, queryResultSize(slice.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
//Verify that the negation can not fail the resolution when the IUs satisfying the negative requirement are not there
IProfile profile = createProfile("TestProfile." + getName());
IPlanner planner = createPlanner();
ProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
changeRequest.add(iu1);
ProvisioningPlan plan = (ProvisioningPlan) planner.getProvisioningPlan(changeRequest, null, null);
assertEquals(0, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(new InstallableUnitQuery("ProviderOf1_1_1"), null)));
assertEquals(2, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(InstallableUnitQuery.ANY, null)));
}
//Test the slicer and the resolver.
public void testNot7() {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection requirements = new ArrayList();
requirements.add(req1);
requirements.add(req2);
iud1.addRequiredCapabilities(requirements);
Collection capabilities = new ArrayList();
capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
MetadataFactory.InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("ProviderOf1");
iud2.setVersion(Version.create("1.0.0"));
Collection capabilities2 = new ArrayList();
capabilities2.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.0.0")));
iud2.addProvidedCapabilities(capabilities2);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
MetadataFactory.InstallableUnitDescription iud3 = new MetadataFactory.InstallableUnitDescription();
iud3.setId("ProviderOf1_1_1");
iud3.setVersion(Version.create("1.0.0"));
Collection capabilities3 = new ArrayList();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
Collection requirements3 = new ArrayList();
requirements3.add(MetadataFactory.createRequiredCapability("DOES-NOT-EXIST", "NEVER", new VersionRange("[1.0.0, 2.0.0)"), null, false, false));
iud3.addRequiredCapabilities(requirements3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
IMetadataRepository repo = createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2, iu3});
// Verify that the slice includes iu3 because the requirement from iu1 is a range including the provided capability of iu3.
Slicer slicer = new Slicer(repo, new Properties(), false);
IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor());
assertEquals(3, queryResultSize(slice.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
//Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1
IProfile profile = createProfile("TestProfile." + getName());
IPlanner planner = createPlanner();
ProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
changeRequest.add(iu1);
ProvisioningPlan plan = (ProvisioningPlan) planner.getProvisioningPlan(changeRequest, null, null);
assertEquals(0, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(new InstallableUnitQuery("ProviderOf1_1_1"), null)));
assertEquals(2, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(InstallableUnitQuery.ANY, null)));
//Verify that the installing iu1 and iu3 will result in a conflict since iu3 is excluded by the requirement of iu1
ProfileChangeRequest changeRequest2 = new ProfileChangeRequest(profile);
Collection<IInstallableUnit> toAdd = new ArrayList<IInstallableUnit>();
toAdd.add(iu1);
toAdd.add(iu3);
changeRequest2.addAll(toAdd);
IProvisioningPlan plan2 = planner.getProvisioningPlan(changeRequest2, null, null);
assertNotOK("The resolution should be failing because of the negation requirement.", plan2.getStatus());
}
public void testNot8() {
MetadataFactory.InstallableUnitDescription iud1 = new MetadataFactory.InstallableUnitDescription();
iud1.setId("TestNegation4");
iud1.setVersion(Version.create("1.0.0"));
RequiredCapability req1 = new RequiredCapability(NS, N, new VersionRange("[1.1.0, 1.2.0)"), null, 0, 0, false);
RequiredCapability req2 = new RequiredCapability(NS, N, new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
Collection requirements = new ArrayList();
requirements.add(req1);
requirements.add(req2);
iud1.addRequiredCapabilities(requirements);
Collection capabilities = new ArrayList();
capabilities.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "TestNegation4", Version.create("1.0.0")));
iud1.addProvidedCapabilities(capabilities);
IInstallableUnit iu1 = MetadataFactory.createInstallableUnit(iud1);
MetadataFactory.InstallableUnitDescription iud2 = new MetadataFactory.InstallableUnitDescription();
iud2.setId("ProviderOf1");
iud2.setVersion(Version.create("1.0.0"));
Collection capabilities2 = new ArrayList();
capabilities2.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.0.0")));
iud2.addProvidedCapabilities(capabilities2);
IInstallableUnit iu2 = MetadataFactory.createInstallableUnit(iud2);
MetadataFactory.InstallableUnitDescription iud3 = new MetadataFactory.InstallableUnitDescription();
iud3.setId("ProviderOf1_1_1");
iud3.setVersion(Version.create("1.0.0"));
Collection capabilities3 = new ArrayList();
capabilities3.add(MetadataFactory.createProvidedCapability(NS, N, Version.create("1.1.1")));
capabilities3.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "ProviderOf1_1_1", Version.create("1.0.0")));
iud3.addProvidedCapabilities(capabilities3);
IInstallableUnit iu3 = MetadataFactory.createInstallableUnit(iud3);
MetadataFactory.InstallableUnitDescription iud4 = new MetadataFactory.InstallableUnitDescription();
iud4.setId("AnotherRoot");
iud4.setVersion(Version.create("1.0.0"));
Collection capabilities4 = new ArrayList();
capabilities4.add(new ProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, "AnotherRoot", Version.create("1.0.0")));
iud4.addProvidedCapabilities(capabilities4);
Collection reqs4 = new ArrayList();
reqs4.add(new RequiredCapability(NS, N, new VersionRange("[1.1.1, 1.1.1]"), null, false, false));
iud4.addRequiredCapabilities(reqs4);
IInstallableUnit iu4 = MetadataFactory.createInstallableUnit(iud4);
IMetadataRepository repo = createTestMetdataRepository(new IInstallableUnit[] {iu1, iu2, iu3, iu4});
// Verify that the slice includes iu3
Slicer slicer = new Slicer(repo, new Properties(), false);
IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1, iu4}, new NullProgressMonitor());
assertEquals(4, queryResultSize(slice.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
// Verify that the slice includes iu3
Slicer slicer2 = new Slicer(repo, new Properties(), false);
IQueryable slice2 = slicer2.slice(new IInstallableUnit[] {iu4}, new NullProgressMonitor());
assertEquals(2, queryResultSize(slice2.query(InstallableUnitQuery.ANY, new NullProgressMonitor())));
//Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1
IProfile profile = createProfile("TestProfile." + getName());
IPlanner planner = createPlanner();
ProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
changeRequest.add(iu1);
ProvisioningPlan plan = (ProvisioningPlan) planner.getProvisioningPlan(changeRequest, null, null);
assertEquals(0, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(new InstallableUnitQuery("ProviderOf1_1_1"), null)));
assertEquals(2, queryResultSize(((PlannerStatus) plan.getStatus()).getPlannedState().query(InstallableUnitQuery.ANY, null)));
//Verify that the installing iu1 and iu4 will result in a conflict since iu3 is excluded by the requirement of iu1
ProfileChangeRequest changeRequest2 = new ProfileChangeRequest(profile);
Collection<IInstallableUnit> toAdd = new ArrayList<IInstallableUnit>();
toAdd.add(iu1);
toAdd.add(iu4);
changeRequest2.addAll(toAdd);
IProvisioningPlan plan2 = planner.getProvisioningPlan(changeRequest2, null, null);
assertNotOK("The resolution should be failing because of the negation requirement.", plan2.getStatus());
}
}
|