Capture & Replay Framework

This framework takes test data generation to the next level by capturing real data. Instead of injecting mocks that load manually written fixtures, the Capture & Replay Framework transparently augments existing classes with proxies that replay previously captured data.

License

License

Categories

Categories

Play Framework User Interface Web Frameworks
GroupId

GroupId

de.codecentric
ArtifactId

ArtifactId

capture-replay-framework
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Capture & Replay Framework
This framework takes test data generation to the next level by capturing real data. Instead of injecting mocks that load manually written fixtures, the Capture & Replay Framework transparently augments existing classes with proxies that replay previously captured data.
Project URL

Project URL

https://github.com/codecentric/capture-replay-framework
Project Organization

Project Organization

codecentric AG
Source Code Management

Source Code Management

https://github.com/codecentric/capture-replay-framework

Download capture-replay-framework

How to add to project

<!-- https://jarcasting.com/artifacts/de.codecentric/capture-replay-framework/ -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>capture-replay-framework</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.codecentric/capture-replay-framework/
implementation 'de.codecentric:capture-replay-framework:1.1.0'
// https://jarcasting.com/artifacts/de.codecentric/capture-replay-framework/
implementation ("de.codecentric:capture-replay-framework:1.1.0")
'de.codecentric:capture-replay-framework:jar:1.1.0'
<dependency org="de.codecentric" name="capture-replay-framework" rev="1.1.0">
  <artifact name="capture-replay-framework" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.codecentric', module='capture-replay-framework', version='1.1.0')
)
libraryDependencies += "de.codecentric" % "capture-replay-framework" % "1.1.0"
[de.codecentric/capture-replay-framework "1.1.0"]

Dependencies

compile (8)

Group / Artifact Type Version
org.springframework : spring-beans jar 4.0.4.RELEASE
org.springframework : spring-context jar 4.0.4.RELEASE
org.springframework : spring-aop jar 4.0.4.RELEASE
org.aspectj : aspectjrt jar 1.8.0
org.aspectj : aspectjweaver jar 1.8.0
org.apache.commons : commons-lang3 jar 3.3.2
com.fasterxml.jackson.core : jackson-databind jar 2.3.3
junit : junit jar 4.11

test (1)

Group / Artifact Type Version
org.springframework : spring-test jar 4.0.4.RELEASE

Project Modules

There are no modules declared in this project.

Capture & Replay Framework

This framework takes test data generation to the next level by capturing real data. Instead of injecting mocks that load manually written fixtures, the Capture & Replay Framework transparently augments existing classes with proxies that replay previously captured data.

Installation

Using Maven

Binaries, sources, and javadocs are available from Maven Central.

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>capture-replay-framework</artifactId>
	<version>1.1.0</version>
</dependency>

Without Maven

You can easily add this library to your classpath. Make sure you add the following dependencies to your classpath:

  • org.springframework:spring-beans
  • org.springframework:spring-context
  • org.springframework:spring-aop
  • org.aspectj:aspectjrt
  • org.aspectj:aspectjweaver
  • org.apache.commons:commons-lang3
  • com.fasterxml.jackson.core:jackson-databind
  • junit:junit

Examples

Annotation-based Spring configuration

The following example demonstrates how a few lines of code enable the Capture & Replay Framework with an annotation-based configuration.

@Configuration
@EnableCaptureReplay(mode = Mode.CAPTURE, dataMapper = "dataMapper")
public class AppConfig {

	@Bean
	public DataMapper dataMapper() {
		return new JsonDataMapper(captureFileProvider());
	}

	@Bean
	public CaptureFileProvider captureFileProvider() {
		// The default implementation writes files into specified directories.
		// This file provider is best suited for data capturing.
		DefaultCaptureFileProvider defaultCaptureFileProvider = new DefaultCaptureFileProvider();
		defaultCaptureFileProvider.setCaptureFilesPath("/tmp");
		defaultCaptureFileProvider.setCaptureFileExtension(".cap.json");
		return defaultCaptureFileProvider;
	}
}

XML-based Spring configuration

The equivalent configuration using XML instead of pure Java is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:cc="http://www.codecentric.de/spring/capture-replay/capture-replay.xsd"
	   xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="
	   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	   http://www.codecentric.de/spring/capture-replay/capture-replay.xsd http://www.codecentric.de/spring/capture-replay/capture-replay.xsd">

	<bean id="captureFileProvider" class="de.codecentric.capturereplay.data.DefaultCaptureFileProvider">
		<property name="captureFilesPath" value="/tmp" />
		<property name="captureFileExtension" value=".cap.json" />
	</bean>

	<bean id="dataMapper" class="de.codecentric.capturereplay.data.JsonDataMapper" >
		<constructor-arg ref="captureFileProvider"/>
	</bean>

	<cc:capture-replay data-mapper-ref="dataMapper" mode="capture"/>

</beans>

Marking capturable methods

You can mark a method as capturable with just a single line of code. Spring AOP is used to augment these methods with CGLIB-powered proxies. You don't have to set up Spring AOP by yourself. The Capture & Replay Framework bootstraps Spring AOP for you.

@Capturable
public YourAwesomeEntity doMagic() {
	// ... make requests to long-running remote services on production servers ...
	// ... calculate the answer to life the universe and everything ...
}

Release Notes

Version 1.1.0

This version introduces the new mode Mode.DISABLED which in fact is what Mode.OFF was in version 1.0.0. Mode.OFF changes its semantics. While Mode.DISABLED allows you to enable the capturing/replaying mechanism at runtime, Mode.OFF does not. Methods that are annotated with @Capturable will not be replaced with proxies if you use Mode.OFF. This new feature is meant for production systems where performance matters and you don't want to toggle capturing/replaying mechanism.

Contributing

Pull requests are welcome.

License

The Capture & Replay Framework is released under version 2.0 of the Apache License.

de.codecentric

codecentric AG

Versions

Version
1.1.0
1.0.0