2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T 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=========================================================
21 package org.onap.policy.daoImp;
23 import static org.junit.Assert.assertNull;
24 import static org.mockito.Mockito.doThrow;
25 import static org.mockito.Mockito.when;
27 import java.util.List;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.policy.conf.HibernateSession;
36 import org.onap.policy.controller.PolicyController;
37 import org.onap.policy.rest.jpa.SystemLogDb;
39 public class SystemLogDbDaoImplTest {
40 private static Session mockSession = Mockito.mock(Session.class);
41 private static SessionFactory sfMock = Mockito.mock(SessionFactory.class);
42 private static Transaction mockTransaction = Mockito.mock(Transaction.class);
43 private SystemLogDbDaoImpl sysLogImpl = new SystemLogDbDaoImpl();
45 @SuppressWarnings("unchecked")
47 public static void setup() {
48 HibernateSession.setSession(sfMock);
50 when(sfMock.openSession()).thenReturn(mockSession);
51 when(mockSession.beginTransaction()).thenReturn(mockTransaction);
53 doThrow(Exception.class).when(mockTransaction).commit();
54 when(mockSession.close()).thenThrow(Exception.class);
56 PolicyController.setjUnit(true);
60 public void testGettingLoggingData() {
61 List<SystemLogDb> loggingData = sysLogImpl.getLoggingData();
62 assertNull(loggingData);
66 public void testGetSystemAlertData() {
67 List<SystemLogDb> systemAlertData = sysLogImpl.getSystemAlertData();
68 assertNull(systemAlertData);
72 public static void resetjUnit() {
73 PolicyController.setjUnit(false);