jApiRecorder

Dynamic proxy to record and replay API method calls.

View the Project on GitHub uscexp/jApiRecorder

jApiRecorder

A dynamic proxy to record and replay API method calls e.g. for testing porposes.

News

15.Aug.2014: New release v1.2.0 which updates the jDotNotation dependency to v1.1.0 (map access for the attribute replacement).

30.Jul.2014: New release v1.1.0 which adds the new feature of latency simulation.

Features

Description

With jApiRecorder one can creat a dynamic proxy of a class to record/replay API method calls.

Modes

There are four modes to go:

ReadWriteStrategy and ContentTypeStrategy

It is possible to implement your own ReadWriteStrategy and/or ContentTypeStrategy. You only have to implement the given interfaces.

Already implemented ContentTypeStrategy is: XStreamContentTypeStrategy which serialize/deserialize the objects to be recorded/replayed with XStream (XML).

Already implemented ReadWriteStrategy is: H2ReadWriteStrategy which reads/writes the serialized objects to be recorded/replayed within a H2 database (memory or file database).

Attribute Replacement

One can replace attribute values in the recorded values. Specify an attribute path from the recorded result object in dot notation form (see jDotNotation) to the attribute one want to change. Set a fix value or use an argument passed to the method call. The value one want to set to an attribute in the result can be manipulated before setting it to the attribute. E.g. one want to change a Date attribute of the result and change it to the current date. One can add serveral replacement value treatments to change the value, in this example to change it to the current date.

Latency Simulation

It is possible to configure latency simulation, real measured or static delay, globally and/or per method call. For real measured latancy simulation one can define how many method calls should be measured to calculate the latency, how many method calls should be skipped (e.g. caching effects) and should the measures be made in one run (at once) or should it be done over several method calls.

Example

An example from a junit test (see more junit tests form more code examples):

ContentTypeStrategy contentTypeStrategy = new XStreamContentTypeStrategy();
ReadWriteStrategy readWriteStrategy = new H2ReadWriteStrategy();
RecordReplayConfiguration recordReplayConfiguration = new RecordReplayConfiguration();
recordReplayConfiguration.addArgumentIndices4PrimaryKey("simpleLevel2Method", 0, 1);
TestClass testClass = (TestClass) RecordReplayManager.newInstance(TestClass.class, RecordReplayMode.RECORD, contentTypeStrategy, readWriteStrategy, recordReplayConfiguration);

Date date = new Date();
String text = "extern";
TestClass result = testClass.simpleLevel2Method(3, text, date);

Assert.assertEquals(text, result.getText());

String value = "post_extern";
ReplacementValue replacementValue = ReplacementValueFactory.createReplacementGivenValue(value);
ReplacementConfiguration replacementConfiguration = new ReplacementConfiguration("text", replacementValue);
recordReplayConfiguration.addReplacementConfiguration("simpleLevel2Method", replacementConfiguration );
testClass = (TestClass) RecordReplayManager.newInstance(TestClass.class, RecordReplayMode.RP_OFFLINE, contentTypeStrategy, readWriteStrategy, recordReplayConfiguration);

Date date2 = new Date();
result = testClass.simpleLevel2Method(3, text, date2);

Assert.assertEquals(value, result.getText());

I want to record/replay the method call simpleLevel2Method in TestClass. First I create a ContentTypeStrategy and a ReadWriteStrategy instance. Then I need a RecordReplayConfiguration where I define which method arguments indices (here 0 and 1) are used to create a primary key for the recorded value for later retrieval. I create a dynamic proxy instance of my TestClass in RECORD Mode. Then I call the method to record the result value. Afterwards I create a ReplacementValue, because I want to change the text attribute in my TestClass on replay. Then I create a ReplacementConfiguration with an attribute path to the text attribute and the replacement value and add it to the RecordReplayConfiguration for simpleLevel2Method. I create a dynamic proxy instance of my TestClass in RP_OFFLINE Mode. After calling the simpleLevel2Method I get the previous recorded value of the TestClass except the text attribute which returns the value I set with the ReplacementConfiguration.

Installation

To use the library in your java project just put the binary jar file to your classpath. The maven dependency can be found here: mvnrepository

(C) 2014 by haui