Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions tck/org.osgi.test.cases.bundle.annotations/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Set javac settings from JDT prefs

-conditionalpackage = org.osgi.test.support.*
-privatepackage = \
${p}.junit
-includeresource = \
Expand All @@ -14,7 +13,5 @@ p: org.osgi.test.cases.bundle.annotations
# way). bnd merges all -make.* entries.
-make.maven: (*).(jar); type=bnd; recipe="bnd/$1.bnd"

testcases.junit3: ${classes;EXTENDS;junit.framework.TestCase;CONCRETE}
testcases.junit4: ${classes;HIERARCHY_ANNOTATED;org.junit.Test;CONCRETE}
testcases.junit5: ${classes;HIERARCHY_INDIRECTLY_ANNOTATED;org.junit.platform.commons.annotation.Testable;CONCRETE}
Test-Cases: ${sort;${uniq;${testcases.junit3};${testcases.junit4};${testcases.junit5}}}
Test-Cases: ${sort;${uniq;${testcases.junit5}}}
6 changes: 0 additions & 6 deletions tck/org.osgi.test.cases.bundle.annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
<version>${junit-jupiter.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi.tck</groupId>
<artifactId>org.osgi.test.support</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- In the original the global bnd buildpath supplies the org.osgi.test libraries -->
<dependency>
<groupId>org.osgi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,40 @@
import static org.osgi.framework.namespace.PackageNamespace.PACKAGE_NAMESPACE;
import static org.osgi.resource.Namespace.REQUIREMENT_FILTER_DIRECTIVE;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.test.support.junit5.AbstractOSGiTestCase;
import org.osgi.test.common.annotation.InjectBundleContext;

public abstract class AnnotationsTestCase extends AbstractOSGiTestCase {
public abstract class AnnotationsTestCase {
@InjectBundleContext
protected BundleContext context;
protected String testMethodName;
protected Bundle impl;
protected BundleRevision revision;

@BeforeEach
void testMethodName(TestInfo testInfo) {
testMethodName = testInfo.getTestMethod().map(Method::getName).get();
}

@BeforeEach
public void obtainBundleRevision() throws Exception {
final String propName = "org.osgi.test.cases.bundle.annotations.bundle.symbolic.name";
String bsn = getProperty(propName);
String bsn = context.getProperty(propName);
assertThat(bsn).as(
"The system property \"%s\" must be set to the Bundle Symbolic Name of the bundle processed by the Bundle Annotations tool.",
propName).isNotNull();
impl = null;
for (Bundle b : getContext().getBundles()) {
for (Bundle b : context.getBundles()) {
if (bsn.equals(b.getSymbolicName())) {
impl = b;
break;
Expand All @@ -62,7 +73,6 @@ public Capability findPackageCapability(String name) {
List<Capability> capabilities = revision
.getCapabilities(PACKAGE_NAMESPACE);
assertThat(capabilities).as("Package capabilities")
.isNotNull()
.isNotEmpty();
for (Capability capability : capabilities) {
Map<String,Object> attributes = capability.getAttributes();
Expand Down Expand Up @@ -91,7 +101,6 @@ public Requirement findPackageRequirement(String name) {
List<Requirement> requirements = revision
.getRequirements(PACKAGE_NAMESPACE);
assertThat(requirements).as("Package %s requirements", name)
.isNotNull()
.isNotEmpty();
String packageFilter = "(" + PACKAGE_NAMESPACE + "=" + name + ")";
for (Requirement requirement : requirements) {
Expand Down Expand Up @@ -121,15 +130,13 @@ public Requirement getPackageRequirement(String name) {
public Requirement getRequirement(String namespace) {
List<Requirement> requirements = revision.getRequirements(namespace);
assertThat(requirements).as("%s requirements", namespace)
.isNotNull()
.hasSize(1);
return requirements.get(0);
}

public Capability getCapability(String namespace) {
List<Capability> capabilities = revision.getCapabilities(namespace);
assertThat(capabilities).as("%s capabilities", namespace)
.isNotNull()
.hasSize(1);
return capabilities.get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.jupiter.api.Test;
import org.osgi.framework.Version;
import org.osgi.resource.Capability;
import org.osgi.test.support.string.Strings;

public class CapabilityAnnotationsTestClass extends AnnotationsTestCase {

Expand All @@ -44,7 +43,7 @@ public void testIndirectlyAnnotatedCapability() throws Exception {
}

private void testAnnotatedCapability() throws Exception {
String namespace = testName.getMethodName();
String namespace = testMethodName;
String name = "allOptions";
Capability capability = getCapability(namespace);
Map<String,String> directives = capability.getDirectives();
Expand All @@ -56,7 +55,7 @@ private void testAnnotatedCapability() throws Exception {
"doubleAttr", "versionAttr", "longList", "stringList",
"doubleList", "versionList",
CAPABILITY_VERSION_ATTRIBUTE, namespace);
assertThat(Strings.split(directives.get(CAPABILITY_USES_DIRECTIVE)))
assertThat(Arrays.asList(directives.get(CAPABILITY_USES_DIRECTIVE).trim().split("\\s*,\\s*")))
.containsExactlyInAnyOrder(
"org.osgi.impl.bundle.annotations.reqcap",
"org.osgi.impl.bundle.annotations.export");
Expand Down Expand Up @@ -88,7 +87,7 @@ private void testAnnotatedCapability() throws Exception {

@Test
public void testDirectlyAnnotatedDefaultOptions() throws Exception {
String namespace = testName.getMethodName();
String namespace = testMethodName;
Capability capability = getCapability(namespace);
Map<String,String> directives = capability.getDirectives();
assertThat(directives).as("capability directives").isEmpty();
Expand All @@ -99,7 +98,7 @@ public void testDirectlyAnnotatedDefaultOptions() throws Exception {

@Test
public void testDirectlyAnnotatedAttributes() throws Exception {
String namespace = testName.getMethodName();
String namespace = testMethodName;
Capability capability = getCapability(namespace);
Map<String,String> directives = capability.getDirectives();
assertThat(directives).as("capability directives")
Expand All @@ -125,7 +124,7 @@ public void testDirectlyAnnotatedAttributes() throws Exception {

@Test
public void testDirectlyAnnotatedAttributesDefaults() throws Exception {
String namespace = testName.getMethodName();
String namespace = testMethodName;
Capability capability = getCapability(namespace);
Map<String,String> directives = capability.getDirectives();
assertThat(directives).as("capability directives").isEmpty();
Expand All @@ -136,7 +135,7 @@ public void testDirectlyAnnotatedAttributesDefaults() throws Exception {

@Test
public void testOverriding() throws Exception {
String namespace = testName.getMethodName();
String namespace = testMethodName;
String name = "override";
Capability capability = getCapability(namespace);
Map<String,String> directives = capability.getDirectives();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.osgi.framework.namespace.PackageNamespace.PACKAGE_NAMESPACE;
import static org.osgi.resource.Namespace.CAPABILITY_USES_DIRECTIVE;
import static org.osgi.resource.Namespace.REQUIREMENT_FILTER_DIRECTIVE;
import static org.osgi.test.common.dictionary.Dictionaries.asMap;
import static org.osgi.test.common.dictionary.Dictionaries.dictionaryOf;

import java.util.Arrays;
import java.util.Map;
Expand All @@ -35,8 +37,6 @@
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.test.assertj.filter.FilterCondition;
import org.osgi.test.support.map.Maps;
import org.osgi.test.support.string.Strings;

@SuppressWarnings("unused")
public class ExportAnnotationsTestCase extends AnnotationsTestCase {
Expand Down Expand Up @@ -99,22 +99,22 @@ public void testSubstitutionCalculated() throws Exception {
Requirement pkg = getPackageRequirement(pkgName);
Map<String,String> directives = pkg.getDirectives();
String filterString = directives.get(REQUIREMENT_FILTER_DIRECTIVE);
Filter filter = getContext().createFilter(filterString);
Filter filter = context.createFilter(filterString);
assertThat(filter)
.as("Package %s requirement filter incorrect: %s", pkgName,
filterString)
.is(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
.is(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.0"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.0")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("0.9"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("0.9")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.1"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.1")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("2.0"))));
Version.valueOf("2.0")))));
}

@Test
Expand All @@ -127,22 +127,22 @@ public void testSubstitutionProvider() throws Exception {
Requirement pkg = getPackageRequirement(pkgName);
Map<String,String> directives = pkg.getDirectives();
String filterString = directives.get(REQUIREMENT_FILTER_DIRECTIVE);
Filter filter = getContext().createFilter(filterString);
Filter filter = context.createFilter(filterString);
assertThat(filter)
.as("Package %s requirement filter incorrect: %s", pkgName,
filterString)
.is(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
.is(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.0"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.0")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("0.9"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("0.9")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.1"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.1")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("2.0"))));
Version.valueOf("2.0")))));
}

@Test
Expand All @@ -155,22 +155,22 @@ public void testSubstitutionConsumer() throws Exception {
Requirement pkg = getPackageRequirement(pkgName);
Map<String,String> directives = pkg.getDirectives();
String filterString = directives.get(REQUIREMENT_FILTER_DIRECTIVE);
Filter filter = getContext().createFilter(filterString);
Filter filter = context.createFilter(filterString);
assertThat(filter)
.as("Package %s requirement filter incorrect: %s", pkgName,
filterString)
.is(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
.is(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.0"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.0")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("0.9"))))
.is(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("0.9")))))
.is(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.1"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.1")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("2.0"))));
Version.valueOf("2.0")))));
}

@Test
Expand Down Expand Up @@ -201,7 +201,7 @@ public void testUses() throws Exception {
Map<String,String> directives = pkg.getDirectives();
assertThat(directives).as("Package capability directives")
.containsKey(CAPABILITY_USES_DIRECTIVE);
assertThat(Strings.split(directives.get(CAPABILITY_USES_DIRECTIVE)))
assertThat(Arrays.asList(directives.get(CAPABILITY_USES_DIRECTIVE).trim().split("\\s*,\\s*")))
.containsExactlyInAnyOrder("bar", "foo");
}

Expand All @@ -212,7 +212,7 @@ public void testUsesCalculated() throws Exception {
Map<String,String> directives = pkg.getDirectives();
assertThat(directives).as("Package capability directives")
.containsKey(CAPABILITY_USES_DIRECTIVE);
assertThat(Strings.split(directives.get(CAPABILITY_USES_DIRECTIVE)))
assertThat(Arrays.asList(directives.get(CAPABILITY_USES_DIRECTIVE).trim().split("\\s*,\\s*")))
.containsExactlyInAnyOrder(
"org.osgi.impl.bundle.annotations.export.uses");
}
Expand All @@ -227,22 +227,22 @@ public void testProviderType() throws Exception {
Requirement pkg = getPackageRequirement(pkgName);
Map<String,String> directives = pkg.getDirectives();
String filterString = directives.get(REQUIREMENT_FILTER_DIRECTIVE);
Filter filter = getContext().createFilter(filterString);
Filter filter = context.createFilter(filterString);
assertThat(filter)
.as("Package %s requirement filter incorrect: %s", pkgName,
filterString)
.is(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
.is(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.0"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.0")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("0.9"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("0.9")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("1.1"))))
.isNot(new FilterCondition(Maps.mapOf(PACKAGE_NAMESPACE,
Version.valueOf("1.1")))))
.isNot(new FilterCondition(asMap(dictionaryOf(PACKAGE_NAMESPACE,
pkgName, CAPABILITY_VERSION_ATTRIBUTE,
Version.valueOf("2.0"))));
Version.valueOf("2.0")))));
}

}
Loading
Loading