com.github.fridujo:spring-automocker

Reactor for Spring-Automocker projects.

License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

com.github.fridujo
ArtifactId

ArtifactId

spring-automocker
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

Reactor for Spring-Automocker projects.

Download spring-automocker

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.26
com.google.guava : guava jar 27.1-jre

provided (13)

Group / Artifact Type Version
org.springframework : spring-context jar 5.1.5.RELEASE
org.springframework : spring-test jar 5.1.5.RELEASE
org.springframework : spring-web jar 5.1.5.RELEASE
javax.servlet : javax.servlet-api jar 4.0.1
org.hamcrest : hamcrest-core jar 2.1
org.springframework : spring-jms jar 5.1.5.RELEASE
javax.jms : javax.jms-api jar 2.0.1
com.mockrunner : mockrunner-jms jar 2.0.1
org.assertj : assertj-core jar 3.12.1
io.dropwizard.metrics : metrics-graphite jar 4.0.5
io.micrometer : micrometer-registry-graphite jar 1.1.3
org.springframework.amqp : spring-rabbit jar 2.1.4.RELEASE
com.github.fridujo : rabbitmq-mock jar 1.0.10

test (4)

Group / Artifact Type Version
org.mockito : mockito-core jar 2.25.0
org.junit.jupiter : junit-jupiter-api jar 5.4.0
org.junit.jupiter : junit-jupiter-engine jar 5.4.0
org.junit.jupiter : junit-jupiter-params jar 5.4.0

Project Modules

There are no modules declared in this project.

Spring-Automocker

Build Status codecov Maven Central License

Automatic detection and mocking of Spring IO components.

Motivation

Writing integration tests for Spring application is often writing the same glue code over and over again. Spring-Automocker was created to avoid re-writing the same boilerplate code and focus on test added value.

Mocking strategies

Property sources

The extension @MockPropertySources adds a ProtocolResolver to Spring context resolving properties file as empty ones.

MVC controllers

The extension @MockWebMvc sets up a MockMvc. This MockMvc instance is either wired on :

  • the org.springframework.web.context.WebApplicationContext if the current context is of such type
  • the @Controller annotated beans otherwise
JDBC Data Sources

The extension @MockJdbc

  • modifies javax.sql.DataSource beans by making them point to a dedicated H2 in-memory database.
  • adds a DataSourceResetter to truncate all tables after each test
JMS Connection Factories

The extension @MockJms

  • replace all javax.jms.ConnectionFactory beans by mockrunner-jms MockConnectionFactory ones
  • for each javax.jms.ConnectionFactory beans adds a JmsMock with the same qualifiers for simplified JMS operations usage
  • adds a DestinationManagerResetter to remove messages from all queues after each test
  • if available, wraps the ErrorHandler of JmsListenerContainerFactory to access errors from matching JmsMock
Micrometer Graphite Meter Registry

The extension @MockMicrometerGraphite replaces the default GraphiteReporter by one baked by GraphiteMock which can be injected like any other bean.

RabbitMQ Connection Factories

The extension @MockAmqp replaces all org.springframework.amqp.rabbit.connection.ConnectionFactory beans by rabbitmq-mock ones.

Utilities

The extension @RegisterTools registers a BeanLocator to easily access beans by partial name.

Example Use

As Spring-Automocker uses spring-test org.springframework.test.context.ContextCustomizerFactory extension mechanism, it is compatible with Spring >= 4.3 (so spring-boot >= 1.4).

Using JUnit 4

Use SpringJUnit4ClassRunner in conjuction with @Automocker

@Automocker
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyApplication.class)
public class MyApplicationTest {

    @Autowired
    private MyService service;

	@Test
	public void my_test() {
		// test injected service
	}
}

Using JUnit 5

Use @ExtendWith(SpringExtension.class) in conjuction with @Automocker

@Automocker
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = MyApplication.class)
public class MyApplicationTest {

    @Autowired
    private MyService service;

	@Test
	public void my_test() {
		// test injected service
	}
}

Getting Started

Maven

Add the following dependency to your pom.xml

<dependency>
    <groupId>com.github.fridujo</groupId>
    <artifactId>spring-automocker</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>

Gradle

Add the following dependency to your build.gradle

repositories {
	mavenCentral()
}

// ...

dependencies {
	// ...
	testCompile('com.github.fridujo:spring-automocker:1.1.0')
	// ...
}

Building from Source

You need JDK-8 to build Spring-Automocker. Core and samples can be built with Maven using the following command.

mvn clean package

All features can be tested through samples with Maven using the following command.

mvn clean test

Since Maven has incremental build support, you can usually omit executing the clean goal.

Installing in the Local Maven Repository

Core and samples can be installed in a local Maven Repository for usage in other projects via the following command.

mvn clean install
com.github.fridujo

Fridujo

It's Esperanto for freezer

Versions

Version
1.2.1
1.2.0
1.1.0
1.0.0