You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2019/10/20 13:52:52 UTC
[plc4x] 17/25: [OSGi] Tests not running yet.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch feature/resolve-split-package-osgi
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 8ea7ea0174270972995d0d0862fe0bb4f9c2a396
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Thu Oct 17 20:31:59 2019 +0200
[OSGi] Tests not running yet.
---
plc4j/karaf-features/karaf-itest/pom.xml | 102 ++++-------
.../java/org/apache/plc4x/karaf/FeatureITest.java | 200 +++++++++++----------
2 files changed, 139 insertions(+), 163 deletions(-)
diff --git a/plc4j/karaf-features/karaf-itest/pom.xml b/plc4j/karaf-features/karaf-itest/pom.xml
index 9d4e3f5..44b2a44 100644
--- a/plc4j/karaf-features/karaf-itest/pom.xml
+++ b/plc4j/karaf-features/karaf-itest/pom.xml
@@ -12,55 +12,49 @@
<artifactId>karaf-itest</artifactId>
<properties>
- <dependency.karaf.version>4.2.1</dependency.karaf.version>
+ <karaf.version>4.2.1</karaf.version>
<pax.version>4.13.1</pax.version>
</properties>
<dependencies>
-<!-- <!– S7 Driver for Build –>-->
-<!-- <dependency>-->
-<!-- <groupId>org.apache.plc4x</groupId>-->
-<!-- <artifactId>driver-s7-feature</artifactId>-->
-<!-- <version>0.5.0-SNAPSHOT</version>-->
-<!-- <scope>test</scope>-->
-<!-- </dependency>-->
-
- <!-- Pax Exam Test setup -->
+ <!-- Provide the KarafTestSupport -->
<dependency>
- <groupId>org.ops4j.pax.exam.samples</groupId>
- <artifactId>pax-exam-sample8-ds</artifactId>
- <version>${pax.version}</version>
+ <groupId>org.apache.karaf.itests</groupId>
+ <artifactId>common</artifactId>
+ <version>${karaf.version}</version>
<scope>test</scope>
</dependency>
+ <!-- Define the Apache Karaf version to download and use for the test -->
+ <!-- We use a released version here to avoid SNAPSHOT resolution -->
<dependency>
- <groupId>org.apache.karaf.features</groupId>
- <artifactId>standard</artifactId>
- <version>${dependency.karaf.version}</version>
- <classifier>features</classifier>
- <type>xml</type>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>apache-karaf</artifactId>
+ <version>${karaf.version}</version>
<scope>test</scope>
+ <type>tar.gz</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.26</version>
<scope>test</scope>
</dependency>
-
+ <!-- Required to use shell commands in the tests -->
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>6.0.0</version>
- <scope>provided</scope>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.core</artifactId>
+ <version>${karaf.version}</version>
+ <scope>test</scope>
</dependency>
-
- <!-- Dependencies for pax exam karaf container -->
+ <!-- Provide the PaxExam Karaf support -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-karaf</artifactId>
<version>${pax.version}</version>
<scope>test</scope>
</dependency>
+ <!-- Provide the PaxExam JUnit extension -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
@@ -68,57 +62,29 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam</artifactId>
- <version>${pax.version}</version>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-aether</artifactId>
- <version>2.6.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
- <scope>test</scope>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>3.1.6</version>
</dependency>
-
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.hamcrest</artifactId>
+ <version>1.3_1</version>
+ <scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-api</artifactId>
- <version>0.5.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.features</groupId>
- <artifactId>org.apache.karaf.features.core</artifactId>
- <version>${dependency.karaf.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.karaf.bundle</groupId>
- <artifactId>org.apache.karaf.bundle.core</artifactId>
- <version>${dependency.karaf.version}</version>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
<plugins>
- <!-- Needed if you use versionAsInProject() -->
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
- <version>1.4.0</version>
<executions>
<execution>
<id>generate-depends-file</id>
@@ -128,14 +94,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemPropertyVariables>
- <pax.exam.karaf.version>${dependency.karaf.version}</pax.exam.karaf.version>
- </systemPropertyVariables>
- </configuration>
- </plugin>
</plugins>
</build>
diff --git a/plc4j/karaf-features/karaf-itest/src/test/java/org/apache/plc4x/karaf/FeatureITest.java b/plc4j/karaf-features/karaf-itest/src/test/java/org/apache/plc4x/karaf/FeatureITest.java
index 1efc1db..b7a12a6 100644
--- a/plc4j/karaf-features/karaf-itest/src/test/java/org/apache/plc4x/karaf/FeatureITest.java
+++ b/plc4j/karaf-features/karaf-itest/src/test/java/org/apache/plc4x/karaf/FeatureITest.java
@@ -13,119 +13,137 @@
*/
package org.apache.plc4x.karaf;
-import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
-import org.apache.plc4x.java.spi.PlcDriver;
+import org.apache.karaf.itests.KarafTestSupport;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.ConfigurationManager;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.container.internal.JavaVersionUtil;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.MavenUrlReference;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.ops4j.pax.exam.options.extra.VMOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
-import javax.inject.Inject;
import java.io.File;
-import java.util.Arrays;
-import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureSecurity;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
@RunWith(PaxExam.class)
-public class FeatureITest {
-
- private static Logger LOG = LoggerFactory.getLogger(FeatureITest.class);
-
- @Inject
- private FeaturesService featuresService;
-
- @Inject
- private BundleContext bundleContext;
+@ExamReactorStrategy(PerClass.class)
+public class FeatureITest extends KarafTestSupport {
+ @Override
@Configuration
public Option[] config() {
- MavenArtifactUrlReference karafUrl = maven()
- .groupId("org.apache.karaf")
- .artifactId("apache-karaf")
- .version(karafVersion())
- .type("zip");
-
- MavenUrlReference karafStandardRepo = maven()
- .groupId("org.apache.karaf.features")
- .artifactId("standard")
- .version(karafVersion())
- .classifier("features")
- .type("xml");
-
- final MavenArtifactUrlReference plc4xRepo = maven()
- .groupId("org.apache.plc4x")
- .artifactId("driver-s7-feature")
- .version("0.5.0-SNAPSHOT")
- .classifier("features")
- .type("xml");
- return new Option[] {
- // KarafDistributionOption.debugConfiguration("5005", true),
- karafDistributionConfiguration()
- .frameworkUrl(karafUrl)
- .unpackDirectory(new File("target", "exam"))
- .useDeployFolder(false),
- keepRuntimeFolder(),
- configureConsole().ignoreLocalConsole(),
- features(karafStandardRepo , "scr"),
- features(plc4xRepo, "driver-s7-feature"),
- mavenBundle()
- .groupId("org.apache.plc4x")
- .artifactId("plc4j-driver-s7")
- .version("0.5.0-SNAPSHOT")
- .start()
- };
- }
-
- public static String karafVersion() {
- ConfigurationManager cm = new ConfigurationManager();
- String karafVersion = cm.getProperty("pax.exam.karaf.version", "3.0.0");
- return karafVersion;
- }
-
+ MavenArtifactUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf").versionAsInProject().type("tar.gz");
+
+ String httpPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_HTTP_PORT), Integer.parseInt(MAX_HTTP_PORT)));
+ String rmiRegistryPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_RMI_REG_PORT), Integer.parseInt(MAX_RMI_REG_PORT)));
+ String rmiServerPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_RMI_SERVER_PORT), Integer.parseInt(MAX_RMI_SERVER_PORT)));
+ String sshPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_SSH_PORT), Integer.parseInt(MAX_SSH_PORT)));
+ String localRepository = System.getProperty("org.ops4j.pax.url.mvn.localRepository");
+ if (localRepository == null) {
+ localRepository = "";
+ }
- @Test
- public void checkFeatureInstalled() throws Exception {
- assertTrue(
- featuresService.isInstalled(featuresService.getFeature("driver-s7-feature"))
- );
+ if (JavaVersionUtil.getMajorVersion() >= 9) {
+ return new Option[]{
+ //KarafDistributionOption.debugConfiguration("8889", true),
+ karafDistributionConfiguration().frameworkUrl(karafUrl).name("Apache Karaf").unpackDirectory(new File("target/exam")),
+ // enable JMX RBAC security, thanks to the KarafMBeanServerBuilder
+ configureSecurity().disableKarafMBeanServerBuilder(),
+ // configureConsole().ignoreLocalConsole(),
+ keepRuntimeFolder(),
+ logLevel(LogLevelOption.LogLevel.INFO),
+ mavenBundle().groupId("org.awaitility").artifactId("awaitility").versionAsInProject(),
+ mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+ mavenBundle().groupId("org.apache.karaf.itests").artifactId("common").versionAsInProject(),
+ editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", httpPort),
+ editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
+ editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
+ editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
+ editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg", "org.ops4j.pax.url.mvn.localRepository", localRepository),
+ new VMOption("--add-reads=java.xml=java.logging"),
+ new VMOption("--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED"),
+ new VMOption("--patch-module"),
+ new VMOption("java.base=lib/endorsed/org.apache.karaf.specs.locator-"
+ + System.getProperty("karaf.version") + ".jar"),
+ new VMOption("--patch-module"),
+ new VMOption("java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-"
+ + System.getProperty("karaf.version") + ".jar"),
+ new VMOption("--add-opens"),
+ new VMOption("java.base/java.security=ALL-UNNAMED"),
+ new VMOption("--add-opens"),
+ new VMOption("java.base/java.net=ALL-UNNAMED"),
+ new VMOption("--add-opens"),
+ new VMOption("java.base/java.lang=ALL-UNNAMED"),
+ new VMOption("--add-opens"),
+ new VMOption("java.base/java.util=ALL-UNNAMED"),
+ new VMOption("--add-opens"),
+ new VMOption("java.naming/javax.naming.spi=ALL-UNNAMED"),
+ new VMOption("--add-opens"),
+ new VMOption("java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"),
+ new VMOption("--add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED"),
+ new VMOption("--add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED"),
+ new VMOption("--add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED"),
+ new VMOption("--add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED"),
+ new VMOption("-classpath"),
+ new VMOption("lib/jdk9plus/*" + File.pathSeparator + "lib/boot/*")
+ };
+ } else {
+ return new Option[]{
+ //KarafDistributionOption.debugConfiguration("8889", true),
+ karafDistributionConfiguration().frameworkUrl(karafUrl).name("Apache Karaf").unpackDirectory(new File("target/exam")),
+ // enable JMX RBAC security, thanks to the KarafMBeanServerBuilder
+ configureSecurity().disableKarafMBeanServerBuilder(),
+ // configureConsole().ignoreLocalConsole(),
+ keepRuntimeFolder(),
+ logLevel(LogLevelOption.LogLevel.INFO),
+ mavenBundle().groupId("org.awaitility").artifactId("awaitility").versionAsInProject(),
+ mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+ mavenBundle().groupId("org.apache.karaf.itests").artifactId("common").versionAsInProject(),
+ editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", httpPort),
+ editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
+ editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
+ editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
+ editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg", "org.ops4j.pax.url.mvn.localRepository", localRepository)
+ };
+ }
}
@Test
- public void checkBundleStarted() throws Exception {
- for (Bundle bundle : bundleContext.getBundles()) {
- System.out.println(bundle.getSymbolicName());
- }
-
- // Try to find the bundle
- final Optional<Bundle> optionalBundle = Arrays.stream(bundleContext.getBundles())
- .filter(bundle -> "org.apache.plc4x.plc4j-driver-s7".equals(bundle.getSymbolicName()))
- .findFirst();
-
- // Ensure that the bundle is resolved
- assertTrue(optionalBundle.isPresent());
-
- // Check if the bundle is active
- assertEquals(Bundle.ACTIVE, optionalBundle.get().getState());
+ public void installAndAssertFeature() throws Exception {
+ // ...
+ final MavenArtifactUrlReference featureRepo = maven()
+ .groupId("org.apache.plc4x")
+ .artifactId("driver-s7-feature")
+ .versionAsInProject()
+ .classifier("xml")
+ .type("feature");
+
+ System.out.println(featureRepo.getURL());
+
+ // ...
+ addFeaturesRepository(featureRepo.getURL());
+ // ...
+ installAndAssertFeature("driver-s7-feature");
+ // Print Bundles
+ String bundles = executeCommand("bundle:list -t 0");
+ System.out.println(bundles);
+ // Print features
+ String features = executeCommand("feature:list -i");
+ System.out.print(features);
}
-}
+}
\ No newline at end of file