seiji / mocking
forked from sogabe/mocking
Seiji Sogabe authored on 16 Sep 2015
RuleSet RuleSet & FindBugs Checkstyle check 1 year ago
src logged startUp time 1 year ago
.gitignore ログまわりの修正 1 year ago
README.md If port is not specified, assign available port automatically. 1 year ago
pom.xml use came-netty4-http instead of netty 1 year ago
README.md

Mocking

Build Status

Mocking is a test framework which is inspired by Restito.

Mocking provides a DSL to:

  • Mimic rest server behavior
  • Record HTTP calls to the server
  • Perform verification against happened calls
  • Automatic serialization

Quick example

public class SampleCodeTest {

    @Rule
    public Mocking mocking = new Mocking();

    @Rule
    public TestNameRule testNameRule = new TestNameRule();

    @Before
    public void setUp() throws Exception {
        RestAssured.port = mocking.getPort();
    }

    @Test
    public void testReadMeSampleCode() {
        Person person = new Person("Bob", 20);

        // Mocking
        mocking.$(
                when("/api/p/{id}").
                        withPathParam("id", 5).
                then().
                        withStatusCode(SC_201_CREATED).
                        withContentType("application/json; charset=UTF-8").
                        withBody(person)
        );

        // Rest-assured
        given().
                pathParam("id", 5).
                accept("application/json").
                contentType("application/json; charset=UTF-8").
                body(person).
        when().
                put("/api/p/{id}").
        then().
                statusCode(SC_201_CREATED).
                contentType("application/json; charset=UTF-8").
                body("name", is("Bob")).
                body("old", is(20));

        // Mocking
        mocking.$(
                put("/api/p/{id}").
                        withPathParam("id", 5).
                then().
                        withAccept("application/json").
                        withContentType("application/json; charset=UTF-8").
                        withBody("name", is("Bob")).
                        withBody("old", is(20)).
                        withoutHeader("Referer")
        );
    }
    
(snip)
    
}