Tests for fix of bug 394156
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/InstallOperationTests.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/InstallOperationTests.java
index fc0c29e..12de2c8 100644
--- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/InstallOperationTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/operations/InstallOperationTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2010 IBM Corporation and others.
+ *  Copyright (c) 2010-2012 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
@@ -7,16 +7,19 @@
  * 
  *  Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Rapicorp, Inc (Pascal Rapicault) - Bug 394156 - Add support for updates from one namespace to another
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.ui.operations;
 
 import java.net.URI;
-import java.util.Collections;
-import java.util.Set;
-import org.eclipse.core.runtime.OperationCanceledException;
+import java.util.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.operations.IStatusCodes;
 import org.eclipse.equinox.p2.core.ProvisionException;
 import org.eclipse.equinox.p2.engine.ProvisioningContext;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
+import org.eclipse.equinox.p2.metadata.expression.*;
 import org.eclipse.equinox.p2.operations.InstallOperation;
 import org.eclipse.equinox.p2.query.QueryUtil;
 import org.eclipse.equinox.p2.repository.IRepository;
@@ -91,4 +94,35 @@
 		getMetadataRepositoryManager().removeRepository(uriC);
 
 	}
+
+	public void testUpdateWithNamespaceChange() {
+		//Create the IU that will be detected as an update
+		InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
+		iud.setId("NewB");
+		iud.setVersion(Version.create("1.0.0"));
+
+		String orExpression = "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && pc.name == 'B')";
+		IExpression expr = ExpressionUtil.parse(orExpression);
+		IMatchExpression<IInstallableUnit> matchExpression = ExpressionUtil.getFactory().matchExpression(expr);
+
+		Collection<IMatchExpression<IInstallableUnit>> updateExpression = new ArrayList<IMatchExpression<IInstallableUnit>>();
+		updateExpression.add(matchExpression);
+		iud.setUpdateDescriptor(MetadataFactory.createUpdateDescriptor(updateExpression, IUpdateDescriptor.HIGH, (String) null, (URI) null));
+		IInstallableUnit newIUB = MetadataFactory.createInstallableUnit(iud);
+
+		//create the IU being updated
+		IInstallableUnit installed = createIU("B");
+
+		//Setup the profile
+		installAsRoots(profile, new IInstallableUnit[] {installed}, true, createPlanner(), createEngine());
+
+		List<IInstallableUnit> ius = new ArrayList<IInstallableUnit>();
+		ius.add(newIUB);
+		InstallOperation op = new InstallOperation(getSession(), ius);
+		op.setProfileId(TESTPROFILE);
+
+		IStatus resolutionStatus = op.resolveModal(getMonitor());
+		assertEquals(IStatusCodes.PROFILE_CHANGE_ALTERED, ((MultiStatus) resolutionStatus).getChildren()[0].getCode());
+		assertEquals(IStatusCodes.ALTERED_IMPLIED_UPDATE, ((MultiStatus) (((MultiStatus) resolutionStatus).getChildren()[0])).getChildren()[0].getCode());
+	}
 }
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AvailableIUWrapperTest.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AvailableIUWrapperTest.java
index 2436d99..1f532db 100644
--- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AvailableIUWrapperTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/query/AvailableIUWrapperTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 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
@@ -8,18 +8,19 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     EclipseSource - ongoing development
+ *     Rapicorp, Inc (Pascal Rapicault) - Bug 394156 - Add support for updates from one namespace to another
  *******************************************************************************/
 package org.eclipse.equinox.p2.tests.ui.query;
 
-import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
-
+import java.net.URI;
 import java.util.*;
-import org.eclipse.equinox.internal.p2.ui.model.CategoryElement;
-import org.eclipse.equinox.internal.p2.ui.model.IIUElement;
+import junit.framework.Assert;
+import org.eclipse.equinox.internal.p2.ui.model.*;
 import org.eclipse.equinox.internal.p2.ui.query.AvailableIUWrapper;
 import org.eclipse.equinox.p2.engine.IProfile;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
+import org.eclipse.equinox.p2.metadata.expression.*;
 import org.eclipse.equinox.p2.query.*;
 import org.eclipse.equinox.p2.tests.MockQueryable;
 
@@ -150,6 +151,43 @@
 		assertEquals("1.2", notInstalled, getIU(iuElement));
 	}
 
+	public void testUpdate() {
+		//Create the IU that will be detected as an update
+		InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
+		iud.setId("NewB");
+		iud.setVersion(Version.create("1.0.0"));
+
+		String orExpression = "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && pc.name == 'B')";
+		IExpression expr = ExpressionUtil.parse(orExpression);
+		IMatchExpression matchExpression = ExpressionUtil.getFactory().matchExpression(expr);
+
+		Collection<IMatchExpression<IInstallableUnit>> updateExpression = new ArrayList<IMatchExpression<IInstallableUnit>>();
+		updateExpression.add(matchExpression);
+		iud.setUpdateDescriptor(MetadataFactory.createUpdateDescriptor(updateExpression, IUpdateDescriptor.HIGH, (String) null, (URI) null));
+		IInstallableUnit newIUB = MetadataFactory.createInstallableUnit(iud);
+
+		//create the IU being updated
+		IInstallableUnit installed = createIU("B");
+
+		//Setup the profile
+		IProfile profile = createProfile("TestProfile");
+		AvailableIUWrapper wrapper = createWrapper(true);
+		Collector collector = new Collector();
+		installAsRoots(profile, new IInstallableUnit[] {installed}, true, createPlanner(), createEngine());
+		wrapper.markInstalledIUs(profile, true);
+
+		//now feed in the installed and non-installed units, and the installed unit should be ignored.
+		collector.accept(newIUB);
+
+		Collection results = wrapper.getElements(collector);
+
+		//Verify 
+		assertEquals("1.1", 1, results.size());
+		Object iuElement = results.iterator().next();
+		assertEquals("1.2", newIUB, getIU(iuElement));
+		Assert.assertTrue(((AvailableIUElement) iuElement).isUpdate());
+	}
+
 	protected IQuery getMockQuery() {
 		return QueryUtil.createIUPropertyQuery("key", "value");
 	}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
index e511f02..118d5cf 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
@@ -7,6 +7,7 @@
  * Contributors: IBM Corporation - initial API and implementation
  ******************************************************************************/
 package org.eclipse.equinox.p2.tests;
+
 import java.io.*;
 import java.lang.reflect.Field;
 import java.net.URI;
@@ -46,7 +47,6 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 
-
 /**
  * Base class for provisioning tests with convenience methods used by multiple tests.
  */
@@ -1028,6 +1028,17 @@
 		}
 	}
 
+	protected IStatus installAsRoots(IProfile profile, IInstallableUnit[] ius, boolean strict, IPlanner planner, IEngine engine) {
+		ProfileChangeRequest req = new ProfileChangeRequest(profile);
+		for (int i = 0; i < ius.length; i++) {
+			req.add(ius[i]);
+			req.setInstallableUnitInclusionRules(ius[i], strict ? ProfileInclusionRules.createStrictInclusionRule(ius[i]) : ProfileInclusionRules.createOptionalInclusionRule(ius[i]));
+			req.setInstallableUnitProfileProperty(ius[i], IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString());
+		}
+
+		return install(req, planner, engine);
+	}
+
 	protected IStatus install(IProfile profile, IInstallableUnit[] ius, boolean strict, IPlanner planner, IEngine engine) {
 		ProfileChangeRequest req = new ProfileChangeRequest(profile);
 		for (int i = 0; i < ius.length; i++) {