8000 GitHub - antechrestos/rest-client-test
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

antechrestos/rest-client-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rest Client Test maven license

Description

This project brings you a simple library to mock spring rest template in order to test your client.

Example: The following example registers a POST made on http://somewhere.org, with the request body "some body". This call will return a OK status code with the content of the file found in classpath fixtures/POST.json.

The call to restTemplate must be a POST on the matching url. The call will check that the body submitted matched the one given at context registration.

restTemplate.setRequestFactory(clientHttpRequestFactory);
clientHttpRequestFactory.register(
		Context.builder()
				.url("http://somewhere.org")
				.queryParameter("some_parameter", Collections.singletonList("some_value"))
				.statusCode(HttpStatus.OK)
				.method(HttpMethod.POST)
				.requestPayload(Payload.builder()
						.type(Payload.Type.RAW_STRING)
						.value("some body")
						.build())
     				.responsePayload(Payload.builder()
      						.type(Payload.Type.CLASSPATH_RESOURCE)
						.value("fixtures/POST.json")
						.build())
				.build()
);
// use restTemplate

Query parameters

Query parameters may either be specified in the urlcreation paramers, or by using the builder method queryParameter. If both way are used, the checked query parameters will be a merge of the two methods. They are checked when the call is made.

Request headers

Headers specified by the builder method header are checked when the call is made.

Request payload

A check on the body that is sent can be made. You may either specify a Payload.Type.RAW_STRING or a Payload.Type.CLASSPATH_RESOURCEwhere the content will be loaded and compared to the sent body.

Status code

The status code that will be returned

Response headers

The headers that will be sent by the call.

Response payload

The response body returned. You may either specify a Payload.Type.RAW_STRING or a Payload.Type.CLASSPATH_RESOURCE where the content will be loaded and sent as a body.

Add to your project

Add the dependency to your project by using maven:

<dependency>
    <groupId>com.github.antechrestos</groupId>
    <artifactId>restclienttest</artifactId>
    <version>1.1.0</version>
</dependency>

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0