How to customize the test environment

How to customize the test environment

Test environments sometimes need special treatment so that it "simulates" a given target system.
Not all are in standard osgi hands.

Customizer in Pax Exam 1.2

Customizer is an option that you can use like any other Option in your configuration phase and provides callback method(s) that are getting called on a certain point in Pax Exams execution phase.

Callbacks

customizeEnvironment

Callback method that can contain steps to finally change/set up the working environment.
It is being called just before the OSGi platform of choice boots.
An exception at this point will make exam stop and not running the test. (actually, the test will fail)

Usage

@Configuration
    public static Option[] configure()
    {
        return options(
            new Customizer()
            {
                @Override
                public void customizeEnvironment( File workingFolder )
                {
                    // do what you want. Use workingFolder to adjust the environment if necessary.
                }
            }
        );
    }

customizeTestProbe

Ability to change the test probe that will be installed.
At a basic ability, you are all on your own to consume the testProbe from InputStream, change it, and provide it/or another back to the caller (return InputStream).

Usage

@Configuration
    public static Option[] configure()
    {
        return options(
            new Customizer()
            {
                @Override
                public InputStream customizeTestProbe( InputStream testProbe )
                {
                    // do what you want. Read/parse or/and use Tinybundles.
                    // at last return your (perhaps modified or entirely new) test probe
                   return testProbe;
                }
            }
        );
    }

But, you are highly recommended to use this functionality of Exam together with the Tinybundles library.

ExecutionCustomizer in Pax Exam 1.1

ExecutionCustomizer is an option that you can use like any other Option in your configuration phase and provides callback method(s) that are getting called on a certain point in Pax Exams execution phase.

Callbacks

  • ExecutionCustomizer.customizeEnvironment(File workingFolder)*
    Callback method that can contain steps to finally change/set up the working environment.
    It is being called just before the OSGi platform of choice boots.
    An exception at this point will make exam stop and not running the test. (actually, the test will fail)

Usage

@Configuration
    public static Option[] configure()
    {
        return options(
            new ExecutionCustomizer()
            {
                @Override
                public void customizeEnvironment( File workingFolder )
                {
                    // do what you want. Use workingFolder to adjust the environment if necessary.
                }
            }
        );
    }