Adding support for SOL005 NBI (SO-3155)
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-service / src / test / java / org / onap / so / etsi / nfvo / ns / lcm / rest / NsLifecycleManagementControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.rest;
21
22 /**
23  * @author Waqas Ikram (waqas.ikram@est.tech)
24  *
25  */
26 import static org.junit.Assert.assertEquals;
27 import java.time.LocalDateTime;
28 import java.util.UUID;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.onap.so.etsi.nfvo.ns.lcm.Constants;
33 import org.onap.so.etsi.nfvo.ns.lcm.JSON;
34 import org.onap.so.etsi.nfvo.ns.lcm.TestApplication;
35 import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest;
36 import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest;
37 import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.boot.test.web.client.TestRestTemplate;
40 import org.springframework.boot.web.client.RestTemplateBuilder;
41 import org.springframework.boot.web.server.LocalServerPort;
42 import org.springframework.http.HttpEntity;
43 import org.springframework.http.HttpHeaders;
44 import org.springframework.http.HttpMethod;
45 import org.springframework.http.HttpStatus;
46 import org.springframework.http.ResponseEntity;
47 import org.springframework.http.converter.json.GsonHttpMessageConverter;
48 import org.springframework.test.context.ActiveProfiles;
49 import org.springframework.test.context.junit4.SpringRunner;
50 import com.google.gson.Gson;
51
52 /**
53  * @author Waqas Ikram (waqas.ikram@est.tech)
54  *
55  */
56 @RunWith(SpringRunner.class)
57 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
58 @ActiveProfiles("test")
59 public class NsLifecycleManagementControllerTest {
60     @LocalServerPort
61     private int port;
62
63     private TestRestTemplate testRestTemplate;
64
65     @Before
66     public void setUp() {
67         final Gson gson = JSON.createGson().create();
68         testRestTemplate = new TestRestTemplate(
69                 new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson)));
70     }
71
72     @Test
73     public void testCreateNs_ValidCreateNsRequest() {
74         final String baseUrl = getNsLcmBaseUrl() + "/ns_instances";
75         final HttpHeaders headers = new HttpHeaders();
76         headers.add(Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, "GLOBAL_CUSTOMER_ID");
77         final HttpEntity<?> request = new HttpEntity<>(getCreateNsRequest(), headers);
78         final ResponseEntity<Void> responseEntity =
79                 testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class);
80         assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
81     }
82
83     @Test
84     public void testCreateNs_ValidDeleteNsRequest() {
85         final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString();
86         final ResponseEntity<Void> responseEntity =
87                 testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, Void.class);
88         assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
89     }
90
91     @Test
92     public void testInstantiateNs_ValidInstantiateNsRequest() {
93         final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/instantiate";
94         final HttpEntity<?> request = new HttpEntity<>(getInstantiateNsRequest());
95         final ResponseEntity<Void> responseEntity =
96                 testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class);
97         assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
98     }
99
100     @Test
101     public void testTerminateNs_ValidInstantiateNsRequest() {
102         final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/terminate";
103         final HttpEntity<?> request = new HttpEntity<>(getTerminateNsRequest());
104         final ResponseEntity<Void> responseEntity =
105                 testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class);
106         assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
107     }
108
109
110     private TerminateNsRequest getTerminateNsRequest() {
111         return new TerminateNsRequest().terminationTime(LocalDateTime.now());
112     }
113
114     private InstantiateNsRequest getInstantiateNsRequest() {
115         return new InstantiateNsRequest().nsFlavourId("FLAVOUR_ID");
116     }
117
118     private CreateNsRequest getCreateNsRequest() {
119         return new CreateNsRequest().nsdId(UUID.randomUUID().toString());
120     }
121
122     private String getNsLcmBaseUrl() {
123         return "http://localhost:" + port + Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL;
124     }
125 }
126