0b49b9177f54bd40b98ef2dc15d66d79d82412cf
[vfc/nfvo/driver/vnfm/svnfm.git] /
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
18
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
26 import static junit.framework.TestCase.assertEquals;
27 import static junit.framework.TestCase.fail;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 public class TestVfcExternalSystemInfoProvider extends TestBase {
32     private VfcExternalSystemInfoProvider vfcExternalSystemInfoProvider;
33
34     @Before
35     public void init() {
36         vfcExternalSystemInfoProvider = new VfcExternalSystemInfoProvider(environment, vfcRestApiProvider);
37         ReflectionTestUtils.setField(VfcExternalSystemInfoProvider.class, "logger", logger);
38     }
39
40     /**
41      * VIM is queried using VF-C APIs
42      */
43     @Test
44     public void testVimRetrieval() throws Exception {
45         VimInfo expectedVimInfo = new VimInfo();
46         when(nsLcmApi.queryVIMInfo(VIM_ID)).thenReturn(buildObservable(expectedVimInfo));
47         //when
48         VimInfo vimInfo = vfcExternalSystemInfoProvider.getVimInfo(VIM_ID);
49         //verify
50         assertEquals(expectedVimInfo, vimInfo);
51     }
52
53     /**
54      * failure to retrieve VIM from VF-C is propagated
55      */
56     @Test
57     public void testUnableToQueryVim() throws Exception {
58         RuntimeException expectedException = new RuntimeException();
59         when(nsLcmApi.queryVIMInfo(VIM_ID)).thenThrow(expectedException);
60         //when
61         try {
62             vfcExternalSystemInfoProvider.getVimInfo(VIM_ID);
63             fail();
64         } catch (Exception e) {
65             assertEquals("Unable to query VIM from VF-C with " + VIM_ID + " identifier", e.getMessage());
66             verify(logger).error("Unable to query VIM from VF-C with " + VIM_ID + " identifier", expectedException);
67         }
68     }
69
70     /**
71      * VNFM is queried using VF-C APIs
72      */
73     @Test
74     public void testVnfmRetrieval() throws Exception {
75         VnfmInfo expectedVimInfo = new VnfmInfo();
76         when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenReturn(buildObservable(expectedVimInfo));
77         //when
78         VnfmInfo vimInfo = vfcExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
79         //verify
80         assertEquals(expectedVimInfo, vimInfo);
81     }
82
83     /**
84      * failure to retrieve VNFM from VF-C is propagated
85      */
86     @Test
87     public void testUnableToQueryVnfm() throws Exception {
88         RuntimeException expectedException = new RuntimeException();
89         when(nsLcmApi.queryVnfmInfo(VNFM_ID)).thenThrow(expectedException);
90         //when
91         try {
92             vfcExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
93             fail();
94         } catch (Exception e) {
95             assertEquals("Unable to query VNFM from VF-C with myVnfmId identifier", e.getMessage());
96             verify(logger).error("Unable to query VNFM from VF-C with myVnfmId identifier", expectedException);
97         }
98     }
99 }