aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java
blob: 058cb2f5ba6b426d3051eb3124ede7e6ebabfbcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.onap.vid.api;

import com.google.common.collect.ImmutableList;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
import org.onap.vid.more.LoggerFormatTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import vid.automation.test.services.SimulatorApi;

import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.testng.AssertJUnit.assertEquals;

public class AsyncInfraApiTest extends BaseApiTest {

    public static final String API_URL = "asyncForTests";

    @BeforeClass
    public void login() {
        super.login();
    }

    @Test
    public void testGetStatusBadRequest() {
        ResponseEntity<String> jobResult = getJob("1234");
        assertEquals(HttpStatus.BAD_REQUEST, jobResult.getStatusCode());
    }

    @Test
    public void testGetStatusNotFound() {
        ResponseEntity<String> jobResult = getJob(UUID.randomUUID().toString());
        assertEquals(HttpStatus.NOT_FOUND, jobResult.getStatusCode());
    }

    private ResponseEntity<String> getJob(String uuid) {
        return restTemplateErrorAgnostic.getForEntity(buildUri(API_URL + "/job/{uuid}"), String.class , uuid);
    }

    @Test
    public void testExceptionHandlingOfVidRestrictedBaseController() {
        //get logs require user role that may need simulator presets
        SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
                new PresetGetSessionSlotCheckIntervalGet(),
                new PresetAAIGetSubscribersGet()), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
        ResponseEntity<String> jobResult = restTemplateErrorAgnostic.getForEntity(buildUri(API_URL + "/error"), String.class);
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobResult.getStatusCode());
        assertThat(jobResult.getBody(), containsString("GenericUncheckedException"));
        assertThat(jobResult.getBody(), containsString("dummy error"));
        String logLines = LoggerFormatTest.getLogLines("error", 15, 0, restTemplate, uri);
        assertThat(logLines, containsString("GenericUncheckedException"));
        assertThat(logLines, containsString("dummy error"));
    }
}