com.github.httpmock:mock-http-server-exec

Mock HTTP Server - Executable

License

License

GroupId

GroupId

com.github.httpmock
ArtifactId

ArtifactId

mock-http-server-exec
Last Version

Last Version

1.1.9
Release Date

Release Date

Type

Type

jar
Description

Description

Mock HTTP Server - Executable
Project URL

Project URL

https://github.com/httpmock/mock-http-server
Source Code Management

Source Code Management

https://github.com/httpmock/mock-http-server

Download mock-http-server-exec

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.httpmock/mock-http-server-exec/ -->
<dependency>
    <groupId>com.github.httpmock</groupId>
    <artifactId>mock-http-server-exec</artifactId>
    <version>1.1.9</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.httpmock/mock-http-server-exec/
implementation 'com.github.httpmock:mock-http-server-exec:1.1.9'
// https://jarcasting.com/artifacts/com.github.httpmock/mock-http-server-exec/
implementation ("com.github.httpmock:mock-http-server-exec:1.1.9")
'com.github.httpmock:mock-http-server-exec:jar:1.1.9'
<dependency org="com.github.httpmock" name="mock-http-server-exec" rev="1.1.9">
  <artifact name="mock-http-server-exec" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.httpmock', module='mock-http-server-exec', version='1.1.9')
)
libraryDependencies += "com.github.httpmock" % "mock-http-server-exec" % "1.1.9"
[com.github.httpmock/mock-http-server-exec "1.1.9"]

Dependencies

compile (8)

Group / Artifact Type Version
com.github.httpmock : mock-http-server-dto jar 1.1.9
com.google.code.gson : gson jar 2.3.1
org.apache.commons : commons-lang3 jar 3.3.2
org.apache.openejb : tomee-util jar 1.7.1
org.apache.openejb : openejb-core jar 4.7.1
commons-io : commons-io jar 2.4
com.jayway.awaitility : awaitility jar 1.6.3
com.jayway.restassured : rest-assured jar 2.4.0

test (6)

Group / Artifact Type Version
commons-codec : commons-codec jar 1.4
org.powermock : powermock-module-junit4 jar 1.6.0
org.powermock : powermock-api-mockito jar 1.6.0
org.hamcrest : hamcrest-all jar 1.3
junit : junit jar 4.11
org.mockito : mockito-all jar 1.10.8

Project Modules

There are no modules declared in this project.

mock-http-server

Coverage Status

With this mock http server you can write integration tests for your application and mock its http based backends. This example shows an integration test which configures the mock to answer for a specific request with a specific response. It also shows how to use this mock server with junit.

import static com.github.httpmock.builder.RequestBuilder.request;
import static com.github.httpmock.builder.ResponseBuilder.response;
import static com.github.httpmock.times.ExcatlyOnce.once;
import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import com.github.httpmock.dto.RequestDto;
import com.github.httpmock.dto.ResponseDto;
import com.jayway.restassured.response.Response;

public class ExampleIT {

	@ClassRule
	public static HttpMockServer mockServer = new HttpMockServer();

	@Rule
	public HttpMock mock = new HttpMock(mockServer);

	@Test
	public void someTest() throws Exception {
		RequestDto request = request().method("POST").url("/some/url").build();
		ResponseDto response = response().payload("data")
				.contentType("text/plain").build();
		mock.when(request).thenRespond(response);

		Response mockResponse = given().baseUri(getBaseUri())
				.basePath(mock.getRequestUrl()).post("/some/url");

		assertThat(mockResponse.getBody().asString(), is("data"));
		assertThat(mockResponse.getContentType(), is("text/plain"));
		mock.verify(request, once());
	}

	private String getBaseUri() {
		return String.format("http://localhost:%d", mockServer.getPort());
	}
}

Versions

Version
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2