Spring-Automocker reactor

Reactor for Spring-Automocker projects.

License

License

Categories

Categories

React User Interface Web Frameworks Auto Application Layer Libs Code Generators Reactor Container Microservices Reactive libraries
GroupId

GroupId

com.github.fridujo
ArtifactId

ArtifactId

spring-automocker-reactor
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

pom
Description

Description

Spring-Automocker reactor
Reactor for Spring-Automocker projects.
Project URL

Project URL

https://github.com/fridujo/spring-automocker
Source Code Management

Source Code Management

https://github.com/fridujo/spring-automocker.git

Download spring-automocker-reactor

How to add to project

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

Dependencies

test (5)

Group / Artifact Type Version
org.assertj : assertj-core jar 3.12.1
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

  • spring-automocker
  • starters/spring-automocker-starter
  • starters/spring-automocker-starter-web
  • starters/spring-automocker-starter-jdbc
  • starters/spring-automocker-starter-jms
  • samples/spring-automocker-amqp-sample
  • starters/spring-automocker-starter-amqp

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