Merge "change management cypress test"
[vid.git] / vid-automation / src / test / java / org / onap / vid / api / AsyncInfraApiTest.java
1 package org.onap.vid.api;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.containsString;
5 import static org.testng.AssertJUnit.assertEquals;
6
7 import com.google.common.collect.ImmutableList;
8 import java.util.UUID;
9 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
10 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
11 import org.onap.vid.more.LoggerFormatTest;
12 import org.onap.vid.more.LoggerFormatTest.LogName;
13 import org.springframework.http.HttpStatus;
14 import org.springframework.http.ResponseEntity;
15 import org.testng.annotations.BeforeClass;
16 import org.testng.annotations.Test;
17 import vid.automation.test.services.SimulatorApi;
18
19 public class AsyncInfraApiTest extends BaseApiTest {
20
21     public static final String API_URL = "asyncForTests";
22
23     @BeforeClass
24     public void login() {
25         super.login();
26     }
27
28     @Test
29     public void testGetStatusBadRequest() {
30         ResponseEntity<String> jobResult = getJob("1234");
31         assertEquals(HttpStatus.BAD_REQUEST, jobResult.getStatusCode());
32     }
33
34     @Test
35     public void testGetStatusNotFound() {
36         ResponseEntity<String> jobResult = getJob(UUID.randomUUID().toString());
37         assertEquals(HttpStatus.NOT_FOUND, jobResult.getStatusCode());
38     }
39
40     private ResponseEntity<String> getJob(String uuid) {
41         return restTemplateErrorAgnostic.getForEntity(buildUri(API_URL + "/job/{uuid}"), String.class , uuid);
42     }
43
44     @Test
45     public void testExceptionHandlingOfVidRestrictedBaseController() {
46         //get logs require user role that may need simulator presets
47         SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
48                 new PresetGetSessionSlotCheckIntervalGet(),
49                 new PresetAAIGetSubscribersGet()), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
50         ResponseEntity<String> jobResult = restTemplateErrorAgnostic.getForEntity(buildUri(API_URL + "/error"), String.class);
51         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobResult.getStatusCode());
52         assertThat(jobResult.getBody(), containsString("GenericUncheckedException"));
53         assertThat(jobResult.getBody(), containsString("dummy error"));
54         String logLines = LoggerFormatTest.getLogLines(LogName.error, 15, 0, restTemplate, uri);
55         assertThat(logLines, containsString("GenericUncheckedException"));
56         assertThat(logLines, containsString("dummy error"));
57     }
58 }