spring-fixtures

A library to help create fixtures in spring applications

License

License

Categories

Categories

Ant Build Tools Net
GroupId

GroupId

net.savantly
ArtifactId

ArtifactId

spring-fixtures
Last Version

Last Version

1.0.0-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

spring-fixtures
A library to help create fixtures in spring applications
Project URL

Project URL

https://github.com/savantly-net/spring-fixtures
Source Code Management

Source Code Management

https://github.com/savantly-net/spring-fixtures

Download spring-fixtures

How to add to project

<!-- https://jarcasting.com/artifacts/net.savantly/spring-fixtures/ -->
<dependency>
    <groupId>net.savantly</groupId>
    <artifactId>spring-fixtures</artifactId>
    <version>1.0.0-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/net.savantly/spring-fixtures/
implementation 'net.savantly:spring-fixtures:1.0.0-RELEASE'
// https://jarcasting.com/artifacts/net.savantly/spring-fixtures/
implementation ("net.savantly:spring-fixtures:1.0.0-RELEASE")
'net.savantly:spring-fixtures:jar:1.0.0-RELEASE'
<dependency org="net.savantly" name="spring-fixtures" rev="1.0.0-RELEASE">
  <artifact name="spring-fixtures" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.savantly', module='spring-fixtures', version='1.0.0-RELEASE')
)
libraryDependencies += "net.savantly" % "spring-fixtures" % "1.0.0-RELEASE"
[net.savantly/spring-fixtures "1.0.0-RELEASE"]

Dependencies

compile (2)

Group / Artifact Type Version
joda-time : joda-time jar 2.9.1
org.springframework.data : spring-data-jpa jar 2.0.5.RELEASE

test (5)

Group / Artifact Type Version
org.eclipse.persistence : eclipselink jar 2.6.2
org.hsqldb : hsqldb jar 2.3.3
junit : junit jar 4.12
org.springframework : spring-test jar 5.0.4.RELEASE
ch.qos.logback : logback-classic jar 1.1.3

Project Modules

There are no modules declared in this project.

spring-fixtures

Spring-fixtures is a library that makes integration testing easier. It is also helpful when prototyping and demonstrating an application.

Fixtures

A fixture can implement the Fixture interface, or extend the provided AbstractBaseFixture

The AbstractBaseFixture manages fixture dependencies on other fixtures. Suppose you have an "Order" entity that requires instances of "Item" and "Customer" entities. The "Item" and "Customer" fixtures can be added as dependencies of the "Order" fixture so the installation of the prerequisites are ensured. An example of this can be found here

The AbstractBaseFixture expects an Entity, and a Repository class that extends CrudReposity

Examples of fixtures and tests are included src/test/java/

Fixture Tests

An abstract fixture test is available. No implementation is required. src/test/java/net/savantly/example/test/AbstractFixtureTest.java

public class ItemFixtureTest extends AbstractFixtureTest<Item, ItemFixture, ItemRepository> {}

RandomGenerator

A RandomGenerator class is provided to mock data for your entities

The RandomGenerator can produce varying lengths of strings or paragraphs, and provides other functions like Address generation, and random date generation in the future or past.

Example Fixture -

@Service
public class ItemFixture extends AbstractBaseFixture<Item, ItemRepository>{
    @Autowired
    public ItemFixture(ItemRepository repository) {
    	super(repository);
    }

    @Override
    public void addEntities(List<Item> entityList) {
    	log.info("Adding Item Entities to Fixture");
    	for (int i = 0; i < 20; i++) {
    		Item item = new Item();
    		item.setDescription(getRandomAlphaWordString(20, 10));
    		item.setPrice(getRandomMoneyValue(8000, 2, false));
    		entityList.add(item);
    		log.debug(String.format("Entity added: %s", item));
    	}
    }

    @Override
    public void addDependencies(List<Fixture<?>> dependencies) {
    	// There are no fixture dependencies
    }
}
net.savantly

Savantly

Savantly custom software solutions for your business

Versions

Version
1.0.0-RELEASE
0.0.1-RELEASE