Add service inventory
[externalapi/nbi.git] / src / test / java / org / onap / nbi / apis / resources / ApiTest.java
1 package org.onap.nbi.apis.resources;
2
3
4 import org.junit.After;
5 import org.junit.AfterClass;
6 import org.junit.BeforeClass;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.junit.runner.RunWith;
10 import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
11 import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.boot.context.embedded.LocalServerPort;
14 import org.springframework.boot.test.context.SpringBootTest;
15 import org.springframework.http.ResponseEntity;
16 import org.springframework.test.context.junit4.SpringRunner;
17 import org.springframework.util.LinkedMultiValueMap;
18 import org.springframework.util.MultiValueMap;
19 import com.github.tomakehurst.wiremock.WireMockServer;
20
21 @RunWith(SpringRunner.class)
22 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
23 public class ApiTest {
24
25     @LocalServerPort
26     int randomServerPort;
27
28     String realServerPort;
29
30     static public WireMockServer wireMockServer = new WireMockServer(8091);
31
32     @Autowired
33     ServiceSpecificationResource serviceSpecificationResource;
34
35     @Autowired
36     ServiceInventoryResource serviceInventoryResource;
37
38     @BeforeClass
39     public static void setUp() throws Exception {
40         wireMockServer.start();
41     }
42
43     @AfterClass
44     public static void tearsDown() throws Exception {
45         wireMockServer.stop();
46
47     }
48
49     @After
50     public void tearsDownUpPort() throws Exception {
51         wireMockServer.resetToDefaultMappings();
52     }
53
54     // serviceCatalog
55
56     @Test
57     @Ignore
58     public void testServiceResourceGetCatalog() throws Exception {
59
60         ResponseEntity<Object> resource =
61                 serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
62         ServiceCatalogAssertions.assertGetServiceCatalog(resource);
63
64     }
65
66     @Test
67     public void testServiceCatalogGetResourceWithoutTosca() throws Exception {
68
69         ResponseEntity<Object> resource = serviceSpecificationResource
70                 .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
71         ServiceCatalogAssertions.asserGetServiceCatalogWithoutTosca(resource);
72
73     }
74
75     @Test
76     public void testServiceCatalogFind() throws Exception {
77
78         ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
79         ServiceCatalogAssertions.assertFindServiceCatalog(resource);
80
81     }
82
83
84     @Test
85     public void testServiceCatalogFindWithFilter() throws Exception {
86
87         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
88         params.add("fields", "name");
89         ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
90         ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);
91
92     }
93
94     // serviceInventory
95
96     @Test
97     public void testServiceResourceGetInventory() throws Exception {
98
99         String serviceName = "vFW";
100         String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
101         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
102         params.add("serviceSpecification.name", serviceName);
103         params.add("relatedParty.id", "6490");
104         ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
105         ServiceInventoryAssertions.assertServiceInventoryGet(resource);
106
107     }
108
109
110     @Test
111     public void testServiceResourceGetInventoryWithServiceSpecId() throws Exception {
112
113         String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
114         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
115         params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
116         params.add("relatedParty.id", "6490");
117         ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
118         ServiceInventoryAssertions.assertServiceInventoryGet(resource);
119
120     }
121
122
123     @Test
124     public void testServiceInventoryFind() throws Exception {
125
126         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
127         String serviceName = "vFW";
128         params.add("serviceSpecification.name", serviceName);
129         params.add("relatedParty.id", "6490");
130
131         ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
132         ServiceInventoryAssertions.assertServiceInventoryFind(resource);
133
134     }
135
136
137     @Test
138     public void testServiceInventoryFindWithServiceSpecId() throws Exception {
139
140         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
141         params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
142         params.add("relatedParty.id", "6490");
143
144         ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
145         ServiceInventoryAssertions.assertServiceInventoryFind(resource);
146
147     }
148
149
150     @Test
151     public void testServiceInventoryFindWithoutParameter() throws Exception {
152
153         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
154         params.add("relatedParty.id", "6490");
155
156         ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
157         ServiceInventoryAssertions.assertServiceInventoryFindWithoutParameter(resource);
158
159     }
160
161 }