1 /*******************************************************************************
2  * Copyright (c) 2008, 2017 IBM Corporation and others.
3  *
4  * This
5  * program and the accompanying materials are made available under the terms of
6  * the Eclipse Public License 2.0 which accompanies this distribution, and is
7  * available at
8  * https://www.eclipse.org/legal/epl-2.0/
9  *
10  * SPDX-License-Identifier: EPL-2.0
11  *
12  * Contributors: 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.core.helpers.LogHelper;
18 import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
19 import org.eclipse.equinox.internal.p2.engine.ProvisioningPlan;
20 import org.eclipse.equinox.p2.engine.*;
21 import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery;
22 import org.eclipse.equinox.p2.metadata.*;
23 import org.eclipse.equinox.p2.planner.IPlanner;
24 import org.eclipse.equinox.p2.query.IQueryResult;
25 import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
26 
27 public class IUProperties extends AbstractProvisioningTest {
28 	private IInstallableUnit a1;
29 	private IInstallableUnit b1;
30 	private IInstallableUnit b11;
31 	private IInstallableUnit c;
32 	private IProfile profile;
33 	private IPlanner planner;
34 	private IEngine engine;
35 	private String profileId;
36 
37 	@Override
setUp()38 	protected void setUp() throws Exception {
39 		super.setUp();
40 		a1 = createIU("A", Version.create("1.0.0"), createRequiredCapabilities(IInstallableUnit.NAMESPACE_IU_ID, "B1", new VersionRange("[1.0.0, 2.0.0)")));
41 
42 		b1 = createIU("B1", Version.create("1.0.0"), true);
43 
44 		b11 = createIU("B1", Version.create("1.1.0"), createRequiredCapabilities(IInstallableUnit.NAMESPACE_IU_ID, "C", new VersionRange("[1.0.0, 3.0.0)")), NO_PROPERTIES, true);
45 
46 		c = createIU("C", Version.createOSGi(2, 0, 0), true);
47 
48 		createTestMetdataRepository(new IInstallableUnit[] {a1, b1, b11, c});
49 
50 		profileId = "TestProfile." + getName();
51 		profile = createProfile(profileId);
52 		planner = createPlanner();
53 		engine = createEngine();
54 
55 	}
56 
testRemoveIUProperty()57 	public void testRemoveIUProperty() {
58 		ProfileChangeRequest req1 = new ProfileChangeRequest(profile);
59 		req1.addInstallableUnits(new IInstallableUnit[] {a1});
60 		req1.setInstallableUnitProfileProperty(a1, "FOO", "BAR");
61 		req1.setInstallableUnitProfileProperty(b1, "FOO", "BAR");
62 		IProvisioningPlan pp1 = planner.getProvisioningPlan(req1, null, null);
63 		assertEquals(IStatus.OK, pp1.getStatus().getSeverity());
64 		IStatus s = engine.perform(pp1, null);
65 		if (!s.isOK())
66 			LogHelper.log(s);
67 		IQueryResult<IInstallableUnit> queryResult = getProfile(profileId).query(new IUProfilePropertyQuery("FOO", IUProfilePropertyQuery.ANY), null);
68 		assertEquals(1, queryResultSize(queryResult));
69 
70 		ProfileChangeRequest req2 = new ProfileChangeRequest(profile);
71 		req2.removeInstallableUnitProfileProperty(b1, "FOO");
72 		ProvisioningPlan pp2 = (ProvisioningPlan) planner.getProvisioningPlan(req2, null, null);
73 		assertEquals(0, pp2.getOperands().length);
74 	}
75 }
76