FixtureScriptsSpec’nProvider

The FixtureScriptsSpecificationProvider configures the FixtureScripts domain service, providing the location to search for fixture scripts and other settings.

The service is used only by the default implementation of FixtureScripts, namely FixtureScriptsDefault.

Of the two designs, we encourage you to implement this "provider" SPI rather than subclass FixtureScripts. The primary benefit (apart from decoupling responsibilities) is that it ensures that there is always an instance of FixtureScripts available for use.

SPI

The SPI defined by the service is:

public interface FixtureScriptsSpecificationProvider {
    @Programmatic
    FixtureScriptsSpecification getSpecification();
}

where FixtureScriptsSpecification exposes these values:

public class FixtureScriptsSpecification {
    public String getPackagePrefix() { /* ... */ }
    public FixtureScripts.NonPersistedObjectsStrategy getNonPersistedObjectsStrategy() { /* ... */ }
    public FixtureScripts.MultipleExecutionStrategy getMultipleExecutionStrategy() { /* ... */ }
    public Class<? extends FixtureScript> getRunScriptDefaultScriptClass() { /* ... */ }
    public DropDownPolicy getRunScriptDropDownPolicy() { /* ... */ }
    public Class<? extends FixtureScript> getRecreateScriptClass() { /* ... */ }
    ...
}

The class is immutable but it has a builder (obtained using FixturescriptsSpecification.builder(…​)) for a fluent API.

Implementation

The SimpleApp starter app has a simple implementation of this service:

import org.springframework.stereotype.Service;

@Service
public class DomainAppFixturesProvider implements FixtureScriptsSpecificationProvider {
    @Override
    public FixtureScriptsSpecification getSpecification() {
        return FixtureScriptsSpecification
                .builder(DomainAppFixturesProvider.class)
                .with(FixtureScripts.MultipleExecutionStrategy.EXECUTE)
                .withRunScriptDefault(RecreateSimpleObjects.class)
                .withRunScriptDropDown(FixtureScriptsSpecification.DropDownPolicy.CHOICES)
                .withRecreate(RecreateSimpleObjects.class)
                .build();
    }
}