8c480d04158727e93a93265beeac390d87c68997
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
4  * ================================================================================
5  * Copyright (C) 2020 Samsung. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vevnfm.service;
22
23 import static org.mockito.Mockito.*;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.so.adapters.vevnfm.aai.AaiConnection;
30 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
31
32 @RunWith(MockitoJUnitRunner.class)
33 public class StartupServiceTest {
34
35     @Mock
36     private AaiConnection aaiConnection;
37
38     @Mock
39     private SubscriberService subscriberService;
40
41     @InjectMocks
42     private StartupService startupService;
43
44     @Test
45     public void testSuccess() throws Exception {
46         // given
47         final String endpoint = "lh";
48
49         when(aaiConnection.receiveVnfm()).thenReturn(endpoint);
50         when(subscriberService.subscribe(endpoint)).thenReturn(true);
51
52         // when
53         startupService.run();
54
55         // then
56         verify(aaiConnection, times(1)).receiveVnfm();
57         verify(subscriberService, times(1)).subscribe(endpoint);
58     }
59
60     @Test(expected = VeVnfmException.class)
61     public void testFailureAai() throws Exception {
62         // given
63         when(aaiConnection.receiveVnfm()).thenReturn(null);
64
65         // when
66         startupService.run();
67     }
68
69     @Test(expected = VeVnfmException.class)
70     public void testFailureSubscriber() throws Exception {
71         // given
72         final String endpoint = "lh";
73
74         when(aaiConnection.receiveVnfm()).thenReturn(endpoint);
75         when(subscriberService.subscribe(endpoint)).thenReturn(false);
76
77         // when
78         startupService.run();
79     }
80 }