2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
18 import java.util.ArrayList;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.onap.aai.api.CloudInfrastructureApi;
23 import org.onap.aai.api.ExternalSystemApi;
24 import org.onap.aai.model.CloudRegion;
25 import org.onap.aai.model.EsrSystemInfo;
26 import org.onap.aai.model.EsrVnfm;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
28 import org.onap.vnfmdriver.model.VimInfo;
29 import org.onap.vnfmdriver.model.VnfmInfo;
31 import static junit.framework.TestCase.assertEquals;
32 import static junit.framework.TestCase.fail;
33 import static org.mockito.Mockito.verify;
34 import static org.mockito.Mockito.when;
35 import static org.springframework.test.util.ReflectionTestUtils.setField;
37 public class TestAAIExternalSystemInfoProvider extends TestBase {
38 private AAIExternalSystemInfoProvider aaiExternalSystemInfoProvider;
40 private AAIRestApiProvider aaiRestApiProvider;
42 private ExternalSystemApi externalSystemApi;
44 private CloudInfrastructureApi cloudInfrastructureApi;
48 setField(AAIExternalSystemInfoProvider.class, "logger", logger);
49 aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
50 when(aaiRestApiProvider.getExternalSystemApi()).thenReturn(externalSystemApi);
51 when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
55 * test query VIM success scenario
58 public void testVim() throws Exception {
59 CloudRegion cloudRegion = new CloudRegion();
60 cloudRegion.setEsrSystemInfoList(new ArrayList<>());
61 EsrSystemInfo vim = new EsrSystemInfo();
62 cloudRegion.getEsrSystemInfoList().add(vim);
63 vim.setPassword("myPassword");
64 vim.setUserName("myUsername");
65 vim.setServiceUrl("http://1.2.3.4:1234/a");
66 vim.setVersion("v123");
67 vim.setSystemStatus("active");
68 vim.setSystemName("name");
70 vim.setSslInsecure(true);
71 vim.setVendor("vendor");
72 when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
74 VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
75 assertEquals("myPassword", vimInfo.getPassword());
76 assertEquals("true", vimInfo.getSslInsecure());
77 assertEquals(null, vimInfo.getSslCacert());
78 assertEquals("myUsername", vimInfo.getUserName());
79 assertEquals("name", vimInfo.getDescription());
80 assertEquals("name", vimInfo.getName());
81 assertEquals("http://1.2.3.4:1234/a", vimInfo.getUrl());
82 assertEquals("active", vimInfo.getStatus());
83 assertEquals("type", vimInfo.getType());
84 assertEquals("v123", vimInfo.getVersion());
85 assertEquals(VIM_ID, vimInfo.getVimId());
86 assertEquals(null, vimInfo.getCreateTime());
91 * test query VIM success scenario for SSL
94 public void testVimSsl() throws Exception {
95 CloudRegion cloudRegion = new CloudRegion();
96 cloudRegion.setEsrSystemInfoList(new ArrayList<>());
97 EsrSystemInfo vim = new EsrSystemInfo();
98 cloudRegion.getEsrSystemInfoList().add(vim);
99 vim.setPassword("myPassword");
100 vim.setUserName("myUsername");
101 vim.setServiceUrl("https://1.2.3.4:1234/a");
102 vim.setVersion("v123");
103 vim.setSystemStatus("active");
104 vim.setSystemName("name");
106 vim.setSslInsecure(false);
107 vim.setSslCacert("cert");
108 vim.setVendor("vendor");
109 when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
111 VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
112 assertEquals("myPassword", vimInfo.getPassword());
113 assertEquals("false", vimInfo.getSslInsecure());
114 assertEquals("cert", vimInfo.getSslCacert());
115 assertEquals("myUsername", vimInfo.getUserName());
116 assertEquals("name", vimInfo.getDescription());
117 assertEquals("name", vimInfo.getName());
118 assertEquals("https://1.2.3.4:1234/a", vimInfo.getUrl());
119 assertEquals("active", vimInfo.getStatus());
120 assertEquals("type", vimInfo.getType());
121 assertEquals("v123", vimInfo.getVersion());
122 assertEquals(VIM_ID, vimInfo.getVimId());
123 assertEquals(null, vimInfo.getCreateTime());
127 * unable to query VIM from AAI results in error
130 public void testVimUnableToQuery() throws Exception {
131 RuntimeException expectedException = new RuntimeException();
132 when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenThrow(expectedException);
135 aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
137 } catch (Exception e) {
138 verify(logger).error("Unable to query VIM with myCloudOwnerId_myRegionName identifier from AAI", expectedException);
139 assertEquals(expectedException, e.getCause());
144 * test VNFM query success scenario
147 public void testVnfmQuery() throws Exception {
148 EsrVnfm vnfm = new EsrVnfm();
149 vnfm.setVimId(VIM_ID);
150 vnfm.setEsrSystemInfoList(new ArrayList<>());
151 EsrSystemInfo esrInfo = new EsrSystemInfo();
152 vnfm.getEsrSystemInfoList().add(esrInfo);
153 esrInfo.setPassword("myPassword");
154 esrInfo.setUserName("myUsername");
155 esrInfo.setServiceUrl("https://1.2.3.4:1234/a");
156 esrInfo.setVersion("v123");
157 esrInfo.setSystemStatus("active");
158 esrInfo.setSystemName("name");
159 esrInfo.setType("type");
160 esrInfo.setSslInsecure(false);
161 esrInfo.setSslCacert("cert");
162 esrInfo.setVendor("vendor");
163 vnfm.setVnfmId(VNFM_ID);
164 when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenReturn(buildObservable(vnfm));
167 VnfmInfo actualVnfmInfo = aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
169 assertEquals("myPassword", actualVnfmInfo.getPassword());
170 assertEquals("https://1.2.3.4:1234/a", actualVnfmInfo.getUrl());
171 assertEquals("myUsername", actualVnfmInfo.getUserName());
172 assertEquals(null, actualVnfmInfo.getCreateTime());
173 assertEquals(null, actualVnfmInfo.getDescription());
174 assertEquals("name", actualVnfmInfo.getName());
175 assertEquals("type", actualVnfmInfo.getType());
176 assertEquals("vendor", actualVnfmInfo.getVendor());
177 assertEquals("v123", actualVnfmInfo.getVersion());
178 assertEquals(VIM_ID, actualVnfmInfo.getVimId());
179 assertEquals(VNFM_ID, actualVnfmInfo.getVnfmId());
183 * unable to query VNFM from AAI results in error
186 public void testVnfmUnableToQuery() throws Exception {
187 RuntimeException expectedException = new RuntimeException();
188 when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenThrow(expectedException);
191 aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
193 } catch (Exception e) {
194 verify(logger).error("Unable to query VNFM with " + VNFM_ID + " identifier from AAI", expectedException);
195 assertEquals(expectedException, e.getCause());