1 /*******************************************************************************
2  *  Copyright (c) 2008, 2017 IBM Corporation and others.
3  *
4  *  This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License 2.0
6  *  which accompanies this distribution, and is available at
7  *  https://www.eclipse.org/legal/epl-2.0/
8  *
9  *  SPDX-License-Identifier: EPL-2.0
10  *
11  *  Contributors:
12  *      IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.equinox.p2.tests.planner;
15 
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
18 import org.eclipse.equinox.p2.engine.*;
19 import org.eclipse.equinox.p2.metadata.*;
20 import org.eclipse.equinox.p2.planner.IPlanner;
21 import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
22 
23 public class PatchTest1b extends AbstractProvisioningTest {
24 	IInstallableUnit a1;
25 	IInstallableUnit b1;
26 	IInstallableUnit b2;
27 	IInstallableUnitPatch p1;
28 
29 	IProfile profile1;
30 	IPlanner planner;
31 	IEngine engine;
32 
33 	@Override
setUp()34 	protected void setUp() throws Exception {
35 		super.setUp();
36 		a1 = createIU("A", Version.create("1.0.0"), new IRequirement[] {MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.0.0, 1.1.0)"), null, false, true)});
37 		b1 = createIU("B", Version.createOSGi(1, 0, 0), true);
38 		b2 = createIU("B", Version.createOSGi(1, 2, 0), true);
39 		IRequirementChange change = MetadataFactory.createRequirementChange(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", VersionRange.emptyRange, null, false, false, false), MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "B", new VersionRange("[1.1.0, 1.3.0)"), null, false, false, true));
40 		p1 = createIUPatch("P", Version.create("1.0.0"), true, new IRequirementChange[] {change}, new IRequirement[][] {{MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "A", VersionRange.emptyRange, null, false, false)}}, null);
41 
42 		createTestMetdataRepository(new IInstallableUnit[] {a1, b1, b2, p1});
43 
44 		profile1 = createProfile("TestProfile." + getName());
45 		planner = createPlanner();
46 		engine = createEngine();
47 	}
48 
testInstall()49 	public void testInstall() {
50 		//A requires B 1.0, the installation of the P will result in B 1.2 to be installed
51 		ProfileChangeRequest req1 = new ProfileChangeRequest(profile1);
52 		req1.addInstallableUnits(new IInstallableUnit[] {a1, p1});
53 		IProvisioningPlan plan1 = planner.getProvisioningPlan(req1, null, null);
54 		assertTrue(IStatus.ERROR != plan1.getStatus().getSeverity());
55 		assertInstallOperand(plan1, a1);
56 		assertInstallOperand(plan1, p1);
57 		assertInstallOperand(plan1, b2);
58 		assertNoOperand(plan1, b1);
59 	}
60 }
61