aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-08-13 13:40:47 +0200
committerkurczews <krzysztof.kurczewski@nokia.com>2018-08-13 13:43:12 +0200
commit2513c3cae11dbc717d2c22ffdd8266aa2e61a800 (patch)
tree7c1a9c1630be657506995f4a291504562bf712b1 /vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java
parent9b45c01d9bb3a4565ed64c20e72511edc0854636 (diff)
Renaming vid-automation #4
Change-Id: I907b9a6c199302d748918e236ee2945d56f4dd26 Issue-ID: VID-205 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java')
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java b/vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java
new file mode 100644
index 000000000..4ac38a0e7
--- /dev/null
+++ b/vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java
@@ -0,0 +1,70 @@
+package org.onap.vid.api;
+
+import com.google.common.collect.ImmutableMap;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.testng.annotations.BeforeClass;
+import vid.automation.test.services.SimulatorApi;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
+import static org.hamcrest.Matchers.either;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static vid.automation.test.services.SimulatorApi.registerExpectation;
+
+/**
+ * Created by Oren on 11/1/17.
+ */
+public class BaseApiAaiTest extends BaseApiTest {
+
+ @BeforeClass
+ public void login() {
+ super.login();
+ }
+
+
+ protected void callAaiWithSimulatedErrorResponse(String [] expectationJsonFileNames, ImmutableMap<String, Object> replacementsForJson, String targetUri, String basicRequestBody, int expectedErrorCode, String expectedResult, HttpMethod method) throws IOException, URISyntaxException {
+
+ registerExpectation(expectationJsonFileNames, replacementsForJson, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
+ RequestEntity<String> request;
+ switch (method) {
+ case POST:
+ //not supported yet
+ break;
+
+ case PUT:
+ request = RequestEntity
+ .put(new URI(targetUri))
+ .body(basicRequestBody);
+ try {
+ restTemplate.exchange(request, String.class);
+ }
+ catch(HttpStatusCodeException e) {
+ assertThat("Wrong propagated status from AAI", e.getStatusCode().value(), is(expectedErrorCode));
+ }
+
+
+ case GET:
+ try {
+ ResponseEntity<String> responseWrapper = restTemplate.getForEntity(targetUri, String.class);
+ assertThat("Wrong propagated status from AAI", responseWrapper.getStatusCode().value(), is(expectedErrorCode));
+ assertThat("The response is in the format of JSON", responseWrapper.getBody(),
+ either(is(expectedResult)).or(jsonStringEquals(expectedResult)));
+ }
+ catch(HttpClientErrorException | HttpServerErrorException e) {
+ assertThat("Wrong propagated status from AAI", e.getStatusCode().value(), is(expectedErrorCode));
+ }
+ break;
+ }
+
+
+ }
+}