CSIT Fix for SDC-2585
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / MonitoringBusinessLogicTest.java
1 /*
2  * -
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
9  *  *
10  *  *      http://www.apache.org/licenses/LICENSE-2.0
11  *  *
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.
17  *  *
18  *  * SPDX-License-Identifier: Apache-2.0
19  *  * ============LICENSE_END=========================================================
20  *
21  */
22
23 package org.openecomp.sdc.be.components.impl;
24
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;
36
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;
41
42 public class MonitoringBusinessLogicTest {
43
44     private MonitoringEvent event;
45
46     @InjectMocks
47     MonitoringBusinessLogic monitoringBusinessLogic;
48
49     @Mock
50     private MonitoringDao monitoringDao;
51
52     @Mock
53     private ComponentsUtils componentsUtils;
54
55     @Before
56     public void setUp() throws Exception {
57         monitoringBusinessLogic = new MonitoringBusinessLogic();
58         MockitoAnnotations.initMocks(this);
59         event = new MonitoringEvent();
60     }
61
62     @Test
63     public void testLogMonitoringEvent_returnsSuccessful() {
64         Mockito.when(monitoringDao.addRecord(any(MonitoringEvent.class))).thenReturn(ActionStatus.OK);
65         assertTrue(monitoringBusinessLogic.logMonitoringEvent(event).isLeft());
66     }
67
68     @Test
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());
73     }
74
75     @Test
76     public void testGetEsPort(){
77         when(monitoringDao.getEsPort()).thenReturn("10");
78         String port = monitoringBusinessLogic.getEsPort();
79         assertEquals("10", port);
80     }
81
82     @Test
83     public void testGetHost(){
84         Mockito.when(monitoringDao.getEsHost()).thenReturn("['127.0.0.1', '[::1]']");
85         assertEquals("127.0.0.1", monitoringBusinessLogic.getEsHost());
86     }
87 }