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 java.util.Collections.singletonList;
15 import static org.hamcrest.core.Is.is;
16 import static org.junit.Assert.assertThat;
18 public class SampleApiTest extends BaseApiTest {
20 private static final String UUID = "927befca-e32c-4f7d-be8d-b4107e0ac31e";
21 private static final String FILE_NAME = "a_file_with_request_setup.json";
22 private static final String REQUEST_BODY = "{ \"foo\": \"bar\" }";
29 @Test(enabled = false)
30 public void createWithSimplestBody() throws IOException, JSONException {
31 final String expectedResult = "" +
33 " \"requestReferences\": {" +
34 " \"requestId\": \"rq1234d1-5a33-55df-13ab-12abad84e331\","+
35 " \"instanceId\": \"" + UUID + "\"" +
39 callWithFineRequest(FILE_NAME,
40 ImmutableMap.of("UUID", UUID),
41 buildUri(), REQUEST_BODY,
42 HttpStatus.ACCEPTED.value(), expectedResult);
45 private String buildUri() {
49 private void callWithFineRequest(String expectationJsonFileName, ImmutableMap<String, Object> replacementsForJson, String targetUri, String requestBody, int expectedStatusCode, String expectedResult) throws JSONException {
50 SimulatorApi.registerExpectation(expectationJsonFileName, replacementsForJson, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
52 MyFooResponseType response = restTemplate.postForObject(targetUri, requestBody, MyFooResponseType.class);
54 assertThat("Wrong propagated status from MSO", response.getStatus(), is(expectedStatusCode));
55 JSONAssert.assertEquals("Wrong propagated body from MSO", expectedResult, getCleanJsonString(response.getEntity()), JSONCompareMode.NON_EXTENSIBLE);
59 private class MyFooResponseType {
60 public int getStatus() {
64 public String getEntity() {