diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2018-06-13 13:38:26 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2018-06-13 13:38:26 +0200 |
commit | d5836f186c269986cb9d86374b54b540bf600930 (patch) | |
tree | e95e2ec309835ef1d285630e87bae5d177e9934b /bundle-plugin/src/test | |
parent | eb80fb0d3a6004431ff13e36e9f480ccb32ec31f (diff) |
Bundle-plugin Scala code converted to Java
Diffstat (limited to 'bundle-plugin/src/test')
16 files changed, 793 insertions, 432 deletions
diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java new file mode 100644 index 00000000000..8cccf0598ab --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java @@ -0,0 +1,85 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.bundle; + +import com.yahoo.container.plugin.bundle.AnalyzeBundle.PublicPackages; +import com.yahoo.container.plugin.osgi.ExportPackages; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static com.yahoo.container.plugin.classanalysis.TestUtilities.throwableMessage; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class AnalyzeBundleTest { + private final List<ExportPackages.Export> exports; + private final Map<String, ExportPackages.Export> exportsByPackageName; + + File jarDir = new File("src/test/resources/jar"); + + public AnalyzeBundleTest() { + File notOsgi = new File(jarDir, "notAOsgiBundle.jar"); + File simple = new File(jarDir, "simple1.jar"); + PublicPackages pp = AnalyzeBundle.publicPackagesAggregated(Arrays.asList(notOsgi, simple)); + this.exports = pp.exports; + this.exportsByPackageName = ExportPackages.exportsByPackageName(exports); + } + + private File jarFile(String name) { + return new File(jarDir, name); + } + + @Test + public void require_that_non_osgi_bundles_are_ignored() { + assertThat(exportsByPackageName.keySet(), not(hasItem("com.yahoo.sample.exported.package.ignored"))); + } + + @Test + public void require_that_exports_are_retrieved_from_manifest_in_jars() { + assertThat(exportsByPackageName.keySet().size(), is(1)); + assertThat(exportsByPackageName.keySet(), hasItem("com.yahoo.sample.exported.package")); + } + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Test + public void require_that_invalid_exports_throws_exception() { + exception.expect(Exception.class); + + exception.expectMessage(containsString("Invalid manifest in bundle")); + exception.expectMessage(matchesPattern("Invalid manifest in bundle '.*errorExport.jar'")); + exception.expectCause(throwableMessage(startsWith("Failed parsing Export-Package"))); + + AnalyzeBundle.publicPackages(jarFile("errorExport.jar")); + } + + private TypeSafeMatcher<String> matchesPattern(String pattern) { + return new TypeSafeMatcher<String>() { + @Override + protected boolean matchesSafely(String s) { + return s.matches(pattern); + } + + @Override + public void describeTo(Description description) { + description.appendText("expects String that matches the pattern ").appendValue(pattern); + } + }; + } +} diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java new file mode 100644 index 00000000000..aba6e8f14e8 --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.java @@ -0,0 +1,167 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.classanalysis; + +import com.yahoo.container.plugin.classanalysis.sampleclasses.Base; +import com.yahoo.container.plugin.classanalysis.sampleclasses.ClassAnnotation; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Derived; +import com.yahoo.container.plugin.classanalysis.sampleclasses.DummyAnnotation; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Fields; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Interface1; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Interface2; +import com.yahoo.container.plugin.classanalysis.sampleclasses.MethodAnnotation; +import com.yahoo.container.plugin.classanalysis.sampleclasses.MethodInvocation; +import com.yahoo.osgi.annotation.ExportPackage; +import com.yahoo.osgi.annotation.Version; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import javax.security.auth.login.LoginException; +import java.awt.Image; +import java.awt.image.ImagingOpException; +import java.awt.image.Kernel; +import java.util.Optional; + +import static com.yahoo.container.plugin.classanalysis.TestUtilities.analyzeClass; +import static com.yahoo.container.plugin.classanalysis.TestUtilities.classFile; +import static com.yahoo.container.plugin.classanalysis.TestUtilities.name; +import static com.yahoo.container.plugin.classanalysis.TestUtilities.throwableMessage; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +/** + * Tests that analysis of class files works. + * + * @author Tony Vaagenes + * @author ollivir + */ +public class AnalyzeClassTest { + @Test + public void require_that_full_class_name_is_returned() { + assertThat(analyzeClass(Base.class).getName(), is(name(Base.class))); + } + + @Test + public void require_that_base_class_is_included() { + assertThat(analyzeClass(Derived.class).getReferencedClasses(), hasItem(name(Base.class))); + } + + @Test + public void require_that_implemented_interfaces_are_included() { + assertThat(analyzeClass(Base.class).getReferencedClasses(), + allOf(hasItem(name(Interface1.class)), hasItem(name(Interface2.class)))); + } + + @Test + public void require_that_interface_can_be_analyzed() { + ClassFileMetaData classMetaData = analyzeClass(Interface1.class); + + assertThat(classMetaData.getName(), is(name(Interface1.class))); + assertThat(classMetaData.getReferencedClasses(), hasItem(name(Interface2.class))); + } + + @Test + public void require_that_return_type_is_included() { + assertThat(analyzeClass(Interface1.class).getReferencedClasses(), hasItem(name(Image.class))); + } + + @Test + public void require_that_parameters_are_included() { + assertThat(analyzeClass(Interface1.class).getReferencedClasses(), hasItem(name(Kernel.class))); + } + + @Test + public void require_that_exceptions_are_included() { + assertThat(analyzeClass(Interface1.class).getReferencedClasses(), hasItem(name(ImagingOpException.class))); + } + + @Test + public void require_that_basic_types_ignored() { + assertThat(analyzeClass(Interface1.class).getReferencedClasses(), not(anyOf(hasItem("int"), hasItem("float")))); + } + + @Test + public void require_that_arrays_of_basic_types_ignored() { + assertThat(analyzeClass(Interface1.class).getReferencedClasses(), not(anyOf(hasItem("int[]"), hasItem("int[][]")))); + } + + @Test + public void require_that_instance_field_types_are_included() { + assertThat(analyzeClass(Fields.class).getReferencedClasses(), hasItem(name(String.class))); + } + + @Test + public void require_that_static_field_types_are_included() { + assertThat(analyzeClass(Fields.class).getReferencedClasses(), hasItem(name(java.util.List.class))); + } + + @Test + public void require_that_field_annotation_is_included() { + assertThat(analyzeClass(Fields.class).getReferencedClasses(), hasItem(name(DummyAnnotation.class))); + } + + @Test + public void require_that_class_annotation_is_included() { + assertThat(analyzeClass(ClassAnnotation.class).getReferencedClasses(), hasItem(name(DummyAnnotation.class))); + } + + @Test + public void require_that_method_annotation_is_included() { + assertThat(analyzeClass(MethodAnnotation.class).getReferencedClasses(), hasItem(name(DummyAnnotation.class))); + } + + @Test + public void require_that_export_package_annotations_are_ignored() { + assertThat(Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.package-info")) + .getReferencedClasses(), not(anyOf(hasItem(name(ExportPackage.class)), hasItem(name(Version.class))))); + } + + @Test + public void require_that_export_annotations_are_processed() { + assertThat( + Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.package-info")).getExportPackage(), + is(Optional.of(new ExportPackageAnnotation(3, 1, 4, "TEST_QUALIFIER-2")))); + } + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void require_that_export_annotations_are_validated() { + expectedException.expect(RuntimeException.class); + expectedException.expectMessage(containsString("invalid/package-info")); + expectedException.expectCause(throwableMessage(containsString("qualifier must follow the format"))); + expectedException.expectCause(throwableMessage(containsString("'EXAMPLE INVALID QUALIFIER'"))); + + Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.invalid.package-info")); + } + + @Test + public void require_that_catch_clauses_are_included() { + assertThat(Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.CatchException")) + .getReferencedClasses(), hasItem(name(LoginException.class))); + } + + @Test + public void require_that_class_references_are_included() { + assertThat(Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.ClassReference")) + .getReferencedClasses(), hasItem(name(Interface1.class))); + } + + @Test + public void require_that_return_type_of_method_invocations_are_included() { + assertThat(analyzeClass(MethodInvocation.class).getReferencedClasses(), hasItem(name(Image.class))); + } + + @Test + public void require_that_attributes_are_included() { + //Uses com/coremedia/iso/Utf8.class from com.googlecode.mp4parser:isoparser:1.0-RC-1 + assertThat(Analyze.analyzeClass(classFile("class/Utf8")).getReferencedClasses(), + hasItem("org.aspectj.weaver.MethodDeclarationLineNumber")); + } +} diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.java new file mode 100644 index 00000000000..d722f1eba2d --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.java @@ -0,0 +1,73 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.classanalysis; + +import com.yahoo.container.plugin.classanalysis.sampleclasses.Base; +import com.yahoo.container.plugin.classanalysis.sampleclasses.ClassWithMethod; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Derived; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Dummy; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Fields; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Interface1; +import com.yahoo.container.plugin.classanalysis.sampleclasses.Methods; +import org.junit.Test; + +import java.io.PrintStream; + +import static com.yahoo.container.plugin.classanalysis.TestUtilities.analyzeClass; +import static com.yahoo.container.plugin.classanalysis.TestUtilities.name; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +/** + * Tests that classes used in method bodies are included in the imports list. + * + * @author tonytv + */ +public class AnalyzeMethodBodyTest { + @Test + public void require_that_class_of_locals_are_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(Base.class))); + } + + @Test + public void require_that_class_of_locals_in_static_method_are_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(Derived.class))); + } + + @Test + public void require_that_field_references_are_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), + allOf(hasItem(name(java.util.List.class)), hasItem(name(Fields.class)))); + } + + @Test + public void require_that_class_owning_field_is_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(System.class))); + } + + @Test + public void require_that_class_containing_method_is_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(PrintStream.class))); + } + + @Test + public void require_that_element_of_new_multidimensional_array_is_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(Interface1.class))); + } + + @Test + public void require_that_basic_arrays_are_not_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), not(hasItem("int[]"))); + } + + @Test + public void require_that_container_generic_parameters_are_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(Dummy.class))); + } + + @Test + public void require_that_class_owning_method_handler_is_included() { + assertThat(analyzeClass(Methods.class).getReferencedClasses(), hasItem(name(ClassWithMethod.class))); + } +} diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/TestUtilities.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/TestUtilities.java new file mode 100644 index 00000000000..6ff6bafd816 --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/TestUtilities.java @@ -0,0 +1,40 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.classanalysis; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +import java.io.File; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class TestUtilities { + public static ClassFileMetaData analyzeClass(Class<?> clazz) { + return Analyze.analyzeClass(classFile(name(clazz))); + } + + public static File classFile(String className) { + return new File("target/test-classes/" + className.replace('.', '/') + ".class"); + } + + public static String name(Class<?> clazz) { + return clazz.getName(); + } + + public static TypeSafeMatcher<Throwable> throwableMessage(final Matcher<String> matcher) { + return new TypeSafeMatcher<Throwable>() { + @Override + protected boolean matchesSafely(Throwable throwable) { + return matcher.matches(throwable.getMessage()); + } + + @Override + public void describeTo(Description description) { + description.appendText("expects Throwable and a message matching ").appendDescriptionOf(matcher); + } + }; + } +} diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/ClassReference.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/ClassReference.java index b4a4f90398f..f650f0f0c7f 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/ClassReference.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/ClassReference.java @@ -6,6 +6,7 @@ package com.yahoo.container.plugin.classanalysis.sampleclasses; */ public class ClassReference { void classReference() { + @SuppressWarnings("unused") Class<?> clazz = Interface1.class; } } diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/MethodInvocation.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/MethodInvocation.java index 992799e3032..a576c764eec 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/MethodInvocation.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/MethodInvocation.java @@ -7,6 +7,7 @@ package com.yahoo.container.plugin.classanalysis.sampleclasses; public class MethodInvocation { void invokeMethod() { Interface1 interface1 = null; + @SuppressWarnings({ "unused", "null" }) Object o = interface1.methodSignatureTest(null, null); } } diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/Methods.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/Methods.java index 568a5070961..abe325768fc 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/Methods.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/classanalysis/sampleclasses/Methods.java @@ -8,6 +8,7 @@ import java.util.Map; * Input for class analysis tests. * @author tonytv */ +@SuppressWarnings("unused") public class Methods { public void method1() { Base b = new Base(); diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ExportPackageParserTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ExportPackageParserTest.java new file mode 100644 index 00000000000..d869b8ec4d9 --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ExportPackageParserTest.java @@ -0,0 +1,295 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.osgi; + +import com.yahoo.container.plugin.osgi.ExportPackages.Export; +import com.yahoo.container.plugin.osgi.ExportPackages.Parameter; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Test; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertThat; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class ExportPackageParserTest { + private final Parameter versionParameter = new Parameter("version", "1.2.3.sample"); + + @Test + public void require_that_package_is_parsed_correctly() { + List<Export> exports = ExportPackageParser.parseExports("sample.exported.package"); + + assertThat(exports.size(), is(1)); + assertThat(exports.get(0).getParameters(), empty()); + assertThat(exports.get(0).getPackageNames(), contains("sample.exported.package")); + } + + @Test + public void require_that_version_is_parsed_correctly() { + List<Export> exports = ExportPackageParser.parseExports("com.yahoo.sample.exported.package;version=\"1.2.3.sample\""); + + assertThat(exports.size(), is(1)); + Export export = exports.get(0); + assertThat(export.getPackageNames(), contains("com.yahoo.sample.exported.package")); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter))); + } + + @Test + public void require_that_multiple_packages_with_same_parameters_is_parsed_correctly() { + List<Export> exports = ExportPackageParser.parseExports("exported.package1;exported.package2;version=\"1.2.3.sample\""); + + assertThat(exports.size(), is(1)); + Export export = exports.get(0); + assertThat(export.getPackageNames(), contains("exported.package1", "exported.package2")); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter))); + } + + @Test + public void require_that_spaces_between_separators_are_allowed() { + List<Export> exports = ExportPackageParser.parseExports("exported.package1 , exported.package2 ; version = \"1.2.3.sample\" "); + + assertThat(exports.size(), is(2)); + Export export = exports.get(0); + assertThat(export.getPackageNames(), contains("exported.package1")); + export = exports.get(1); + assertThat(export.getPackageNames(), contains("exported.package2")); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter))); + } + + @SuppressWarnings("unchecked") + @Test + public void require_that_multiple_parameters_for_a_package_is_parsed_correctly() { + List<Export> exports = ExportPackageParser.parseExports("exported.package;version=\"1.2.3.sample\";param2=true"); + + assertThat(exports.size(), is(1)); + Export export = exports.get(0); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter), parameterMatching("param2", "true"))); + } + + @Test + public void require_that_multiple_exports_are_parsed_correctly() { + List<Export> exports = ExportPackageParser.parseExports("exported.package1,exported.package2"); + assertThat(exports.size(), is(2)); + Export export = exports.get(0); + assertThat(export.getPackageNames(), contains("exported.package1")); + assertThat(export.getParameters(), empty()); + export = exports.get(1); + assertThat(export.getPackageNames(), contains("exported.package2")); + assertThat(export.getParameters(), empty()); + + exports = ExportPackageParser.parseExports("exported.package1;version=\"1.2.3.sample\",exported.package2"); + assertThat(exports.size(), is(2)); + export = exports.get(0); + assertThat(export.getPackageNames(), contains("exported.package1")); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter))); + export = exports.get(1); + assertThat(export.getPackageNames(), contains("exported.package2")); + assertThat(export.getParameters(), empty()); + + exports = ExportPackageParser.parseExports("exported.package1,exported.package2;version=\"1.2.3.sample\""); + assertThat(exports.size(), is(2)); + export = exports.get(0); + assertThat(export.getPackageNames(), contains("exported.package1")); + assertThat(export.getParameters(), empty()); + export = exports.get(1); + assertThat(export.getPackageNames(), contains("exported.package2")); + assertThat(export.getParameters(), contains(parameterMatching(versionParameter))); + } + + @Test + public void require_that_long_string_literals_do_not_cause_stack_overflow_error() { + //From jersey-server-1.13.jar + String exportHeader = "com.sun.jersey.server.impl.wadl;uses:=\"com.sun.jersey.api.model,com.sun.resea" + + "rch.ws.wadl,com.sun.jersey.api.wadl.config,com.sun.jersey.server.wadl,com.sun." + + "jersey.api.core,javax.xml.bind,javax.ws.rs.core,com.sun.jersey.server.impl.uri" + + ",com.sun.jersey.core.spi.factory,com.sun.jersey.server.impl.model.method,com.s" + + "un.jersey.api.uri,com.sun.jersey.core.header,com.sun.jersey.spi.dispatch,javax" + + ".ws.rs,com.sun.jersey.spi.resource\";version=\"1.13.0\",com.sun.jersey.server." + + "impl.model.parameter.multivalued;uses:=\"com.sun.jersey.spi,javax.ws.rs.core,c" + + "om.sun.jersey.api.container,com.sun.jersey.impl,javax.xml.parsers,org.xml.sax," + + "javax.xml.transform,javax.xml.bind.annotation,javax.xml.transform.sax,com.sun." + + "jersey.spi.inject,javax.xml.bind,javax.ws.rs.ext,com.sun.jersey.api.model,com." + + "sun.jersey.core.reflection,javax.ws.rs,com.sun.jersey.core.spi.component,com.s" + + "un.jersey.core.header\";version=\"1.13.0\",com.sun.jersey.server.impl.model.pa" + + "rameter;uses:=\"com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com" + + ".sun.jersey.server.impl.model.parameter.multivalued,com.sun.jersey.spi.inject," + + "com.sun.jersey.api,com.sun.jersey.api.core,com.sun.jersey.server.impl.inject,j" + + "avax.ws.rs.core,javax.ws.rs,com.sun.jersey.core.header,com.sun.jersey.api.repr" + + "esentation\";version=\"1.13.0\",com.sun.jersey.server.impl.application;uses:=" + + "\"com.sun.jersey.core.spi.component,com.sun.jersey.api.core,com.sun.jersey.spi" + + ",com.sun.jersey.spi.inject,javax.ws.rs.core,com.sun.jersey.api.container,javax" + + ".ws.rs.ext,com.sun.jersey.spi.container,com.sun.jersey.core.reflection,com.sun" + + ".jersey.api.model,com.sun.jersey.impl,com.sun.jersey.spi.dispatch,com.sun.jers" + + "ey.server.impl.model,com.sun.jersey.server.impl.wadl,com.sun.jersey.server.imp" + + "l.uri,com.sun.jersey.core.spi.factory,com.sun.jersey.api.uri,com.sun.jersey.se" + + "rver.impl.uri.rules,com.sun.jersey.spi.uri.rules,com.sun.jersey.server.spi.com" + + "ponent,com.sun.jersey.core.util,com.sun.jersey.core.header,com.sun.jersey.core" + + ".spi.component.ioc,javax.ws.rs,com.sun.jersey.server.impl,com.sun.jersey.serve" + + "r.wadl,com.sun.jersey.server.impl.inject,com.sun.jersey.server.impl.component," + + "com.sun.jersey.spi.monitoring,com.sun.jersey.server.impl.monitoring,com.sun.je" + + "rsey.api.container.filter,com.sun.jersey.server.impl.model.parameter.multivalu" + + "ed,com.sun.jersey.server.impl.model.parameter,com.sun.jersey.server.impl.templ" + + "ate,com.sun.jersey.spi.template,com.sun.jersey.server.impl.resource,com.sun.je" + + "rsey.server.impl.modelapi.annotation,com.sun.jersey.server.impl.container.filt" + + "er,com.sun.jersey.server.impl.modelapi.validation,com.sun.jersey.api,com.sun.j" + + "ersey.spi.service\";version=\"1.13.0\",com.sun.jersey.server.impl.component;us" + + "es:=\"com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jerse" + + "y.server.spi.component,com.sun.jersey.api.core,com.sun.jersey.core.spi.compone" + + "nt.ioc,com.sun.jersey.server.impl.inject,com.sun.jersey.server.impl.resource,c" + + "om.sun.jersey.api.container,com.sun.jersey.core.reflection,com.sun.jersey.spi." + + "inject\";version=\"1.13.0\",com.sun.jersey.server.impl.provider;uses:=\"com.su" + + "n.jersey.core.spi.factory,com.sun.jersey.api.container,com.sun.jersey.api.core" + + ",javax.ws.rs.core\";version=\"1.13.0\",com.sun.jersey.server.impl.template;use" + + "s:=\"com.sun.jersey.core.spi.component,com.sun.jersey.api.view,com.sun.jersey." + + "spi.template,javax.ws.rs.core,com.sun.jersey.core.header,com.sun.jersey.server" + + ".impl.model.method,com.sun.jersey.spi.dispatch,com.sun.jersey.api.uri,javax.ws" + + ".rs,com.sun.jersey.spi.inject,javax.ws.rs.ext,com.sun.jersey.server.impl.uri.r" + + "ules,com.sun.jersey.server.probes,com.sun.jersey.core.reflection,com.sun.jerse" + + "y.spi.uri.rules,com.sun.jersey.spi.container,com.sun.jersey.api.core\";version" + + "=\"1.13.0\",com.sun.jersey.server.osgi;uses:=\"com.sun.jersey.server.impl.prov" + + "ider,org.osgi.framework,javax.ws.rs.ext\";version=\"1.13.0\",com.sun.jersey.se" + + "rver.wadl.generators.resourcedoc.model;uses:=\"javax.xml.bind.annotation,javax" + + ".xml.namespace\";version=\"1.13.0\",com.sun.jersey.server.impl.resource;uses:=" + + "\"com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.se" + + "rver.spi.component,com.sun.jersey.api.core,com.sun.jersey.api.container,javax." + + "ws.rs,com.sun.jersey.server.impl.inject,com.sun.jersey.core.spi.component.ioc," + + "javax.ws.rs.core\";version=\"1.13.0\",com.sun.jersey.server.impl.monitoring;us" + + "es:=\"com.sun.jersey.spi.monitoring,com.sun.jersey.spi.service,com.sun.jersey." + + "api.model,com.sun.jersey.spi.container,javax.ws.rs.ext,com.sun.jersey.core.spi" + + ".component\";version=\"1.13.0\",com.sun.jersey.server.impl.modelapi.annotation" + + ";uses:=\"com.sun.jersey.api.model,javax.ws.rs.core,javax.ws.rs,com.sun.jersey." + + "core.reflection,com.sun.jersey.core.header,com.sun.jersey.impl\";version=\"1.1" + + "3.0\",com.sun.jersey.server.impl.container;uses:=\"com.sun.jersey.server.impl." + + "application,com.sun.jersey.spi.container,com.sun.jersey.api.container\";versio" + + "n=\"1.13.0\",com.sun.jersey.server.wadl;uses:=\"javax.ws.rs.core,com.sun.resea" + + "rch.ws.wadl,javax.xml.namespace,com.sun.jersey.api.model,javax.xml.bind,javax." + + "ws.rs,com.sun.jersey.server.wadl.generators,com.sun.jersey.server.impl.modelap" + + "i.annotation,com.sun.jersey.server.impl\";version=\"1.13.0\",com.sun.jersey.se" + + "rver.impl.model.method.dispatch;uses:=\"com.sun.jersey.api.model,com.sun.jerse" + + "y.api.core,com.sun.jersey.spi.container,com.sun.jersey.server.impl.inject,com." + + "sun.jersey.api,javax.ws.rs.core,com.sun.jersey.core.spi.factory,com.sun.jersey" + + ".spi.inject,com.sun.jersey.spi.dispatch,com.sun.jersey.core.spi.component,java" + + "x.ws.rs,com.sun.jersey.server.impl.model.parameter.multivalued,com.sun.jersey." + + "api.representation,com.sun.jersey.api.container\";version=\"1.13.0\",com.sun.j" + + "ersey.server.impl;uses:=\"javax.naming,com.sun.jersey.api.core,com.sun.jersey." + + "core.header,javax.ws.rs.core,com.sun.jersey.server.impl.model,com.sun.jersey.s" + + "pi.container\";version=\"1.13.0\",com.sun.jersey.server.wadl.generators.resour" + + "cedoc;uses:=\"com.sun.jersey.api.model,com.sun.jersey.server.wadl.generators.r" + + "esourcedoc.model,com.sun.jersey.server.wadl.generators.resourcedoc.xhtml,com.s" + + "un.research.ws.wadl,javax.xml.namespace,com.sun.jersey.server.wadl,javax.xml.b" + + "ind,javax.ws.rs.core\";version=\"1.13.0\",com.sun.jersey.server.impl.container" + + ".httpserver;uses:=\"com.sun.net.httpserver,com.sun.jersey.spi.container,javax." + + "ws.rs.core,com.sun.jersey.core.header,com.sun.jersey.api.container,com.sun.jer" + + "sey.core.util,com.sun.jersey.api.core\";version=\"1.13.0\",com.sun.jersey.serv" + + "er.impl.container.filter;uses:=\"com.sun.jersey.api.model,com.sun.jersey.spi.c" + + "ontainer,com.sun.jersey.core.spi.component,com.sun.jersey.api.core,javax.ws.rs" + + ",com.sun.jersey.server.impl.uri,javax.ws.rs.core\";version=\"1.13.0\",com.sun." + + "jersey.server.wadl.generators.resourcedoc.xhtml;uses:=\"javax.xml.bind,javax.x" + + "ml.namespace,javax.xml.bind.annotation\";version=\"1.13.0\",com.sun.jersey.ser" + + "ver.impl.uri.rules;uses:=\"com.sun.jersey.spi.uri.rules,com.sun.jersey.api.uri" + + ",com.sun.jersey.api.core,com.sun.jersey.server.impl.model.method,com.sun.jerse" + + "y.spi.dispatch,com.sun.jersey.core.header,javax.ws.rs.core,com.sun.jersey.api." + + "model,com.sun.jersey.server.probes,com.sun.jersey.core.reflection,com.sun.jers" + + "ey.server.impl.template,com.sun.jersey.spi.monitoring,com.sun.jersey.api,com.s" + + "un.jersey.spi.container,com.sun.jersey.server.impl.uri,javax.ws.rs,com.sun.jer" + + "sey.api.container,com.sun.jersey.server.impl.inject,com.sun.jersey.spi.inject," + + "com.sun.jersey.server.impl.uri.rules.automata\";version=\"1.13.0\",com.sun.jer" + + "sey.server.spi.component;uses:=\"com.sun.jersey.spi.inject,com.sun.jersey.api." + + "model,com.sun.jersey.core.spi.component,com.sun.jersey.api.core,com.sun.jersey" + + ".server.impl.inject,com.sun.jersey.api.container,com.sun.jersey.core.spi.compo" + + "nent.ioc\";version=\"1.13.0\",com.sun.jersey.server.probes;version=\"1.13.0\"," + + "com.sun.jersey.server.wadl.generators;uses:=\"com.sun.research.ws.wadl,javax.x" + + "ml.bind.annotation,com.sun.jersey.api.model,com.sun.jersey.server.wadl,javax.x" + + "ml.bind,javax.ws.rs.core,com.sun.jersey.api,javax.xml.namespace,javax.xml.tran" + + "sform,javax.xml.transform.stream\";version=\"1.13.0\",com.sun.jersey.server.im" + + "pl.modelapi.validation;uses:=\"com.sun.jersey.api.model,javax.ws.rs,com.sun.je" + + "rsey.impl,com.sun.jersey.api.core,com.sun.jersey.core.reflection,javax.ws.rs.c" + + "ore\";version=\"1.13.0\",com.sun.jersey.server.impl.model.method;uses:=\"com.s" + + "un.jersey.api.container,com.sun.jersey.spi.dispatch,com.sun.jersey.api.uri,com" + + ".sun.jersey.api.model,com.sun.jersey.server.impl.container.filter,com.sun.jers" + + "ey.impl,com.sun.jersey.spi.container,com.sun.jersey.spi.inject,com.sun.jersey." + + "api.core,javax.ws.rs.core,com.sun.jersey.core.header\";version=\"1.13.0\",com." + + "sun.jersey.server.impl.model;uses:=\"javax.ws.rs,com.sun.jersey.impl,com.sun.j" + + "ersey.api.container,com.sun.jersey.core.header,com.sun.jersey.core.header.read" + + "er,com.sun.jersey.api.core,javax.ws.rs.core,com.sun.jersey.server.impl.model.m" + + "ethod,com.sun.jersey.server.impl.container.filter,com.sun.jersey.api.model,com" + + ".sun.jersey.server.impl.wadl,com.sun.jersey.spi.monitoring,com.sun.jersey.serv" + + "er.impl.uri,com.sun.jersey.spi.container,com.sun.jersey.server.impl.inject,com" + + ".sun.jersey.spi.inject,com.sun.jersey.api.uri,com.sun.jersey.core.spi.componen" + + "t,com.sun.jersey.server.impl.uri.rules,com.sun.jersey.server.impl.template,com" + + ".sun.jersey.api.view,com.sun.jersey.spi.uri.rules\";version=\"1.13.0\",com.sun" + + ".jersey.server.impl.uri.rules.automata;uses:=\"com.sun.jersey.server.impl.uri," + + "com.sun.jersey.spi.uri.rules,com.sun.jersey.server.impl.uri.rules,com.sun.jers" + + "ey.api.uri\";version=\"1.13.0\",com.sun.jersey.server.impl.uri;uses:=\"com.sun" + + ".jersey.api.uri,javax.ws.rs.core\";version=\"1.13.0\",com.sun.jersey.server.im" + + "pl.inject;uses:=\"com.sun.jersey.api.core,com.sun.jersey.spi.inject,javax.ws.r" + + "s,com.sun.jersey.api.container,com.sun.jersey.api.model,com.sun.jersey.core.sp" + + "i.component,com.sun.jersey.core.spi.factory\";version=\"1.13.0\",com.sun.jerse" + + "y.spi.scanning;uses:=\"org.objectweb.asm,com.sun.jersey.core.reflection,com.su" + + "n.jersey.core.spi.scanning,javax.ws.rs,javax.ws.rs.ext\";version=\"1.13.0\",co" + + "m.sun.jersey.spi.resource;uses:=\"com.sun.jersey.server.impl.resource,com.sun." + + "jersey.server.spi.component\";version=\"1.13.0\",com.sun.jersey.spi.template;u" + + "ses:=\"com.sun.jersey.api.view,javax.ws.rs.core,com.sun.jersey.api.container\"" + + ";version=\"1.13.0\",com.sun.jersey.spi.dispatch;uses:=\"com.sun.jersey.api.cor" + + "e\";version=\"1.13.0\",com.sun.jersey.spi.uri.rules;uses:=\"com.sun.jersey.api" + + ".core,com.sun.jersey.api.model,com.sun.jersey.spi.container,com.sun.jersey.api" + + ".uri\";version=\"1.13.0\",com.sun.jersey.spi.container;uses:=\"javax.ws.rs,com" + + ".sun.jersey.api.representation,com.sun.jersey.core.header,com.sun.jersey.spi,j" + + "avax.ws.rs.core,com.sun.jersey.api.container,com.sun.jersey.api.core,com.sun.j" + + "ersey.core.util,com.sun.jersey.core.header.reader,com.sun.jersey.server.impl,c" + + "om.sun.jersey.core.reflection,javax.ws.rs.ext,com.sun.jersey.server.impl.model" + + ",com.sun.jersey.api,com.sun.jersey.api.uri,com.sun.jersey.core.spi.factory,com" + + ".sun.jersey.spi.monitoring,com.sun.jersey.api.model,com.sun.jersey.core.spi.co" + + "mponent,com.sun.jersey.server.impl.application,com.sun.jersey.impl,com.sun.jer" + + "sey.spi.inject,com.sun.jersey.spi.dispatch,com.sun.jersey.server.impl.inject,c" + + "om.sun.jersey.core.spi.component.ioc,com.sun.jersey.spi.service\";version=\"1." + + "13.0\",com.sun.jersey.spi.monitoring;uses:=\"com.sun.jersey.api.model,com.sun." + + "jersey.spi.container,javax.ws.rs.ext\";version=\"1.13.0\",com.sun.jersey.api;u" + + "ses:=\"javax.ws.rs,javax.ws.rs.core,com.sun.jersey.core.header,com.sun.jersey." + + "core.spi.factory\";version=\"1.13.0\",com.sun.jersey.api.core;uses:=\"javax.ws" + + ".rs.core,com.sun.jersey.core.spi.scanning,com.sun.jersey.api.model,com.sun.jer" + + "sey.api.uri,javax.ws.rs,com.sun.jersey.core.header,com.sun.jersey.api.represen" + + "tation,com.sun.jersey.core.util,javax.ws.rs.ext,com.sun.jersey.api.container,c" + + "om.sun.jersey.spi.scanning,com.sun.jersey.spi.container,com.sun.jersey.server." + + "impl.application\";version=\"1.13.0\",com.sun.jersey.api.wadl.config;uses:=\"c" + + "om.sun.jersey.server.wadl,com.sun.jersey.api.core,com.sun.jersey.core.reflecti" + + "on,com.sun.jersey.server.wadl.generators\";version=\"1.13.0\",com.sun.jersey.a" + + "pi.model;uses:=\"javax.ws.rs.core,com.sun.jersey.spi.container\";version=\"1.1" + + "3.0\",com.sun.jersey.api.view;version=\"1.13.0\",com.sun.jersey.api.container." + + "filter;uses:=\"javax.ws.rs,com.sun.jersey.spi.container,javax.ws.rs.core,com.s" + + "un.jersey.api.container,com.sun.jersey.api.core,com.sun.jersey.core.util,com.s" + + "un.jersey.core.header,com.sun.jersey.api.representation,com.sun.jersey.api.mod" + + "el,javax.annotation.security\";version=\"1.13.0\",com.sun.jersey.api.container" + + ";uses:=\"com.sun.jersey.api.core,com.sun.jersey.spi.container,com.sun.jersey.s" + + "pi.service,com.sun.jersey.core.spi.component.ioc\";version=\"1.13.0\",com.sun." + + "jersey.api.container.httpserver;uses:=\"com.sun.net.httpserver,com.sun.jersey." + + "api.core,com.sun.jersey.api.container,com.sun.jersey.core.spi.component.ioc\";" + + "version=\"1.13.0\",com.sun.research.ws.wadl;uses:=\"javax.xml.bind.annotation," + + "javax.xml.bind.annotation.adapters,javax.xml.namespace\";version=\"1.13.0\""; + ExportPackageParser.parseExports(exportHeader); + } + + private static TypeSafeMatcher<Parameter> parameterMatching(final String name, final String value) { + return new TypeSafeMatcher<Parameter>() { + @Override + protected boolean matchesSafely(Parameter parameter) { + return parameter.getName().equals(name) && parameter.getValue().equals(value); + } + + @Override + public void describeTo(Description description) { + description.appendText("Parameter with name ").appendValue(name).appendText(" with value ").appendValue(value); + } + }; + } + + private static TypeSafeMatcher<Parameter> parameterMatching(final Parameter param) { + return parameterMatching(param.getName(), param.getValue()); + } +} diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ImportPackageTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ImportPackageTest.java new file mode 100644 index 00000000000..23960323a31 --- /dev/null +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/osgi/ImportPackageTest.java @@ -0,0 +1,130 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.plugin.osgi; + +import com.yahoo.container.plugin.osgi.ExportPackages.Export; +import com.yahoo.container.plugin.osgi.ExportPackages.Parameter; +import com.yahoo.container.plugin.osgi.ImportPackages.Import; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class ImportPackageTest { + private static final String PACKAGE_NAME = "com.yahoo.exported"; + private Set<String> referencedPackages = Collections.singleton(PACKAGE_NAME); + private Map<String, Export> exports = exportByPackageName(new Export(singletonList(PACKAGE_NAME), Collections.emptyList())); + private Map<String, Export> exportsWithVersion = exportByPackageName( + new Export(singletonList(PACKAGE_NAME), singletonList(new Parameter("version", "1.3")))); + + private static Map<String, Export> exportByPackageName(Export export) { + return ExportPackages.exportsByPackageName(singletonList(export)); + } + + @Test + public void require_that_non_implemented_import_with_matching_export_is_included() { + Set<Import> imports = calculateImports(referencedPackages, emptySet(), exports); + assertThat(imports, contains(importMatching(PACKAGE_NAME, ""))); + } + + @Test + public void require_that_non_implemented_import_without_matching_export_is_excluded() { + Set<Import> imports = calculateImports(referencedPackages, emptySet(), emptyMap()); + assertThat(imports, empty()); + } + + @Test + public void require_that_implemented_import_with_matching_export_is_excluded() { + Set<Import> imports = calculateImports(referencedPackages, referencedPackages, exports); + + assertThat(imports, empty()); + } + + @Test + public void require_that_version_is_included() { + Set<Import> imports = calculateImports(referencedPackages, emptySet(), exportsWithVersion); + + assertThat(imports, contains(importMatching(PACKAGE_NAME, "1.3"))); + } + + @Test + public void require_that_all_versions_up_to_the_next_major_version_is_in_range() { + assertThat(new Import("foo", Optional.of("1.2")).importVersionRange().get(), is("[1.2,2)")); + } + + // TODO: Detecting guava packages should be based on bundle-symbolicName, not package name. + @Test + public void require_that_for_guava_all_future_major_versions_are_in_range() { + Optional<String> rangeWithInfiniteUpperLimit = Optional.of("[18.1," + ImportPackages.INFINITE_VERSION + ")"); + assertThat(new Import("com.google.common", Optional.of("18.1")).importVersionRange(), is(rangeWithInfiniteUpperLimit)); + assertThat(new Import("com.google.common.foo", Optional.of("18.1")).importVersionRange(), is(rangeWithInfiniteUpperLimit)); + assertThat(new Import("com.google.commonality", Optional.of("18.1")).importVersionRange(), is(Optional.of("[18.1,19)"))); + } + + @Test + public void require_that_none_version_gives_non_version_range() { + assertThat(new Import("foo", Optional.empty()).importVersionRange(), is(Optional.empty())); + } + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void require_that_exception_is_thrown_when_major_component_is_non_numeric() { + expectedException.expect(IllegalArgumentException.class); + new Import("foo", Optional.of("1notValid.2")); + } + + @Test + public void require_that_osgi_import_supports_missing_version() { + assertThat(new Import("com.yahoo.exported", Optional.empty()).asOsgiImport(), is("com.yahoo.exported")); + } + + @Test + public void require_that_osgi_import_version_range_includes_all_versions_from_the_current_up_to_the_next_major_version() { + assertThat(new Import("com.yahoo.exported", Optional.of("1.2")).asOsgiImport(), is("com.yahoo.exported;version=\"[1.2,2)\"")); + } + + @Test + public void require_that_osgi_import_version_range_ignores_qualifier() { + assertThat(new Import("com.yahoo.exported", Optional.of("1.2.3.qualifier")).asOsgiImport(), + is("com.yahoo.exported;version=\"[1.2.3,2)\"")); + } + + private static Set<Import> calculateImports(Set<String> referencedPackages, Set<String> implementedPackages, + Map<String, Export> exportedPackages) { + return new HashSet<>(ImportPackages.calculateImports(referencedPackages, implementedPackages, exportedPackages).values()); + } + + private static TypeSafeMatcher<Import> importMatching(String packageName, String version) { + return new TypeSafeMatcher<Import>() { + @Override + protected boolean matchesSafely(Import anImport) { + return anImport.packageName().equals(packageName) && anImport.version().equals(version); + } + + @Override + public void describeTo(Description description) { + description.appendText("an Import of package ").appendValue(packageName).appendText(" with version ").appendValue(version); + } + }; + } +} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala deleted file mode 100644 index 3ef1b1fea87..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.scala +++ /dev/null @@ -1,41 +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.container.plugin.bundle - -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import org.junit.Test -import com.yahoo.container.plugin.bundle.AnalyzeBundle.PublicPackages -import com.yahoo.container.plugin.osgi.ExportPackages -import java.io.File - -import org.scalatest.Matchers - -/** - * @author tonytv - */ -class AnalyzeBundleTest extends JUnitSuite with AssertionsForJUnit with Matchers { - val jarDir = new File("src/test/resources/jar") - - val PublicPackages(exports, globals) = AnalyzeBundle.publicPackagesAggregated( - List("notAOsgiBundle.jar", "simple1.jar").map(jarFile)) - - val exportsByPackageName = ExportPackages.exportsByPackageName(exports) - - def jarFile(name : String) : File = new File(jarDir, name) - - @Test - def require_that_non_osgi_bundles_are_ignored() { - exportsByPackageName should not contain key("com.yahoo.sample.exported.package.ignored") - } - - @Test - def require_that_exports_are_retrieved_from_manifest_in_jars() { - exportsByPackageName.keySet should be (Set("com.yahoo.sample.exported.package")) - } - - @Test - def require_that_invalid_exports_throws_exception() { - val exception = intercept[Exception](AnalyzeBundle.publicPackages(jarFile("errorExport.jar"))) - exception.getMessage should startWith regex ("Invalid manifest in bundle '.*errorExport.jar'") - exception.getCause.getMessage should startWith ("Failed parsing Export-Package") - } -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala deleted file mode 100644 index e2d0e3c6f10..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeClassTest.scala +++ /dev/null @@ -1,118 +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.container.plugin.classanalysis - -import org.junit.Test -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import java.awt.Image -import java.awt.image.{ImagingOpException, Kernel} - -import sampleclasses._ -import TestUtilities._ -import com.yahoo.osgi.annotation.{ExportPackage, Version} -import javax.security.auth.login.LoginException - -import org.scalatest.Matchers - -/** - * Tests that analysis of class files works. - * @author tonytv - */ -class AnalyzeClassTest extends JUnitSuite with AssertionsForJUnit with Matchers { - @Test def require_that_full_class_name_is_returned() { - analyzeClass[Base].name should be(name[Base]) - } - - @Test def require_that_base_class_is_included() { - analyzeClass[Derived].referencedClasses should contain (name[Base]) - } - - @Test def require_that_implemented_interfaces_are_included() { - analyzeClass[Base].referencedClasses should (contain (name[Interface1]) and contain (name[Interface2])) - } - - @Test def require_that_interface_can_be_analyzed() { - val classMetaData = analyzeClass[Interface1] - - classMetaData.name should be(name[Interface1]) - classMetaData.referencedClasses should contain(name[Interface2]) - } - - @Test def require_that_return_type_is_included() { - analyzeClass[Interface1].referencedClasses should contain (name[Image]) - } - - @Test def require_that_parameters_are_included() { - analyzeClass[Interface1].referencedClasses should contain (name[Kernel]) - } - - @Test def require_that_exceptions_are_included() { - analyzeClass[Interface1].referencedClasses should contain (name[ImagingOpException]) - } - - @Test def require_that_basic_types_ignored() { - analyzeClass[Interface1].referencedClasses should not (contain ("int") or contain ("float")) - } - - @Test def require_that_arrays_of_basic_types_ignored() { - analyzeClass[Interface1].referencedClasses should not (contain ("int[]") or contain ("int[][]")) - } - - @Test def require_that_instance_field_types_are_included() { - analyzeClass[Fields].referencedClasses should contain (name[String]) - } - - @Test def require_that_static_field_types_are_included() { - analyzeClass[Fields].referencedClasses should contain (name[java.util.List[_]]) - } - - @Test def require_that_field_annotation_is_included() { - analyzeClass[Fields].referencedClasses should contain (name[DummyAnnotation]) - } - - @Test def require_that_class_annotation_is_included() { - analyzeClass[ClassAnnotation].referencedClasses should contain(name[DummyAnnotation]) - } - - @Test def require_that_method_annotation_is_included() { - analyzeClass[MethodAnnotation].referencedClasses should contain(name[DummyAnnotation]) - } - - @Test def require_that_export_package_annotations_are_ignored() { - Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.package-info")). - referencedClasses should not (contain (name[ExportPackage]) or contain (name[Version])) - } - - @Test def require_that_export_annotations_are_processed() { - Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.package-info")). - exportPackage should be (Some(ExportPackageAnnotation(3, 1, 4, "TEST_QUALIFIER-2"))) - } - - @Test def require_that_export_annotations_are_validated() { - val exception = intercept[RuntimeException] { - Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.invalid.package-info")) - } - - exception.getMessage should include ("invalid/package-info") - exception.getCause.getMessage should include ("qualifier must follow the format") - exception.getCause.getMessage should include ("'EXAMPLE INVALID QUALIFIER'") - } - - @Test def require_that_catch_clauses_are_included() { - Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.CatchException")). - referencedClasses should contain(name[LoginException]) - } - - @Test def require_that_class_references_are_included() { - Analyze.analyzeClass(classFile("com.yahoo.container.plugin.classanalysis.sampleclasses.ClassReference")). - referencedClasses should contain(name[Interface1]) - } - - @Test def require_that_return_type_of_method_invocations_are_included() { - analyzeClass[MethodInvocation].referencedClasses should contain(name[Image]) - } - - @Test def require_that_attributes_are_included() { - //Uses com/coremedia/iso/Utf8.class from com.googlecode.mp4parser:isoparser:1.0-RC-1 - Analyze.analyzeClass(classFile("class/Utf8")).referencedClasses should contain("org.aspectj.weaver.MethodDeclarationLineNumber") - } -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala deleted file mode 100644 index 43f52884f39..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/AnalyzeMethodBodyTest.scala +++ /dev/null @@ -1,52 +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.container.plugin.classanalysis - -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import sampleclasses._ -import TestUtilities._ -import org.junit.Test -import java.io.PrintStream - -import org.scalatest.Matchers - -/** - * Tests that classes used in method bodies are included in the imports list. - * @author tonytv - */ -class AnalyzeMethodBodyTest extends JUnitSuite with AssertionsForJUnit with Matchers { - @Test def require_that_class_of_locals_are_included() { - analyzeClass[Methods].referencedClasses should contain(name[Base]) - } - - @Test def require_that_class_of_locals_in_static_method_are_included() { - analyzeClass[Methods].referencedClasses should contain(name[Derived]) - } - - @Test def require_that_field_references_are_included() { - analyzeClass[Methods].referencedClasses should (contain (name[java.util.List[_]]) and contain (name[Fields])) - } - - @Test def require_that_class_owning_field_is_included() { - analyzeClass[Methods].referencedClasses should contain (name[System]) - } - - @Test def require_that_class_containing_method_is_included() { - analyzeClass[Methods].referencedClasses should contain (name[PrintStream]) - } - - @Test def require_that_element_of_new_multidimensional_array_is_included() { - analyzeClass[Methods].referencedClasses should contain (name[Interface1]) - } - - @Test def require_that_basic_arrays_are_not_included() { - analyzeClass[Methods].referencedClasses should not (contain("int[]")) - } - - @Test def require_that_container_generic_parameters_are_included() { - analyzeClass[Methods].referencedClasses should contain(name[Dummy]) - } - - @Test def require_that_class_owning_method_handler_is_included() { - analyzeClass[Methods].referencedClasses should contain(name[ClassWithMethod]) - } -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/TestUtilities.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/TestUtilities.scala deleted file mode 100644 index fbc3554e9e9..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/classanalysis/TestUtilities.scala +++ /dev/null @@ -1,18 +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.container.plugin.classanalysis - -import scala.reflect.ClassTag -import java.io.File - -/** - * @author tonytv - */ -object TestUtilities { - def analyzeClass[T](implicit m: ClassTag[T]) = - Analyze.analyzeClass(classFile(name(m))) - - def classFile(className : String) = - new File("target/test-classes/" + className.replace('.', '/') + ".class") - - def name[T](implicit m: ClassTag[T]) = m.runtimeClass.getName -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala deleted file mode 100644 index 5ddc7fef16d..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ExportPackageParserTest.scala +++ /dev/null @@ -1,63 +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.container.plugin.osgi - -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import org.junit.Test -import ExportPackages.{Export, Parameter} -import org.scalatest.Matchers - -/** - * @author tonytv - */ -class ExportPackageParserTest extends JUnitSuite with AssertionsForJUnit with Matchers { - val versionParameter = Parameter("version", "1.2.3.sample") - - @Test - def require_that_package_is_parsed_correctly() { - ExportPackageParser.parseAll("sample.exported.package").get should - be (List(Export(List("sample.exported.package"), List()))) - } - - @Test - def require_that_version_is_parsed_correctly() { - ExportPackageParser.parseAll("com.yahoo.sample.exported.package;version=\"1.2.3.sample\"").get should - be (List(Export(List("com.yahoo.sample.exported.package"), List(versionParameter)))) - } - - @Test - def require_that_multiple_packages_with_same_parameters_is_parsed_correctly() { - ExportPackageParser.parseAll("exported.package1;exported.package2;version=\"1.2.3.sample\"").get should - be (List(Export(List("exported.package1", "exported.package2"), List(versionParameter)))) - } - - @Test - def require_that_multiple_parameters_for_a_package_is_parsed_correctly() { - ExportPackageParser.parseAll("exported.package;version=\"1.2.3.sample\";param2=true").get.head.parameters should - be (List(versionParameter, Parameter("param2", "true"))) - } - - @Test - def require_that_multiple_exports_are_parsed_correctly() { - ExportPackageParser.parseAll("exported.package1,exported.package2").get should - be(List( - Export(List("exported.package1"), List()), - Export(List("exported.package2"), List()))) - - ExportPackageParser.parseAll("exported.package1;version=\"1.2.3.sample\",exported.package2").get should - be (List( - Export(List("exported.package1"), List(versionParameter)), - Export(List("exported.package2"), List()))) - - ExportPackageParser.parseAll("exported.package1,exported.package2;version=\"1.2.3.sample\"").get should - be(List( - Export(List("exported.package1"), List()), - Export(List("exported.package2"), List(versionParameter)))) - } - - @Test - def require_that_long_string_literals_do_not_cause_stack_overflow_error() { - //From jersey-server-1.13.jar - val export = """com.sun.jersey.server.impl.wadl;uses:="com.sun.jersey.api.model,com.sun.research.ws.wadl,com.sun.jersey.api.wadl.config,com.sun.jersey.server.wadl,com.sun.jersey.api.core,javax.xml.bind,javax.ws.rs.core,com.sun.jersey.server.impl.uri,com.sun.jersey.core.spi.factory,com.sun.jersey.server.impl.model.method,com.sun.jersey.api.uri,com.sun.jersey.core.header,com.sun.jersey.spi.dispatch,javax.ws.rs,com.sun.jersey.spi.resource";version="1.13.0",com.sun.jersey.server.impl.model.parameter.multivalued;uses:="com.sun.jersey.spi,javax.ws.rs.core,com.sun.jersey.api.container,com.sun.jersey.impl,javax.xml.parsers,org.xml.sax,javax.xml.transform,javax.xml.bind.annotation,javax.xml.transform.sax,com.sun.jersey.spi.inject,javax.xml.bind,javax.ws.rs.ext,com.sun.jersey.api.model,com.sun.jersey.core.reflection,javax.ws.rs,com.sun.jersey.core.spi.component,com.sun.jersey.core.header";version="1.13.0",com.sun.jersey.server.impl.model.parameter;uses:="com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.server.impl.model.parameter.multivalued,com.sun.jersey.spi.inject,com.sun.jersey.api,com.sun.jersey.api.core,com.sun.jersey.server.impl.inject,javax.ws.rs.core,javax.ws.rs,com.sun.jersey.core.header,com.sun.jersey.api.representation";version="1.13.0",com.sun.jersey.server.impl.application;uses:="com.sun.jersey.core.spi.component,com.sun.jersey.api.core,com.sun.jersey.spi,com.sun.jersey.spi.inject,javax.ws.rs.core,com.sun.jersey.api.container,javax.ws.rs.ext,com.sun.jersey.spi.container,com.sun.jersey.core.reflection,com.sun.jersey.api.model,com.sun.jersey.impl,com.sun.jersey.spi.dispatch,com.sun.jersey.server.impl.model,com.sun.jersey.server.impl.wadl,com.sun.jersey.server.impl.uri,com.sun.jersey.core.spi.factory,com.sun.jersey.api.uri,com.sun.jersey.server.impl.uri.rules,com.sun.jersey.spi.uri.rules,com.sun.jersey.server.spi.component,com.sun.jersey.core.util,com.sun.jersey.core.header,com.sun.jersey.core.spi.component.ioc,javax.ws.rs,com.sun.jersey.server.impl,com.sun.jersey.server.wadl,com.sun.jersey.server.impl.inject,com.sun.jersey.server.impl.component,com.sun.jersey.spi.monitoring,com.sun.jersey.server.impl.monitoring,com.sun.jersey.api.container.filter,com.sun.jersey.server.impl.model.parameter.multivalued,com.sun.jersey.server.impl.model.parameter,com.sun.jersey.server.impl.template,com.sun.jersey.spi.template,com.sun.jersey.server.impl.resource,com.sun.jersey.server.impl.modelapi.annotation,com.sun.jersey.server.impl.container.filter,com.sun.jersey.server.impl.modelapi.validation,com.sun.jersey.api,com.sun.jersey.spi.service";version="1.13.0",com.sun.jersey.server.impl.component;uses:="com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.server.spi.component,com.sun.jersey.api.core,com.sun.jersey.core.spi.component.ioc,com.sun.jersey.server.impl.inject,com.sun.jersey.server.impl.resource,com.sun.jersey.api.container,com.sun.jersey.core.reflection,com.sun.jersey.spi.inject";version="1.13.0",com.sun.jersey.server.impl.provider;uses:="com.sun.jersey.core.spi.factory,com.sun.jersey.api.container,com.sun.jersey.api.core,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.impl.template;uses:="com.sun.jersey.core.spi.component,com.sun.jersey.api.view,com.sun.jersey.spi.template,javax.ws.rs.core,com.sun.jersey.core.header,com.sun.jersey.server.impl.model.method,com.sun.jersey.spi.dispatch,com.sun.jersey.api.uri,javax.ws.rs,com.sun.jersey.spi.inject,javax.ws.rs.ext,com.sun.jersey.server.impl.uri.rules,com.sun.jersey.server.probes,com.sun.jersey.core.reflection,com.sun.jersey.spi.uri.rules,com.sun.jersey.spi.container,com.sun.jersey.api.core";version="1.13.0",com.sun.jersey.server.osgi;uses:="com.sun.jersey.server.impl.provider,org.osgi.framework,javax.ws.rs.ext";version="1.13.0",com.sun.jersey.server.wadl.generators.resourcedoc.model;uses:="javax.xml.bind.annotation,javax.xml.namespace";version="1.13.0",com.sun.jersey.server.impl.resource;uses:="com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.server.spi.component,com.sun.jersey.api.core,com.sun.jersey.api.container,javax.ws.rs,com.sun.jersey.server.impl.inject,com.sun.jersey.core.spi.component.ioc,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.impl.monitoring;uses:="com.sun.jersey.spi.monitoring,com.sun.jersey.spi.service,com.sun.jersey.api.model,com.sun.jersey.spi.container,javax.ws.rs.ext,com.sun.jersey.core.spi.component";version="1.13.0",com.sun.jersey.server.impl.modelapi.annotation;uses:="com.sun.jersey.api.model,javax.ws.rs.core,javax.ws.rs,com.sun.jersey.core.reflection,com.sun.jersey.core.header,com.sun.jersey.impl";version="1.13.0",com.sun.jersey.server.impl.container;uses:="com.sun.jersey.server.impl.application,com.sun.jersey.spi.container,com.sun.jersey.api.container";version="1.13.0",com.sun.jersey.server.wadl;uses:="javax.ws.rs.core,com.sun.research.ws.wadl,javax.xml.namespace,com.sun.jersey.api.model,javax.xml.bind,javax.ws.rs,com.sun.jersey.server.wadl.generators,com.sun.jersey.server.impl.modelapi.annotation,com.sun.jersey.server.impl";version="1.13.0",com.sun.jersey.server.impl.model.method.dispatch;uses:="com.sun.jersey.api.model,com.sun.jersey.api.core,com.sun.jersey.spi.container,com.sun.jersey.server.impl.inject,com.sun.jersey.api,javax.ws.rs.core,com.sun.jersey.core.spi.factory,com.sun.jersey.spi.inject,com.sun.jersey.spi.dispatch,com.sun.jersey.core.spi.component,javax.ws.rs,com.sun.jersey.server.impl.model.parameter.multivalued,com.sun.jersey.api.representation,com.sun.jersey.api.container";version="1.13.0",com.sun.jersey.server.impl;uses:="javax.naming,com.sun.jersey.api.core,com.sun.jersey.core.header,javax.ws.rs.core,com.sun.jersey.server.impl.model,com.sun.jersey.spi.container";version="1.13.0",com.sun.jersey.server.wadl.generators.resourcedoc;uses:="com.sun.jersey.api.model,com.sun.jersey.server.wadl.generators.resourcedoc.model,com.sun.jersey.server.wadl.generators.resourcedoc.xhtml,com.sun.research.ws.wadl,javax.xml.namespace,com.sun.jersey.server.wadl,javax.xml.bind,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.impl.container.httpserver;uses:="com.sun.net.httpserver,com.sun.jersey.spi.container,javax.ws.rs.core,com.sun.jersey.core.header,com.sun.jersey.api.container,com.sun.jersey.core.util,com.sun.jersey.api.core";version="1.13.0",com.sun.jersey.server.impl.container.filter;uses:="com.sun.jersey.api.model,com.sun.jersey.spi.container,com.sun.jersey.core.spi.component,com.sun.jersey.api.core,javax.ws.rs,com.sun.jersey.server.impl.uri,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.wadl.generators.resourcedoc.xhtml;uses:="javax.xml.bind,javax.xml.namespace,javax.xml.bind.annotation";version="1.13.0",com.sun.jersey.server.impl.uri.rules;uses:="com.sun.jersey.spi.uri.rules,com.sun.jersey.api.uri,com.sun.jersey.api.core,com.sun.jersey.server.impl.model.method,com.sun.jersey.spi.dispatch,com.sun.jersey.core.header,javax.ws.rs.core,com.sun.jersey.api.model,com.sun.jersey.server.probes,com.sun.jersey.core.reflection,com.sun.jersey.server.impl.template,com.sun.jersey.spi.monitoring,com.sun.jersey.api,com.sun.jersey.spi.container,com.sun.jersey.server.impl.uri,javax.ws.rs,com.sun.jersey.api.container,com.sun.jersey.server.impl.inject,com.sun.jersey.spi.inject,com.sun.jersey.server.impl.uri.rules.automata";version="1.13.0",com.sun.jersey.server.spi.component;uses:="com.sun.jersey.spi.inject,com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.api.core,com.sun.jersey.server.impl.inject,com.sun.jersey.api.container,com.sun.jersey.core.spi.component.ioc";version="1.13.0",com.sun.jersey.server.probes;version="1.13.0",com.sun.jersey.server.wadl.generators;uses:="com.sun.research.ws.wadl,javax.xml.bind.annotation,com.sun.jersey.api.model,com.sun.jersey.server.wadl,javax.xml.bind,javax.ws.rs.core,com.sun.jersey.api,javax.xml.namespace,javax.xml.transform,javax.xml.transform.stream";version="1.13.0",com.sun.jersey.server.impl.modelapi.validation;uses:="com.sun.jersey.api.model,javax.ws.rs,com.sun.jersey.impl,com.sun.jersey.api.core,com.sun.jersey.core.reflection,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.impl.model.method;uses:="com.sun.jersey.api.container,com.sun.jersey.spi.dispatch,com.sun.jersey.api.uri,com.sun.jersey.api.model,com.sun.jersey.server.impl.container.filter,com.sun.jersey.impl,com.sun.jersey.spi.container,com.sun.jersey.spi.inject,com.sun.jersey.api.core,javax.ws.rs.core,com.sun.jersey.core.header";version="1.13.0",com.sun.jersey.server.impl.model;uses:="javax.ws.rs,com.sun.jersey.impl,com.sun.jersey.api.container,com.sun.jersey.core.header,com.sun.jersey.core.header.reader,com.sun.jersey.api.core,javax.ws.rs.core,com.sun.jersey.server.impl.model.method,com.sun.jersey.server.impl.container.filter,com.sun.jersey.api.model,com.sun.jersey.server.impl.wadl,com.sun.jersey.spi.monitoring,com.sun.jersey.server.impl.uri,com.sun.jersey.spi.container,com.sun.jersey.server.impl.inject,com.sun.jersey.spi.inject,com.sun.jersey.api.uri,com.sun.jersey.core.spi.component,com.sun.jersey.server.impl.uri.rules,com.sun.jersey.server.impl.template,com.sun.jersey.api.view,com.sun.jersey.spi.uri.rules";version="1.13.0",com.sun.jersey.server.impl.uri.rules.automata;uses:="com.sun.jersey.server.impl.uri,com.sun.jersey.spi.uri.rules,com.sun.jersey.server.impl.uri.rules,com.sun.jersey.api.uri";version="1.13.0",com.sun.jersey.server.impl.uri;uses:="com.sun.jersey.api.uri,javax.ws.rs.core";version="1.13.0",com.sun.jersey.server.impl.inject;uses:="com.sun.jersey.api.core,com.sun.jersey.spi.inject,javax.ws.rs,com.sun.jersey.api.container,com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.core.spi.factory";version="1.13.0",com.sun.jersey.spi.scanning;uses:="org.objectweb.asm,com.sun.jersey.core.reflection,com.sun.jersey.core.spi.scanning,javax.ws.rs,javax.ws.rs.ext";version="1.13.0",com.sun.jersey.spi.resource;uses:="com.sun.jersey.server.impl.resource,com.sun.jersey.server.spi.component";version="1.13.0",com.sun.jersey.spi.template;uses:="com.sun.jersey.api.view,javax.ws.rs.core,com.sun.jersey.api.container";version="1.13.0",com.sun.jersey.spi.dispatch;uses:="com.sun.jersey.api.core";version="1.13.0",com.sun.jersey.spi.uri.rules;uses:="com.sun.jersey.api.core,com.sun.jersey.api.model,com.sun.jersey.spi.container,com.sun.jersey.api.uri";version="1.13.0",com.sun.jersey.spi.container;uses:="javax.ws.rs,com.sun.jersey.api.representation,com.sun.jersey.core.header,com.sun.jersey.spi,javax.ws.rs.core,com.sun.jersey.api.container,com.sun.jersey.api.core,com.sun.jersey.core.util,com.sun.jersey.core.header.reader,com.sun.jersey.server.impl,com.sun.jersey.core.reflection,javax.ws.rs.ext,com.sun.jersey.server.impl.model,com.sun.jersey.api,com.sun.jersey.api.uri,com.sun.jersey.core.spi.factory,com.sun.jersey.spi.monitoring,com.sun.jersey.api.model,com.sun.jersey.core.spi.component,com.sun.jersey.server.impl.application,com.sun.jersey.impl,com.sun.jersey.spi.inject,com.sun.jersey.spi.dispatch,com.sun.jersey.server.impl.inject,com.sun.jersey.core.spi.component.ioc,com.sun.jersey.spi.service";version="1.13.0",com.sun.jersey.spi.monitoring;uses:="com.sun.jersey.api.model,com.sun.jersey.spi.container,javax.ws.rs.ext";version="1.13.0",com.sun.jersey.api;uses:="javax.ws.rs,javax.ws.rs.core,com.sun.jersey.core.header,com.sun.jersey.core.spi.factory";version="1.13.0",com.sun.jersey.api.core;uses:="javax.ws.rs.core,com.sun.jersey.core.spi.scanning,com.sun.jersey.api.model,com.sun.jersey.api.uri,javax.ws.rs,com.sun.jersey.core.header,com.sun.jersey.api.representation,com.sun.jersey.core.util,javax.ws.rs.ext,com.sun.jersey.api.container,com.sun.jersey.spi.scanning,com.sun.jersey.spi.container,com.sun.jersey.server.impl.application";version="1.13.0",com.sun.jersey.api.wadl.config;uses:="com.sun.jersey.server.wadl,com.sun.jersey.api.core,com.sun.jersey.core.reflection,com.sun.jersey.server.wadl.generators";version="1.13.0",com.sun.jersey.api.model;uses:="javax.ws.rs.core,com.sun.jersey.spi.container";version="1.13.0",com.sun.jersey.api.view;version="1.13.0",com.sun.jersey.api.container.filter;uses:="javax.ws.rs,com.sun.jersey.spi.container,javax.ws.rs.core,com.sun.jersey.api.container,com.sun.jersey.api.core,com.sun.jersey.core.util,com.sun.jersey.core.header,com.sun.jersey.api.representation,com.sun.jersey.api.model,javax.annotation.security";version="1.13.0",com.sun.jersey.api.container;uses:="com.sun.jersey.api.core,com.sun.jersey.spi.container,com.sun.jersey.spi.service,com.sun.jersey.core.spi.component.ioc";version="1.13.0",com.sun.jersey.api.container.httpserver;uses:="com.sun.net.httpserver,com.sun.jersey.api.core,com.sun.jersey.api.container,com.sun.jersey.core.spi.component.ioc";version="1.13.0",com.sun.research.ws.wadl;uses:="javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,javax.xml.namespace";version="1.13.0""" - ExportPackageParser.parseAll(export) //throws StackOverflow exception on scala library 2.10.2 - } -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala deleted file mode 100644 index 4011f170da9..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/osgi/ImportPackageTest.scala +++ /dev/null @@ -1,95 +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.container.plugin.osgi - -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import org.junit.Test -import ImportPackages.Import -import ExportPackages.{Export, Parameter} -import org.scalatest.Matchers - -/** - * @author tonytv - */ -class ImportPackageTest extends JUnitSuite with AssertionsForJUnit with Matchers { - val referencedPackages = Set("com.yahoo.exported") - val exports = exportByPackageName(Export(List("com.yahoo.exported"), List())) - val exportsWithVersion = exportByPackageName(exports.head._2.copy(parameters = List(Parameter("version", "1.3")))) - - def exportByPackageName(export : Export) = ExportPackages.exportsByPackageName(List(export)) - @Test - def require_that_non_implemented_import_with_matching_export_is_included() { - val imports = calculateImports(referencedPackages, implementedPackages = Set(), exportedPackages = exports) - imports should be (Set(Import("com.yahoo.exported", None))) - } - - - @Test - def require_that_non_implemented_import_without_matching_export_is_excluded() { - val imports = calculateImports(referencedPackages, implementedPackages = Set(), exportedPackages = Map()) - imports should be (Set()) - } - - @Test - def require_that_implemented_import_with_matching_export_is_excluded() { - val imports = calculateImports( - referencedPackages, - implementedPackages = referencedPackages, - exportedPackages = exports) - - imports should be (Set()) - } - - @Test - def require_that_version_is_included() { - val imports = calculateImports(referencedPackages, implementedPackages = Set(), exportedPackages = exportsWithVersion) - - imports should be (Set(Import("com.yahoo.exported", Some("1.3")))) - } - - @Test - def require_that_all_versions_up_to_the_next_major_version_is_in_range() { - Import("foo", Some("1.2")).importVersionRange should be (Some("[1.2,2)")) - } - - // TODO: Detecting guava packages should be based on bundle-symbolicName, not package name. - @Test - def require_that_for_guava_all_future_major_versions_are_in_range() { - val rangeWithInfiniteUpperLimit = Some("[18.1," + ImportPackages.InfiniteVersion + ")") - Import("com.google.common", Some("18.1")).importVersionRange should be (rangeWithInfiniteUpperLimit) - Import("com.google.common.foo", Some("18.1")).importVersionRange should be (rangeWithInfiniteUpperLimit) - - Import("com.google.commonality", Some("18.1")).importVersionRange should be (Some("[18.1,19)")) - } - - @Test - def require_that_none_version_gives_non_version_range() { - Import("foo", None).importVersionRange should be (None) - } - - @Test - def require_that_exception_is_thrown_when_major_component_is_non_numeric() { - intercept[IllegalArgumentException](Import("foo", Some("1notValid.2"))) - } - - @Test - def require_that_osgi_import_supports_missing_version() { - Import("com.yahoo.exported", None).asOsgiImport should be ("com.yahoo.exported") - } - - @Test - def require_that_osgi_import_version_range_includes_all_versions_from_the_current_up_to_the_next_major_version() { - Import("com.yahoo.exported", Some("1.2")).asOsgiImport should be ("com.yahoo.exported;version=\"[1.2,2)\"") - } - - @Test - def require_that_osgi_import_version_range_ignores_qualifier() { - Import("com.yahoo.exported", Some("1.2.3.qualifier")).asOsgiImport should be ("com.yahoo.exported;version=\"[1.2.3,2)\"") - } - - - def calculateImports(referencedPackages : Set[String], - implementedPackages : Set[String], - exportedPackages : Map[String, Export]) : Set[Import] = { - ImportPackages.calculateImports(referencedPackages, implementedPackages, exportedPackages).values.toSet - } -} diff --git a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala b/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala deleted file mode 100644 index 7efb0392f5e..00000000000 --- a/bundle-plugin/src/test/scala/com/yahoo/container/plugin/util/IOTest.scala +++ /dev/null @@ -1,45 +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.container.plugin.util - -import org.scalatest.junit.{AssertionsForJUnit, JUnitSuite} -import org.junit.Test -import IO.using -import java.io.Closeable - -import org.scalatest.Matchers - -/** - * @author tonytv - */ -class IOTest extends JUnitSuite with AssertionsForJUnit with Matchers { - class ClosingException extends RuntimeException - class FunctionException extends RuntimeException - - object throwWhenClosingResource extends Closeable { - def close() { - throw new ClosingException() - } - } - - def throwFunction(r : throwWhenClosingResource.type) = throw new FunctionException - def nonThrowingFunction(r : throwWhenClosingResource.type) = 42 - - @Test - def require_that_function_exception_is_prioritized_over_closing_exception() { - intercept[FunctionException]{ - using(throwWhenClosingResource, readOnly = false)(throwFunction) - } - } - - @Test - def require_that_closing_exception_is_ignored_when_read_only() { - using(throwWhenClosingResource, readOnly = true)(nonThrowingFunction) should be (nonThrowingFunction(null)) - } - - @Test - def require_that_closing_exception_is_rethrown_when_not_read_only() { - intercept[ClosingException] { - using(throwWhenClosingResource, readOnly = false)(nonThrowingFunction) - } - } -} |