Added test for 362692.
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AbstractPlannerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AbstractPlannerTest.java
index a3ffe62..af2f74b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AbstractPlannerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AbstractPlannerTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2011 IBM Corporation 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
@@ -12,8 +12,8 @@
 
 import java.io.File;
 import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.Iterator;
+import java.net.URI;
+import java.util.*;
 import org.eclipse.equinox.internal.p2.engine.*;
 import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest;
 import org.eclipse.equinox.p2.engine.*;
@@ -31,6 +31,40 @@
 	private File previousStoreValue = null;
 	IMetadataRepository repo = null;
 
+	public static class ExpectedOperands {
+		Set added = new HashSet();
+		Set removed = new HashSet();
+		Set updated = new HashSet();
+
+		void added(IInstallableUnit unit) {
+			added.add(unit);
+		}
+
+		void added(Set units) {
+			added.addAll(units);
+		}
+
+		void removed(IInstallableUnit unit) {
+			removed.add(unit);
+		}
+
+		void removed(Set units) {
+			removed.addAll(units);
+		}
+
+		void updated(IInstallableUnit unit) {
+			updated.add(unit);
+		}
+
+		void updated(Set units) {
+			updated.addAll(units);
+		}
+	}
+
+	protected IProfile getProfile() {
+		return profile;
+	}
+
 	/*
 	 * Return the root of the data for this test. e.g. "testData/bug302582"
 	 */
@@ -117,6 +151,37 @@
 	}
 
 	/*
+	 * Take the given plan and compress additons/removals so they look like updates. 
+	 * Good for viewing while debugging.
+	 */
+	protected Collection compress(IProvisioningPlan plan) {
+		Map<String, InstallableUnitOperand> result = new HashMap<String, InstallableUnitOperand>();
+		Operand[] operands = ((ProvisioningPlan) plan).getOperands();
+		for (int i = 0; i < operands.length; i++) {
+			if (!(operands[i] instanceof InstallableUnitOperand))
+				continue;
+			InstallableUnitOperand operand = (InstallableUnitOperand) operands[i];
+			String id = operand.first() == null ? operand.second().getId() : operand.first().getId();
+			InstallableUnitOperand existing = result.get(id);
+			if (existing == null) {
+				result.put(id, operand);
+			} else {
+				IInstallableUnit first = existing.first() == null ? operand.first() : existing.first();
+				IInstallableUnit second = existing.second() == null ? operand.second() : existing.second();
+				result.put(id, new InstallableUnitOperand(first, second));
+			}
+		}
+		return result.values();
+	}
+
+	protected ProvisioningContext getContext(Collection<URI> repoLocations) {
+		ProvisioningContext result = new ProvisioningContext(getAgent());
+		result.setMetadataRepositories(repoLocations == null ? new URI[0] : repoLocations.toArray(new URI[repoLocations.size()]));
+		result.setArtifactRepositories(new URI[0]);
+		return result;
+	}
+
+	/*
 	 * Assert that all the IU operands in the expected plan are contained in the actual plan.
 	 */
 	protected void assertContains(String message, IProvisioningPlan expectedPlan, IProvisioningPlan actualPlan) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug362692.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug362692.java
new file mode 100644
index 0000000..1701527
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/Bug362692.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.planner;
+
+import java.net.URI;
+import java.util.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.planner.IPlanner;
+import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
+import org.eclipse.equinox.p2.query.*;
+import org.eclipse.equinox.p2.tests.TestActivator;
+
+public class Bug362692 extends AbstractPlannerTest {
+
+	// path to our data
+	protected String getTestDataPath() {
+		return "testData/bug362692";
+	}
+
+	// profile id
+	protected String getProfileId() {
+		return "bootProfile";
+	}
+
+	/*
+	 * Test data registry profiles:
+	 * 1320249157454 - empty
+	 * 1320261982041 - already has highest versions
+	 * 1320270552610 - highest versions of all except PluginC
+	 * 1320769530050 - Already installed: PluginA 1.1.1, PluginB 1.1.1, PluginC 1.1.3, PluginD 1.1.3, PluginE 1.1.4
+	 */
+	public void testInstall() {
+		IPlanner planner = createPlanner();
+
+		// this is the set of IUs we expect in the final result - highest version only
+		Set<IInstallableUnit> expected = new HashSet<IInstallableUnit>();
+		IQueryResult queryResult = repo.query(QueryUtil.createIUQuery("PluginA", Version.createOSGi(1, 1, 1, null)), new NullProgressMonitor());
+		expected.addAll(queryResult.toSet());
+		queryResult = repo.query(QueryUtil.createIUQuery("PluginB", Version.createOSGi(1, 1, 2, null)), new NullProgressMonitor());
+		expected.addAll(queryResult.toSet());
+		queryResult = repo.query(QueryUtil.createIUQuery("PluginC", Version.createOSGi(1, 1, 3, null)), new NullProgressMonitor());
+		expected.addAll(queryResult.toSet());
+		queryResult = repo.query(QueryUtil.createIUQuery("PluginD", Version.createOSGi(1, 1, 4, null)), new NullProgressMonitor());
+		expected.addAll(queryResult.toSet());
+		queryResult = repo.query(QueryUtil.createIUQuery("PluginE", Version.createOSGi(1, 1, 5, null)), new NullProgressMonitor());
+		expected.addAll(queryResult.toSet());
+
+		// create the actual plan - install everything in the repo as optional (mimic the dropins folder)
+		Set<IInstallableUnit> toAdd = new HashSet<IInstallableUnit>();
+		IQueryResult allIUs = repo.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor());
+		// we don't want to re-install units which are already installed in the profile so remove them. (this is what the reconciler does)
+		boolean already = false;
+		for (Iterator<IInstallableUnit> iter = allIUs.iterator(); iter.hasNext();) {
+			IInstallableUnit iu = iter.next();
+			boolean installed = !getProfile().query(QueryUtil.createIUQuery(iu.getId(), iu.getVersion()), new NullProgressMonitor()).isEmpty();
+			if (installed) {
+				System.out.println("Already installed: " + iu.getId() + " " + iu.getVersion());
+				already = true;
+			} //else
+			toAdd.add(iu);
+		}
+		if (!already)
+			System.out.println("Already installed: None!");
+		validate(expected, toAdd);
+
+		// mimic a product "-clean" and re-install everything which is already in the profile.
+		toAdd.addAll(getProfile().query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()).toSet());
+
+		// set the metadata repositories on the provisioning context. one for the dropins and one for the shared area
+		Collection<URI> repoURLs = new ArrayList<URI>();
+		repoURLs.add(repo.getLocation());
+		repoURLs.add(new Path(getTestDataPath()).append("shared").toFile().toURI());
+		ProvisioningContext context = getContext(repoURLs);
+		context.setExtraInstallableUnits(new ArrayList(toAdd));
+		IProfileChangeRequest actualChangeRequest = createProfileChangeRequest(toAdd, null, null);
+		IProvisioningPlan plan = planner.getProvisioningPlan(actualChangeRequest, context, new NullProgressMonitor());
+		Collection compressedPlan = compress(plan);
+		if (compressedPlan.isEmpty())
+			System.out.println("Plan: ...is empty!");
+		for (Iterator iter = compressedPlan.iterator(); iter.hasNext();) {
+			System.out.println("Plan: " + iter.next());
+		}
+		validate(expected, plan);
+	}
+
+	/*
+	 * All of the expected IUs should either already be installed in the profile (and not be removed) 
+	 * or in the list of additions.
+	 */
+	private void validate(Collection<IInstallableUnit> expected, Collection<IInstallableUnit> toAdd) {
+		MultiStatus errors = new MultiStatus(TestActivator.PI_PROV_TESTS, IStatus.OK, "Errors while validating plan.", null);
+		for (IInstallableUnit unit : expected) {
+			IQuery query = QueryUtil.createIUQuery(unit.getId(), unit.getVersion());
+			// already in the profile?
+			IQueryResult queryResult = getProfile().query(query, new NullProgressMonitor());
+			if (queryResult.isEmpty()) {
+				// not in the profile, should be an incoming addition then
+				if (!toAdd.contains(unit)) {
+					errors.add(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, unit.getId() + " " + unit.getVersion() + " isn't in the profile and isn't an incoming addition."));
+				}
+			} else {
+				// expected IU is already in the profile
+			}
+		}
+		assertOK("Errors while validating plan.", errors);
+	}
+
+	/*
+	 * All of the expected IUs should either already be installed in the profile (and not be removed) 
+	 * or in the plan as an addition.
+	 */
+	private void validate(Collection<IInstallableUnit> expected, IProvisioningPlan plan) {
+		MultiStatus errors = new MultiStatus(TestActivator.PI_PROV_TESTS, IStatus.OK, "Errors while validating plan.", null);
+		for (IInstallableUnit unit : expected) {
+			IQuery query = QueryUtil.createIUQuery(unit.getId(), unit.getVersion());
+			// already in the profile?
+			IQueryResult queryResult = getProfile().query(query, new NullProgressMonitor());
+			if (queryResult.isEmpty()) {
+				// not in the profile, should be an incoming addition then
+				if (plan.getAdditions().query(query, new NullProgressMonitor()).isEmpty()) {
+					errors.add(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, unit.getId() + " " + unit.getVersion() + " isn't in the profile and isn't an incoming addition."));
+				}
+			} else {
+				// IU is in the profile, ensure we aren't removing it
+				if (!plan.getRemovals().query(query, new NullProgressMonitor()).isEmpty()) {
+					errors.add(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, unit.getId() + " " + unit.getVersion() + " is in the profile but is being removed."));
+				}
+			}
+		}
+		assertOK("Errors while validating plan.", errors);
+	}
+}