com.capitalone.dashboard.testutil.TestRestTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Core package shared by API layer and Microservices
package com.capitalone.dashboard.testutil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
public class TestRestTemplate extends RestTemplate {
private Map> response;
public TestRestTemplate(Map> response) {
this.response = response;
}
public Map> getResponse() {
return response;
}
public void addResponse(String key, TestResponse testResponse) {
if (response == null) {
response = new HashMap<>();
}
this.response.put(key, testResponse);
}
public void addResponse(String key, T body, HttpStatus httpStatus) {
if (response == null) {
response = new HashMap<>();
}
this.response.put(key, new TestResponse<>(body, httpStatus));
}
public void clearResponse() {
if (response != null) {
response.clear();
}
}
@Override
public ResponseEntity exchange(String var1, HttpMethod var2, HttpEntity> var3, Class var4, Object... var5) throws RestClientException {
if (response.containsKey(var1)) {
return new ResponseEntity(response.get(var1).getBody(),response.get(var1).getStatus());
} else {
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy