Server Mode

Introduction

Pax Exam's OSGi containers have a server mode which can be used to simply launch and provision an OSGi framework, without any Pax Exam bundles or probes. This server mode can be considered as a lightweight alternative to Pax Runner.

Server mode can be used for keeping tests strictly separate from the system under test. Example: for testing the web interface of an OSGi web application based on Pax Web, you want to use a plain old Java application, based on HttpClient, Selenium or Thucydides, without having to worry about embedding these into an OSGi environment.

There are different ways of launching an OSGi container in server mode:

Plumbing API

ExamSystem system = PaxExamRuntime.createServerSystem(CoreOptions.options(...));
TestContainer container = PaxExamRuntime.createContainer(system);
container.start();

JUnit Rule

public class MyTest {
 
     @Rule
     public PaxExamServer exam = new PaxExamServer();
 }

This rule starts a Pax Exam container before each test and stops it after the test. The configuration options for the exam container are taken from a method in the test class annotated with @Configuration. The test class must contain a unique no-args method with this annotation and with return type Option[].

Alternatively, you can pass a class literal to the PaxExamServer constructor. In this case, the @Configuration method will be taken from the class given by the constructor argument.

Maven Plugin

See separate article on the Exam Maven Plugin.