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