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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
22 import org.onap.vnfmdriver.model.VimInfo;
23 import org.onap.vnfmdriver.model.VnfmInfo;
24 import org.springframework.test.util.ReflectionTestUtils;
25 import retrofit2.Call;
27 import static junit.framework.TestCase.assertEquals;
28 import static junit.framework.TestCase.fail;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 public class TestVfcExternalSystemInfoProvider extends TestBase {
33 private VfcExternalSystemInfoProvider vfcExternalSystemInfoProvider;
37 vfcExternalSystemInfoProvider = new VfcExternalSystemInfoProvider(environment, vfcRestApiProvider);
38 ReflectionTestUtils.setField(VfcExternalSystemInfoProvider.class, "logger", logger);
42 * VIM is queried using VF-C APIs
45 public void testVimRetrieval() throws Exception {
46 VimInfo expectedVimInfo = new VimInfo();
47 Call<VimInfo> vimInfoCall = buildCall(expectedVimInfo);
48 when(nsLcmApi.queryVIMInfo(VIM_ID)).thenReturn(vimInfoCall);
50 VimInfo vimInfo = vfcExternalSystemInfoProvider.getVimInfo(VIM_ID);
52 assertEquals(expectedVimInfo, vimInfo);
56 * failure to retrieve VIM from VF-C is propagated
59 public void testUnableToQueryVim() throws Exception {
60 RuntimeException expectedException = new RuntimeException();
61 when(nsLcmApi.queryVIMInfo(VIM_ID)).thenThrow(expectedException);
64 vfcExternalSystemInfoProvider.getVimInfo(VIM_ID);
66 } catch (Exception e) {
67 assertEquals("Unable to query VIM from VF-C with " + VIM_ID + " identifier", e.getMessage());
68 verify(logger).error("Unable to query VIM from VF-C with " + VIM_ID + " identifier", expectedException);
73 * VNFM is queried using VF-C APIs
76 public void testVnfmRetrieval() throws Exception {
77 VnfmInfo expectedVimInfo = new VnfmInfo();
78 Call<VnfmInfo> vnfmInfoCall = buildCall(expectedVimInfo);
79 when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(vnfmInfoCall);
81 VnfmInfo vimInfo = vfcExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
83 assertEquals(expectedVimInfo, vimInfo);
87 * failure to retrieve VNFM from VF-C is propagated
90 public void testUnableToQueryVnfm() throws Exception {
91 RuntimeException expectedException = new RuntimeException();
92 when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenThrow(expectedException);
95 vfcExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
97 } catch (Exception e) {
98 assertEquals("Unable to query VNFM from VF-C with myVnfmId identifier", e.getMessage());
99 verify(logger).error("Unable to query VNFM from VF-C with myVnfmId identifier", expectedException);