1 /*******************************************************************************
2  *  Copyright (c) 2005, 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 java.io.File;
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
19 import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry;
20 import org.eclipse.equinox.p2.engine.IProfile;
21 import org.eclipse.equinox.p2.engine.IProvisioningPlan;
22 import org.eclipse.equinox.p2.metadata.IInstallableUnit;
23 import org.eclipse.equinox.p2.planner.IPlanner;
24 import org.eclipse.equinox.p2.planner.ProfileInclusionRules;
25 import org.eclipse.equinox.p2.query.IQueryResult;
26 import org.eclipse.equinox.p2.query.QueryUtil;
27 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
28 import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
29 
30 public class Bug254481dataSet2 extends AbstractProvisioningTest {
31 	IProfile profile = null;
32 	IMetadataRepository repo = null;
33 
34 	@Override
setUp()35 	protected void setUp() throws Exception {
36 		super.setUp();
37 		File reporegistry1 = getTestData("test data bug 254481", "testData/bug254481/dataSet2/profileRegistry");
38 		File tempFolder = getTempFolder();
39 		copy("0.2", reporegistry1, tempFolder);
40 		SimpleProfileRegistry registry = new SimpleProfileRegistry(getAgent(), tempFolder, null, false);
41 		profile = registry.getProfile("bootProfile");
42 		assertNotNull(profile);
43 		repo = getMetadataRepositoryManager().loadRepository(getTestData("test data bug 254481", "testData/bug254481/dataSet2/repo").toURI(), null);
44 		assertNotNull(repo);
45 	}
46 
47 	@Override
tearDown()48 	protected void tearDown() throws Exception {
49 		getMetadataRepositoryManager().removeRepository(getTestData("test data bug 254481", "testData/bug254481/dataSet2/repo").toURI());
50 		super.tearDown();
51 	}
52 
testInstallFeaturePatch()53 	public void testInstallFeaturePatch() {
54 		IQueryResult<IInstallableUnit> c = repo.query(QueryUtil.createIUQuery("org.eclipse.jdt.feature.patch.feature.group"), new NullProgressMonitor());
55 		assertEquals(1, queryResultSize(c));
56 		IInstallableUnit patch = c.iterator().next();
57 		ProfileChangeRequest request = new ProfileChangeRequest(profile);
58 		request.addInstallableUnits(new IInstallableUnit[] {patch});
59 		request.setInstallableUnitInclusionRules(patch, ProfileInclusionRules.createOptionalInclusionRule(patch));
60 		IPlanner planner = createPlanner();
61 		IProvisioningPlan plan = planner.getProvisioningPlan(request, null, new NullProgressMonitor());
62 		assertInstallOperand(plan, patch);
63 		assertEquals(1, queryResultSize(plan.getAdditions().query(QueryUtil.createIUQuery("org.eclipse.jdt.core"), null)));
64 		assertEquals(1, queryResultSize(plan.getAdditions().query(QueryUtil.createIUQuery("org.eclipse.jdt.core.manipulation"), null)));
65 	}
66 }
67