2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.vid.services;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.vid.aai.AaiClient;
29 import org.onap.vid.aai.AaiOverTLSClient;
30 import org.onap.vid.model.probes.ExternalComponentStatus;
31 import org.onap.vid.model.probes.StatusMetadata;
32 import org.onap.vid.mso.MsoBusinessLogic;
33 import org.onap.vid.scheduler.SchedulerService;
35 import javax.inject.Inject;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
40 import static org.assertj.core.api.Assertions.assertThat;
41 import static org.mockito.Mockito.mock;
42 import static org.mockito.Mockito.when;
44 @RunWith(MockitoJUnitRunner.class)
45 public class ProbeServiceTest {
47 private AaiClient aaiClient;
48 private AaiOverTLSClient newAaiClient;
49 private SchedulerService schedulerService;
50 private MsoBusinessLogic msoBusinessLogic;
51 private VidService vidService;
52 private List<ProbeInterface> probeInterfaces;
53 private ProbeService probeService;
56 public void setUp() throws Exception {
57 aaiClient = mock(AaiClient.class);
58 newAaiClient = mock(AaiOverTLSClient.class);
59 schedulerService = mock(SchedulerService.class);
60 msoBusinessLogic = mock(MsoBusinessLogic.class);
61 vidService = mock(VidService.class);
63 probeInterfaces = Arrays.asList(aaiClient, newAaiClient, schedulerService, msoBusinessLogic, vidService);
64 probeService = new ProbeService(probeInterfaces);
68 public void shouldGetProbes() {
70 StatusMetadata statusMetadata = mock(StatusMetadata.class);
72 ExternalComponentStatus statusAai =
73 new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, true, statusMetadata);
74 ExternalComponentStatus statusScheduler =
75 new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, false, statusMetadata);
76 ExternalComponentStatus statusMso =
77 new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, true, statusMetadata);
78 ExternalComponentStatus statusSdc =
79 new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, false, statusMetadata);
81 List<ExternalComponentStatus> expectedStatuses =
82 Arrays.asList(statusAai, statusAai, statusScheduler, statusMso, statusSdc);
84 when(aaiClient.probeComponent()).thenReturn(statusAai);
85 when(newAaiClient.probeComponent()).thenReturn(statusAai);
86 when(schedulerService.probeComponent()).thenReturn(statusScheduler);
87 when(msoBusinessLogic.probeComponent()).thenReturn(statusMso);
88 when(vidService.probeComponent()).thenReturn(statusSdc);
91 List<ExternalComponentStatus> actualStatuses = probeService.getProbe();
94 assertThat(actualStatuses).isEqualTo(expectedStatuses);