Rule Them All

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

GroupId

GroupId

com.github.rmannibucau
ArtifactId

ArtifactId

rule-them-all
Last Version

Last Version

0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Rule Them All
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Source Code Management

Source Code Management

https://github.com/rmannibucau/featured-mock

Download rule-them-all

How to add to project

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

Dependencies

compile (11)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.1
org.mockftpserver : MockFtpServer Optional jar 2.4
junit : junit Optional jar 4.12
org.springframework : spring-test Optional jar 3.1.1.RELEASE
org.springframework : spring-context Optional jar 3.1.1.RELEASE
com.hazelcast : hazelcast Optional jar 3.2.3
org.apache.sshd : sshd-core Optional jar 0.12.0
com.github.detro : phantomjsdriver Optional jar 1.2.0
org.apache.geronimo.specs : geronimo-jpa_2.0_spec Optional jar 1.1
org.jboss.arquillian.extension : arquillian-persistence-dbunit jar 1.0.0.Alpha7
org.dbunit : dbunit Optional jar 2.5.0

test (6)

Group / Artifact Type Version
org.slf4j : slf4j-jdk14 jar 1.7.5
com.jcraft : jsch jar 0.1.51
org.jboss.arquillian.extension : arquillian-phantom-binary jar 2.1.1
org.jboss.arquillian.extension : arquillian-phantom-binary jar 2.1.1
org.jboss.arquillian.extension : arquillian-phantom-binary jar 2.1.1
com.h2database : h2 jar 1.4.187

Project Modules

There are no modules declared in this project.

Featured Mock

The idea of this small project is to be able to use files (in the test classpath) to mock either method return or http requests.

Mock interfaces

Use com.github.rmannibucau.featuredmock.mock.FeaturedMock#mock method to generate a proxy. The rule to find the content are simple: it matches a file in the classloader built from the qualified class name (interface) and method name. For instance org.superbiz.MyInterface#myMethod will look for org/superbiz/MyInterface/myMethod[extension] file.

By default json, yml and xml files are searched.

When creating a mock you can specify a custom com.github.rmannibucau.featuredmock.mock.unmarshaller.Unmarshaller. The unmarshaller will be used to convert the file to objects (jackson for json and jaxb for xml by default).

Sample (Mock creation, json feature and result after calling a method):

{ "attr1": "uno", "attr2": "due" }
// DTO
public class Value {
    private String attr1;
    private String attr2;

    public String getAttr1() {
        return attr1;
    }

    public void setAttr1(final String attr1) {
        this.attr1 = attr1;
    }

    public String getAttr2() {
        return attr2;
    }

    public void setAttr2(final String attr2) {
        this.attr2 = attr2;
    }
}

// Service
public interface API {
    Value foo();
}

// mock usage
final API api = api = FeaturedMock.mock(API.class);
final Value value = api.foo();
// value.getAttr1() == "uno"
// value.getAttr2() == "due"

HTTP mock

You need to create a server. Here is a sample:

// the builder API supports host, ssl etc...
final FeaturedHttpServer server = new FeaturedHttpServerBuilder().port(1234).build().start();
// do some work
server.stop();

The idea is the same as with featured mocks excepted the file used to respond is found from the request uri. For instance a request on http://localhost:1234/foo/bar will match a file /foo/bar[ext].

Extension can be the same as for featured mock or no extension at all. In this last case the response type will be text/plain.

Note: if you need to match the same url for two http methods you can prefix your file name with the http method and -. For instance GET-foo/bar.

Note: com.github.rmannibucau.featuredmock.http.ContentTypeMapper allows you to change the extension to use for a particular request type. It is based on accept header.

Versions

Version
0.3
0.2
0.1