aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST
diff options
context:
space:
mode:
authorPeyton Puckett <peyton.puckett@att.com>2020-02-18 15:59:17 -0600
committerPeyton Puckett <pp5762@att.com>2020-02-18 17:45:50 -0600
commit9a03ea31d42b8a73c3aa8f96bbad85093cb169a7 (patch)
tree7ec86476197440450bb55d977b773f504fc19d2b /ONAP-PAP-REST
parent9f774daf0c3e317c9542c9fe4108772006b267a9 (diff)
Update policy-engine to fix failing jUnit tests after jdk11 upgrade
Issue-ID: POLICY-1590 Change-Id: I9f5a05112d943d7f3b6b0e807bf6ae4f2b993e55 Signed-off-by: Peyton Puckett <peyton.puckett@att.com> Signed-off-by: Peyton Puckett <pp5762@att.com>
Diffstat (limited to 'ONAP-PAP-REST')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreationTest.java24
1 files changed, 24 insertions, 0 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))