1 package org.onap.nbi.apis.resources;
4 import org.junit.After;
5 import org.junit.AfterClass;
6 import org.junit.BeforeClass;
7 import org.junit.Ignore;
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;
21 @RunWith(SpringRunner.class)
22 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
23 public class ApiTest {
28 String realServerPort;
30 static public WireMockServer wireMockServer = new WireMockServer(8091);
33 ServiceSpecificationResource serviceSpecificationResource;
36 ServiceInventoryResource serviceInventoryResource;
39 public static void setUp() throws Exception {
40 wireMockServer.start();
44 public static void tearsDown() throws Exception {
45 wireMockServer.stop();
50 public void tearsDownUpPort() throws Exception {
51 wireMockServer.resetToDefaultMappings();
58 public void testServiceResourceGetCatalog() throws Exception {
60 ResponseEntity<Object> resource =
61 serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
62 ServiceCatalogAssertions.assertGetServiceCatalog(resource);
67 public void testServiceCatalogGetResourceWithoutTosca() throws Exception {
69 ResponseEntity<Object> resource = serviceSpecificationResource
70 .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
71 ServiceCatalogAssertions.asserGetServiceCatalogWithoutTosca(resource);
76 public void testServiceCatalogFind() throws Exception {
78 ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
79 ServiceCatalogAssertions.assertFindServiceCatalog(resource);
85 public void testServiceCatalogFindWithFilter() throws Exception {
87 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
88 params.add("fields", "name");
89 ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
90 ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);
97 public void testServiceResourceGetInventory() throws Exception {
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);
111 public void testServiceResourceGetInventoryWithServiceSpecId() throws Exception {
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);
124 public void testServiceInventoryFind() throws Exception {
126 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
127 String serviceName = "vFW";
128 params.add("serviceSpecification.name", serviceName);
129 params.add("relatedParty.id", "6490");
131 ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
132 ServiceInventoryAssertions.assertServiceInventoryFind(resource);
138 public void testServiceInventoryFindWithServiceSpecId() throws Exception {
140 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
141 params.add("serviceSpecification.id", "1e3feeb0-8e36-46c6-862c-236d9c626439");
142 params.add("relatedParty.id", "6490");
144 ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
145 ServiceInventoryAssertions.assertServiceInventoryFind(resource);
151 public void testServiceInventoryFindWithoutParameter() throws Exception {
153 MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
154 params.add("relatedParty.id", "6490");
156 ResponseEntity<Object> resource = serviceInventoryResource.findServiceInventory(params);
157 ServiceInventoryAssertions.assertServiceInventoryFindWithoutParameter(resource);