diff options
author | Pascal Rapicault | 2012-12-09 22:51:20 +0000 |
---|---|---|
committer | Pascal Rapicault | 2012-12-09 22:54:10 +0000 |
commit | 9cc112f1924c5e15c59f848b473835e3787774db (patch) | |
tree | 6acf460b3001551c4f33bf8da6879b3f26a7add9 /bundles/org.eclipse.equinox.p2.tests.ui | |
parent | 3d04353d8947710873181679046fa3ab8fa2fc98 (diff) | |
download | rt.equinox.p2-9cc112f1924c5e15c59f848b473835e3787774db.tar.gz rt.equinox.p2-9cc112f1924c5e15c59f848b473835e3787774db.tar.xz rt.equinox.p2-9cc112f1924c5e15c59f848b473835e3787774db.zip |
Tests for fix of bug 394156v20121209-225410
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests.ui')
2 files changed, 84 insertions, 12 deletions
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 fc0c29ee5..12de2c8aa 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 @@ public class InstallOperationTests extends AbstractProvisioningUITest { 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 2436d9987..1f532db6d 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 @@ public class AvailableIUWrapperTest extends AbstractQueryTest { 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"); } |