aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-plugin-test
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-23 17:00:35 +0200
committergjoranv <gv@verizonmedia.com>2019-10-23 17:09:43 +0200
commit8ea607e6a3b637fdcd9e5f8d3914bb3c66e360c3 (patch)
tree1e06cfa9c2a77d8c39c8848ad38c21cae78d4769 /bundle-plugin-test
parenteb182bfea2182d35994cbf5ca3d0ea0ec600379c (diff)
Update tests to make them pass on factory.
- These tests have been failing silently on factory for some time, and would break the build now that tests are run with surefire-plugin.
Diffstat (limited to 'bundle-plugin-test')
-rw-r--r--bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java43
1 files changed, 28 insertions, 15 deletions
diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
index 3c0379952fa..a46abce1dff 100644
--- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
+++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
@@ -14,9 +14,12 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import static com.yahoo.osgi.maven.ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME;
@@ -28,8 +31,8 @@ import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
* Verifies the bundle jar file built and its manifest.
@@ -39,6 +42,11 @@ import static org.junit.Assert.assertThat;
public class BundleTest {
static final String TEST_BUNDLE_PATH = System.getProperty("test.bundle.path", ".") + "/";
+ // If bundle-plugin-test is compiled in a mvn command that also built dependencies, e.g. jrt,
+ // the artifact is jrt.jar, otherwise the installed and versioned artifact
+ // is used: jrt-7-SNAPSHOT.jar or e.g. jrt-7.123.45.jar.
+ private static String snapshotOrVersionOrNone = "(-\\d+((-SNAPSHOT)|((\\.\\d+(\\.\\d+)?)?))?)?\\.jar";
+
private JarFile jarFile;
private Attributes mainAttributes;
@@ -114,23 +122,28 @@ public class BundleTest {
public void require_that_manifest_contains_bundle_class_path() {
String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath");
assertThat(bundleClassPath, containsString(".,"));
- // If bundle-plugin-test is compiled in a mvn command that also built jrt,
- // the jrt artifact is jrt.jar, otherwise the installed and versioned artifact
- // is used: jrt-7-SNAPSHOT.jar.
- assertThat(bundleClassPath, anyOf(
- containsString("dependencies/jrt-7-SNAPSHOT.jar"),
- containsString("dependencies/jrt.jar")));
+
+ Pattern jrtPattern = Pattern.compile("dependencies/jrt" + snapshotOrVersionOrNone);
+ assertTrue("Bundle class path did not contain jrt.", jrtPattern.matcher(bundleClassPath).find());
}
@Test
public void require_that_component_jar_file_contains_compile_artifacts() {
- ZipEntry versionedEntry = jarFile.getEntry("dependencies/jrt-7-SNAPSHOT.jar");
- ZipEntry unversionedEntry = jarFile.getEntry("dependencies/jrt.jar");
- if (versionedEntry == null) {
- assertNotNull(unversionedEntry);
- } else {
- assertNull(unversionedEntry);
+ String depJrt = "dependencies/jrt";
+ Pattern jrtPattern = Pattern.compile(depJrt + snapshotOrVersionOrNone);
+ ZipEntry jrtEntry = null;
+
+ Enumeration<JarEntry> entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+ var e = entries.nextElement();
+ if (e.getName().startsWith(depJrt)) {
+ if (jrtPattern.matcher(e.getName()).matches()) {
+ jrtEntry = e;
+ break;
+ }
+ }
}
+ assertNotNull("Component jar file did not contain jrt dependency.", jrtEntry);
}
@@ -166,7 +179,7 @@ public class BundleTest {
hasItems(
endsWith("target/classes"),
anyOf(
- allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")),
- containsString("jrt/target/jrt.jar"))));
+ allOf(containsString("/jrt-"), containsString(".jar")),
+ containsString("/jrt.jar"))));
}
}