diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /bundle-plugin-test/src |
Publish
Diffstat (limited to 'bundle-plugin-test/src')
6 files changed, 201 insertions, 0 deletions
diff --git a/bundle-plugin-test/src/main/java/InDefaultPackage.java b/bundle-plugin-test/src/main/java/InDefaultPackage.java new file mode 100644 index 00000000000..64e7bb8a72b --- /dev/null +++ b/bundle-plugin-test/src/main/java/InDefaultPackage.java @@ -0,0 +1,3 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +public class InDefaultPackage {} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java new file mode 100644 index 00000000000..9ddb15c16cb --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java @@ -0,0 +1,37 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.test; + +import com.yahoo.prelude.hitfield.XMLString; +import com.yahoo.search.Query; +import com.yahoo.search.Result; +import com.yahoo.search.Searcher; +import com.yahoo.search.result.Hit; +import com.yahoo.search.searchchain.Execution; +import com.yahoo.text.BooleanParser; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * A searcher adding a new hit. + * + * @author Joe Developer + */ +public class SimpleSearcher extends Searcher { + + public Result search(Query query,Execution execution) { + try { + BooleanParser.parseBoolean("true"); + XMLString xmlString = new XMLString("<sampleXmlString/>"); + + Hit hit = new Hit("Hello world!"); + hit.setField("json", new JSONObject().put("price", 42).toString()); + + Result result = execution.search(query); + result.hits().add(hit); + return result; + + } catch (JSONException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java new file mode 100644 index 00000000000..52211de45ca --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java @@ -0,0 +1,12 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.test; + + +/** + * A searcher adding a new hit. + * TODO: add annotation check + * @author Joe Developer + */ +public class SimpleSearcher2 extends SimpleSearcher { + public void dummy() {} +} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java new file mode 100644 index 00000000000..8ed830ab7d7 --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java @@ -0,0 +1,6 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage(version = @Version(major = 1, minor = 2, micro = 3, qualifier = "RELEASE")) +package com.yahoo.test; + +import com.yahoo.osgi.annotation.ExportPackage; +import com.yahoo.osgi.annotation.Version; diff --git a/bundle-plugin-test/src/main/resources/configdefinitions/test.def b/bundle-plugin-test/src/main/resources/configdefinitions/test.def new file mode 100644 index 00000000000..ddbde9706e2 --- /dev/null +++ b/bundle-plugin-test/src/main/resources/configdefinitions/test.def @@ -0,0 +1,5 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +version=1 +namespace=example + +exampleKey string default="exampleValue" diff --git a/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java new file mode 100644 index 00000000000..f8c205307e8 --- /dev/null +++ b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java @@ -0,0 +1,138 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo; + +import com.yahoo.vespa.scalalib.osgi.maven.ProjectBundleClassPaths; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import scala.collection.JavaConversions; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +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 static org.hamcrest.CoreMatchers.allOf; +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.assertThat; +import static org.hamcrest.CoreMatchers.containsString; + +/** + * Verifies the bundle jar file built and its manifest. + * @author tonytv + */ +public class BundleIT { + private JarFile jarFile; + private Attributes mainAttributes; + + @Before + public void setup() { + try { + File componentJar = findBundleJar(); + jarFile = new JarFile(componentJar); + Manifest manifest = jarFile.getManifest(); + mainAttributes = manifest.getMainAttributes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private File findBundleJar() { + File[] componentFile = new File("target").listFiles(new FilenameFilter() { + @Override + public boolean accept(File file, String fileName) { + return fileName.endsWith("-deploy.jar") || fileName.endsWith("-jar-with-dependencies.jar"); + } + }); + + if (componentFile.length != 1) { + throw new RuntimeException("Failed finding component jar file"); + } + + return componentFile[0]; + } + + @Test + @Ignore + public void require_that_manifest_version_matches_pom_version() { + assertThat(mainAttributes.getValue("Bundle-Version"), is("5.1.0")); + } + + @Test + public void require_that_bundle_symbolic_name_matches_pom_artifactId() { + assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("bundle-plugin-test")); + } + + @Test + public void require_that_manifest_contains_inferred_imports() { + String importPackage = mainAttributes.getValue("Import-Package"); + assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); + //Not available from jdisc at the moment, scope temporarily changed to compile. + //assertThat(importPackage, containsString("org.json")); + } + + @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 + public void require_that_manifest_contains_bundle_class_path() { + String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath"); + assertThat(bundleClassPath, containsString(".,")); + assertThat(bundleClassPath, containsString("dependencies/jrt-6-SNAPSHOT.jar")); + } + + @Test + public void require_that_component_jar_file_contains_compile_artifacts() { + assertNotNull(jarFile.getEntry("dependencies/jrt-6-SNAPSHOT.jar")); + } + + + @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")); + } + + @Test + public void bundle_class_path_mappings_are_generated() throws URISyntaxException { + URL mappingsUrl = getClass().getResource("/" + ProjectBundleClassPaths.classPathMappingsFileName()); + assertNotNull( + "Could not find " + ProjectBundleClassPaths.classPathMappingsFileName() + " in the test output directory", + mappingsUrl); + + ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(Paths.get(mappingsUrl.toURI())); + + assertThat(bundleClassPaths.mainBundle().bundleSymbolicName(), is("bundle-plugin-test")); + + Collection<String> mainBundleClassPaths = + JavaConversions.asJavaCollection(bundleClassPaths.mainBundle().classPathElements()); + + assertThat(mainBundleClassPaths, + hasItems( + endsWith("target/classes"), + allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")))); + } +} |