Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made examples use Exam 2.1

  • Loading branch information...
commit f923d05428998892eeaf61a613b2be5af3f4cf0a 1 parent 021f440
Toni Menzel authored
View
14 README.md
@@ -1,4 +1,4 @@
-# Welcome to the Pax Exam Learning Project
+# Welcome to the Pax Exam Strategy Guide
We assume you are familar with the basic principles of OSGi.
Otherwise, here are some interesting links to get to know OSGi any better:
@@ -179,6 +179,8 @@ Here's what you find and the recommended order of reading:
* <https://github.com/tonit/Learn-PaxExam/tree/master/lesson-player>
+* <https://github.com/tonit/Learn-PaxExam/tree/master/lesson-servermode>
+
When reading the examples, its best to have a focus on:
@@ -186,6 +188,16 @@ When reading the examples, its best to have a focus on:
* the Test Sources, which are documented extensively.
+
+# Server Mode
+
+It may sound a bit odd but Pax Exam is also an interesting bootsprapper for OSGi Platforms.
+You can use regular Pax Exam Configuration API (those Options you are collecting) to launch a OSGi framework solely for launching the
+an OSGi platform and not running automated tests (and shut down the system after that automatically).
+
+For an example, please have a look at
+
+
# Differences to Pax Exam 1.x
View
2  lesson-cxf/pom.xml
@@ -15,7 +15,7 @@
<artifactId>lesson-cxf</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - CXF</name>
+ <name>Pax Exam Strategy Guide - CXF</name>
<dependencies>
View
2  lesson-junit/pom.xml
@@ -14,7 +14,7 @@
<artifactId>lesson-junit</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - JUnit4</name>
+ <name>Pax Exam Strategy Guide - JUnit4</name>
<dependencies>
<dependency>
View
2  lesson-junit/src/test/java/org/ops4j/pax/exam/lesson3/LessonTest.java
@@ -20,6 +20,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
+import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.TestAddress;
import org.ops4j.pax.exam.TestProbeBuilder;
@@ -131,6 +132,7 @@ public void withBC( BundleContext ctx )
assertThat( ctx, is( notNullValue() ) );
System.out.println( "BundleContext of bundle injected: " + ctx.getBundle().getSymbolicName() );
+
}
@Test
View
2  lesson-nativecontainer/pom.xml
@@ -14,7 +14,7 @@
<artifactId>lesson-nativecontainer</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - Native Container</name>
+ <name>Pax Exam Strategy Guide - Native Container</name>
<dependencies>
<dependency>
View
2  lesson-paxrunnercontainer/pom.xml
@@ -14,7 +14,7 @@
<artifactId>lesson-paxrunnercontainer</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - PaxRunner Container</name>
+ <name>Pax Exam Strategy Guide - PaxRunner Container</name>
<dependencies>
<dependency>
View
3  lesson-player/pom.xml
@@ -14,7 +14,8 @@
<artifactId>lesson-player</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - Player</name>
+ <name>Pax Exam Strategy Guide - Player</name>
+
<dependencies>
<dependency>
View
2  lesson-plumbing/pom.xml
@@ -14,7 +14,7 @@
<artifactId>lesson-plumbing</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - Plumbing</name>
+ <name>Pax Exam Strategy Guide - Plumbing</name>
<dependencies>
<dependency>
View
5 lesson-plumbing/src/test/java/org/ops4j/pax/exam/lesson1/LessonTest.java
@@ -50,6 +50,7 @@
*/
public class LessonTest {
+
@Test
public void testLesson1Unit1()
throws Exception
@@ -66,7 +67,8 @@ public void testLesson1Unit1()
*
*/
ExamSystem system = createTestSystem( new Option[]{
-
+ allFrameworksVersions(),
+ equinox()
});
TestProbeProvider p = makeProbe(system);
@@ -127,6 +129,7 @@ private TestProbeProvider makeProbe(ExamSystem system)
// passing parameters.
probe.addTest( Probe.class, "probe3", "Parameter" );
+
return probe.build();
}
}
View
5 lesson-porcelain/pom.xml
@@ -13,9 +13,8 @@
<groupId>com.okidokiteam.learnpaxexam</groupId>
<artifactId>lesson-porcelain</artifactId>
<version>0.9.0-SNAPSHOT</version>
-
- <name>Pax Exam Learning Center - Porcelain</name>
-
+ <name>Pax Exam Strategy Guide - Porcelain</name>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
View
5 lesson-porcelain/src/test/java/org/ops4j/pax/exam/lesson2/LessonTest.java
@@ -33,6 +33,7 @@
import org.ops4j.pax.exam.spi.StagedExamReactorFactory;
import org.ops4j.pax.exam.spi.driversupport.DefaultExamReactor;
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
+import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
/**
* This is a copy of lesson 1 but with a higher level abstraction on how we interact with TestContainers.
@@ -57,15 +58,15 @@ public void testLesson2Unit1()
throws Exception
{
TestContainerFactory factory = getTestContainerFactory();
-
ExamSystem system = createTestSystem();
+
ExxamReactor reactor = new DefaultExamReactor( system, factory );
TestProbeProvider probe = makeProbe(system);
reactor.addProbe( probe );
reactor.addConfiguration( options( junitBundles(), easyMockBundles() ) );
- StagedExamReactorFactory strategy = new AllConfinedStagedReactorFactory();
+ StagedExamReactorFactory strategy = new EagerSingleStagedReactorFactory();
StagedExamReactor stagedReactor = reactor.stage( strategy );
try {
for( TestAddress call : stagedReactor.getTargets() ) {
View
59 lesson-servermode/pom.xml
@@ -0,0 +1,59 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+
+<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 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.okidokiteam.learnpaxexam</groupId>
+ <artifactId>learn-exam-reactor</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>com.okidokiteam.learnpaxexam</groupId>
+ <artifactId>lesson-servermode</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+
+ <name>Pax Exam Strategy Guide - Server Mode</name>
+
+ <dependencies>
+ <!-- Pax Exam Dependencies -->
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>${felixversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-assembly</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-testforge</artifactId>
+ <version>${paxexamversion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- For sane logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
View
53 lesson-servermode/src/main/java/org/ops4j/pax/exam/servermode/SimpleServer.java
@@ -0,0 +1,53 @@
+package org.ops4j.pax.exam.servermode;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+import org.ops4j.pax.exam.ExamSystem;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.TestContainer;
+import org.ops4j.pax.exam.spi.container.PaxExamRuntime;
+
+public class SimpleServer
+{
+
+ /**
+ * When creating a longer running process where you want to interact with the system manually (lets say by using a shell or web console),
+ * you should do that in runner that does not shutdown threads automatically when the method exits.
+ * A Main Entry is a good example. A @Test using JUnit Testrunner would be a bad example because it will shutdown the framework.
+ *
+ * The only thing to do differently than usual (lets say to lesson-plumbing) is to use the "createServerSystem" factory method instead of "createTestSystem".
+ * Technically you could use the other factory, but you would end up with the additional Pax Exam bundles in your process.
+ * The ServerSysten factory also sets some default options like "keepOriginalUrls" and "keepCaches".
+ * You see, thise is just candy, you can still use the "createTestSystem" method and put together the options yourself.
+ *
+ * Another quite important option you should set when considering a server like process kicked of by pax exam is to set the workingDirectory manually.
+ * If you do not set this, pax exam will create a unique temporary folder for you. This may or may not be desired.
+ *
+ */
+ public static void main( String[] args )
+ throws Exception
+ {
+ // The usual configuration
+ String gogoVersion = "0.8.0";
+ Option[] options = options(
+ // those two bundles are loaded automatically when using the test container.
+ // but you don't get anything pre-loaded in "Server Mode".
+ mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version("1.6.1"),
+ mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.2.0"),
+
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.gogo.runtime").version(gogoVersion),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.gogo.shell").version(gogoVersion),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.gogo.command").version(gogoVersion),
+ workingDirectory( System.getProperty( "user.dir") + "/target/server" )
+ );
+
+
+ // create a proper ExamSystem with your options. Focus on "createServerSystem"
+ ExamSystem system = PaxExamRuntime.createServerSystem( options );
+
+ // create Container (you should have exactly one configured!) and start.
+ TestContainer container = PaxExamRuntime.createContainer( system );
+ container.start();
+
+ }
+}
View
2  lesson-tinybundles/pom.xml
@@ -14,7 +14,7 @@
<artifactId>lesson-tinybundles</artifactId>
<version>0.9.0-SNAPSHOT</version>
- <name>Pax Exam Learning Center - Tinybundles</name>
+ <name>Pax Exam Strategy Guide - Tinybundles</name>
<dependencies>
<dependency>
View
4 pom.xml
@@ -6,10 +6,10 @@
<version>0.9.0-SNAPSHOT</version>
<packaging>pom</packaging>
- <name>Pax Exam Learning Center</name>
+ <name>Pax Exam Strategy Guide</name>
<properties>
- <paxexamversion>2.1.0-SNAPSHOT</paxexamversion>
+ <paxexamversion>2.1.0</paxexamversion>
<paxrunnerversion>1.7.4</paxrunnerversion>
<paxurlversion>1.3.3</paxurlversion>
<felixversion>3.2.2</felixversion>
Please sign in to comment.
Something went wrong with that request. Please try again.