Align javax.servlet version used in test with main product
When building Virgo with a clean Gradle cache this test fails.
With this commit we reuse the bundle used to assemble Virgo itself.
diff --git a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
index 77f2411..592fdf7 100644
--- a/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
+++ b/org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/BundleBridgeTests.java
@@ -11,9 +11,11 @@
package org.eclipse.virgo.kernel.artifact.bundle;
+import static java.util.Objects.requireNonNull;
+import static org.eclipse.virgo.kernel.artifact.bundle.BundleBridge.convertToDictionary;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -34,14 +36,13 @@
/**
* <p>
- * Unit tests for {@link org.eclipse.virgo.kernel.artifact.bundle.BundleBridge BundleBridge}. Uses a combination of real
- * bundle files and static test data.
+ * Unit tests for {@link BundleBridge BundleBridge}. Uses a combination of real bundle files and static test data.
* </p>
- *
+ *
* <strong>Concurrent Semantics</strong><br />
- *
+ *
* Threadsafe test case
- *
+ *
*/
public class BundleBridgeTests {
@@ -62,7 +63,7 @@
private static final String BUNDLE_NAME_HEADER_NAME = "Bundle-Name";
@BeforeClass
- public static void setUp() throws Exception {
+ public static void setUp() {
BUNDLE_BRIDGE = new BundleBridge(new StubHashGenerator());
}
@@ -71,7 +72,7 @@
File file = new File("foo/bar.jar");
try {
BUNDLE_BRIDGE.generateArtifactDescriptor(file);
- assertTrue("Should throw exception", false);
+ fail("Should throw exception");
} catch (ArtifactGenerationException age) {
assertEquals("ArtifactType in exception is incorrect", age.getArtifactType(), BundleBridge.BRIDGE_TYPE);
}
@@ -82,7 +83,7 @@
File file = new File("./src/test/resources/wars/testbad01.war"); // contains Erroneous-Data: Bundle-Version
try {
BUNDLE_BRIDGE.generateArtifactDescriptor(file);
- assertTrue("Should throw exception", false);
+ fail("Should throw exception");
} catch (ArtifactGenerationException age) {
assertEquals("ArtifactType in exception is incorrect", age.getArtifactType(), BundleBridge.BRIDGE_TYPE);
}
@@ -90,11 +91,12 @@
@Test
public void testGenerateArtefact() throws ArtifactGenerationException {
- File jarsDirectory = new File(
- System.getProperty("user.home") + "/.gradle/caches/modules-2/files-2.1/org.eclipse.virgo.mirrored/org.apache.commons.dbcp/1.4.0.v201204271417/4378c1a6c057f1e1da2b8287351b288c2c13e6c0/org.apache.commons.dbcp-1.4.0.v201204271417.jar");
+ File jarsDirectory = new File(System.getProperty("user.home")
+ + "/.gradle/caches/modules-2/files-2.1/org.eclipse.virgo.mirrored/org.apache.commons.dbcp/1.4.0.v201204271417/"
+ + "4378c1a6c057f1e1da2b8287351b288c2c13e6c0/org.apache.commons.dbcp-1.4.0.v201204271417.jar");
File directoriesDirectory = new File("./src/test/resources/directories");
- Set<ArtifactDescriptor> artefacts = new HashSet<ArtifactDescriptor>();
+ Set<ArtifactDescriptor> artefacts = new HashSet<>();
artefacts.add(BUNDLE_BRIDGE.generateArtifactDescriptor(jarsDirectory));
@@ -115,24 +117,25 @@
testAttributes = testArtefact.getAttribute(Constants.BUNDLE_SYMBOLICNAME);
assertEquals("Error on: " + testArtefact.toString(), stubAttributes.iterator().next().getValue(),
- testAttributes.iterator().next().getValue());
+ testAttributes.iterator().next().getValue());
stubAttributes = stubArtefact.getAttribute(ARTEFACT_ATTRIBUTE_VERSION);
testAttributes = testArtefact.getAttribute(Constants.BUNDLE_VERSION);
assertEquals("Error on: " + testArtefact.toString(), stubAttributes.iterator().next().getValue(),
- testAttributes.iterator().next().getValue());
+ testAttributes.iterator().next().getValue());
}
}
@Test
public void testBuildDictionary() throws ArtifactGenerationException, IOException {
- File testFile = new File(
- System.getProperty("user.home") + "/.gradle/caches/modules-2/files-2.1/org.eclipse.virgo.mirrored/javax.servlet/3.1.0.v201410161800/e0e698d1be57aaef38e54428f5c09c7fe0cf594e/javax.servlet-3.1.0.v201410161800.jar");
+ File testFile = new File(System.getProperty("user.home")
+ + "/.gradle/caches/modules-2/files-2.1/org.eclipse.virgo.mirrored/javax.servlet/3.1.0.20170128/"
+ + "e1928d3e6307028208245e12ca5d11b9a451daf9/javax.servlet-3.1.0.20170128.jar");
ArtifactDescriptor inputArtefact = BUNDLE_BRIDGE.generateArtifactDescriptor(testFile);
- Dictionary<String, String> dictionary = BundleBridge.convertToDictionary(inputArtefact);
+ Dictionary<String, String> dictionary = requireNonNull(convertToDictionary(inputArtefact));
JarFile testJar = new JarFile(testFile);
Attributes attributes = testJar.getManifest().getMainAttributes();
@@ -140,13 +143,13 @@
testJar.close();
assertEquals("Failed to match regenerated " + Constants.BUNDLE_SYMBOLICNAME, dictionary.get(Constants.BUNDLE_SYMBOLICNAME),
- attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
+ attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("Failed to match regenerated " + Constants.BUNDLE_VERSION, dictionary.get(Constants.BUNDLE_VERSION),
- attributes.getValue(Constants.BUNDLE_VERSION));
+ attributes.getValue(Constants.BUNDLE_VERSION));
assertEquals("Failed to match regenerated " + BUNDLE_MANIFEST_VERSION_HEADER_NAME, dictionary.get(BUNDLE_MANIFEST_VERSION_HEADER_NAME),
- attributes.getValue(BUNDLE_MANIFEST_VERSION_HEADER_NAME));
+ attributes.getValue(BUNDLE_MANIFEST_VERSION_HEADER_NAME));
assertEquals("Failed to match regenerated " + BUNDLE_NAME_HEADER_NAME, dictionary.get(BUNDLE_NAME_HEADER_NAME),
- attributes.getValue(BUNDLE_NAME_HEADER_NAME));
+ attributes.getValue(BUNDLE_NAME_HEADER_NAME));
}
@@ -187,13 +190,13 @@
}
private Set<ArtifactDescriptor> generateArtefacts(File directory) throws ArtifactGenerationException {
- Set<ArtifactDescriptor> artefacts = new HashSet<ArtifactDescriptor>();
+ Set<ArtifactDescriptor> artefacts = new HashSet<>();
File[] fileList = directory.listFiles();
if (fileList == null) {
- throw new IllegalStateException("Failed to list files inside '" + directory + "'.");
- }
- for (File fileInDir : fileList) {
+ throw new IllegalStateException("Failed to list files inside '" + directory + "'.");
+ }
+ for (File fileInDir : fileList) {
if (!fileInDir.getName().endsWith(".jar") && !fileInDir.getName().contains("sources")) {
ArtifactDescriptor artefact = BUNDLE_BRIDGE.generateArtifactDescriptor(fileInDir);
if (artefact != null) {