Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodor Boev2018-01-03 17:48:52 +0000
committerAlexander Kurtakov2018-01-16 18:56:02 +0000
commita7a99e1fa49938a8f62d44d5c443d38981afeace (patch)
tree8d9152f0908a5030f2a93a818d6bb0b07facb946 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse
parentf539d2ad9b77c9a9f03b9f4cdad08c5847dc8025 (diff)
downloadrt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.tar.gz
rt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.tar.xz
rt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.zip
Bug 528387 - Dedicated xml elements for generic requirementsI20180119-0110I20180118-2000I20180117-2000
- Renamed IProvidedCapability.getAttributes() to getProperties(). This is in sync with other parts of p2 that use "properties" for such data. E.g. the IU properties. - Extended content.xml read/write with a new serialization format for requirements with the "requiredProperties" element. It is used to build an IRequirement that has a standard match expression that applies an LDAP filter to the capability properties. It was not possible to extend the existing "required" element in a way that will make old p2 builds ignore the extended version. - Extended the content.xml read/write shared properties handling logic with "type" attribute. Older p2 builds will ignore it and use strings. Also the "type" attribute only appears in the "properties" extension of "provides" which will be ignored by old p2 builds to begin with. - Some additional cleanup to the content.xml read/write - Increased the current content.xml format version from 1.1.0 to 1.2.0. Old p2 builds declare compatibility with [1.0.0, 2). - Made the handling of the property types supported by a capability safer. E.g. unknown types are converted to Strings. E.g. ProvidedCapability verifies that only supported types are used. - Made the handling of generic requirements reflect the real semantics. E.g. with correct handling of the resolution:=optional|mandatory flag rather than to declare everything optional to avoid breakages in older p2 builds. This is possible because the "requiredProperties" element is completely ignored by older builds. E.g. now if an extender or service is missing provisioning will fail as it is supposed to. - Added factory methods to MetadataFactory for LDAP based requirements. - Added a planner test for LDAP requirements - Cleaned up the AutomatedDirectorTest - Cleaned up some LDAP matching test cases. Change-Id: Ifff77b3ea4c9cea33fd236ed101b1f33c173891d Signed-off-by: Todor Boev <rinsvind@gmail.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/AutomatedDirectorTest.java255
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java33
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/AllTests.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java439
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java20
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PropertyMatchRequirement.java111
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/BundlesActionTest.java109
9 files changed, 626 insertions, 386 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/AutomatedDirectorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/AutomatedDirectorTest.java
index f229b4e66..d726d6a5b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/AutomatedDirectorTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/AutomatedDirectorTest.java
@@ -10,14 +10,16 @@ package org.eclipse.equinox.p2.tests.director;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Test;
-import junit.framework.TestSuite;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.internal.provisional.p2.director.IDirector;
import org.eclipse.equinox.p2.engine.IProfile;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
@@ -25,20 +27,6 @@ import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
* Various automated tests of the {@link IDirector} API.
*/
public class AutomatedDirectorTest extends AbstractProvisioningTest {
- //private static Version version = Version.createOSGi(1, 0, 0);
-
- public static Test suite() {
- return new TestSuite(AutomatedDirectorTest.class);
- }
-
- public AutomatedDirectorTest() {
- super("");
- }
-
- public AutomatedDirectorTest(String name) {
- super(name);
- }
-
/**
* Tests installing an IU that has a filtered dependency on another IU. When
* the filter is satisfied, the dependency is active and the required IU should
@@ -46,26 +34,39 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* and the second IU should not be installed.
*/
public void testInstallFilteredCapability() {
- //The IU that is required
+ final String envKey = "filterKey";
+ final String envVal = "true";
+
+ // The IU that is required
IInstallableUnit requiredIU = createIU("required." + getName());
// The IU to be installed
- IMatchExpression<IInstallableUnit> filter = createFilter("FilterKey", "true");
- IRequirement capability = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), ANY_VERSION, filter, false, false);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), new IRequirement[] {capability});
+ IMatchExpression<IInstallableUnit> requirementFilter = createFilter(envKey, envVal);
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), ANY_VERSION, requirementFilter, false, false)
+ };
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Metadata repository
IInstallableUnit[] allUnits = new IInstallableUnit[] {requiredIU, toInstallIU};
createTestMetdataRepository(allUnits);
- IDirector director = createDirector();
- //Install into a profile in which the filter is satisfied
+ // Install into a profile in which the requirement filter is satisfied
Map<String, String> properties = new HashMap<>();
- properties.put(IProfile.PROP_ENVIRONMENTS, "FilterKey=true");
+ properties.put(IProfile.PROP_ENVIRONMENTS, envKey + "=" + envVal);
+
+ // Profile
IProfile satisfied = createProfile("Satisfied." + getName(), properties);
+
+ // Profile change request
ProfileChangeRequest request = new ProfileChangeRequest(satisfied);
request.add(toInstallIU);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- assertTrue("1.0", result.isOK());
+
+ assertTrue(result.isOK());
assertProfileContains("1.1", satisfied, allUnits);
}
@@ -73,25 +74,41 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* Tests installing an IU that has an optional prerequisite that is available.
*/
public void testInstallOptionalAvailable() {
- String capabilityId = "test." + getName();
+ final String capabilityNamespace = "test.capability";
+ final String capabilityName = "test." + getName();
+ final Version capabilityVersion = DEFAULT_VERSION;
+
//The IU that exports the capability
- IInstallableUnit requiredIU = createIU("required." + getName(), new IProvidedCapability[] {MetadataFactory.createProvidedCapability("test.capability", capabilityId, DEFAULT_VERSION)});
+ IProvidedCapability[] provides = new IProvidedCapability[] {
+ MetadataFactory.createProvidedCapability(capabilityNamespace, capabilityName, capabilityVersion)
+ };
+ IInstallableUnit requiredIU = createIU("required." + getName(), provides);
//The IU that optionally requires the capability
- IRequirement required = MetadataFactory.createRequirement("test.capability", capabilityId, ANY_VERSION, null, /* optional=> */true, /* multiple=> */false, /* greedy=>*/false);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), new IRequirement[] {required});
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(capabilityNamespace, capabilityName, ANY_VERSION, null, /* optional=> */true, /* multiple=> */false, /* greedy=>*/false)
+ };
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Metadata repository
IInstallableUnit[] allUnits = new IInstallableUnit[] {toInstallIU, requiredIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+
+ // Change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- if (!result.isOK())
+ if (!result.isOK()) {
LogHelper.log(result);
+ }
+
+ // The requiredIu is not installed, because the optional requirement is not greedy
assertTrue("1.0", result.isOK());
assertProfileContains("1.1", profile, toInstallArray);
}
@@ -100,21 +117,34 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* Tests installing an IU that has an optional prerequisite that is not available.
*/
public void testInstallOptionalUnavailable() {
- String capabilityId = "test." + getName();
- //no IU will be available that exports this capability
- IRequirement required = MetadataFactory.createRequirement("test.capability", capabilityId, ANY_VERSION, null, true, false);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), new IRequirement[] {required});
+ final String capabilityNamespace = "test.capability";
+ final String capabilityName = "test." + getName();
+
+ // no IU will be available that exports this capability
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(capabilityNamespace, capabilityName, ANY_VERSION, null, /* optional=> */true, /* multiple=> */false)
+ };
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
+ // Profile
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+
+ // Change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
request.addInstallableUnits(allUnits);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- if (!result.isOK())
+ if (!result.isOK()) {
LogHelper.log(result);
+ }
+
+ // The UI is installed because the requirement is optional
assertTrue("1.0", result.isOK());
assertProfileContains("1.1", profile, allUnits);
}
@@ -124,30 +154,50 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* the capability has a platform filter that is not satisfied.
*/
public void testInstallPlatformFilter() {
- //The IU that exports the capability
- String capabilityId = "test." + getName();
- IProvidedCapability[] provides = new IProvidedCapability[] {MetadataFactory.createProvidedCapability("test.capability", capabilityId, DEFAULT_VERSION)};
- IInstallableUnit requiredIU = createIU("required." + getName(), createFilter("osgi.os", "blort"), provides);
+ // Profile environment
+ final String osKey = "osgi.os";
+ final String osVal = "blort";
+
+ // Test capability
+ final String capabilityNamespace = "test.capability";
+ final String capabilityName = "test." + getName();
+ final Version capabilityVersion = DEFAULT_VERSION;
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), createRequiredCapabilities("test.capability", capabilityId, ANY_VERSION, (IMatchExpression<IInstallableUnit>) null));
+ // The IU that exports the capability
+ IProvidedCapability[] provides = new IProvidedCapability[] {MetadataFactory.createProvidedCapability(capabilityNamespace, capabilityName, capabilityVersion)};
+ IInstallableUnit requiredIU = createIU("required." + getName(), createFilter(osKey, osVal), provides);
+ // Installed IU
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), createRequiredCapabilities(capabilityNamespace, capabilityName, ANY_VERSION, (IMatchExpression<IInstallableUnit>) null));
+
+ // Metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {requiredIU, toInstallIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
- IProfile profile = createProfile("TestProfile." + getName());
IDirector director = createDirector();
+
+ // Profile that does not satisfy the OS requirement
+ IProfile profile = createProfile("TestProfile." + getName());
+
+ // Request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provision - should fail since requireIU can't be installed on the current environment
IStatus result = director.provision(request, null, null);
assertTrue("1.0", !result.isOK());
- //try again with the filter satisfied
+ // New profile that satisfies the OS requirement
Map<String, String> properties = new HashMap<>();
- properties.put(IProfile.PROP_ENVIRONMENTS, "osgi.os=blort");
- IProfile profile2 = createProfile("TestProfile2." + getName(), properties);
- request = new ProfileChangeRequest(profile2);
+ properties.put(IProfile.PROP_ENVIRONMENTS, osKey + "=" + osVal);
+ profile = createProfile("TestProfile2." + getName(), properties);
+
+ // New request
+ request = new ProfileChangeRequest(profile);
request.addInstallableUnits(toInstallArray);
+
+ // New provisioning - should succeed
result = director.provision(request, null, null);
assertTrue("2.0", result.isOK());
}
@@ -156,27 +206,42 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* Tests installing an IU that has an unsatisfied platform filter
*/
public void testInstallPlatformFilterUnsatisfied() {
- //The IU to install
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), createFilter("osgi.os", "blort"), NO_PROVIDES);
+ // Profile environment
+ final String osKey = "osgi.os";
+ final String osVal = "blort";
+
+ // The IU to install that needs a concrete environment
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), createFilter(osKey, osVal), NO_PROVIDES);
+
+ // Metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {toInstallIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
+ // Profile without a matching environment
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+
+ // Change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provisioning failure: incompatible environment
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- assertTrue("1.0", !result.isOK());
+ assertTrue(!result.isOK());
- //try again with the filter satisfied
+ // Profile with matching environment
Map<String, String> properties = new HashMap<>();
- properties.put(IProfile.PROP_ENVIRONMENTS, "osgi.os=blort");
- IProfile profile2 = createProfile("TestProfile2." + getName(), properties);
- request = new ProfileChangeRequest(profile2);
+ properties.put(IProfile.PROP_ENVIRONMENTS, osKey + "=" + osVal);
+ profile = createProfile("TestProfile2." + getName(), properties);
+
+ // New change request
+ request = new ProfileChangeRequest(profile);
request.addInstallableUnits(toInstallArray);
+
+ // Provisioning success
result = director.provision(request, null, null);
- assertTrue("2.0", result.isOK());
+ assertTrue(result.isOK());
}
/**
@@ -184,24 +249,39 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* that the IU providing the capability is installed.
*/
public void testSimpleInstallRequired() {
- String capabilityId = "test." + getName();
+ // Test capability
+ String capabilityNamespace = "test.capability";
+ String capabilityName = "test." + getName();
+
//The IU that exports the capability
- IInstallableUnit requiredIU = createIU("required." + getName(), new IProvidedCapability[] {MetadataFactory.createProvidedCapability("test.capability", capabilityId, DEFAULT_VERSION)});
+ IProvidedCapability[] provides = new IProvidedCapability[] {
+ MetadataFactory.createProvidedCapability(capabilityNamespace, capabilityName, DEFAULT_VERSION)
+ };
+ IInstallableUnit requiredIU = createIU("required." + getName(), provides);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), createRequiredCapabilities("test.capability", capabilityId, ANY_VERSION, (IMatchExpression<IInstallableUnit>) null));
+ // The IU that requires the capability
+ IRequirement[] requires = createRequiredCapabilities(capabilityNamespace, capabilityName, ANY_VERSION, (IMatchExpression<IInstallableUnit>) null);
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Crate the metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {requiredIU, toInstallIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
+ // Provision
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+ // Create the profile change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- if (!result.isOK())
+ if (!result.isOK()) {
LogHelper.log(result);
+ }
+
assertTrue("1.0", result.isOK());
assertProfileContains("1.1", profile, allUnits);
}
@@ -211,24 +291,34 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* specifying a version range (any version will do).
*/
public void testInstallRequiredNoVersion() {
- //The IU that is needed
+ // The IU that is needed
IInstallableUnit requiredIU = createIU("required." + getName());
- IRequirement capability = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), null, null, false, false);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), new IRequirement[] {capability});
+ // The IU that is installed
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), null, null, false, false)
+ };
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {requiredIU, toInstallIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
+ // Profile
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+ // Profile change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- if (!result.isOK())
+ if (!result.isOK()) {
LogHelper.log(result);
+ }
+
assertTrue("1.0", result.isOK());
assertProfileContains("1.1", profile, allUnits);
}
@@ -239,25 +329,34 @@ public class AutomatedDirectorTest extends AbstractProvisioningTest {
* capability on the IU namespace.
*/
public void testSimpleInstallRequiredIU() {
- //The IU that exports the capability
+ // The IU that is required. It exports it's identity capability by default.
IInstallableUnit requiredIU = createIU("required." + getName());
- IRequirement capability = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), ANY_VERSION, null, false, false);
- IInstallableUnit toInstallIU = createIU("toInstall." + getName(), new IRequirement[] {capability});
+ // The IU that is installed
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, requiredIU.getId(), ANY_VERSION, null, false, false)
+ };
+ IInstallableUnit toInstallIU = createIU("toInstall." + getName(), requires);
+ // Create the metadata repo
IInstallableUnit[] allUnits = new IInstallableUnit[] {requiredIU, toInstallIU};
- IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
createTestMetdataRepository(allUnits);
IProfile profile = createProfile("TestProfile." + getName());
- IDirector director = createDirector();
+ // Create the profile change request
ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ IInstallableUnit[] toInstallArray = new IInstallableUnit[] {toInstallIU};
request.addInstallableUnits(toInstallArray);
+
+ // Provision
+ IDirector director = createDirector();
IStatus result = director.provision(request, null, null);
- if (!result.isOK())
+ if (!result.isOK()) {
LogHelper.log(result);
- assertTrue("1.0", result.isOK());
+ }
+
+ assertTrue(result.isOK());
assertProfileContains("1.1", profile, allUnits);
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
index f085f9415..609d1d69a 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
@@ -12,21 +12,42 @@ package org.eclipse.equinox.p2.tests.engine;
import java.io.File;
import java.net.URI;
-import java.util.*;
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
-import org.eclipse.equinox.internal.p2.engine.*;
+import org.eclipse.equinox.internal.p2.engine.BeginOperationEvent;
+import org.eclipse.equinox.internal.p2.engine.CommitOperationEvent;
+import org.eclipse.equinox.internal.p2.engine.EngineSession;
+import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
+import org.eclipse.equinox.internal.p2.engine.Phase;
+import org.eclipse.equinox.internal.p2.engine.PhaseEvent;
+import org.eclipse.equinox.internal.p2.engine.PhaseSet;
+import org.eclipse.equinox.internal.p2.engine.ProfileEvent;
+import org.eclipse.equinox.internal.p2.engine.RollbackOperationEvent;
import org.eclipse.equinox.internal.p2.repository.DownloadProgressEvent;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.engine.IEngine;
+import org.eclipse.equinox.p2.engine.IPhaseSet;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.engine.PhaseSetFactory;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.query.*;
+import org.eclipse.equinox.p2.query.IQuery;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
@@ -176,7 +197,7 @@ public class PhaseSetTest extends AbstractProvisioningTest {
getArtifactRepositoryManager().loadRepository(repoURI, null);
doProvisioning(repoURI, phaseSet, query, expectedCode, monitor);
// make sure the listener handles all event already that are dispatched asynchronously
- listener.latch.await(10, TimeUnit.SECONDS);
+ listener.latch.await(15, TimeUnit.SECONDS);
assertFalse("Engine still do provisioning after pausing.", listener.hasProvisioningEventAfterPaused);
pauseJob.join();
} finally {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
index 1ccc188bf..476d0daed 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/RequirementToString.java
@@ -23,18 +23,23 @@ import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
public class RequirementToString extends TestCase {
public void testRequirementWithEmptyRange() {
IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "expectedName", VersionRange.emptyRange, null, false, false);
- assertEquals("expectedNameSpace expectedName 0.0.0", req.toString());
+ assertEquals("expectedNameSpace; expectedName 0.0.0", req.toString());
}
public void testStandardRequirement() {
IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "expectedName", new VersionRange("[1.0.0, 2.0.0)"), null, false, false);
- assertEquals("expectedNameSpace expectedName [1.0.0,2.0.0)", req.toString());
+ assertEquals("expectedNameSpace; expectedName [1.0.0,2.0.0)", req.toString());
+ }
+
+ public void testPropertiesRequirement() {
+ IRequirement req = MetadataFactory.createRequirement("expectedNameSpace", "(key=val)", null, 1, 1, true);
+ assertEquals("expectedNameSpace; (key=val)", req.toString());
}
public void testFancyRequirement() {
- Object[] expressionParameters = new Object[] {"expectedId1, expectedVersion1", "expectedId2, expectedVersion2"};
+ Object[] expressionParameters = new Object[] {"expectedId1", "expectedVersion1", "expectedId2", "expectedVersion2"};
IMatchExpression<IInstallableUnit> iuMatcher = ExpressionUtil.getFactory().<IInstallableUnit> matchExpression(ExpressionUtil.parse("(id == $0 && version == $1) || (id == $2 && version == $3)"), expressionParameters);
IRequirement req = MetadataFactory.createRequirement(iuMatcher, null, 1, 1, true);
- assertEquals("id == $0 && version == $1 || id == $2 && version == $3 expectedId1, expectedVersion1 expectedId2, expectedVersion2", req.toString().trim());
+ assertEquals("id == $0 && version == $1 || id == $2 && version == $3 (expectedId1, expectedVersion1, expectedId2, expectedVersion2)", req.toString().trim());
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/AllTests.java
index 27ebc00b8..8e5be56d7 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/AllTests.java
@@ -4,13 +4,16 @@
* 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.metadata.expression;
-import junit.framework.*;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Performs all automated director tests.
@@ -20,7 +23,7 @@ public class AllTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(ExpressionTest.class);
- suite.addTestSuite(FilterTest.class);
+ suite.addTest(new JUnit4TestAdapter(FilterTest.class));
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
index 0d6895ac2..4a51833fb 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
@@ -10,19 +10,225 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata.expression;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.*;
-import junit.framework.*;
-import org.eclipse.equinox.p2.metadata.expression.*;
-import org.osgi.framework.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.expression.ExpressionParseException;
+import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
+import org.eclipse.equinox.p2.metadata.expression.IFilterExpression;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+public class FilterTest {
+ @Test
+ public void testComparable() throws Exception {
+ IFilterExpression f1 = ExpressionUtil.parseLDAP("(comparable=42)");
+ Object comp;
+ Map<String, Object> hash = new HashMap<>();
+
+ comp = new SampleComparable("42");
+ hash.put("comparable", comp);
+ assertTrue("does not match filter", f1.match(hash));
+ assertTrue("does not match filter", f1.match(new DictionaryServiceReference(hash)));
+
+ comp = Long.valueOf(42);
+ hash.put("comparable", comp);
+ assertTrue("does not match filter", f1.match(hash));
+ assertTrue("does not match filter", f1.match(new DictionaryServiceReference(hash)));
+
+ IFilterExpression f2 = ExpressionUtil.parseLDAP("(comparable=42)");
+ hash = new Hashtable<>();
+
+ comp = new SampleComparable("42");
+ hash.put("comparable", comp);
+ assertTrue("does not match filter", f2.match(hash));
+ assertTrue("does not match filter", f2.match(new DictionaryServiceReference(hash)));
+
+ comp = Long.valueOf(42);
+ hash.put("comparable", comp);
+ assertTrue("does not match filter", f2.match(hash));
+ assertTrue("does not match filter", f2.match(new DictionaryServiceReference(hash)));
+
+ assertEquals("not equal", f1, f2);
+ }
+
+ @Test
+ public void testFilterEquality() {
+ Filter f1 = ExpressionUtil.parseLDAP("( a = bedroom )");
+ Filter f2 = ExpressionUtil.parseLDAP(" (a= bedroom ) ");
+ assertEquals("not equal", "(a= bedroom )", f1.toString());
+ assertEquals("not equal", "(a= bedroom )", f2.toString());
+ assertEquals("not equal", f1, f2);
+ assertEquals("not equal", f2, f1);
+ assertEquals("not equal", f1.hashCode(), f2.hashCode());
+
+ f1 = ExpressionUtil.parseLDAP("(status =\\28o*\\5c\\29\\2a)");
+ assertEquals("not equal", "(status=\\28o*\\5c\\29\\2a)", f1.toString());
+
+ f1 = ExpressionUtil.parseLDAP("(|(a=1)(&(a=1)(b=1)))");
+ f2 = ExpressionUtil.parseLDAP("(a=1)");
+
+ f1 = ExpressionUtil.parseLDAP("(|(&(os=macos)(ws=cocoa)(arch=x86))(&(ws=cocoa)(os=macos)(arch=ppc)))");
+ f2 = ExpressionUtil.parseLDAP("(&(os=macos)(ws=cocoa)(|(arch=x86)(arch=ppc)))");
+ assertEquals("not equal: f1:" + f1.toString() + ", f2:" + f1.toString(), f1, f2);
+
+ f1 = ExpressionUtil.parseLDAP("(&(|(x=a)(y=b)(z=a))(|(x=a)(y=b)(z=b)))");
+ f2 = ExpressionUtil.parseLDAP("(|(x=a)(y=b)(&(z=a)(z=b)))");
+ assertEquals("not equal: f1:" + f1.toString() + ", f2:" + f1.toString(), f1, f2);
+
+ f1 = ExpressionUtil.parseLDAP("(&(a=1)(|(a=1)(b=1)))");
+ f2 = ExpressionUtil.parseLDAP("(a=1)");
+
+ f1 = ExpressionUtil.parseLDAP("(|(a=1)(&(a=1)(b=1)))");
+ f2 = ExpressionUtil.parseLDAP("(a=1)");
+ assertEquals("not equal: f1:" + f1.toString() + ", f2:" + f1.toString(), f1, f2);
+ }
+
+ @Test
+ public void testFilterMatching() {
+ Dictionary<String, Object> props = new Hashtable<>();
+ props.put("room", "bedroom");
+ props.put("channel", Integer.valueOf(34));
+ props.put("status", "(on\\)*");
+ props.put("max record time", Long.valueOf(150));
+ props.put("canrecord", "true(x)");
+ props.put("shortvalue", Short.valueOf((short) 1000));
+ props.put("bytevalue", Byte.valueOf((byte) 10));
+ props.put("floatvalue", Float.valueOf(1.01f));
+ props.put("doublevalue", Double.valueOf(2.01));
+ props.put("charvalue", Character.valueOf('A'));
+ props.put("booleanvalue", Boolean.FALSE);
+ props.put("listvalue", Arrays.asList(1, 2, 3));
+ props.put("versionlistvalue", Arrays.asList(Version.create("1"), Version.create("2"), Version.create("3")));
+ props.put("weirdvalue", new Hashtable<>());
+ props.put("bigintvalue", new BigInteger("4123456"));
+ props.put("bigdecvalue", new BigDecimal("4.123456"));
+
+ assertMatch("(room=*)", props);
+ assertNoMatch("(rooom=*)", props);
+ assertMatch("(room=bedroom)", props);
+ assertMatch("(room~= B E D R O O M )", props);
+ assertNoMatch("(room=abc)", props);
+ assertMatch(" ( room >=aaaa)", props);
+ assertNoMatch("(room <=aaaa)", props);
+ assertMatch(" ( room =b*) ", props);
+ assertMatch(" ( room =*m) ", props);
+ assertMatch("(room=bed*room)", props);
+ assertMatch(" ( room =b*oo*m) ", props);
+ assertMatch(" ( room =*b*oo*m*) ", props);
+ assertNoMatch(" ( room =b*b* *m*) ", props);
+ assertMatch(" (& (room =bedroom) (channel = 34))", props);
+ assertNoMatch(" (& (room =b*) (room =*x) (channel=34))", props);
+ assertMatch("(| (room =bed*)(channel=222)) ", props);
+ assertMatch("(| (room =boom*)(channel=34)) ", props);
+ assertMatch(" (! (room =ab*b*oo*m*) ) ", props);
+ assertMatch(" (status =\\(o*\\\\\\)\\*) ", props);
+ assertMatch(" (status =\\28o*\\5c\\29\\2a) ", props);
+ assertMatch(" (status =\\28o*\\5C\\29\\2A) ", props);
+ assertMatch(" (canRecord =true\\(x\\)) ", props);
+ assertMatch("(max Record Time <=150) ", props);
+ assertMatch("(shortValue >= 100) ", props);
+ assertMatch(" ( & ( byteValue <= 100 ) ( byteValue >= 10 ) ) ", props);
+ assertMatch("(bigIntValue = 4123456) ", props);
+ assertMatch("(bigDecValue = 4.123456) ", props);
+ assertMatch("(floatValue >= 1.0) ", props);
+ assertMatch("(doubleValue <= 2.011) ", props);
+ assertMatch("(charValue ~= a) ", props);
+ assertMatch("(booleanValue = false) ", props);
+ assertMatch("(listvalue>=0)", props);
+ assertMatch("(listvalue=3)", props);
+ assertMatch("(!(listvalue>=4))", props);
+ assertMatch("(versionlistvalue>=0)", props);
+ assertMatch("(versionlistvalue=3)", props);
+ assertMatch("(!(versionlistvalue>=4))", props);
+ assertMatch("(& (| (room =d*m) (room =bed*) (room=abc)) (! (channel=999)))", props);
+ assertNoMatch("(room=bedroom)", null);
+ assertNoMatch("(weirdValue = 100) ", props);
+ }
+
+ @Test
+ public void testFilterParserErrors() {
+ assertParseError("()");
+ assertParseError("(=foo)");
+ assertParseError("(");
+ assertParseError("(abc = ))");
+ assertParseError("(& (abc = xyz) (& (345))");
+ assertParseError(" (room = b**oo!*m*) ) ");
+ assertParseError(" (room = b**oo)*m*) ) ");
+ assertParseError(" (room = *=b**oo*m*) ) ");
+ assertParseError(" (room = =b**oo*m*) ) ");
+ }
+
+ private void assertMatch(String query, Dictionary<String, Object> props) {
+ expectMatch(query, props, true);
+ }
+
+ private void assertNoMatch(String query, Dictionary<String, Object> props) {
+ expectMatch(query, props, false);
+ }
+
+ private void expectMatch(String query, Dictionary<String, Object> props, boolean match) {
+ Filter f = ExpressionUtil.parseLDAP(query);
+
+ // TODO Doing raw conversion here for simplicity; could convert to Dictionary<String, ?>
+ // but the filter impl must still handle cases where non String keys are used.
+ assertEquals(match, f.match(props));
+
+ ServiceReference ref = new DictionaryServiceReference((Map<String, ? extends Object>) props);
+ assertEquals(match, f.match(ref));
+ }
+
+ private void assertParseError(String query) {
+ try {
+ ExpressionUtil.parseLDAP(query);
+ fail("expected exception");
+ } catch (ExpressionParseException e) {
+ // Pass
+ }
+ }
+
+ private static class SampleComparable implements Comparable<SampleComparable> {
+ private int value = -1;
+
+ public SampleComparable(String value) {
+ this.value = Integer.parseInt(value);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof SampleComparable && value == ((SampleComparable) o).value;
+ }
+
+ @Override
+ public int compareTo(SampleComparable o) {
+ return value - o.value;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(value);
+ }
+ }
-public class FilterTest extends TestCase {
private static class DictionaryServiceReference implements ServiceReference {
private final Map<String, ? extends Object> dictionary;
-
+
private final String[] keys;
-
+
DictionaryServiceReference(Map<String, ? extends Object> dictionary) {
if (dictionary == null) {
this.dictionary = null;
@@ -42,17 +248,17 @@ public class FilterTest extends TestCase {
}
this.keys = keyList.toArray(new String[keyList.size()]);
}
-
+
@Override
public int compareTo(Object reference) {
throw new UnsupportedOperationException();
}
-
+
@Override
public Bundle getBundle() {
return null;
}
-
+
@Override
public Object getProperty(String k) {
for (int i = 0, length = keys.length; i < length; i++) {
@@ -63,230 +269,25 @@ public class FilterTest extends TestCase {
}
return null;
}
-
+
@Override
public String[] getPropertyKeys() {
return keys.clone();
}
-
+
@Override
public Bundle[] getUsingBundles() {
throw new UnsupportedOperationException();
}
-
+
@Override
public boolean isAssignableTo(Bundle bundle, String className) {
throw new UnsupportedOperationException();
}
-
+
@Override
public Dictionary<String, Object> getProperties() {
return new Hashtable<>(dictionary);
}
}
-
- private static class SampleComparable implements Comparable<SampleComparable> {
- private int value = -1;
-
- public SampleComparable(String value) {
- this.value = Integer.parseInt(value);
- }
-
- @Override
- public boolean equals(Object o) {
- return o instanceof SampleComparable && value == ((SampleComparable) o).value;
- }
-
- @Override
- public int compareTo(SampleComparable o) {
- return value - o.value;
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
- }
-
- static final int ISTRUE = 1;
-
- static final int ISFALSE = 2;
-
- static final int ISILLEGAL = 3;
-
- public static Test suite() {
- return new TestSuite(FilterTest.class);
- }
-
- public void testComparable() throws Exception {
- IFilterExpression f1 = ExpressionUtil.parseLDAP("(comparable=42)"); //$NON-NLS-1$
- Object comp;
- Map<String, Object> hash = new HashMap<>();
-
- comp = new SampleComparable("42"); //$NON-NLS-1$
- hash.put("comparable", comp); //$NON-NLS-1$
- assertTrue("does not match filter", f1.match(hash)); //$NON-NLS-1$
- assertTrue("does not match filter", f1.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
-
- comp = Long.valueOf(42);
- hash.put("comparable", comp); //$NON-NLS-1$
- assertTrue("does not match filter", f1.match(hash)); //$NON-NLS-1$
- assertTrue("does not match filter", f1.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
-
- IFilterExpression f2 = ExpressionUtil.parseLDAP("(comparable=42)"); //$NON-NLS-1$
- hash = new Hashtable<>();
-
- comp = new SampleComparable("42"); //$NON-NLS-1$
- hash.put("comparable", comp); //$NON-NLS-1$
- assertTrue("does not match filter", f2.match(hash)); //$NON-NLS-1$
- assertTrue("does not match filter", f2.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
-
- comp = Long.valueOf(42);
- hash.put("comparable", comp); //$NON-NLS-1$
- assertTrue("does not match filter", f2.match(hash)); //$NON-NLS-1$
- assertTrue("does not match filter", f2.match(new DictionaryServiceReference(hash))); //$NON-NLS-1$
-
- assertEquals("not equal", f1, f2); //$NON-NLS-1$
- }
-
- public void testFilter() {
- Dictionary<String, Object> props = new Hashtable<>();
- props.put("room", "bedroom"); //$NON-NLS-1$ //$NON-NLS-2$
- props.put("channel", Integer.valueOf(34)); //$NON-NLS-1$
- props.put("status", "(on\\)*"); //$NON-NLS-1$//$NON-NLS-2$
- props.put("max record time", Long.valueOf(150)); //$NON-NLS-1$
- props.put("canrecord", "true(x)"); //$NON-NLS-1$ //$NON-NLS-2$
- props.put("shortvalue", Short.valueOf((short) 1000)); //$NON-NLS-1$
- props.put("bytevalue", Byte.valueOf((byte) 10)); //$NON-NLS-1$
- props.put("floatvalue", Float.valueOf(1.01f)); //$NON-NLS-1$
- props.put("doublevalue", Double.valueOf(2.01)); //$NON-NLS-1$
- props.put("charvalue", Character.valueOf('A')); //$NON-NLS-1$
- props.put("booleanvalue", Boolean.FALSE); //$NON-NLS-1$
- props.put("weirdvalue", new Hashtable<>()); //$NON-NLS-1$
- try {
- props.put("bigintvalue", new BigInteger("4123456")); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (NoClassDefFoundError e) {
- // ignore
- }
- try {
- props.put("bigdecvalue", new BigDecimal("4.123456")); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (NoClassDefFoundError e) {
- // ignore
- }
-
- testFilter("(room=*)", props, ISTRUE); //$NON-NLS-1$
- testFilter("(rooom=*)", props, ISFALSE); //$NON-NLS-1$
- testFilter("(room=bedroom)", props, ISTRUE); //$NON-NLS-1$
- testFilter("(room~= B E D R O O M )", props, ISTRUE); //$NON-NLS-1$
- testFilter("(room=abc)", props, ISFALSE); //$NON-NLS-1$
- testFilter(" ( room >=aaaa)", props, ISTRUE); //$NON-NLS-1$
- testFilter("(room <=aaaa)", props, ISFALSE); //$NON-NLS-1$
- testFilter(" ( room =b*) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" ( room =*m) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(room=bed*room)", props, ISTRUE); //$NON-NLS-1$
- testFilter(" ( room =b*oo*m) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" ( room =*b*oo*m*) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" ( room =b*b* *m*) ", props, ISFALSE); //$NON-NLS-1$
- testFilter(" (& (room =bedroom) (channel = 34))", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (& (room =b*) (room =*x) (channel=34))", props, ISFALSE); //$NON-NLS-1$
- testFilter("(| (room =bed*)(channel=222)) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(| (room =boom*)(channel=34)) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (! (room =ab*b*oo*m*) ) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (status =\\(o*\\\\\\)\\*) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (status =\\28o*\\5c\\29\\2a) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (status =\\28o*\\5C\\29\\2A) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" (canRecord =true\\(x\\)) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(max Record Time <=150) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(shortValue >= 100) ", props, ISTRUE); //$NON-NLS-1$
- testFilter(" ( & ( byteValue <= 100 ) ( byteValue >= 10 ) ) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(bigIntValue = 4123456) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(bigDecValue = 4.123456) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(floatValue >= 1.0) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(doubleValue <= 2.011) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(charValue ~= a) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(booleanValue = false) ", props, ISTRUE); //$NON-NLS-1$
- testFilter("(& (| (room =d*m) (room =bed*) (room=abc)) (! (channel=999)))", props, ISTRUE); //$NON-NLS-1$
- testFilter("(room=bedroom)", null, ISFALSE); //$NON-NLS-1$
-
- testFilter("()", props, ISILLEGAL); //$NON-NLS-1$
- testFilter("(=foo)", props, ISILLEGAL); //$NON-NLS-1$
- testFilter("(", props, ISILLEGAL); //$NON-NLS-1$
- testFilter("(abc = ))", props, ISILLEGAL); //$NON-NLS-1$
- testFilter("(& (abc = xyz) (& (345))", props, ISILLEGAL); //$NON-NLS-1$
- testFilter(" (room = b**oo!*m*) ) ", props, ISILLEGAL); //$NON-NLS-1$
- testFilter(" (room = b**oo)*m*) ) ", props, ISILLEGAL); //$NON-NLS-1$
- testFilter(" (room = *=b**oo*m*) ) ", props, ISILLEGAL); //$NON-NLS-1$
- testFilter(" (room = =b**oo*m*) ) ", props, ISILLEGAL); //$NON-NLS-1$
-
- try {
- Filter f1 = ExpressionUtil.parseLDAP("( a = bedroom )"); //$NON-NLS-1$
- Filter f2 = ExpressionUtil.parseLDAP(" (a= bedroom ) "); //$NON-NLS-1$
- assertEquals("not equal", "(a= bedroom )", f1.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("not equal", "(a= bedroom )", f2.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("not equal", f1, f2); //$NON-NLS-1$
- assertEquals("not equal", f2, f1); //$NON-NLS-1$
- assertEquals("not equal", f1.hashCode(), f2.hashCode()); //$NON-NLS-1$
-
- f1 = ExpressionUtil.parseLDAP("(status =\\28o*\\5c\\29\\2a)");
- assertEquals("not equal", "(status=\\28o*\\5c\\29\\2a)", f1.toString()); //$NON-NLS-1$ //$NON-NLS-2$
-
- f1 = ExpressionUtil.parseLDAP("(|(a=1)(&(a=1)(b=1)))"); //$NON-NLS-1$
- f2 = ExpressionUtil.parseLDAP("(a=1)"); //$NON-NLS-1$
- System.out.println(f2.toString());
- System.out.println(f1.toString());
-
- f1 = ExpressionUtil.parseLDAP("(|(&(os=macos)(ws=cocoa)(arch=x86))(&(ws=cocoa)(os=macos)(arch=ppc)))"); //$NON-NLS-1$
- f2 = ExpressionUtil.parseLDAP("(&(os=macos)(ws=cocoa)(|(arch=x86)(arch=ppc)))"); //$NON-NLS-1$
- System.out.println(f2.toString());
- System.out.println(f1.toString());
- assertEquals("not equal", f1, f2); //$NON-NLS-1$
-
- f1 = ExpressionUtil.parseLDAP("(&(|(x=a)(y=b)(z=a))(|(x=a)(y=b)(z=b)))"); //$NON-NLS-1$
- f2 = ExpressionUtil.parseLDAP("(|(x=a)(y=b)(&(z=a)(z=b)))"); //$NON-NLS-1$
- System.out.println(f2.toString());
- System.out.println(f1.toString());
- assertEquals("not equal", f1, f2); //$NON-NLS-1$
-
- f1 = ExpressionUtil.parseLDAP("(&(a=1)(|(a=1)(b=1)))"); //$NON-NLS-1$
- f2 = ExpressionUtil.parseLDAP("(a=1)"); //$NON-NLS-1$
- System.out.println(f2.toString());
- System.out.println(f1.toString());
-
- f1 = ExpressionUtil.parseLDAP("(|(a=1)(&(a=1)(b=1)))"); //$NON-NLS-1$
- f2 = ExpressionUtil.parseLDAP("(a=1)"); //$NON-NLS-1$
- System.out.println(f2.toString());
- System.out.println(f1.toString());
- assertEquals("not equal", f1, f2); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- fail("unexpected invalid syntax: " + e); //$NON-NLS-1$
- }
- testFilter("(weirdValue = 100) ", props, ISFALSE); //$NON-NLS-1$
-
- }
-
- private void testFilter(String query, Dictionary<String, Object> props, int expect) {
- final ServiceReference ref = new DictionaryServiceReference((Map<String, ? extends Object>) props);
- Filter f1;
- try {
- f1 = ExpressionUtil.parseLDAP(query);
-
- if (expect == ISILLEGAL) {
- fail("expected exception"); //$NON-NLS-1$
- }
- } catch (ExpressionParseException e) {
- System.out.println(e.toString());
- if (expect != ISILLEGAL) {
- fail("exception: " + e.toString()); //$NON-NLS-1$
- }
- return;
- }
-
- // TODO Doing raw conversion here for simplicity; could convert to Dictionary<String, ?>
- // but the filter impl must still handle cases where non String keys are used.
- boolean val = f1.match(props);
- assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
-
- val = f1.match(ref);
- assertEquals("wrong result", expect == ISTRUE, val); //$NON-NLS-1$
- }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
index 022b6549f..605143491 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
@@ -179,14 +179,14 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
class SPIProvidedCapability implements IProvidedCapability {
private final String namespace;
- private final Map<String, Object> attributes;
+ private final Map<String, Object> properties;
public SPIProvidedCapability(String namespace, String name, Version version) {
this.namespace = namespace;
- this.attributes = new HashMap<>();
- attributes.put(namespace, name);
- attributes.put(ProvidedCapability.ATTRIBUTE_VERSION, version);
+ this.properties = new HashMap<>();
+ properties.put(namespace, name);
+ properties.put(IProvidedCapability.PROPERTY_VERSION, version);
}
@Override
@@ -199,7 +199,7 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
if (!(namespace.equals(otherCapability.getNamespace()))) {
return false;
}
- if (!(attributes.equals(otherCapability.getAttributes()))) {
+ if (!(properties.equals(otherCapability.getProperties()))) {
return false;
}
return true;
@@ -207,12 +207,12 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
@Override
public String toString() {
- return namespace + "; " + attributes;
+ return namespace + "; " + properties;
}
@Override
public String getName() {
- return (String) attributes.get(namespace);
+ return (String) properties.get(namespace);
}
@Override
@@ -222,12 +222,12 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
@Override
public Version getVersion() {
- return (Version) attributes.get(ProvidedCapability.ATTRIBUTE_VERSION);
+ return (Version) properties.get(IProvidedCapability.PROPERTY_VERSION);
}
@Override
- public Map<String, Object> getAttributes() {
- return Collections.unmodifiableMap(attributes);
+ public Map<String, Object> getProperties() {
+ return Collections.unmodifiableMap(properties);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PropertyMatchRequirement.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PropertyMatchRequirement.java
new file mode 100644
index 000000000..4d709c93a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PropertyMatchRequirement.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2017 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 static org.eclipse.core.runtime.IStatus.ERROR;
+import static org.eclipse.core.runtime.IStatus.OK;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.equinox.internal.p2.director.Explanation.MissingIU;
+import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
+import org.eclipse.equinox.internal.provisional.p2.director.PlannerStatus;
+import org.eclipse.equinox.internal.provisional.p2.director.RequestStatus;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.planner.IPlanner;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+public class PropertyMatchRequirement extends AbstractProvisioningTest {
+ private IInstallableUnit providerIu;
+ private IInstallableUnit consumerIu;
+
+ private IProfile profile;
+ private IPlanner planner;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // A standard OSGi service representation
+ String osgiService = "osgi.service";
+ String objectClass = "objectClass";
+ List<String> objectClassList = Arrays.asList("org.example.A", "org.example.B", "org.example.C");
+
+ // Provider.
+ // TODO Check if p2 really needs a name. IProvidedCapability.equals() can differentiate by properties only.
+ Map<String, Object> capability = new HashMap<>();
+ capability.put(osgiService, "ignored-1");
+ capability.put(objectClass, objectClassList);
+
+ IProvidedCapability[] provides = new IProvidedCapability[] {
+ MetadataFactory.createProvidedCapability(osgiService, capability)
+ };
+ providerIu = createIU("provider", DEFAULT_VERSION, provides);
+
+ // Consumer
+ String requirement = String.format("(%s=%s)", objectClass, objectClassList.get(0));
+ IRequirement[] requires = new IRequirement[] {
+ MetadataFactory.createRequirement(osgiService, requirement, null, 1, 1, true)
+ };
+ consumerIu = createIU("consumer", DEFAULT_VERSION, requires);
+
+ // Planner
+ profile = createProfile("test." + getName());
+ planner = createPlanner();
+ }
+
+ public void testMandatoryPresent() {
+ createTestMetdataRepository(new IInstallableUnit[] {providerIu, consumerIu});
+
+ ProfileChangeRequest req = new ProfileChangeRequest(profile);
+ req.add(consumerIu);
+
+ // Must pass
+ IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
+ assertEquals(OK, plan.getStatus().getSeverity());
+
+ // And both consumer and provider must be installed
+ assertInstallOperand(plan, consumerIu);
+ assertInstallOperand(plan, providerIu);
+ }
+
+ public void testMandatoryAbsent() {
+ createTestMetdataRepository(new IInstallableUnit[] {consumerIu});
+
+ ProfileChangeRequest req = new ProfileChangeRequest(profile);
+ req.add(consumerIu);
+
+ // Must fail
+ IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
+ assertEquals(ERROR, plan.getStatus().getSeverity());
+
+ // With a good explanation
+ RequestStatus requestStatus = ((PlannerStatus) plan.getStatus()).getRequestStatus();
+ IRequirement consumerReq = consumerIu.getRequirements().iterator().next();
+ requestStatus.getExplanations()
+ .stream()
+ .filter(e -> e instanceof MissingIU)
+ .filter(e -> (((MissingIU) e).req.toString()).equals(consumerReq.toString()))
+ .findFirst()
+ .orElseGet(() -> {
+ fail("Did not find explanation for missing requirement: " + consumerReq);
+ return null;
+ });
+
+ // And the consumer must not be installed
+ assertNoOperand(plan, consumerIu);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java
index 058cca76c..faf51598b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java
@@ -27,15 +27,13 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IProvidedCapability;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
-import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
-import org.eclipse.equinox.p2.metadata.expression.IExpression;
-import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.AbstractPublisherAction;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
import org.eclipse.equinox.p2.publisher.IPublisherResult;
@@ -92,18 +90,25 @@ public abstract class ActionTest extends AbstractProvisioningTest {
verifyRequirement(actual, namespace, name, range, null, 1, 1, true);
}
- protected void verifyRequirement(Collection<IRequirement> actual, String namespace, String name, VersionRange range, String filterStr, int minCard, int maxCard, boolean greedy) {
- IRequirement expected = MetadataFactory.createRequirement(namespace, name, range, null, minCard, maxCard, greedy);
+ protected void verifyRequirement(Collection<IRequirement> actual, String namespace, String name, VersionRange range, String envFilter, int minCard, int maxCard, boolean greedy) {
+ IRequirement expected = MetadataFactory.createRequirement(namespace, name, range, InstallableUnit.parseFilter(envFilter), minCard, maxCard, greedy);
verifyRequirement(actual, expected);
}
- protected void verifyRequirement(Collection<IRequirement> actual, String matchExpr, int minCard, int maxCard, boolean greedy) {
- IExpression expr = ExpressionUtil.parse(matchExpr);
- IMatchExpression<IInstallableUnit> matcher = ExpressionUtil.getFactory().matchExpression(expr);
- IRequirement expected = MetadataFactory.createRequirement(matcher, null, minCard, maxCard, greedy);
+ protected void verifyRequirement(Collection<IRequirement> actual, String namespace, String propsFilter, String envFilter, int minCard, int maxCard, boolean greedy) {
+ IRequirement expected = MetadataFactory.createRequirement(namespace, propsFilter, InstallableUnit.parseFilter(envFilter), minCard, maxCard, greedy);
verifyRequirement(actual, expected);
}
+ /**
+ * Safe to use only if actual and expected were created by the same method of {@link MetadataFactory}
+ * because match expressions are not safe to compare for equality.
+ *
+ * This must be guaranteed by all sub-class test cases
+ *
+ * @param actual
+ * @param expected
+ */
protected void verifyRequirement(Collection<IRequirement> actual, IRequirement expected) {
for (IRequirement act : actual) {
if (expected.getMatches().equals(act.getMatches())) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/BundlesActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/BundlesActionTest.java
index af99bfe42..7e3ab0344 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/BundlesActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/BundlesActionTest.java
@@ -77,18 +77,19 @@ import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
public class BundlesActionTest extends ActionTest {
private static final String OSGI = PublisherHelper.OSGI_BUNDLE_CLASSIFIER;
private static final String OSGI_IDENTITY = "osgi.identity";
+ private static final String OSGI_EE = "osgi.ee";
private static final String JAVA_PACKAGE = "java.package";//$NON-NLS-1$
- private static final String JAVA_EE_1_4_REQ = "providedCapabilities.exists(pc | pc.namespace == 'osgi.ee' && pc.attributes ~= filter('(|(&(osgi.ee=JavaSE)(version=1.4))(&(osgi.ee=CDC/Foundation)(version=1.1)))'))";
- private static final String JAVA_EE_1_6_REQ = "providedCapabilities.exists(pc | pc.namespace == 'osgi.ee' && pc.attributes ~= filter('(&(osgi.ee=JavaSE)(version=1.6))'))";
+ private static final String JAVA_EE_1_4 = "(|(&(osgi.ee=JavaSE)(version=1.4))(&(osgi.ee=CDC/Foundation)(version=1.1)))";
+ private static final String JAVA_EE_1_6 = "(&(osgi.ee=JavaSE)(version=1.6))";
private static final String TEST1_IUD_NAME = "iud";//$NON-NLS-1$
private static final String TEST1_PROVZ_NAME = "iuz";//$NON-NLS-1$
private static final String TEST1_PROVBUNDLE_NAME = "test1";//$NON-NLS-1$
- private static final String TEST1_REQ_EE_FILTER = JAVA_EE_1_4_REQ;
+ private static final String TEST1_REQ_EE = JAVA_EE_1_4;
private static final String TEST2_REQ_A_NAME = "iua";//$NON-NLS-1$
private static final String TEST2_REQ_B_NAME = "iub";//$NON-NLS-1$
private static final String TEST2_REQ_C_NAME = "iuc";//$NON-NLS-1$
- private static final String TEST2_REQ_EE_FILTER = JAVA_EE_1_4_REQ;
+ private static final String TEST2_REQ_EE = JAVA_EE_1_4;
private static final String TEST2_PROV_Z_NAME = "iuz";//$NON-NLS-1$
private static final String TEST2_PROV_Y_NAME = "iuy";//$NON-NLS-1$
private static final String TEST2_PROV_X_NAME = "iux";//$NON-NLS-1$
@@ -99,9 +100,9 @@ public class BundlesActionTest extends ActionTest {
private static final String TEST4_REQ_PACKAGE_OPTGREEDY_NAME = "iuf";//$NON-NLS-1$
private static final String TEST4_REQ_BUNDLE_OPTIONAL_NAME = "iug";//$NON-NLS-1$
private static final String TEST4_REQ_BUNDLE_OPTGREEDY_NAME = "iuh";//$NON-NLS-1$
- private static final String TEST5_REQ_EE_FILTER = JAVA_EE_1_4_REQ;
+ private static final String TEST5_REQ_EE = JAVA_EE_1_4;
private static final String TEST5_PROV_BUNDLE_NAME = "test5";//$NON-NLS-1$
- private static final String TESTDYN_REQ_EE_FILTER = JAVA_EE_1_6_REQ;
+ private static final String TESTDYN_REQ_EE = JAVA_EE_1_6;
private static final File TEST_BASE = new File(TestActivator.getTestDataFolder(), "BundlesActionTest");//$NON-NLS-1$
private static final File TEST_FILE1 = new File(TEST_BASE, TEST1_PROVBUNDLE_NAME);
@@ -173,32 +174,32 @@ public class BundlesActionTest extends ActionTest {
bundlesAction.perform(info, results, new NullProgressMonitor());
Collection<IInstallableUnit> ius = results.getIUs(null, null);
- assertEquals("1.0", 1, ius.size());
+ assertEquals(1, ius.size());
info = new PublisherInfo();
results = new PublisherResult();
bundlesAction = new BundlesAction(new File[] {foo});
bundlesAction.perform(info, results, new NullProgressMonitor());
ius = results.getIUs(null, null);
- assertEquals("2.0", 1, ius.size());
+ assertEquals(1, ius.size());
QueryableArray queryableArray = new QueryableArray(ius.toArray(new IInstallableUnit[ius.size()]));
IQueryResult<IInstallableUnit> result = queryableArray.query(QueryUtil.createIUQuery("foo"), null);
- assertEquals("3.1", 1, queryResultSize(result));
+ assertEquals(1, queryResultSize(result));
IInstallableUnit iu = result.iterator().next();
TranslationSupport utils = new TranslationSupport();
utils.setTranslationSource(queryableArray);
- assertEquals("3.2", "English Foo", utils.getIUProperty(iu, IInstallableUnit.PROP_NAME));
+ assertEquals("English Foo", utils.getIUProperty(iu, IInstallableUnit.PROP_NAME));
bundlesAction = new BundlesAction(new File[] {foo_fragment});
bundlesAction.perform(info, results, new NullProgressMonitor());
ius = results.getIUs(null, null);
- assertEquals("2.0", 3, ius.size());
+ assertEquals(3, ius.size());
queryableArray = new QueryableArray(ius.toArray(new IInstallableUnit[ius.size()]));
result = queryableArray.query(QueryUtil.createIUQuery("foo"), null);
- assertEquals("2.1", 1, queryResultSize(result));
+ assertEquals(1, queryResultSize(result));
iu = result.iterator().next();
utils.setTranslationSource(queryableArray);
- assertEquals("2.2", "German Foo", utils.getIUProperty(iu, IInstallableUnit.PROP_NAME, Locale.GERMAN.toString()));
+ assertEquals("German Foo", utils.getIUProperty(iu, IInstallableUnit.PROP_NAME, Locale.GERMAN.toString()));
}
private void verifyBundlesAction() throws Exception {
@@ -217,7 +218,7 @@ public class BundlesActionTest extends ActionTest {
IArtifactDescriptor[] descriptors = artifactRepository.getArtifactDescriptors(key2);
// Should have one canonical and one packed
- assertTrue("1.0", descriptors.length == 2);
+ assertEquals(2, descriptors.length);
int packedIdx;
int canonicalIdx;
@@ -244,18 +245,18 @@ public class BundlesActionTest extends ActionTest {
}
private void verifyBundle1() {
- ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST1_PROVBUNDLE_NAME, IPublisherResult.ROOT));
- assertTrue(ius.size() == 1);
+ List<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST1_PROVBUNDLE_NAME, IPublisherResult.ROOT));
+ assertEquals(1, ius.size());
IInstallableUnit bundle1IU = ius.get(0);
- assertNotNull("1.0", bundle1IU);
- assertEquals("1.1", bundle1IU.getVersion(), BUNDLE1_VERSION);
+ assertNotNull(bundle1IU);
+ assertEquals(bundle1IU.getVersion(), BUNDLE1_VERSION);
// check required capabilities
- Collection<IRequirement> requiredCapability = bundle1IU.getRequirements();
- verifyRequirement(requiredCapability, TEST1_IU_D_NAMESPACE, TEST1_IUD_NAME, TEST1_IU_D_VERSION_RANGE);
- verifyRequirement(requiredCapability, TEST1_REQ_EE_FILTER, 0, 1, true);
- assertEquals("2.0", 2, requiredCapability.size());
+ Collection<IRequirement> requirements = bundle1IU.getRequirements();
+ verifyRequirement(requirements, TEST1_IU_D_NAMESPACE, TEST1_IUD_NAME, TEST1_IU_D_VERSION_RANGE);
+ verifyRequirement(requirements, OSGI_EE, TEST1_REQ_EE, null, 1, 1, true);
+ assertEquals(2, requirements.size());
// check provided capabilities
Collection<IProvidedCapability> providedCapabilities = bundle1IU.getProvidedCapabilities();
@@ -264,7 +265,7 @@ public class BundlesActionTest extends ActionTest {
verifyProvidedCapability(providedCapabilities, OSGI, TEST1_PROVBUNDLE_NAME, BUNDLE1_VERSION);
verifyProvidedCapability(providedCapabilities, TEST1_PROV_Z_NAMESPACE, TEST1_PROVZ_NAME, TEST2_PROVZ_VERSION);
verifyProvidedCapability(providedCapabilities, PublisherHelper.NAMESPACE_ECLIPSE_TYPE, "source", Version.create("1.0.0"));//$NON-NLS-1$//$NON-NLS-2$
- assertEquals("2.1", 5, providedCapabilities.size());
+ assertEquals(5, providedCapabilities.size());
Collection<ITouchpointData> data = bundle1IU.getTouchpointData();
boolean found = false;
@@ -277,27 +278,27 @@ public class BundlesActionTest extends ActionTest {
found = true;
}
}
- assertTrue("3.0", found);
+ assertTrue(found);
}
private void verifyBundle2() {
- ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST2_PROV_BUNDLE_NAME, IPublisherResult.ROOT));
- assertTrue(ius.size() == 1);
- IInstallableUnit bundle2IU = ius.get(0);
+ List<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST2_PROV_BUNDLE_NAME, IPublisherResult.ROOT));
+ assertEquals(1, ius.size());
- assertNotNull(bundle2IU);
- assertEquals(bundle2IU.getVersion(), BUNDLE2_VERSION);
+ IInstallableUnit bundleIu = ius.get(0);
+ assertNotNull(bundleIu);
+ assertEquals(bundleIu.getVersion(), BUNDLE2_VERSION);
// check required capabilities
- Collection<IRequirement> requirements = bundle2IU.getRequirements();
+ Collection<IRequirement> requirements = bundleIu.getRequirements();
verifyRequirement(requirements, TEST2_IU_A_NAMESPACE, TEST2_REQ_A_NAME, TEST2_IU_A_VERSION_RANGE);
verifyRequirement(requirements, TEST2_IU_B_NAMESPACE, TEST2_REQ_B_NAME, TEST2_IU_B_VERSION_RANGE);
verifyRequirement(requirements, TEST2_IU_C_NAMESPACE, TEST2_REQ_C_NAME, TEST2_IU_C_VERSION_RANGE);
- verifyRequirement(requirements, TEST2_REQ_EE_FILTER, 0, 1, true);
- assertTrue(requirements.size() == 4 /*number of tested elements*/);
+ verifyRequirement(requirements, OSGI_EE, TEST2_REQ_EE, null, 1, 1, true);
+ assertEquals(4, requirements.size());
// check provided capabilities
- Collection<IProvidedCapability> providedCapabilities = bundle2IU.getProvidedCapabilities();
+ Collection<IProvidedCapability> providedCapabilities = bundleIu.getProvidedCapabilities();
verifyProvidedCapability(providedCapabilities, PROVBUNDLE_NAMESPACE, TEST2_PROV_BUNDLE_NAME, PROVBUNDLE2_VERSION);
verifyProvidedCapability(providedCapabilities, OSGI, TEST2_PROV_BUNDLE_NAME, BUNDLE2_VERSION);
verifyProvidedCapability(providedCapabilities, OSGI_IDENTITY, TEST2_PROV_BUNDLE_NAME, BUNDLE2_VERSION);
@@ -308,11 +309,11 @@ public class BundlesActionTest extends ActionTest {
assertEquals(7, providedCapabilities.size()); /*number of tested elements*/
// check %bundle name is correct
- Map<String, String> prop = bundle2IU.getProperties();
+ Map<String, String> prop = bundleIu.getProperties();
assertTrue(prop.get("org.eclipse.equinox.p2.name").toString().equalsIgnoreCase("%bundleName"));//$NON-NLS-1$//$NON-NLS-2$
assertTrue(prop.get("org.eclipse.equinox.p2.provider").toString().equalsIgnoreCase("%providerName"));//$NON-NLS-1$//$NON-NLS-2$
- Collection<ITouchpointData> data = bundle2IU.getTouchpointData();
+ Collection<ITouchpointData> data = bundleIu.getTouchpointData();
boolean found = false;
for (ITouchpointData td : data) {
ITouchpointInstruction configure = td.getInstruction("configure");
@@ -323,18 +324,17 @@ public class BundlesActionTest extends ActionTest {
found = true;
}
}
- assertFalse("3.0", found);
-
+ assertFalse(found);
}
private void verifyBundle3() {
// also a regression test for bug 393051: manifest headers use uncommon (but valid) capitalization
ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST3_PROV_BUNDLE_NAME, IPublisherResult.ROOT));
+ assertEquals(1, ius.size());
- assertTrue(ius.size() == 1);
- IInstallableUnit bundle3IU = ius.get(0);
+ IInstallableUnit bundleIu = ius.get(0);
- IUpdateDescriptor updateDescriptor = bundle3IU.getUpdateDescriptor();
+ IUpdateDescriptor updateDescriptor = bundleIu.getUpdateDescriptor();
String name = RequiredCapability.extractName(updateDescriptor.getIUsBeingUpdated().iterator().next());
VersionRange range = RequiredCapability.extractRange(updateDescriptor.getIUsBeingUpdated().iterator().next());
String description = updateDescriptor.getDescription();
@@ -349,36 +349,31 @@ public class BundlesActionTest extends ActionTest {
private void verifyBundle4() {
ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST4_PROV_BUNDLE_NAME, IPublisherResult.ROOT));
- assertTrue(ius.size() == 1);
- IInstallableUnit bundle4IU = ius.get(0);
+ assertEquals(1, ius.size());
- assertNotNull("1.0", bundle4IU);
- assertEquals("1.1", bundle4IU.getVersion(), BUNDLE4_VERSION);
+ IInstallableUnit bundleIu = ius.get(0);
+ assertNotNull(bundleIu);
+ assertEquals(bundleIu.getVersion(), BUNDLE4_VERSION);
// check required capabilities
- Collection<IRequirement> requirements = bundle4IU.getRequirements();
+ Collection<IRequirement> requirements = bundleIu.getRequirements();
verifyRequirement(requirements, JAVA_PACKAGE, TEST4_REQ_PACKAGE_OPTIONAL_NAME, DEFAULT_VERSION_RANGE, null, 0, 1, false);
verifyRequirement(requirements, JAVA_PACKAGE, TEST4_REQ_PACKAGE_OPTGREEDY_NAME, DEFAULT_VERSION_RANGE, null, 0, 1, true);
verifyRequirement(requirements, OSGI, TEST4_REQ_BUNDLE_OPTIONAL_NAME, DEFAULT_VERSION_RANGE, null, 0, 1, false);
verifyRequirement(requirements, OSGI, TEST4_REQ_BUNDLE_OPTGREEDY_NAME, DEFAULT_VERSION_RANGE, null, 0, 1, true);
- assertEquals("2.0", 4, requirements.size());
+ assertEquals(4, requirements.size());
}
private void verifyBundle5() {
ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(TEST5_PROV_BUNDLE_NAME, IPublisherResult.ROOT));
- assertTrue(ius.size() == 1);
+ assertEquals(1, ius.size());
+
IInstallableUnit bundle5IU = ius.get(0);
Collection<IRequirement> requirements = bundle5IU.getRequirements();
- verifyRequirement(requirements, TEST5_REQ_EE_FILTER, 0, 1, true);
- assertTrue(requirements.size() == 2);
- IRequirement requirement = requirements.iterator().next();
-
- int min = requirement.getMin();
- int max = requirement.getMax();
-
- assertTrue(min == 6);
- assertTrue(max == 7);
+ verifyRequirement(requirements, OSGI_EE, TEST5_REQ_EE, null, 1, 1, true);
+ verifyRequirement(requirements, "bar", "foo", VersionRange.emptyRange, null, 6, 7, true);
+ assertEquals(2, requirements.size());
}
@Override
@@ -491,7 +486,7 @@ public class BundlesActionTest extends ActionTest {
IInstallableUnit iu = BundlesAction.createBundleIU(BundlesAction.createBundleDescription(testData), null, new PublisherInfo());
Collection<IRequirement> requirements = iu.getRequirements();
- verifyRequirement(requirements, TESTDYN_REQ_EE_FILTER, 0, 1, true);
+ verifyRequirement(requirements, OSGI_EE, TESTDYN_REQ_EE, null, 1, 1, true);
assertEquals(1, requirements.size());
}

Back to the top