summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2012-09-28 11:15:23 (EDT)
committerTobias Oberlies2012-09-28 12:36:57 (EDT)
commit7cd8464a2a1bec3a24092d8274109f461ad19181 (patch)
tree775b74085c849a9a148e299cffe69d7692cafd86
parentf72633ae25b4e1d13c360084c507a3df664af2e2 (diff)
downloadrt.equinox.p2-7cd8464a2a1bec3a24092d8274109f461ad19181.zip
rt.equinox.p2-7cd8464a2a1bec3a24092d8274109f461ad19181.tar.gz
rt.equinox.p2-7cd8464a2a1bec3a24092d8274109f461ad19181.tar.bz2
390361 Check for IUs created by product action using matchers
- Refactoring: use matchers for checking presence of certain IUs in the publisher result. - Extract common steps of getting a unique IU from the result into a method getUniquePublishedIU.
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ActionTest.java52
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java52
2 files changed, 65 insertions, 39 deletions
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 00c2016..694d3d1 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
@@ -10,19 +10,23 @@
package org.eclipse.equinox.p2.tests.publisher.actions;
import static org.easymock.EasyMock.*;
+import static org.junit.Assert.assertThat;
import java.io.*;
import java.util.*;
import junit.framework.Assert;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.*;
+import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.junit.internal.matchers.TypeSafeMatcher;
@SuppressWarnings({"cast", "restriction", "unchecked"})
public abstract class ActionTest extends AbstractProvisioningTest {
@@ -213,4 +217,48 @@ public abstract class ActionTest extends AbstractProvisioningTest {
protected final void addContextIU(String unitId, String unitVersion, String filter) {
publisherResult.addIU(createIU(unitId, Version.create(unitVersion), filter, NO_PROVIDES), IPublisherResult.NON_ROOT);
}
+
+ /**
+ * Queries the publisher result for installable units with the given ID, and
+ * returns the result if there is exactly one such IU, or fails otherwise.
+ */
+ protected final IInstallableUnit getUniquePublishedIU(String id) {
+ assertThat(publisherResult, containsUniqueIU(id));
+
+ IQueryResult<IInstallableUnit> queryResult = publisherResult.query(QueryUtil.createIUQuery(id), new NullProgressMonitor());
+ return queryResult.iterator().next();
+ }
+
+ public static Matcher<IPublisherResult> containsIU(final String id) {
+ final IQuery<IInstallableUnit> query = QueryUtil.createIUQuery(id);
+ return new TypeSafeMatcher<IPublisherResult>() {
+
+ public void describeTo(Description description) {
+ description.appendText("contains a unit " + id);
+ }
+
+ @Override
+ public boolean matchesSafely(IPublisherResult item) {
+ IQueryResult<IInstallableUnit> queryResult = item.query(query, null);
+ return queryResultSize(queryResult) > 0;
+ }
+ };
+ }
+
+ public static Matcher<IPublisherResult> containsUniqueIU(final String id) {
+ final IQuery<IInstallableUnit> query = QueryUtil.createIUQuery(id);
+ return new TypeSafeMatcher<IPublisherResult>() {
+
+ public void describeTo(Description description) {
+ description.appendText("contains exactly one unit " + id);
+ }
+
+ @Override
+ public boolean matchesSafely(IPublisherResult item) {
+ IQueryResult<IInstallableUnit> queryResult = item.query(query, null);
+ return queryResultSize(queryResult) == 1;
+ }
+ };
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java
index 17728c0..49eb38b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ProductActionTest.java
@@ -15,6 +15,7 @@ import static org.easymock.EasyMock.createNiceMock;
import static org.eclipse.equinox.p2.tests.publisher.actions.StatusMatchers.okStatus;
import static org.eclipse.equinox.p2.tests.publisher.actions.StatusMatchers.statusWithMessageWhich;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.junit.matchers.JUnitMatchers.hasItem;
@@ -134,56 +135,43 @@ public class ProductActionTest extends ActionTest {
addContextIU("org.eclipse.core.runtime", "4.0.0");
performProductAction(productFile1);
- publisherResult = new PublisherResult();
+ setupPublisherResult();
addContextIU("org.eclipse.core.runtime", "4.0.0");
performProductAction(productFile2);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + configSpec + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
+ assertThat(publisherResult, containsUniqueIU(flavorArg + configSpec + "org.eclipse.core.runtime"));
}
public void testMultiPlatformCUs_DifferentPlatforms() throws Exception {
ProductFile productFile = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString());
setConfiguration(LINUX_CONFIG_SPEC);
-
addContextIU("org.eclipse.core.runtime", "0.0.0", WIN_FILTER);
performProductAction(productFile);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 0, queryResultSize(queryResult));
-
- queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("2.0", 0, queryResultSize(queryResult));
+ assertThat(publisherResult, not(containsIU(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime")));
+ assertThat(publisherResult, not(containsIU(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime")));
}
public void testMultiPlatformCUs_SamePlatforms() throws Exception {
ProductFile productFile = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString());
setConfiguration(LINUX_CONFIG_SPEC);
-
addContextIU("org.eclipse.core.runtime", "0.0.0", LINUX_FILTER);
performProductAction(productFile);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
-
- queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("2.0", 0, queryResultSize(queryResult));
+ assertThat(publisherResult, containsUniqueIU(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"));
+ assertThat(publisherResult, not(containsIU(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime")));
}
public void testMultiPlatformCUs_SamePlatforms_NoVersion() throws Exception {
ProductFile productFile = new ProductFile(TestData.getFile("ProductActionTest", "unboundedVersionConfigurations.product").toString());
setConfiguration(LINUX_CONFIG_SPEC);
-
addContextIU("org.eclipse.core.runtime", null, LINUX_FILTER);
performProductAction(productFile);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
-
- queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("2.0", 0, queryResultSize(queryResult));
+ assertThat(publisherResult, containsUniqueIU(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"));
+ assertThat(publisherResult, not(containsIU(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime")));
}
public void testMultiPlatformCUs_SamePlatforms_BoundedVersions() throws Exception {
@@ -196,11 +184,8 @@ public class ProductActionTest extends ActionTest {
performProductAction(productFile);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
-
- queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("2.0", 0, queryResultSize(queryResult));
+ assertThat(publisherResult, containsUniqueIU(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"));
+ assertThat(publisherResult, not(containsIU(flavorArg + WIN_CONFIG_SPEC + "org.eclipse.core.runtime")));
}
public void testCUsHost() throws Exception {
@@ -213,9 +198,7 @@ public class ProductActionTest extends ActionTest {
performProductAction(productFile);
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) queryResult.iterator().next();
+ IInstallableUnitFragment fragment = (IInstallableUnitFragment) getUniquePublishedIU(flavorArg + LINUX_CONFIG_SPEC + "org.eclipse.core.runtime");
assertEquals("1.1", "org.eclipse.core.runtime", RequiredCapability.extractName(fragment.getHost().iterator().next().getMatches()));
assertEquals("1.2", Version.create("4.0.0"), RequiredCapability.extractRange(fragment.getHost().iterator().next().getMatches()).getMinimum());
assertEquals("1.3", Version.create("1.0.0"), fragment.getVersion());
@@ -243,9 +226,7 @@ public class ProductActionTest extends ActionTest {
performProductAction(productFile);
// there is a CU for the IU because it applies to all platforms
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + configSpecANY + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("1.0", 1, queryResultSize(queryResult));
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) queryResult.iterator().next();
+ IInstallableUnitFragment fragment = (IInstallableUnitFragment) getUniquePublishedIU(flavorArg + configSpecANY + "org.eclipse.core.runtime");
assertEquals("1.1", "org.eclipse.core.runtime", RequiredCapability.extractName(fragment.getHost().iterator().next().getMatches()));
assertEquals("1.2", Version.create("4.0.0"), RequiredCapability.extractRange(fragment.getHost().iterator().next().getMatches()).getMinimum());
assertEquals("1.3", Version.create("1.0.0"), fragment.getVersion());
@@ -262,8 +243,7 @@ public class ProductActionTest extends ActionTest {
performProductAction(productFile);
// there is no CU for the IU because it is platform specific
- IQueryResult queryResult = publisherResult.query(QueryUtil.createIUQuery(flavorArg + configSpecANY + "org.eclipse.core.runtime"), new NullProgressMonitor());
- assertEquals("2.0", 0, queryResultSize(queryResult));
+ assertThat(publisherResult, not(containsIU(flavorArg + configSpecANY + "org.eclipse.core.runtime")));
}
public void testProductFileWithRepoAdvice() throws Exception {
@@ -310,9 +290,7 @@ public class ProductActionTest extends ActionTest {
IStatus status = testAction.perform(new PublisherInfo(), publisherResult, null);
assertThat(status, is(okStatus()));
- Collection productIUs = publisherResult.getIUs("productWithAdvice.product", IPublisherResult.NON_ROOT);
- assertEquals("1.0", 1, productIUs.size());
- IInstallableUnit product = (IInstallableUnit) productIUs.iterator().next();
+ IInstallableUnit product = getUniquePublishedIU("productWithAdvice.product");
Collection<ITouchpointData> data = product.getTouchpointData();
assertEquals("1.1", 1, data.size());
String configure = data.iterator().next().getInstruction("configure").getBody();