Extensions can be added to Concordion using an annotation in the fixture class and/or using a system property.
Within a fixture class, fields that are annotated with @org.concordion.api.extension.Extension
will be
added to Concordion as extensions.
Fields with this annotation must be public and must implement org.concordion.api.extension.ConcordionExtension
.
Executing the following fixture:
import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import org.concordion.api.extension.Extension; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) public class ExampleFixture { @Extension public ConcordionExtension extension = new FakeExtension1(); @Extension public FakeExtension2 extension2 = new FakeExtension2(); }
will install both extensions FakeExtension1, FakeExtension2.
Extensions will be loaded from the fixture class and any of its superclasses in parent-first order. A common pattern is to have the extensions defined in a "base fixture".
Executing the following fixture:
import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import org.concordion.api.extension.Extension; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) public class ExampleFixture extends BaseFixture { @Extension public ConcordionExtension extension = new FakeExtension1("ExampleExtension"); }
which has superclass
import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import org.concordion.api.extension.Extension; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) public class BaseFixture { @Extension public FakeExtension2 extension2 = new FakeExtension2("SuperExtension"); }
will install both the extensions initialised with parameters SuperExtension, ExampleExtension.
As an alternative, extensions that require no state from the fixture can be defined statically on the fixture class with the @org.concordion.api.extension.Extensions
annotation. This annotation is parameterised with a list of the extension, or extension factory, classes to be installed.
Extensions must implement org.concordion.api.extension.ConcordionExtension
.
Extension factories must implement org.concordion.api.extension.ConcordionExtensionFactory
.
Executing the following fixture:
import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import org.concordion.api.extension.Extensions; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) @Extensions({FakeExtension1.class, FakeExtension2Factory.class}) public class ExampleFixture { }
will install both extensions FakeExtension1, FakeExtension2FromFactory.
Extensions will be loaded from the fixture class and any of its superclasses in parent-first order. A common pattern is to have the extensions defined in a "base fixture".
Executing the following fixture:
import org.junit.runner.RunWith; import org.concordion.integration.junit4.ConcordionRunner; import org.concordion.api.extension.Extensions; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) public class ExampleFixture extends BaseFixture { }
which has superclass
import org.junit.runner.RunWith; import org.concordion.integration.junit4.ConcordionRunner; import org.concordion.api.extension.Extensions; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) @Extensions({FakeExtension1.class, FakeExtension2.class}) public class BaseFixture { }
will install both extensions FakeExtension1, FakeExtension2.
Executing the following fixture:
import org.junit.runner.RunWith; import org.concordion.integration.junit4.ConcordionRunner; import org.concordion.api.extension.Extensions; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) @Extensions({FakeExtension2.class}) public class ExampleFixture extends BaseFixture { }
which has superclass
import org.junit.runner.RunWith; import org.concordion.integration.junit4.ConcordionRunner; import org.concordion.api.extension.Extensions; import org.concordion.api.extension.ConcordionExtension; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) @Extensions({FakeExtension1.class}) public class BaseFixture { }
will install both extensions FakeExtension1, FakeExtension2.
Alternatively, extensions can be specified by setting a system property. This can be useful if the extensions need to be configured independently from the fixtures.
Set the system property concordion.extensions
to a comma-separated list containing:
All extensions and/or extension factories must be present on the classpath.
Extensions must implement org.concordion.api.extension.ConcordionExtension
.
Extension factories must implement org.concordion.api.extension.ConcordionExtensionFactory
.
Given the system property concordion.extensions
is set to "test.concordion.extension.fake.FakeExtension1, test.concordion.extension.fake.FakeExtension2Factory
",
Concordion fixtures will be run with both extensions FakeExtension1, FakeExtension2FromFactory.
In some cases, you may wish to combine multiple methods of configuration from above.
Executing the following fixture:
import org.concordion.integration.junit4.ConcordionRunner; import org.junit.runner.RunWith; import org.concordion.api.extension.*; import test.concordion.extension.fake.*; @RunWith(ConcordionRunner.class) @Extensions({FakeExtension1.class}) public class ExampleFixture { @Extension public ConcordionExtension extension = new FakeExtension2(); }
with the system property concordion.extensions
set to "test.concordion.extension.fake.FakeExtension3
",
will install the extensions FakeExtension1, FakeExtension2, FakeExtension3.