Skip to main content
summaryrefslogtreecommitdiffstats
blob: f591fb8466d40fd45ce06618e5109a87680572f8 (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
package org.eclipse.equinox.p2.tests.planner;

import java.util.Iterator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.planner.*;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

//This test verify that one patch can replace another one.
public class Bug300572 extends AbstractProvisioningTest {
	public void testInstallSecondPatch() throws ProvisionException {
		IProvisioningAgentProvider provider = getAgentProvider();
		IProvisioningAgent agent = provider.createAgent(getTestData("Bug300572 data", "testData/bug300572/p2").toURI());
		IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
		//The following repo contains the second patch to be installed
		IMetadataRepository repo = repoMgr.loadRepository(getTestData("bug300572 data", "testData/bug300572/repo/").toURI(), new NullProgressMonitor());

		IPlanner planner = (IPlanner) agent.getService(IPlanner.SERVICE_NAME);
		//The profile already contains a a feature (hellofeature) and a patch for it (hellopatch).
		IProfile sdkProfile = ((IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME)).getProfile("SDKProfile");
		assertFalse(sdkProfile.query(QueryUtil.createIUQuery("hellopatch.feature.group"), null).isEmpty());
		assertFalse(sdkProfile.query(QueryUtil.createIUQuery("hellofeature.feature.group"), null).isEmpty());

		//Try to optionally install the second patch. We install all the IUs from the repo since it contains only the patch and its necessary IUs.
		IProfileChangeRequest request = planner.createChangeRequest(sdkProfile);
		IQueryResult<IInstallableUnit> allIUs = repo.query(QueryUtil.ALL_UNITS, null);
		request.addAll(allIUs.toUnmodifiableSet());
		for (Iterator<IInstallableUnit> allIUsIterator = allIUs.iterator(); allIUsIterator.hasNext();) {
			IInstallableUnit iu = allIUsIterator.next();
			request.setInstallableUnitInclusionRules(iu, ProfileInclusionRules.createOptionalInclusionRule(iu));
		}

		ProvisioningContext pc = new ProvisioningContext(agent);

		IProvisioningPlan plan = planner.getProvisioningPlan(request, pc, new NullProgressMonitor());
		assertOK("plan is not ok", plan.getStatus());
		assertFalse("hellopatch.feature.group not found", plan.getAdditions().query(QueryUtil.createIUQuery("hellopatch.feature.group", Version.create("1.0.2.201001211536")), null).isEmpty());
	}
}

Back to the top