From 9a03ea31d42b8a73c3aa8f96bbad85093cb169a7 Mon Sep 17 00:00:00 2001 From: Peyton Puckett Date: Tue, 18 Feb 2020 15:59:17 -0600 Subject: Update policy-engine to fix failing jUnit tests after jdk11 upgrade Issue-ID: POLICY-1590 Change-Id: I9f5a05112d943d7f3b6b0e807bf6ae4f2b993e55 Signed-off-by: Peyton Puckett Signed-off-by: Peyton Puckett --- .../rest/policycontroller/PolicyCreationTest.java | 24 ++++++++++++++++++++++ POLICY-SDK-APP/pom.xml | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java index 0c029b433..c182b9bb5 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java @@ -29,14 +29,23 @@ import static org.mockito.ArgumentMatchers.eq; import com.mockrunner.mock.web.MockHttpServletRequest; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.junit.Test; import org.mockito.Mockito; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDao; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDaoTransaction; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.rest.jpa.PolicyVersion; +import org.powermock.reflect.Whitebox; import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.mock.web.MockHttpServletResponse; @@ -92,6 +101,21 @@ public class PolicyCreationTest { .isInstanceOf(IllegalArgumentException.class); policyData.setConfigPolicyType("Base"); Mockito.when(policyData.getRuleData()).thenReturn(new LinkedHashMap<>()); + + SessionFactory mockSessionFactory = Mockito.mock(SessionFactory.class); + Session mockSession = Mockito.mock(Session.class); + Criteria mockCriteria = Mockito.mock(Criteria.class); + List policyDbDaoEntityList = new LinkedList<>(); + + Mockito.when(mockSessionFactory.openSession()).thenReturn(mockSession); + Mockito.when(mockSession.createCriteria(PolicyDbDaoEntity.class)).thenReturn(mockCriteria); + Mockito.when(mockCriteria.list()).thenReturn(policyDbDaoEntityList); + Whitebox.setInternalState(PolicyDbDao.class, "sessionfactory", mockSessionFactory); + + PolicyDbDao mockPolicyDbDao = Mockito.mock(PolicyDbDao.class); + PolicyDbDaoTransaction mockTransaction = Mockito.mock(PolicyDbDaoTransaction.class); + Mockito.when(mockPolicyDbDao.getNewTransaction()).thenReturn(mockTransaction); + assertThatCode(() -> creation.savePolicy(policyData, response)).doesNotThrowAnyException(); policyData.setConfigPolicyType("ClosedLoop_PM"); assertThatThrownBy(() -> creation.savePolicy(policyData, response)) diff --git a/POLICY-SDK-APP/pom.xml b/POLICY-SDK-APP/pom.xml index 14179fafc..aa02984e4 100644 --- a/POLICY-SDK-APP/pom.xml +++ b/POLICY-SDK-APP/pom.xml @@ -274,12 +274,12 @@ org.apache.poi poi - 3.17 + 4.1.1 org.apache.poi poi-ooxml - 3.17 + 4.1.1 org.apache.xmlbeans -- cgit 1.2.3-korg