Adding AAI ESR endpoints
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / ExternalSystemEsrControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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.aaisimulator.controller;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.onap.so.aaisimulator.utils.Constants.EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL;
26 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_PASSWORD;
27 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SERVICE_URL;
28 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_ID;
29 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_LIST_URL;
30 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_TYPE;
31 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_TYEP;
32 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_USERNAME;
33 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VENDOR;
34 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VIM_ID;
35 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VNFM_ID;
36 import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VNFM_URL;
37 import static org.onap.so.aaisimulator.utils.TestConstants.SYSTEM_NAME;
38 import java.io.IOException;
39 import java.util.List;
40 import org.junit.After;
41 import org.junit.Test;
42 import org.onap.aai.domain.yang.EsrSystemInfo;
43 import org.onap.aai.domain.yang.EsrSystemInfoList;
44 import org.onap.aai.domain.yang.EsrVnfm;
45 import org.onap.aai.domain.yang.EsrVnfmList;
46 import org.onap.so.aaisimulator.service.providers.ExternalSystemCacheServiceProvider;
47 import org.onap.so.aaisimulator.utils.TestUtils;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.http.HttpStatus;
50 import org.springframework.http.ResponseEntity;
51
52 /**
53  * @author Waqas Ikram (waqas.ikram@est.tech)
54  *
55  */
56 public class ExternalSystemEsrControllerTest extends AbstractSpringBootTest {
57
58     @Autowired
59     private ExternalSystemCacheServiceProvider externalSystemCacheServiceProvider;
60
61     @After
62     public void after() {
63         externalSystemCacheServiceProvider.clearAll();
64     }
65
66     @Test
67     public void test_putEsrVnfm_successfullyAddedToCache() throws Exception {
68         final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID);
69         addEsrVnfmAndAssertResponse(esrVnfmUrl);
70
71         final ResponseEntity<EsrVnfm> response = testRestTemplateService.invokeHttpGet(esrVnfmUrl, EsrVnfm.class);
72         assertEquals(HttpStatus.OK, response.getStatusCode());
73
74         assertTrue(response.hasBody());
75
76         final EsrVnfm actualEsrVnfm = response.getBody();
77         assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId());
78         assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId());
79
80     }
81
82     @Test
83     public void test_getEsrVnfmList_getAllEsrVnfmsFromCache() throws Exception {
84         final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID);
85         addEsrVnfmAndAssertResponse(esrVnfmUrl);
86
87         final String esrVnfmListUrl = getUrl(EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL);
88         final ResponseEntity<EsrVnfmList> response =
89                 testRestTemplateService.invokeHttpGet(esrVnfmListUrl, EsrVnfmList.class);
90
91         assertTrue(response.hasBody());
92
93         final EsrVnfmList actualEsrVnfmList = response.getBody();
94
95         final List<EsrVnfm> esrVnfmList = actualEsrVnfmList.getEsrVnfm();
96         assertNotNull(esrVnfmList);
97         assertEquals(1, esrVnfmList.size());
98         final EsrVnfm actualEsrVnfm = esrVnfmList.get(0);
99         assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId());
100         assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId());
101
102     }
103
104     @Test
105     public void test_putEsrSystemInfo_successfullyAddedToCache() throws Exception {
106         final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID);
107         addEsrVnfmAndAssertResponse(esrVnfmUrl);
108         final String esrSystemInfoListUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID, ESR_SYSTEM_INFO_LIST_URL);
109
110         final String esrSystemInfoUrl = esrSystemInfoListUrl + "/esr-system-info/" + ESR_SYSTEM_INFO_ID;
111         final ResponseEntity<Void> esrSystemInfoResponse =
112                 testRestTemplateService.invokeHttpPut(esrSystemInfoUrl, TestUtils.getEsrSystemInfo(), Void.class);
113         assertEquals(HttpStatus.ACCEPTED, esrSystemInfoResponse.getStatusCode());
114
115         final ResponseEntity<EsrSystemInfoList> response =
116                 testRestTemplateService.invokeHttpGet(esrSystemInfoListUrl, EsrSystemInfoList.class);
117         assertEquals(HttpStatus.OK, response.getStatusCode());
118
119         assertTrue(response.hasBody());
120         final EsrSystemInfoList actualEsrSystemInfoList = response.getBody();
121
122         final List<EsrSystemInfo> esrSystemInfoList = actualEsrSystemInfoList.getEsrSystemInfo();
123         assertNotNull(esrSystemInfoList);
124         assertEquals(1, esrSystemInfoList.size());
125
126         final EsrSystemInfo esrSystemInfo = esrSystemInfoList.get(0);
127         assertEquals(ESR_SYSTEM_INFO_ID, esrSystemInfo.getEsrSystemInfoId());
128         assertEquals(SYSTEM_NAME, esrSystemInfo.getSystemName());
129         assertEquals(ESR_TYEP, esrSystemInfo.getType());
130         assertEquals(ESR_VENDOR, esrSystemInfo.getVendor());
131         assertEquals(ESR_SERVICE_URL, esrSystemInfo.getServiceUrl());
132         assertEquals(ESR_USERNAME, esrSystemInfo.getUserName());
133         assertEquals(ESR_PASSWORD, esrSystemInfo.getPassword());
134         assertEquals(ESR_SYSTEM_TYPE, esrSystemInfo.getSystemType());
135
136
137     }
138
139     private void addEsrVnfmAndAssertResponse(final String esrVnfmUrl) throws IOException {
140         final ResponseEntity<Void> esrVnfmResponse =
141                 testRestTemplateService.invokeHttpPut(esrVnfmUrl, TestUtils.getEsrVnfm(), Void.class);
142         assertEquals(HttpStatus.ACCEPTED, esrVnfmResponse.getStatusCode());
143     }
144 }