summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/nbi/apis/resources/ApiTest.java
blob: df2fb24c351b5587ebce94e775f00394440aa255 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package org.onap.nbi.apis.resources;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.github.tomakehurst.wiremock.WireMockServer;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ApiTest {

    @LocalServerPort
    int randomServerPort;

    String realServerPort;

    static public WireMockServer wireMockServer = new WireMockServer(8091);

    @Autowired
    ServiceSpecificationResource serviceSpecificationResource;

    @Autowired
    ServiceInventoryResource serviceInventoryResource;

    @BeforeClass
    public static void setUp() throws Exception {
        wireMockServer.start();
    }

    @AfterClass
    public static void tearsDown() throws Exception {
        wireMockServer.stop();

    }

    @After
    public void tearsDownUpPort() throws Exception {
        wireMockServer.resetToDefaultMappings();
    }

    // serviceCatalog

    @Test
    @Ignore
    public void testServiceResourceGetCatalog() throws Exception {

        ResponseEntity<Object> resource =
                serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
        ServiceCatalogAssertions.assertGetServiceCatalog(resource);

    }

    @Test
    public void testServiceCatalogGetResourceWithoutTosca() throws Exception {

        ResponseEntity<Object> resource = serviceSpecificationResource
                .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
        ServiceCatalogAssertions.asserGetServiceCatalogWithoutTosca(resource);

    }

    @Test
    public void testServiceCatalogFind() throws Exception {

        ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
        ServiceCatalogAssertions.assertFindServiceCatalog(resource);

    }


    @Test
    public void testServiceCatalogFindWithFilter() throws Exception {

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("fields", "name");
        ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
        ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);

    }

    // serviceInventory

    @Test
    public void testServiceResourceGetInventory() throws Exception {

        String serviceName = "vFW";
        String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("serviceSpecification.name", serviceName);
        params.add("relatedParty.id", "6490");
        ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
        ServiceInventoryAssertions.assertServiceInventoryGet(resource);

    }


    @Test
    public void testServiceResourceGetInventoryWithServiceSpecId() throws Exception {

        String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
        params.add("relatedParty.id", "6490");
        ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
        ServiceInventoryAssertions.assertServiceInventoryGet(resource);

    }


    @Test
    public void testServiceInventoryFind() throws Exception {

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        String serviceName = "vFW";
        params.add("serviceSpecification.name", serviceName);
        params.add("relatedParty.id", "6490");

        ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
        ServiceInventoryAssertions.assertServiceInventoryFind(resource);

    }


    @Test
    public void testServiceInventoryFindWithServiceSpecId() throws Exception {

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
        params.add("relatedParty.id", "6490");

        ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
        ServiceInventoryAssertions.assertServiceInventoryFind(resource);

    }


    @Test
    public void testServiceInventoryFindWithoutParameter() throws Exception {

        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("relatedParty.id", "6490");

        ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
        ServiceInventoryAssertions.assertServiceInventoryFindWithoutParameter(resource);

    }

}