2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 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;
29 import org.hibernate.HibernateException;
30 import org.hibernate.Session;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.Transaction;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.policy.conf.HibernateSession;
38 import org.onap.policy.controller.PolicyController;
39 import org.onap.policy.rest.jpa.SystemLogDb;
41 public class SystemLogDbDaoImplTest {
42 private static Session mockSession = Mockito.mock(Session.class);
43 private static SessionFactory sfMock = Mockito.mock(SessionFactory.class);
44 private static Transaction mockTransaction = Mockito.mock(Transaction.class);
45 private SystemLogDbDaoImpl sysLogImpl = new SystemLogDbDaoImpl();
47 @SuppressWarnings("unchecked")
49 public static void setup() {
50 HibernateSession.setSession(sfMock);
52 when(sfMock.openSession()).thenReturn(mockSession);
53 when(mockSession.beginTransaction()).thenReturn(mockTransaction);
55 doThrow(HibernateException.class).when(mockTransaction).commit();
56 when(mockSession.close()).thenThrow(HibernateException.class);
58 PolicyController.setjUnit(true);
62 public void testGettingLoggingData() {
63 List<SystemLogDb> loggingData = sysLogImpl.getLoggingData();
64 assertNull(loggingData);
68 public void testGetSystemAlertData() {
69 List<SystemLogDb> systemAlertData = sysLogImpl.getSystemAlertData();
70 assertNull(systemAlertData);
74 public static void resetjUnit() {
75 PolicyController.setjUnit(false);