org.expedientframework.facilemock:facile-mock-http-proxy

The parent module for mocking framework.

Лицензия

Лицензия

Группа

Группа

org.expedientframework.facilemock
Идентификатор

Идентификатор

facile-mock-http-proxy
Последняя версия

Последняя версия

1.0.0-M1
Дата

Дата

Тип

Тип

jar
Описание

Описание

The parent module for mocking framework.
Система контроля версий

Система контроля версий

https://github.com/ajeydudhe/facile-mock/tree/master/facile-mock-http-proxy

Скачать facile-mock-http-proxy

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.expedientframework.facilemock/facile-mock-http-proxy/ -->
<dependency>
    <groupId>org.expedientframework.facilemock</groupId>
    <artifactId>facile-mock-http-proxy</artifactId>
    <version>1.0.0-M1</version>
</dependency>
// https://jarcasting.com/artifacts/org.expedientframework.facilemock/facile-mock-http-proxy/
implementation 'org.expedientframework.facilemock:facile-mock-http-proxy:1.0.0-M1'
// https://jarcasting.com/artifacts/org.expedientframework.facilemock/facile-mock-http-proxy/
implementation ("org.expedientframework.facilemock:facile-mock-http-proxy:1.0.0-M1")
'org.expedientframework.facilemock:facile-mock-http-proxy:jar:1.0.0-M1'
<dependency org="org.expedientframework.facilemock" name="facile-mock-http-proxy" rev="1.0.0-M1">
  <artifact name="facile-mock-http-proxy" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.expedientframework.facilemock', module='facile-mock-http-proxy', version='1.0.0-M1')
)
libraryDependencies += "org.expedientframework.facilemock" % "facile-mock-http-proxy" % "1.0.0-M1"
[org.expedientframework.facilemock/facile-mock-http-proxy "1.0.0-M1"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
org.expedientframework.facilemock : facile-mock-core jar 1.0.0-M1
net.lightbody.bmp : browsermob-core jar 2.1.5
com.fasterxml.jackson.core : jackson-databind jar 2.8.11.2
org.apache.logging.log4j : log4j-core jar 2.11.1
org.apache.logging.log4j : log4j-slf4j-impl jar 2.11.1

test (4)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-engine jar 5.3.1
org.apache.httpcomponents : httpclient jar 4.5.6
commons-io : commons-io jar 2.6
org.assertj : assertj-core jar 3.11.1

Модули Проекта

Данный проект не имеет модулей.

Build Status MIT licensed

facile-mock - Simple mocking library for BrowserMobProxy.

WORK IN PROGRESS Work in progress.

facile-mock is a simple mocking library for BrowserMobProxy to allow mocking the http requests in the tests. It allows running a given test with given scope as unit test or integration test. In case of the scope as integration test the mocking will be skipped altogether and run against actual server.

Adding the library reference

Add the maven dependency to your pom.xml as follows:

<dependency>
    <groupId>org.expedientframework.facilemock</groupId>
    <artifactId>facile-mock-http-proxy</artifactId>
    <version>1.0.0-M1</version>
</dependency>

Usage

try(HttpMockContext mock = HttpProxyManagerFactory.createMockContext(unitTest()))
{
  final int port = mock.getHttpProxyManager().getPort();
  mock.when(post(urlEquals("/dummy"))).then(respondWith("Hello from mock for post !!!"));
  final response = postAndGetResponseBody(port, "/dummy");
  assertThat(response).as("Response").isEqualTo("Hello from mock for post !!!");
}
  • HttpProxyManagerFactory.createMockContext() creates the mocking context indicating that we are executing unit tests so that the mocking should be honoured. If you mark it as integration tests then no mocking will be done and the http calls will be made to live server as per the url. So you can run same tests as unit tests with mocking and integration tests without mocking. You just need to passing in proper parameter to createMockContext() at runtime.
  • mock.when() takes the mocking condition which in this case says that for post request with url equal to /dummy we should return a mock response.
  • then() specifies that we should respond with a dummy string value.
  • The postAndGetResponseBody() method makes a http call with the given port on which the http proxy is listening as follows:
public int postAndGetResponseStatus(final int port, final String endpoint)
{
    try(CloseableHttpClient httpClient = HttpClientBuilder.create().setProxy(new HttpHost("localhost", port)))
    {
      final HttpPost post = new HttpPost("http://sampleHostDoesNotExistsBlah.com" + endpoint);
      post.setEntity(new StringEntity("Dummy request body."));
      try(CloseableHttpResponse httpResponse = httpClient.execute(post))
      {
        return httpResponse.getStatusLine().getStatusCode();
      }
    }
    catch (IOException e)
    {
      throw new RuntimeException(e);
    }
}

Версии библиотеки

Версия
1.0.0-M1