Skip to content
Open

Ocx #1038

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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.osgi.test.example.api</name>
<name>org.osgi.test.example.demo</name>
<comment></comment>
<projects>
</projects>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
Copyright (c) Contributors to the Eclipse Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
-->
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-4relative [%.15thread] %-5level %logger{36}:%line - %msg%n</pattern>
</encoder>
</appender>

<logger name="org.osgi.test" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
131 changes: 131 additions & 0 deletions examples/osgi-test-example-mvn/org.osgi.test.example.demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.osgi.test.example</groupId>
<artifactId>org.osgi.test.example.parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>org.osgi.test.example.demo</artifactId>

<description>OSGi Testing Example - Demonstrates all Features</description>
<name>${project.groupId}:${project.artifactId}</name>
<url>https://www.osgi.org</url>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cm</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.namespace.service</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.test.common</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.test.junit5.cm</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<version>1.9.26</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.test.assertj.framework</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.test.junit5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- We let bnd-testing-maven-plugin do all the testing -->
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<!--
https://github.com/bndtools/bnd/tree/master/maven-plugins/bnd-maven-plugin#test-jar-goal
-->
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<bnd><![CDATA[
p = ${project.artifactId}
Export-Package: ${p}.test.*;-split-package:=first

-make: (*).(jar); type=bnd; recipe="${.}/testbundles/$1.bnd"
-includeresource:\
embeddedTestBundles/tb1.jar=tb1.jar,\

-noextraheaders: true
-noimportjava: true
]]></bnd>
<!-- prevents from include testbundles-->
<includeClassesDir>false</includeClassesDir>
<testCases>junit5</testCases>
<!--
https://github.com/bndtools/bnd/tree/master/maven-plugins/bnd-maven-plugin#aspects-common-to-both-test-goals
-->
<artifactFragment>true</artifactFragment>
<!--
If true, make the tests artifact a fragment using ${project.artifactId} as the
Fragment-Host header and setting the
Bundle-SymbolicName of the tests artifact to
${project.artifactId}-tests. Defaults to false
-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-testing-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.osgi.test.example.demo.api;

public interface EchoService {

String echo(String text);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*******************************************************************************/
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.bundle.Export
package org.osgi.test.example.api;
package org.osgi.test.example.demo.api;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.osgi.test.example.demo.complex;

import org.osgi.service.component.annotations.Component;
import org.osgi.test.example.demo.api.EchoService;

@Component(property = "type=complex")
public class ComplexEchoService implements EchoService {

@Override
public String echo(String text) {
return text +" "+ text;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.osgi.test.example.demo.simple;

import org.osgi.service.component.annotations.Component;
import org.osgi.test.example.demo.api.EchoService;

@Component(property = "type=simple")
public class SimpleEchoService implements EchoService {

@Override
public String echo(String text) {
return text;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.osgi.test.example.demo.simple;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;

@Component(service = Object.class, property = {"type=simple", "f=b"}, scope = ServiceScope.PROTOTYPE)
public class SimpleService {

@Activate
private void act() throws InterruptedException {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
Copyright (c) Contributors to the Eclipse Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
-->
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-4relative [%.15thread] %-5level %logger{36}:%line - %msg%n</pattern>
</encoder>
</appender>

<logger name="org.osgi.test" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.osgi.test.example.demo.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.BundleContext;
import org.osgi.test.common.annotation.InjectBundleContext;
import org.osgi.test.junit5.context.BundleContextExtension;

@ExtendWith(BundleContextExtension.class)
public class Demo_01_BundleContextExtension_ExtendWith_Test {

@InjectBundleContext
BundleContext bc;

@Test
void bundleContextExists() throws Exception {
assertThat(bc).isNotNull();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.osgi.test.example.demo.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.osgi.framework.BundleContext;
import org.osgi.test.common.annotation.InjectBundleContext;

//@ExtendWith(BundleContextExtension.class)
public class Demo_02_BundleContextExtension_Plain_Test {

// does the @ExtendWith(BundleContextExtension.class)
@InjectBundleContext
BundleContext bc;

@Test
void bundleContextExists() throws Exception {
assertThat(bc).isNotNull();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.osgi.test.example.demo.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.osgi.framework.BundleContext;
import org.osgi.test.common.annotation.InjectBundleContext;

public class Demo_03_InjectBundleContext_Test {

@InjectBundleContext
BundleContext bc1;

@Test
void bundleContextExists() throws Exception {
assertThat(bc1).isNotNull();
}

@Test
void bundleContextExists(@InjectBundleContext BundleContext bc2) throws Exception {
assertThat(bc2).isNotNull();

bc2.addBundleListener(event -> System.out.println(event));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.osgi.test.example.demo.test;

import org.junit.jupiter.api.Test;
import org.osgi.framework.BundleContext;
import org.osgi.test.assertj.bundlecontext.BundleContextAssert;
import org.osgi.test.common.annotation.InjectBundleContext;

public class Demo_04_BundleContext_Assert_Test {

@InjectBundleContext
BundleContext bc;

@Test
void bundleContextAssert() throws Exception {

BundleContextAssert bcAssert = BundleContextAssert.assertThat(bc)//
.hasBundleWithId(0)//
.doesNotHaveBundleWithId(-1);

bcAssert.hasProperty("org.osgi.service.http.port")//
.doesNotHaveProperty("foo")//
.hasPropertyWithKeyThat("org.osgi.service.http.port").isEqualTo("*");

bcAssert.hasBundlesThat()//
.hasSizeGreaterThanOrEqualTo(3);

bcAssert.hasBundleWithIdThat(0).hasSymbolicName("org.eclipse.osgi");
}

}
Loading
Loading