|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.p2.tests.planner; |
| 12 |
|
| 13 |
import java.io.File; |
| 14 |
import java.lang.reflect.Field; |
| 15 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 16 |
import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; |
| 17 |
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest; |
| 18 |
import org.eclipse.equinox.p2.engine.*; |
| 19 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
| 20 |
import org.eclipse.equinox.p2.metadata.Version; |
| 21 |
import org.eclipse.equinox.p2.planner.IPlanner; |
| 22 |
import org.eclipse.equinox.p2.planner.IProfileChangeRequest; |
| 23 |
import org.eclipse.equinox.p2.query.*; |
| 24 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
| 25 |
|
| 26 |
public class Bug306424 extends AbstractProvisioningTest { |
| 27 |
|
| 28 |
private File previousStoreValue = null; |
| 29 |
private IProfile profile; |
| 30 |
|
| 31 |
protected String getTestDataPath() { |
| 32 |
return "testData/bug306424"; |
| 33 |
} |
| 34 |
|
| 35 |
protected void tearDown() throws Exception { |
| 36 |
SimpleProfileRegistry realProfileRegistry = (SimpleProfileRegistry) getProfileRegistry(); |
| 37 |
|
| 38 |
Field profilesMapField = SimpleProfileRegistry.class.getDeclaredField("profiles"); //$NON-NLS-1$ |
| 39 |
profilesMapField.setAccessible(true); |
| 40 |
profilesMapField.set(realProfileRegistry, null); |
| 41 |
|
| 42 |
Field profileStore = SimpleProfileRegistry.class.getDeclaredField("store"); |
| 43 |
profileStore.setAccessible(true); |
| 44 |
profileStore.set(realProfileRegistry, previousStoreValue); |
| 45 |
super.tearDown(); |
| 46 |
} |
| 47 |
|
| 48 |
/* |
| 49 |
* /* (non-Javadoc) |
| 50 |
* @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#setUp() |
| 51 |
*/ |
| 52 |
protected void setUp() throws Exception { |
| 53 |
super.setUp(); |
| 54 |
File reporegistry1 = getTestData("loading planner test data", getTestDataPath()); |
| 55 |
File tempFolder = getTempFolder(); |
| 56 |
copy("0.2", reporegistry1, tempFolder); |
| 57 |
IProfileRegistry realProfileRegistry = getProfileRegistry(); |
| 58 |
//Tweak the running profile registry |
| 59 |
Field profileStore = SimpleProfileRegistry.class.getDeclaredField("store"); |
| 60 |
profileStore.setAccessible(true); |
| 61 |
previousStoreValue = (File) profileStore.get(realProfileRegistry); |
| 62 |
profileStore.set(realProfileRegistry, new File(tempFolder, "p2/org.eclipse.equinox.p2.engine/profileRegistry")); |
| 63 |
|
| 64 |
Field profilesMapField = SimpleProfileRegistry.class.getDeclaredField("profiles"); //$NON-NLS-1$ |
| 65 |
profilesMapField.setAccessible(true); |
| 66 |
profilesMapField.set(realProfileRegistry, null); |
| 67 |
//End of tweaking the profile registry |
| 68 |
|
| 69 |
profile = realProfileRegistry.getProfile("PlatformProfile"); |
| 70 |
assertNotNull(profile); |
| 71 |
} |
| 72 |
|
| 73 |
public void testInstall() { |
| 74 |
IPlanner planner = createPlanner(); |
| 75 |
|
| 76 |
IInstallableUnit b = createIU("b", Version.create("1.0")); |
| 77 |
IProfileChangeRequest changeRequest = new ProfileChangeRequest(profile); |
| 78 |
changeRequest.remove(b); |
| 79 |
IProvisioningPlan plan = planner.getProvisioningPlan(changeRequest, null, new NullProgressMonitor()); |
| 80 |
IQueryable result = plan.getRemovals(); |
| 81 |
IQueryResult<IInstallableUnit> r = result.query(QueryUtil.ALL_UNITS, getMonitor()); |
| 82 |
assertFalse("1.0", r.isEmpty()); |
| 83 |
} |
| 84 |
} |