3 * * ============LICENSE_START=======================================================
4 * * Copyright (C) 2019 Nordix Foundation.
5 * * ================================================================================
6 * * Licensed under the Apache License, Version 2.0 (the "License");
7 * * you may not use this file except in compliance with the License.
8 * * You may obtain a copy of the License at
10 * * http://www.apache.org/licenses/LICENSE-2.0
12 * * Unless required by applicable law or agreed to in writing, software
13 * * distributed under the License is distributed on an "AS IS" BASIS,
14 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * * See the License for the specific language governing permissions and
16 * * limitations under the License.
18 * * SPDX-License-Identifier: Apache-2.0
19 * * ============LICENSE_END=========================================================
23 package org.openecomp.sdc.be.components.impl;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.dao.api.ActionStatus;
32 import org.openecomp.sdc.be.dao.impl.MonitoringDao;
33 import org.openecomp.sdc.be.impl.ComponentsUtils;
34 import org.openecomp.sdc.common.monitoring.MonitoringEvent;
35 import org.openecomp.sdc.exception.ResponseFormat;
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertTrue;
39 import static org.mockito.ArgumentMatchers.any;
40 import static org.mockito.Mockito.when;
42 public class MonitoringBusinessLogicTest {
44 private MonitoringEvent event;
47 MonitoringBusinessLogic monitoringBusinessLogic;
50 private MonitoringDao monitoringDao;
53 private ComponentsUtils componentsUtils;
56 public void setUp() throws Exception {
57 monitoringBusinessLogic = new MonitoringBusinessLogic();
58 MockitoAnnotations.initMocks(this);
59 event = new MonitoringEvent();
63 public void testLogMonitoringEvent_returnsSuccessful() {
64 Mockito.when(monitoringDao.addRecord(any(MonitoringEvent.class))).thenReturn(ActionStatus.OK);
65 assertTrue(monitoringBusinessLogic.logMonitoringEvent(event).isLeft());
69 public void testLogMonitoringEvent_returnsError() {
70 Mockito.when(monitoringDao.addRecord(any(MonitoringEvent.class))).thenReturn(ActionStatus.GENERAL_ERROR);
71 Mockito.when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
72 assertTrue(monitoringBusinessLogic.logMonitoringEvent(event).isRight());
76 public void testGetEsPort(){
77 when(monitoringDao.getEsPort()).thenReturn("10");
78 String port = monitoringBusinessLogic.getEsPort();
79 assertEquals("10", port);
83 public void testGetHost(){
84 Mockito.when(monitoringDao.getEsHost()).thenReturn("['127.0.0.1', '[::1]']");
85 assertEquals("127.0.0.1", monitoringBusinessLogic.getEsHost());