1 package org.onap.vid.api;
3 import com.google.common.collect.ImmutableMap;
4 import org.json.JSONException;
5 import org.skyscreamer.jsonassert.JSONAssert;
6 import org.skyscreamer.jsonassert.JSONCompareMode;
7 import org.springframework.http.HttpStatus;
8 import org.testng.annotations.BeforeClass;
9 import org.testng.annotations.Test;
10 import vid.automation.test.services.SimulatorApi;
12 import java.io.IOException;
14 import static org.hamcrest.core.Is.is;
15 import static org.junit.Assert.assertThat;
17 public class SampleApiTest extends BaseApiTest {
19 private static final String UUID = "927befca-e32c-4f7d-be8d-b4107e0ac31e";
20 private static final String FILE_NAME = "a_file_with_request_setup.json";
21 private static final String REQUEST_BODY = "{ \"foo\": \"bar\" }";
28 @Test(enabled = false)
29 public void createWithSimplestBody() throws IOException, JSONException {
30 final String expectedResult = "" +
32 " \"requestReferences\": {" +
33 " \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e331\","+
34 " \"instanceId\": \"" + UUID + "\"" +
38 callWithFineRequest(FILE_NAME,
39 ImmutableMap.of("UUID", UUID),
40 buildUri(), REQUEST_BODY,
41 HttpStatus.ACCEPTED.value(), expectedResult);
44 private String buildUri() {
48 private void callWithFineRequest(String expectationJsonFileName, ImmutableMap<String, Object> replacementsForJson, String targetUri, String requestBody, int expectedStatusCode, String expectedResult) throws JSONException {
49 SimulatorApi.registerExpectation(expectationJsonFileName, replacementsForJson, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
51 MyFooResponseType response = restTemplate.postForObject(targetUri, requestBody, MyFooResponseType.class);
53 assertThat("Wrong propagated status from MSO", response.getStatus(), is(expectedStatusCode));
54 JSONAssert.assertEquals("Wrong propagated body from MSO", expectedResult, getCleanJsonString(response.getEntity()), JSONCompareMode.NON_EXTENSIBLE);
58 private class MyFooResponseType {
59 public int getStatus() {
63 public String getEntity() {