From 8df43991a6effe3a44e91509aeb4babe10681eec Mon Sep 17 00:00:00 2001 From: Keith Hughes Date: Sun, 11 Dec 2016 18:45:24 -0700 Subject: [PATCH] Make Moquette into OSGi bundles. Add integration test to confirm that Moquette has become a bundle. --- broker/pom.xml | 23 +++ netty_parser/pom.xml | 22 +++ osgi_test/pom.xml | 167 ++++++++++++++++++ .../moquette/test/osgi/MoquetteOsgiTest.java | 69 ++++++++ pom.xml | 1 + 5 files changed, 282 insertions(+) create mode 100644 osgi_test/pom.xml create mode 100644 osgi_test/src/test/java/io/moquette/test/osgi/MoquetteOsgiTest.java diff --git a/broker/pom.xml b/broker/pom.xml index d675c1c0..b78af667 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -162,6 +162,29 @@ + + + + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + + + bundle-manifest + process-classes + + manifest + + + + diff --git a/netty_parser/pom.xml b/netty_parser/pom.xml index 58e3cd20..fe2e7036 100644 --- a/netty_parser/pom.xml +++ b/netty_parser/pom.xml @@ -79,6 +79,28 @@ + + + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + + + bundle-manifest + process-classes + + manifest + + + + diff --git a/osgi_test/pom.xml b/osgi_test/pom.xml new file mode 100644 index 00000000..d71213b7 --- /dev/null +++ b/osgi_test/pom.xml @@ -0,0 +1,167 @@ + + 4.0.0 + + ../ + moquette-parent + io.moquette + 0.9-SNAPSHOT + + + moquette-osgi-test + jar + Moquette - OSGi test + + + 4.6.0 + 1.4.0 + + + + + io.moquette + moquette-broker + ${project.version} + test + + + + org.ops4j.pax.exam + pax-exam-container-native + ${pax.exam.version} + test + + + + org.ops4j.pax.exam + pax-exam-junit4 + ${pax.exam.version} + test + + + + org.ops4j.pax.exam + pax-exam-link-mvn + ${pax.exam.version} + test + + + + org.ops4j.pax.url + pax-url-aether + ${url.version} + test + + + + org.apache.felix + org.apache.felix.framework + 5.0.0 + test + + + + ch.qos.logback + logback-core + 0.9.20 + test + + + + javax.inject + javax.inject + 1 + test + + + + ch.qos.logback + logback-classic + 0.9.20 + test + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + compile + + + + + + + + + + + + + + + run + + + + + + + org.ops4j.pax.exam + exam-maven-plugin + ${pax.exam.version} + + io.moquette.test.osgi.MoquetteOsgiTest + + + + + start-container + stop-container + + + + + + + org.apache.servicemix.tooling + depends-maven-plugin + 1.2 + + + generate-depends-file + generate-resources + + generate-depends-file + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.12 + + + + integration-test + + + + + always + none + 1 + + + + + diff --git a/osgi_test/src/test/java/io/moquette/test/osgi/MoquetteOsgiTest.java b/osgi_test/src/test/java/io/moquette/test/osgi/MoquetteOsgiTest.java new file mode 100644 index 00000000..5616e8b1 --- /dev/null +++ b/osgi_test/src/test/java/io/moquette/test/osgi/MoquetteOsgiTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016 The original author or authors + * ------------------------------------------------------ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * The Apache License v2.0 is available at + * http://www.opensource.org/licenses/apache2.0.php + * + * You may elect to redistribute this code under either of these licenses. + */ + +package io.moquette.test.osgi; + +import static org.junit.Assert.*; +import static org.ops4j.pax.exam.CoreOptions.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import javax.inject.Inject; + +/** + * Run a set of unit tests inside of an OSGi container to make sure + * Moquette works in the OSGi container, + */ +@RunWith(PaxExam.class) +public class MoquetteOsgiTest { + @Inject + private BundleContext bundleContext; + + @Configuration + public Option[] config() { + + return options( + junitBundles(), + mavenBundle("io.moquette", "moquette-broker") + ); + } + + /** + * Look for a bundle with moquette in the name. + * + *

+ * If the OSGi headers are not in the moquette jar, this will fail. + */ + @Test + public void testCanFindOsgiBundle() throws Exception { + for (Bundle b : bundleContext.getBundles()) { + System.out.format("%s %d\n", b.getSymbolicName(), b.getState()); + if (b.getSymbolicName().indexOf("moquette") != -1) { + return; + } + } + + // If found no bundles with moquette in the name, fail the test. + fail(); + } +} diff --git a/pom.xml b/pom.xml index e38c6817..ec8a1550 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,7 @@ broker distribution embedding_moquette + osgi_test