Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2021-08-18 07:00:28 +0000
committerAlexander Kurtakov2021-08-20 14:31:27 +0000
commit9dc7cd4c3662d7245006a4b880a5403d1b5a6616 (patch)
tree9cbf80f292d103ba7365bd1f2b2746a25d3f343f
parent3e0983faacd89a61ffb35bd78764b630497bf345 (diff)
downloadrt.equinox.p2-9dc7cd4c3662d7245006a4b880a5403d1b5a6616.tar.gz
rt.equinox.p2-9dc7cd4c3662d7245006a4b880a5403d1b5a6616.tar.xz
rt.equinox.p2-9dc7cd4c3662d7245006a4b880a5403d1b5a6616.zip
Bug 575470 - JREActionTest.testDefaultJavaProfile fails with Java 16
Convert to JUnit4 and use direct assert methods for better reporting. Change-Id: I2b3eb4849524e64e19416202ae9a419d28f4576a Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/184190
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java21
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java53
2 files changed, 42 insertions, 32 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java
index c17384334..c423c5dd5 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2018 compeople AG and others.
+ * Copyright (c) 2007, 2021 compeople AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -22,7 +22,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
@@ -146,20 +145,20 @@ public class TestData {
ZipEntry entry1 = (ZipEntry) file1[0];
ZipEntry entry2 = (ZipEntry) file2[0];
// compare the entries
- Assert.assertTrue(entry1.getName().equals(entry2.getName()));
- Assert.assertTrue(entry1.getSize() == entry2.getSize());
+ Assert.assertEquals(entry1.getName(), entry2.getName());
+ Assert.assertEquals(entry1.getSize(), entry2.getSize());
// TODO for now skip over the timestamp as they seem to be different
// assertTrue(entry1.getTime() == entry2.getTime());
- Assert.assertTrue(entry1.isDirectory() == entry2.isDirectory());
- Assert.assertTrue(entry1.getCrc() == entry2.getCrc());
- Assert.assertTrue(entry1.getMethod() == entry2.getMethod());
+ Assert.assertEquals(entry1.isDirectory(), entry2.isDirectory());
+ Assert.assertEquals(entry1.getCrc(), entry2.getCrc());
+ Assert.assertEquals(entry1.getMethod(), entry2.getMethod());
// check the content of the entries
- Assert.assertTrue(Arrays.equals((byte[]) file1[1], (byte[]) file2[1]));
+ Assert.assertArrayEquals((byte[]) file1[1], (byte[]) file2[1]);
}
// ensure that we have consumed all of the entries in the second JAR
- Assert.assertTrue(jar2.size() == 0);
+ Assert.assertEquals(0, jar2.size());
}
/**
@@ -181,11 +180,11 @@ public class TestData {
File entry1 = (File) file1[0];
ZipEntry entry2 = (ZipEntry) file2[0];
- Assert.assertTrue(entry1.isDirectory() == entry2.isDirectory());
+ Assert.assertEquals(entry1.isDirectory(), entry2.isDirectory());
// check the content of the entries
if (compareContent)
- Assert.assertTrue(Arrays.equals((byte[]) file1[1], (byte[]) file2[1]));
+ Assert.assertArrayEquals((byte[]) file1[1], (byte[]) file2[1]);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
index 0382ee4f2..dd1b6193e 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2018 Code 9 and others.
+ * Copyright (c) 2008, 2021 Code 9 and others.
*
* This
* program and the accompanying materials are made available under the terms of
@@ -59,7 +59,12 @@ import org.eclipse.equinox.p2.tests.TestData;
import org.eclipse.equinox.p2.tests.TestMetadataRepository;
import org.eclipse.equinox.p2.tests.publisher.TestArtifactRepository;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class JREActionTest extends ActionTest {
private File J14 = new File(TestActivator.getTestDataFolder(), "JREActionTest/1.4/"); //$NON-NLS-1$
@@ -72,12 +77,14 @@ public class JREActionTest extends ActionTest {
protected TestMetadataRepository metadataRepository;
@Override
+ @Before
public void setUp() throws Exception {
setupPublisherInfo();
setupPublisherResult();
}
// TODO this name is misleading: the test doesn't test the real Java 1.4 JRE IU but a broken local copy of the 1.4 profile
+ @Test
public void test14() throws Exception {
performAction(new JREAction(J14));
@@ -87,6 +94,7 @@ public class JREActionTest extends ActionTest {
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.j2se,1.4.0"), J14, "J2SE-1.4.profile"); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void test15() throws Exception {
performAction(new JREAction(J15));
@@ -96,6 +104,7 @@ public class JREActionTest extends ActionTest {
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.j2se,1.5.0"), J15, "J2SE-1.5.profile"); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void test16() throws Exception {
performAction(new JREAction(J16));
@@ -105,6 +114,7 @@ public class JREActionTest extends ActionTest {
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.javase,1.6.0"), J16, "JavaSE-1.6.profile"); //$NON-NLS-1$//$NON-NLS-2$
}
+ @Test
public void testOSGiMin() throws Exception {
performAction(new JREAction("OSGi/Minimum-1.2"));
@@ -113,6 +123,7 @@ public class JREActionTest extends ActionTest {
// verifyConfigIU("a.jre.osgi.minimum", jreVersion); // TODO config IU is not needed!?
}
+ @Test
public void testPackageVersionsFromJreFolder() throws Exception {
performAction(new JREAction(jreWithPackageVersionsFolder));
@@ -123,6 +134,7 @@ public class JREActionTest extends ActionTest {
verifyArtifactRepository(ArtifactKey.parse("binary,a.jre.test,1.0.0"), jreWithPackageVersionsFolder, "test-1.0.0.profile"); //$NON-NLS-1$//$NON-NLS-2$
}
+ @Test
public void testPackageVersionsFromJavaProfile() throws Exception {
// introduced for bug 334519: directly point to a profile file
performAction(new JREAction(jreWithPackageVersionsProfile));
@@ -132,6 +144,7 @@ public class JREActionTest extends ActionTest {
assertThat(providedCapabilities, hasItem(MetadataFactory.createProvidedCapability(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, "my.package", Version.create("1.0.0"))));
}
+ @Test
public void testDefaultJavaProfile() throws Exception {
performAction(new JREAction((String) null));
@@ -140,19 +153,13 @@ public class JREActionTest extends ActionTest {
// verifyConfigIU(DEFAULT_JRE_NAME, DEFAULT_JRE_VERSION); // TODO config IU is not needed!?
}
+ @Test(expected = IllegalArgumentException.class)
public void testNonExistingJreLocation() {
File nonExistingProfile = new File(jreWithPackageVersionsFolder, "no.profile");
- try {
- performAction(new JREAction(nonExistingProfile));
- fail("Expected failure when the JRE location does not exists.");
- // TODO shouldn't this be an error status?
- } catch (IllegalArgumentException e) {
- // test is successful
- } catch (Exception e) {
- fail("Expected IllegalArgumentException when the JRE location does not exists, caught " + e.getClass().getName());
- }
+ performAction(new JREAction(nonExistingProfile));
}
+ @Test
public void testOsgiEECapabilities() {
// added for bug 388566
performAction(new JREAction("J2SE-1.5"));
@@ -165,6 +172,7 @@ public class JREActionTest extends ActionTest {
assertThat(capabilities, not(hasItem(createEECapability("J2SE", "1.5"))));
}
+ @Test
public void testSingleOsgiEECapability() {
// contains a single version:Version attribute instead of the common version:List<Version>
performAction(new JREAction("OSGi/Minimum-1.0"));
@@ -174,6 +182,7 @@ public class JREActionTest extends ActionTest {
assertThat(capabilities, hasItem(createEECapability("OSGi/Minimum", "1.0")));
}
+ @Test
public void testInvalidOsgiEECapabilitySpec() {
testAction = new JREAction(new File(TestActivator.getTestDataFolder(), "JREActionTest/invalidOsgiEE/ee-capability-syntax-test.profile"));
IStatus status = testAction.perform(publisherInfo, publisherResult, new NullProgressMonitor());
@@ -186,7 +195,7 @@ public class JREActionTest extends ActionTest {
assertThat(Arrays.asList(eeStatus.getChildren()), hasItem(statusWithMessageWhich(containsString("Syntax error in version '1.a.invalidversion'"))));
assertThat(Arrays.asList(eeStatus.getChildren()), hasItem(statusWithMessageWhich(containsString("Ignoring unknown capability namespace 'other.namespace'"))));
assertThat(Arrays.asList(eeStatus.getChildren()), hasItem(statusWithMessageWhich(containsString("Cannot specify both 'version:Version' and 'version:List<Version>'"))));
- assertThat(eeStatus.getChildren().length, is(5));
+ assertEquals(5, eeStatus.getChildren().length);
}
private void performAction(JREAction jreAction) {
@@ -198,11 +207,11 @@ public class JREActionTest extends ActionTest {
IInstallableUnit foo = getPublishedUnit(id);
// check version
- assertTrue(foo.getVersion().equals(jreVersion));
+ assertEquals(jreVersion, foo.getVersion());
// check touchpointType
assertTrue(foo.getTouchpointType().getId().equalsIgnoreCase("org.eclipse.equinox.p2.native")); //$NON-NLS-1$
- assertTrue(foo.getTouchpointType().getVersion().equals(Version.create("1.0.0"))); //$NON-NLS-1$
+ assertEquals(Version.create("1.0.0"), foo.getTouchpointType().getVersion()); //$NON-NLS-1$
// check provided capabilities
Collection<IProvidedCapability> fooProvidedCapabilities = foo.getProvidedCapabilities();
@@ -214,19 +223,21 @@ public class JREActionTest extends ActionTest {
IInstallableUnit bar = getPublishedUnit("config." + id);
Map<?, ?> instructions = bar.getTouchpointData().iterator().next().getInstructions();
- assertTrue(((ITouchpointInstruction) instructions.get("install")).getBody().equals("unzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$//$NON-NLS-2$
- assertTrue(((ITouchpointInstruction) instructions.get("uninstall")).getBody().equals("cleanupzip(source:@artifact, target:${installFolder});")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("unzip(source:@artifact, target:${installFolder});", //$NON-NLS-1$
+ ((ITouchpointInstruction) instructions.get("install")).getBody()); //$NON-NLS-1$
+ assertEquals("cleanupzip(source:@artifact, target:${installFolder});", //$NON-NLS-1$
+ ((ITouchpointInstruction) instructions.get("uninstall")).getBody()); //$NON-NLS-1$
assertTrue(bar instanceof IInstallableUnitFragment);
Collection<IRequirement> requiredCapability = ((IInstallableUnitFragment) bar).getHost();
verifyRequirement(requiredCapability, IInstallableUnit.NAMESPACE_IU_ID, id, new VersionRange(jreVersion, true, Version.MAX_VERSION, true));
- assertTrue(requiredCapability.size() == 1);
+ assertEquals(1, requiredCapability.size());
Collection<IProvidedCapability> providedCapability = bar.getProvidedCapabilities();
verifyProvidedCapability(providedCapability, IInstallableUnit.NAMESPACE_IU_ID, "config." + id, jreVersion); //$NON-NLS-1$
- assertTrue(providedCapability.size() == 1);
+ assertEquals(1, providedCapability.size());
- assertTrue(bar.getProperty("org.eclipse.equinox.p2.type.fragment").equals("true")); //$NON-NLS-1$//$NON-NLS-2$
- assertTrue(bar.getVersion().equals(jreVersion));
+ assertEquals("true", bar.getProperty("org.eclipse.equinox.p2.type.fragment")); //$NON-NLS-1$//$NON-NLS-2$
+ assertEquals(jreVersion, bar.getVersion());
}
private void verifyArtifactRepository(IArtifactKey key, File JRELocation, final String fileName) throws IOException {
@@ -244,13 +255,13 @@ public class JREActionTest extends ActionTest {
private IInstallableUnit getPublishedUnit(String id) {
Collection<IInstallableUnit> units = publisherResult.getIUs(id, IPublisherResult.ROOT);
- assertThat(units.size(), is(1));
+ assertEquals(1, units.size());
return units.iterator().next();
}
private Collection<IProvidedCapability> getPublishedCapabilitiesOf(String id) {
Collection<IInstallableUnit> ius = publisherResult.getIUs(id, IPublisherResult.ROOT);
- assertThat(ius.size(), is(1));
+ assertEquals(1, ius.size());
IInstallableUnit iu = ius.iterator().next();
return iu.getProvidedCapabilities();
}

Back to the top