X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fpolicycontroller%2FPolicyCreationTest.java;h=c182b9bb5f0be12f79644299dd37f3d9bac75595;hb=refs%2Fchanges%2F33%2F101933%2F3;hp=08c1659f9fe40ef540608530d2476afe1bb4c7bb;hpb=2f41a033ed0eae09aa1624d8287687de8a972a5d;p=policy%2Fengine.git 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 08c1659f9..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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,19 +23,29 @@ package org.onap.policy.pap.xacml.rest.policycontroller; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyString; +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; @@ -90,6 +100,22 @@ public class PolicyCreationTest { assertThatThrownBy(() -> creation.savePolicy(policyData, response)) .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))