Add serviceCatalog rest services
[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.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.boot.context.embedded.LocalServerPort;
13 import org.springframework.boot.test.context.SpringBootTest;
14 import org.springframework.http.ResponseEntity;
15 import org.springframework.test.context.junit4.SpringRunner;
16 import org.springframework.util.LinkedMultiValueMap;
17 import org.springframework.util.MultiValueMap;
18 import com.github.tomakehurst.wiremock.WireMockServer;
19
20 @RunWith(SpringRunner.class)
21 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
22 public class ApiTest {
23
24     @LocalServerPort
25     int randomServerPort;
26
27     String realServerPort;
28
29
30     static public WireMockServer wireMockServer = new WireMockServer(8091);
31
32     @Autowired
33     ServiceSpecificationResource serviceSpecificationResource;
34
35     @BeforeClass
36     public static void setUp() throws Exception {
37         wireMockServer.start();
38     }
39
40     @AfterClass
41     public static void tearsDown() throws Exception {
42         wireMockServer.stop();
43
44     }
45
46     @After
47     public void tearsDownUpPort() throws Exception {
48         wireMockServer.resetToDefaultMappings();
49     }
50
51     @Test
52     @Ignore
53     public void testServiceResourceGetCatalog() throws Exception {
54
55         ResponseEntity<Object> resource =
56                 serviceSpecificationResource.getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
57         ServiceCatalogAssertions.assertGetServiceCatalog(resource);
58
59     }
60
61     @Test
62     public void testServiceCatalogGetResourceWithoutTosca() throws Exception {
63
64         ResponseEntity<Object> resource = serviceSpecificationResource
65                 .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439_withoutTosca", null);
66         ServiceCatalogAssertions.asserGetServiceCatalogWithoutTosca(resource);
67
68     }
69
70     @Test
71     public void testServiceCatalogFind() throws Exception {
72
73         ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(null);
74         ServiceCatalogAssertions.assertFindServiceCatalog(resource);
75
76     }
77
78
79     @Test
80     public void testServiceCatalogFindWithFilter() throws Exception {
81
82         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
83         params.add("fields", "name");
84         ResponseEntity<Object> resource = serviceSpecificationResource.findServiceSpecification(params);
85         ServiceCatalogAssertions.assertFindServiceCatalogWIthFilter(resource);
86
87     }
88
89 }