aboutsummaryrefslogtreecommitdiffstats
path: root/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroValidatorTest.java
blob: 8288d70c213beae19779ea4d1fa887ff0e0ccd65 (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
59
60
61
62
package org.onap.so.client.sniro;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.onap.so.client.exception.BadResponseException;

public class SniroValidatorTest {

    @Test
    public void validateDemandsResponse_success() throws BadResponseException {
        Map<String, Object> testMap = new LinkedHashMap<>();
        testMap.put("requestStatus", "accepted");
        new SniroValidator().validateDemandsResponse(testMap);
    }

    @Test
    public void validateDemandsResponse_emptyResponse() {
        try {
            new SniroValidator().validateDemandsResponse(new LinkedHashMap<>());
        } catch (BadResponseException e) {
            assertThat(e.getMessage()).contains("Sniro Managers synchronous response is empty");
        }
    }

    @Test
    public void validateDemandsResponse_responseWithErrorMessage() {
        String message = "An error occurred";
        Map<String, Object> testMap = new LinkedHashMap<>();
        testMap.put("requestStatus", "not_accepted");
        testMap.put("statusMessage", message);
        try {
            new SniroValidator().validateDemandsResponse(testMap);
        } catch (BadResponseException e) {
            assertThat(e.getMessage()).contains("Sniro Managers synchronous response indicates failed: " + message);
        }
    }

    @Test
    public void validateDemandsResponse_responseWithoutMessage() {
        Map<String, Object> testMap = new LinkedHashMap<>();
        testMap.put("requestStatus", "not_accepted");
        testMap.put("statusMessage", "");
        try {
            new SniroValidator().validateDemandsResponse(testMap);
        } catch (BadResponseException e) {
            assertThat(e.getMessage()).contains("error message not provided");
        }
    }

    @Test
    public void validateDemandsResponse_responseWithoutRequestStatus() {
        Map<String, Object> testMap = new LinkedHashMap<>();
        testMap.put("statusMessage", "");
        try {
            new SniroValidator().validateDemandsResponse(testMap);
        } catch (BadResponseException e) {
            assertThat(e.getMessage()).contains("Sniro Managers synchronous response does not contain: request status");
        }
    }
}