X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FPolicyDBDaoTest.java;h=07c30909ac3b4fbaf56ad0407464b37d9d827d8d;hp=0e89a7085483199eebb3ad930a9e84a0c5647da7;hb=c2ca6ea5cb44103903e1409e8dd6db80167e61e8;hpb=97ce3b94390c10a1af43ed5614ca976095c0097d diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java index 0e89a7085..07c30909a 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java @@ -21,8 +21,10 @@ package org.onap.policy.pap.xacml.rest.components; import static org.junit.Assert.fail; + import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.util.XACMLProperties; + import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -30,7 +32,12 @@ import java.nio.file.Paths; import java.util.Date; import java.util.List; import java.util.Properties; +import javax.persistence.Persistence; import javax.persistence.PersistenceException; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; @@ -48,7 +55,7 @@ import org.onap.policy.pap.xacml.rest.DataToNotifyPdp; import org.onap.policy.pap.xacml.rest.components.PolicyDBDao.PolicyDBDaoTestClass; import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation; -import org.onap.policy.rest.XACMLRestProperties; +import org.onap.policy.rest.XacmlRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.PolicyDBException; import org.onap.policy.rest.jpa.DatabaseLockEntity; @@ -60,8 +67,6 @@ import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.std.pap.StdEngine; import org.onap.policy.xacml.std.pap.StdPDPGroup; import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; public class PolicyDBDaoTest { private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class); @@ -101,6 +106,8 @@ public class PolicyDBDaoTest { } public static SessionFactory setupH2DbDaoImpl(String dbName) { + setUpAuditDb(); + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pap.properties"); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); @@ -119,7 +126,8 @@ public class PolicyDBDaoTest { SessionFactory sessionFac = sessionBuilder.buildSessionFactory(); new PolicyDBDao(sessionFac); - new PolicyDbDaoTransactionInstance(sessionFac).isJunit = true; + PolicyDbDaoTransactionInstance.setJunit(true); + new PolicyDbDaoTransactionInstance(sessionFac); CommonClassDaoImpl.setSessionfactory(sessionFac); new DataToNotifyPdp(new CommonClassDaoImpl()); PolicyCreation.setCommonClassDao(new CommonClassDaoImpl()); @@ -150,6 +158,16 @@ public class PolicyDBDaoTest { return sessionFac; } + private static void setUpAuditDb() { + Properties properties = new Properties(); + properties.put(XacmlRestProperties.PROP_PAP_DB_DRIVER, "org.h2.Driver"); + properties.put(XacmlRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest"); + properties.put(XacmlRestProperties.PROP_PAP_DB_USER, "sa"); + properties.put(XacmlRestProperties.PROP_PAP_DB_PASSWORD, ""); + + // create the DB and then close it + Persistence.createEntityManagerFactory("testPapPU", properties).close(); + } @Test public void testGetConfigFile() { @@ -323,7 +341,6 @@ public class PolicyDBDaoTest { session2.getTransaction().commit(); session2.close(); - // add a pdp to a group group = dbd.getNewTransaction(); try { @@ -362,7 +379,6 @@ public class PolicyDBDaoTest { session3.getTransaction().commit(); session3.close(); - group = dbd.getNewTransaction(); try { group.removePdpFromGroup("http://localhost:4344/pdp/", "testuser"); @@ -440,7 +456,6 @@ public class PolicyDBDaoTest { session5.getTransaction().commit(); session5.close(); - group = dbd.getNewTransaction(); try { OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"), Paths.get("/")); @@ -480,7 +495,6 @@ public class PolicyDBDaoTest { session7.getTransaction().commit(); session7.close(); - group = dbd.getNewTransaction(); try { OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"), Paths.get("/")); @@ -554,7 +568,7 @@ public class PolicyDBDaoTest { try { // Add 1000 ms to the timeout just to be sure it actually times out int sleepTime = - Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; + Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; if (logger.isDebugEnabled()) { Date date = new java.util.Date(); logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + "\n sleepTime = " + sleepTime @@ -572,7 +586,6 @@ public class PolicyDBDaoTest { } Assert.assertFalse(t.isTransactionOpen()); - if (logger.isDebugEnabled()) { Date date = new java.util.Date(); logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + "\n a = dbd.getNewTransaction() " @@ -590,7 +603,7 @@ public class PolicyDBDaoTest { try { // Add 1000 ms to the timeout just to be sure it actually times out int sleepTime = - Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; + Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; if (logger.isDebugEnabled()) { Date date = new java.util.Date(); logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + "\n sleepTime = " + sleepTime @@ -622,12 +635,10 @@ public class PolicyDBDaoTest { Assert.assertTrue(b.isTransactionOpen()); b.close(); - - // Now let's test the transaction wait time timeout. Shorten the wait time to 1000 ms - System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT, "1000"); + System.setProperty(XacmlRestProperties.PROP_PAP_TRANS_WAIT, "1000"); // And let's lengthen the transaction timeout to 5000 ms - System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT, "5000"); + System.setProperty(XacmlRestProperties.PROP_PAP_TRANS_TIMEOUT, "5000"); // get a transacton PolicyDBDaoTransaction t1 = dbd.getNewTransaction(); if (logger.isDebugEnabled()) {