Skip to main content
summaryrefslogtreecommitdiffstats
blob: a4b062a1c448810e1cc2585f52b1c40b79c42bec (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
/*******************************************************************************
 * Copyright (c) 2011 Sonatype, Inc. 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: 
 * Sonatype, Inc. - initial implementation and ideas 
 ******************************************************************************/
package org.eclipse.equinox.p2.tests.planner;

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

public class LuckyTest4 extends AbstractProvisioningTest {
	@IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 1 \n" + "depends: platform = 1\n")
	public IInstallableUnit sdk1;

	@IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 1 \n")
	public IInstallableUnit platform1;

	@IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2\n")
	public IInstallableUnit sdk2;

	@IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 2 \n")
	public IInstallableUnit platform2;

	@IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 1 \n")
	public IInstallableUnit egit1;

	@IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 2 \n")
	public IInstallableUnit egit2;

	IProfile profile;

	private IPlanner planner;

	private IEngine engine;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		IULoader.loadIUs(this);
		profile = createProfile("TestProfile." + getName());
		createTestMetdataRepository(new IInstallableUnit[] {sdk1, platform1, sdk2, platform2, egit1, egit2});
		planner = createPlanner();
		engine = createEngine();

		//Setup the initial state of the profile
		assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine));
		assertOK(install(profile, new IInstallableUnit[] {egit1}, false, planner, engine));
		assertEquals("STRICT", profile.getInstallableUnitProperty(sdk1, "org.eclipse.equinox.p2.internal.inclusion.rules"));
		assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit1, "org.eclipse.equinox.p2.internal.inclusion.rules"));
	}

	//Verify that both strict and optional dependencies are updated and the properties appropriately conserved
	public void testInstallSDK2() {
		assertNotOK(install(profile, new IInstallableUnit[] {platform2, egit2}, true, planner, engine));

		ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor());
		assertEquals(2, res.getAdditions().size());
		assertTrue(res.getAdditions().contains(sdk2));
		assertTrue(res.getAdditions().contains(egit2));
		assertEquals(2, res.getRemovals().size());
		assertTrue(res.getRemovals().contains(sdk1));
		assertTrue(res.getRemovals().contains(egit1));

		assertOK(install(res, planner, engine));
		assertProfileContains("validate new profile", profile, new IInstallableUnit[] {sdk2, platform2, egit2});
		assertEquals("STRICT", profile.getInstallableUnitProperty(sdk2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
		assertEquals(null, profile.getInstallableUnitProperty(platform2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
		assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
	}

	//Check that 
	public void updateWithInterference() {
		assertNotOK(install(profile, new IInstallableUnit[] {platform2, egit2}, true, planner, engine));

		ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor());
		assertEquals(2, res.getAdditions().size());
		assertTrue(res.getAdditions().contains(sdk2));
		assertTrue(res.getAdditions().contains(egit2));
		assertEquals(2, res.getRemovals().size());
		assertTrue(res.getRemovals().contains(sdk1));
		assertTrue(res.getRemovals().contains(egit1));

		assertOK(install(res, planner, engine));
		assertProfileContains("validate new profile", profile, new IInstallableUnit[] {sdk2, platform2, egit2});
		assertEquals("STRICT", profile.getInstallableUnitProperty(sdk2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
		assertEquals(null, profile.getInstallableUnitProperty(platform2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
		assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit2, "org.eclipse.equinox.p2.internal.inclusion.rules"));

	}
}

Back to the top