-
Notifications
You must be signed in to change notification settings - Fork 26
Home
jandudek edited this page Jul 31, 2013
·
71 revisions
Welcome to Jadler, Java http mocking library.
If you need a simple way to create a stub http server in your integration tests, look no further! Writing tests for http client applications can be as easy as:
@Test
public void getAccount() {
onRequest()
.havingMethodEqualTo("GET")
.havingURIEqualTo("/accounts/1")
.havingBody(isEmptyOrNullString())
.havingHeaderEqualTo("Accept", "application/json")
.respond()
.withTimeout(2, SECONDS)
.withStatus(200)
.withBody("{\\"account\\":{\\"id\\" : 1}}")
.withEncoding(Charset.forName("UTF-8"))
.withContentType("application/json; charset=UTF-8");
final AccountService service = new AccountServiceRestImpl("http", "localhost", port());
final Account account = service.getAccount(1);
assertThat(account, is(notNullValue()));
assertThat(account.getId(), is(1));
}
@Test
public void deleteAccount() {
onRequest()
.havingMethodEqualTo("DELETE")
.havingPathEqualTo("/accounts/" + ID)
.respond()
.withStatus(204);
final AccountManager am = new AccountManagerImpl("http", "localhost", port());
final Account account = am.deleteAccount(ID);
verifyThatRequest()
.havingMethodEqualTo("DELETE")
.havingPathEqualTo("/accounts/" + ID)
.receivedOnce();
}
Jadler 0.9.5 released! Special thanks to @benky, @liry and @jumarko for their contributions!
To add Jadler to your Java project just put the following dependency to the Maven pom.xml
file:
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-all</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>