From dbfa0726b21b589d48410990a675a578f8ae7535 Mon Sep 17 00:00:00 2001 From: gjoranv Date: Mon, 21 Oct 2019 16:31:58 +0200 Subject: Use surefire instead of failsafe plugin. - No need to use integration tests after test bundles have been moved to separate modules. --- bundle-plugin-test/integration-test/pom.xml | 16 +- .../src/test/java/com/yahoo/BundleIT.java | 172 --------------------- .../src/test/java/com/yahoo/BundleTest.java | 172 +++++++++++++++++++++ .../java/com/yahoo/ExportPackageVersionIT.java | 68 -------- .../java/com/yahoo/ExportPackageVersionTest.java | 68 ++++++++ bundle-plugin-test/test-bundles/main/pom.xml | 5 +- bundle-plugin-test/test-bundles/pom.xml | 10 +- 7 files changed, 255 insertions(+), 256 deletions(-) delete mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java create mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleTest.java delete mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java create mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionTest.java (limited to 'bundle-plugin-test') diff --git a/bundle-plugin-test/integration-test/pom.xml b/bundle-plugin-test/integration-test/pom.xml index 642d74fb0e9..42d3b0e4d62 100644 --- a/bundle-plugin-test/integration-test/pom.xml +++ b/bundle-plugin-test/integration-test/pom.xml @@ -56,23 +56,13 @@ org.apache.maven.plugins - maven-failsafe-plugin - 2.9 - - - integration-test - - integration-test - verify - - - + maven-surefire-plugin - false + ${test.hide} ${project.build.directory}/dependency - ${test.hide} + false diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java deleted file mode 100644 index 5e76b08ab9f..00000000000 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo; - -import com.yahoo.osgi.maven.ProjectBundleClassPaths; -import com.yahoo.vespa.config.VespaVersion; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collection; -import java.util.jar.Attributes; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import java.util.zip.ZipEntry; - -import static com.yahoo.osgi.maven.ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.CoreMatchers.containsString; -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; - -/** - * Verifies the bundle jar file built and its manifest. - * - * @author Tony Vaagenes - */ -public class BundleIT { - static final String TEST_BUNDLE_PATH = System.getProperty("test.bundle.path", ".") + "/"; - - private JarFile jarFile; - private Attributes mainAttributes; - - @Before - public void setup() { - try { - File componentJar = findBundleJar("main"); - jarFile = new JarFile(componentJar); - Manifest manifest = jarFile.getManifest(); - mainAttributes = manifest.getMainAttributes(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - static File findBundleJar(String bundleName) { - Path bundlePath = Paths.get(TEST_BUNDLE_PATH, bundleName + "-bundle.jar"); - if (! Files.exists(bundlePath)) { - throw new RuntimeException("Failed finding component jar file: " + bundlePath); - } - - return bundlePath.toFile(); - } - - @Test - public void require_that_bundle_version_is_added_to_manifest() { - String bundleVersion = mainAttributes.getValue("Bundle-Version"); - - // Because of snapshot builds, we can only verify the major version. - int majorBundleVersion = Integer.valueOf(bundleVersion.substring(0, bundleVersion.indexOf('.'))); - assertThat(majorBundleVersion, is(VespaVersion.major)); - } - - @Test - public void require_that_bundle_symbolic_name_matches_pom_artifactId() { - assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("main")); - } - - @Test - public void require_that_manifest_contains_inferred_imports() { - String importPackage = mainAttributes.getValue("Import-Package"); - - // From SimpleSearcher - assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); - assertThat(importPackage, containsString("org.json")); - - // From SimpleSearcher2 - assertThat(importPackage, containsString("com.yahoo.processing")); - assertThat(importPackage, containsString("com.yahoo.metrics.simple")); - assertThat(importPackage, containsString("com.google.inject")); - } - - @Test - public void require_that_manifest_contains_manual_imports() { - String importPackage = mainAttributes.getValue("Import-Package"); - - assertThat(importPackage, containsString("manualImport.withoutVersion")); - assertThat(importPackage, containsString("manualImport.withVersion;version=\"12.3.4\"")); - - for (int i=1; i<=2; ++i) - assertThat(importPackage, containsString("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); - } - - @Test - public void require_that_manifest_contains_exports() { - String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("com.yahoo.test;version=1.2.3.RELEASE")); - } - - @Test - // TODO: use another jar than jrt, which now pulls in a lot of dependencies that pollute the manifest of the - // generated bundle. (It's compile scoped in pom.xml to be added to the bundle-cp.) - 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"))); - } - - @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); - } - } - - - @Test - public void require_that_web_inf_url_is_propagated_to_the_manifest() { - String webInfUrl = mainAttributes.getValue("WebInfUrl"); - assertThat(webInfUrl, containsString("/WEB-INF/web.xml")); - } - - // TODO Vespa 8: Remove, the classpath mappings file is only needed for jersey resources to work in the application test framework. - // When this test is removed, also remove the maven-resources-plugin from the 'main' test bundle's pom. - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - @SuppressWarnings("unchecked") - @Test - public void bundle_class_path_mappings_are_generated() throws Exception { - ZipEntry classpathMappingsEntry = jarFile.getEntry(CLASSPATH_MAPPINGS_FILENAME); - - assertNotNull( - "Could not find " + CLASSPATH_MAPPINGS_FILENAME + " in the test bundle", - classpathMappingsEntry); - - Path mappingsFile = tempFolder.newFile(CLASSPATH_MAPPINGS_FILENAME).toPath(); - Files.copy(jarFile.getInputStream(classpathMappingsEntry), mappingsFile, REPLACE_EXISTING); - - ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(mappingsFile); - - assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("main")); - - Collection mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements; - - assertThat(mainBundleClassPaths, - hasItems( - endsWith("target/classes"), - anyOf( - allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")), - containsString("jrt/target/jrt.jar")))); - } -} diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleTest.java new file mode 100644 index 00000000000..9fb7e0e03ca --- /dev/null +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleTest.java @@ -0,0 +1,172 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo; + +import com.yahoo.osgi.maven.ProjectBundleClassPaths; +import com.yahoo.vespa.config.VespaVersion; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +import static com.yahoo.osgi.maven.ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.CoreMatchers.containsString; +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; + +/** + * Verifies the bundle jar file built and its manifest. + * + * @author Tony Vaagenes + */ +public class BundleTest { + static final String TEST_BUNDLE_PATH = System.getProperty("test.bundle.path", ".") + "/"; + + private JarFile jarFile; + private Attributes mainAttributes; + + @Before + public void setup() { + try { + File componentJar = findBundleJar("main"); + jarFile = new JarFile(componentJar); + Manifest manifest = jarFile.getManifest(); + mainAttributes = manifest.getMainAttributes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + static File findBundleJar(String bundleName) { + Path bundlePath = Paths.get(TEST_BUNDLE_PATH, bundleName + "-bundle.jar"); + if (! Files.exists(bundlePath)) { + throw new RuntimeException("Failed finding component jar file: " + bundlePath); + } + + return bundlePath.toFile(); + } + + @Test + public void require_that_bundle_version_is_added_to_manifest() { + String bundleVersion = mainAttributes.getValue("Bundle-Version"); + + // Because of snapshot builds, we can only verify the major version. + int majorBundleVersion = Integer.valueOf(bundleVersion.substring(0, bundleVersion.indexOf('.'))); + assertThat(majorBundleVersion, is(VespaVersion.major)); + } + + @Test + public void require_that_bundle_symbolic_name_matches_pom_artifactId() { + assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("main")); + } + + @Test + public void require_that_manifest_contains_inferred_imports() { + String importPackage = mainAttributes.getValue("Import-Package"); + + // From SimpleSearcher + assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); + assertThat(importPackage, containsString("org.json")); + + // From SimpleSearcher2 + assertThat(importPackage, containsString("com.yahoo.processing")); + assertThat(importPackage, containsString("com.yahoo.metrics.simple")); + assertThat(importPackage, containsString("com.google.inject")); + } + + @Test + public void require_that_manifest_contains_manual_imports() { + String importPackage = mainAttributes.getValue("Import-Package"); + + assertThat(importPackage, containsString("manualImport.withoutVersion")); + assertThat(importPackage, containsString("manualImport.withVersion;version=\"12.3.4\"")); + + for (int i=1; i<=2; ++i) + assertThat(importPackage, containsString("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); + } + + @Test + public void require_that_manifest_contains_exports() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("com.yahoo.test;version=1.2.3.RELEASE")); + } + + @Test + // TODO: use another jar than jrt, which now pulls in a lot of dependencies that pollute the manifest of the + // generated bundle. (It's compile scoped in pom.xml to be added to the bundle-cp.) + 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"))); + } + + @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); + } + } + + + @Test + public void require_that_web_inf_url_is_propagated_to_the_manifest() { + String webInfUrl = mainAttributes.getValue("WebInfUrl"); + assertThat(webInfUrl, containsString("/WEB-INF/web.xml")); + } + + // TODO Vespa 8: Remove, the classpath mappings file is only needed for jersey resources to work in the application test framework. + // When this test is removed, also remove the maven-resources-plugin from the 'main' test bundle's pom. + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + @SuppressWarnings("unchecked") + @Test + public void bundle_class_path_mappings_are_generated() throws Exception { + ZipEntry classpathMappingsEntry = jarFile.getEntry(CLASSPATH_MAPPINGS_FILENAME); + + assertNotNull( + "Could not find " + CLASSPATH_MAPPINGS_FILENAME + " in the test bundle", + classpathMappingsEntry); + + Path mappingsFile = tempFolder.newFile(CLASSPATH_MAPPINGS_FILENAME).toPath(); + Files.copy(jarFile.getInputStream(classpathMappingsEntry), mappingsFile, REPLACE_EXISTING); + + ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(mappingsFile); + + assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("main")); + + Collection mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements; + + assertThat(mainBundleClassPaths, + hasItems( + endsWith("target/classes"), + anyOf( + allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")), + containsString("jrt/target/jrt.jar")))); + } +} diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java deleted file mode 100644 index e2cee71ca9e..00000000000 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.util.jar.Attributes; -import java.util.jar.JarFile; - -import static com.yahoo.BundleIT.findBundleJar; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -/** - * Verifies that the 'useArtifactVersionForExportPackages' setting for the bundle-plugin works as intended. - * - * @author gjoranv - */ -public class ExportPackageVersionIT { - - private static Attributes mainAttributes; - - @BeforeClass - public static void setup() { - try { - File componentJar = findBundleJar("artifact-version-for-exports"); - mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Test - public void artifact_version_without_qualifier_is_used_as_export_version() { - // Bundle-Version is artifact version without qualifier - String bundleVersion = mainAttributes.getValue("Bundle-Version"); - String expectedExport = "ai.vespa.noversion;version=" + bundleVersion; - - String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString(expectedExport)); - - // Verify that there is no qualifier - assertThat(exportPackage, not(containsString(expectedExport + "."))); - } - - @Test - public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version() { - String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("ai.vespa.explicitversion;version=2.4.6.RELEASE")); - } - - @Test - public void artifact_version_of_dependency_is_used_as_export_version_for_package_in_compile_scoped_dependency() { - String exportPackage = mainAttributes.getValue("Export-Package"); - // Verify against the artifact version from the test bundle's pom. - assertThat(exportPackage, containsString("ai.vespa.noversion_dep;version=3.2.1")); - } - - @Test - public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version_of_compile_scoped_dependency() { - String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("ai.vespa.explicitversion_dep;version=3.6.9.RELEASE")); - } - -} diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionTest.java new file mode 100644 index 00000000000..307a0698bd1 --- /dev/null +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionTest.java @@ -0,0 +1,68 @@ +// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.jar.Attributes; +import java.util.jar.JarFile; + +import static com.yahoo.BundleTest.findBundleJar; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +/** + * Verifies that the 'useArtifactVersionForExportPackages' setting for the bundle-plugin works as intended. + * + * @author gjoranv + */ +public class ExportPackageVersionTest { + + private static Attributes mainAttributes; + + @BeforeClass + public static void setup() { + try { + File componentJar = findBundleJar("artifact-version-for-exports"); + mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + public void artifact_version_without_qualifier_is_used_as_export_version() { + // Bundle-Version is artifact version without qualifier + String bundleVersion = mainAttributes.getValue("Bundle-Version"); + String expectedExport = "ai.vespa.noversion;version=" + bundleVersion; + + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString(expectedExport)); + + // Verify that there is no qualifier + assertThat(exportPackage, not(containsString(expectedExport + "."))); + } + + @Test + public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("ai.vespa.explicitversion;version=2.4.6.RELEASE")); + } + + @Test + public void artifact_version_of_dependency_is_used_as_export_version_for_package_in_compile_scoped_dependency() { + String exportPackage = mainAttributes.getValue("Export-Package"); + // Verify against the artifact version from the test bundle's pom. + assertThat(exportPackage, containsString("ai.vespa.noversion_dep;version=3.2.1")); + } + + @Test + public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version_of_compile_scoped_dependency() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("ai.vespa.explicitversion_dep;version=3.6.9.RELEASE")); + } + +} diff --git a/bundle-plugin-test/test-bundles/main/pom.xml b/bundle-plugin-test/test-bundles/main/pom.xml index 90d575c2a0b..c9c9ea270eb 100644 --- a/bundle-plugin-test/test-bundles/main/pom.xml +++ b/bundle-plugin-test/test-bundles/main/pom.xml @@ -52,8 +52,9 @@ maven-resources-plugin - copy-resources - prepare-package + copy-bundle-classpath-mappings-from-test-to-main + + process-test-sources copy-resources diff --git a/bundle-plugin-test/test-bundles/pom.xml b/bundle-plugin-test/test-bundles/pom.xml index b18c0b9ba3f..285efd6183e 100644 --- a/bundle-plugin-test/test-bundles/pom.xml +++ b/bundle-plugin-test/test-bundles/pom.xml @@ -26,9 +26,17 @@ bundle-plugin ${project.version} + + generate-classpath-mappings + generate-test-sources + + generate-bundle-classpath-mappings + + package-test-bundles - process-classes + + test-compile generate-osgi-manifest assemble-container-plugin -- cgit v1.2.3