1 package org.onap.vid.api;
3 import com.google.common.collect.ImmutableMap;
4 import org.springframework.http.HttpMethod;
5 import org.springframework.http.RequestEntity;
6 import org.springframework.http.ResponseEntity;
7 import org.springframework.web.client.HttpClientErrorException;
8 import org.springframework.web.client.HttpServerErrorException;
9 import org.springframework.web.client.HttpStatusCodeException;
10 import org.testng.annotations.BeforeClass;
11 import vid.automation.test.services.SimulatorApi;
13 import java.io.IOException;
15 import java.net.URISyntaxException;
17 import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
18 import static org.hamcrest.Matchers.either;
19 import static org.hamcrest.core.Is.is;
20 import static org.junit.Assert.assertThat;
21 import static vid.automation.test.services.SimulatorApi.registerExpectation;
24 * Created by Oren on 11/1/17.
26 public class BaseApiAaiTest extends BaseApiTest {
34 protected void callAaiWithSimulatedErrorResponse(String [] expectationJsonFileNames, ImmutableMap<String, Object> replacementsForJson, String targetUri, String basicRequestBody, int expectedErrorCode, String expectedResult, HttpMethod method) throws IOException, URISyntaxException {
36 registerExpectation(expectationJsonFileNames, replacementsForJson, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
37 RequestEntity<String> request;
44 request = RequestEntity
45 .put(new URI(targetUri))
46 .body(basicRequestBody);
48 restTemplate.exchange(request, String.class);
50 catch(HttpStatusCodeException e) {
51 assertThat("Wrong propagated status from AAI", e.getStatusCode().value(), is(expectedErrorCode));
57 ResponseEntity<String> responseWrapper = restTemplate.getForEntity(targetUri, String.class);
58 assertThat("Wrong propagated status from AAI", responseWrapper.getStatusCode().value(), is(expectedErrorCode));
59 assertThat("The response is in the format of JSON", responseWrapper.getBody(),
60 either(is(expectedResult)).or(jsonStringEquals(expectedResult)));
62 catch(HttpClientErrorException | HttpServerErrorException e) {
63 assertThat("Wrong propagated status from AAI", e.getStatusCode().value(), is(expectedErrorCode));