aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/nbi/apis/resources/ServiceCatalogAssertions.java
blob: 19e2a2a0b1f016ea0338896dcbbc1bde752bcbbc (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package org.onap.nbi.apis.resources;


import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import static org.assertj.core.api.Assertions.assertThat;


public class ServiceCatalogAssertions {


    public static void assertGetServiceCatalog(ResponseEntity<Object> resource) {
        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
        LinkedHashMap service = (LinkedHashMap) resource.getBody();
        assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
        assertThat(service.get("name")).isEqualTo("vFW");
        assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
        assertThat(service.get("toscaModelURL")).isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439/toscaModel");
        assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
        assertThat(service.get("version")).isEqualTo("2.0");
        assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
        assertThat(service.get("@type")).isEqualTo("ONAPservice");
        assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
        LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
        assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
        assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");


        assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
        LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
        assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
        assertThat(resource1.get("instanceName")).isEqualTo("vFW-vSINK 0");
        assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
        assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
        assertThat(resource1.get("modelCustomizationId")).isEqualTo("f7ae574e-fd5f-41e7-9b21-75e001561c96");
        assertThat(resource1.get("modelCustomizationName")).isEqualTo("vFW-vSINK");

        assertThat(((ArrayList) service.get("serviceSpecCharacteristic")).size()).isEqualTo(4);
        ArrayList serviceSPecCharacteristics = (ArrayList) service.get("serviceSpecCharacteristic");
        for (Object serviceSPecCharacteristic : serviceSPecCharacteristics) {
            LinkedHashMap serviceSPecCharacteristicMap = (LinkedHashMap) serviceSPecCharacteristic;
            if (serviceSPecCharacteristicMap.get("name").toString().equals("cpus")) {
                assertThat(serviceSPecCharacteristicMap.get("valueType")).isEqualTo("integer");
                assertThat(serviceSPecCharacteristicMap.get("@type")).isEqualTo("ONAPserviceCharacteristic");
                ArrayList serviceSpecCharacteristicValues = (ArrayList) serviceSPecCharacteristicMap.get("serviceSpecCharacteristicValue");
                for (Object serviceSpecCharacteristicValue : serviceSpecCharacteristicValues) {
                    LinkedHashMap serviceSpecCharacteristicValueMap = (LinkedHashMap) serviceSpecCharacteristicValue;
                    if (serviceSpecCharacteristicValueMap.get("value").toString().equals("2")) {
                        assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(true);
                        assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
                    } else {
                        assertThat(serviceSpecCharacteristicValueMap.get("isDefault")).isEqualTo(false);
                        assertThat(serviceSpecCharacteristicValueMap.get("valueType")).isEqualTo("integer");
                    }
                }
            }
        }
    }



    public static void asserGetServiceCatalogWithoutTosca(ResponseEntity<Object> resource) {
        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
        LinkedHashMap service = (LinkedHashMap) resource.getBody();
        assertThat(service.get("id")).isEqualTo("1e3feeb0-8e36-46c6-862c-236d9c626439");
        assertThat(service.get("name")).isEqualTo("vFW");
        assertThat(service.get("invariantUUID")).isEqualTo("b58a118e-eeb9-4f6e-bdca-e292f84d17df");
        assertThat(service.get("toscaModelURL")).isEqualTo("/sdc/v1/catalog/services/1e3feeb0-8e36-46c6-862c-236d9c626439toto/toscaModel");
        assertThat(service.get("distributionStatus")).isEqualTo("DISTRIBUTED");
        assertThat(service.get("version")).isEqualTo("2.0");
        assertThat(service.get("lifecycleStatus")).isEqualTo("CERTIFIED");
        assertThat(service.get("@type")).isEqualTo("ONAPservice");
        assertThat(((ArrayList) service.get("attachment")).size()).isEqualTo(5);
        LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty");
        assertThat(relatedParty.get("name")).isEqualTo("Joni Mitchell");
        assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");


        assertThat(((ArrayList) service.get("resourceSpecification")).size()).isEqualTo(2);
        LinkedHashMap resource1 = (LinkedHashMap) ((ArrayList) service.get("resourceSpecification")).get(0);
        assertThat(resource1.get("name")).isEqualTo("vFW-vSINK");
        assertThat(resource1.get("instanceName")).isEqualTo("vFW-vSINK 0");
        assertThat(resource1.get("resourceInvariantUUID")).isEqualTo("18b90934-aa82-456f-938e-e74a07a426f3");
        assertThat(resource1.get("@type")).isEqualTo("ONAPresource");
        assertThat(resource1.get("modelCustomizationId")).isNull();
        assertThat(resource1.get("modelCustomizationName")).isNull();

        assertThat(service.get("serviceSpecCharacteristic")).isNull();
    }




    public static void assertFindServiceCatalog(ResponseEntity<Object> resource) {
        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
        ArrayList body = (ArrayList) resource.getBody();
        assertThat(body.size()).isEqualTo(21);
        LinkedHashMap service1 = (LinkedHashMap) body.get(0);
        assertThat(service1.get("id")).isEqualTo("446afaf6-79b5-420e-aff8-7551b00bb510");
        assertThat(service1.get("name")).isEqualTo("FreeRadius-service");
        assertThat(service1.get("invariantUUID")).isEqualTo("7e4781e8-6c6e-41c5-b889-6a321d5f2490");
        assertThat(service1.get("category")).isEqualTo("Network L4+");
        assertThat(service1.get("distributionStatus")).isEqualTo("DISTRIBUTED");
        assertThat(service1.get("version")).isEqualTo("1.0");
        assertThat(service1.get("lifecycleStatus")).isEqualTo("CERTIFIED");
        LinkedHashMap relatedParty = (LinkedHashMap) service1.get("relatedParty");
        assertThat(relatedParty.get("role")).isEqualTo("lastUpdater");
    }



    public static void assertFindServiceCatalogWIthFilter(ResponseEntity<Object> resource) {
        assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK);
        ArrayList body = (ArrayList) resource.getBody();
        assertThat(body.size()).isEqualTo(21);


        ObjectNode service1 = (ObjectNode) body.get(0);
        assertThat(service1.get("id")).isNull();
        assertThat(service1.get("name").asText()).isEqualTo("FreeRadius-service");
        assertThat(service1.get("invariantUUID")).isNull();
        assertThat(service1.get("category")).isNull();
        assertThat(service1.get("distributionStatus")).isNull();
        assertThat(service1.get("version")).isNull();
        assertThat(service1.get("lifecycleStatus")).isNull();
        assertThat(service1.get("relatedParty")).isNull();
    }

}