Concordion > Extension >

Extension Configuration

Extensions can be added to Concordion using an annotation in the fixture class and/or using a system property.

Annotations

@Extension

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.

Example - Extensions fields

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".

Example - Extension fields in superclass

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.

@Extensions

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.

Example - Extensions

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".

Example - Extensions from superclass are loaded

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.

Example - All Extensions from class hierarchy are loaded

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.

System Property

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.

Examples

Example - System Property

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.

Combining the configuration methods

In some cases, you may wish to combine multiple methods of configuration from above.

Example - Combined configuration methods

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.