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=e4da430a57c75532baf67341a8413dbf9daa3244;hb=c2ca6ea5cb44103903e1409e8dd6db80167e61e8;hpb=86554962a34c4e7c16821f91a12242a4ffb36368 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 e4da430a5..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,12 +32,12 @@ import java.nio.file.Paths; import java.util.Date; import java.util.List; import java.util.Properties; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; 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; @@ -53,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; @@ -156,13 +158,12 @@ 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, ""); + 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(); @@ -340,7 +341,6 @@ public class PolicyDBDaoTest { session2.getTransaction().commit(); session2.close(); - // add a pdp to a group group = dbd.getNewTransaction(); try { @@ -379,7 +379,6 @@ public class PolicyDBDaoTest { session3.getTransaction().commit(); session3.close(); - group = dbd.getNewTransaction(); try { group.removePdpFromGroup("http://localhost:4344/pdp/", "testuser"); @@ -457,7 +456,6 @@ public class PolicyDBDaoTest { session5.getTransaction().commit(); session5.close(); - group = dbd.getNewTransaction(); try { OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"), Paths.get("/")); @@ -497,7 +495,6 @@ public class PolicyDBDaoTest { session7.getTransaction().commit(); session7.close(); - group = dbd.getNewTransaction(); try { OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"), Paths.get("/")); @@ -571,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 @@ -589,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() " @@ -607,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 @@ -639,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()) {