d3da7c86ecc968e3b41a73e230f90fddb24b0e81
[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.junit.Assert.assertNull;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import java.util.Collections;
28 import java.util.List;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.aai.domain.yang.EsrSystemInfo;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class SubscriptionSchedulerTest {
38
39     private static final String URL = "url";
40     private static final String ID = "id044";
41
42     @Mock
43     private SubscriberService subscriberService;
44
45     @InjectMocks
46     private SubscriptionScheduler subscriptionScheduler;
47
48     @Test
49     public void testFullScenario() throws Exception {
50         // given
51         final EsrSystemInfo info = new EsrSystemInfo();
52         info.setServiceUrl(URL);
53         final List<EsrSystemInfo> infos = Collections.singletonList(info);
54
55         when(subscriberService.subscribe(eq(info))).thenReturn(ID);
56         when(subscriberService.checkSubscription(eq(info), eq(ID))).thenReturn(false);
57
58         // when
59         subscriptionScheduler.setInfos(infos);
60         subscriptionScheduler.subscribeTask();
61         subscriptionScheduler.checkSubscribeTask();
62
63         // then
64         verify(subscriberService).subscribe(info);
65         verify(subscriberService).checkSubscription(info, ID);
66
67         assertNull(subscriptionScheduler.getEsrIds().get(0).getId());
68     }
69 }