X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ECOMP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FPolicyDBDaoTest.java;h=6cb8e071bc59bf79e4068fa1fe8143d7780d53a4;hb=7e547eaa55920dfbc9691eab33bb728395b50cf2;hp=81f33c99b9937d1aac0e9b1ee0b4973496868682;hpb=91d04c64771832a0b8815ffbe1f0f9920320d94d;p=policy%2Fengine.git diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java index 81f33c99b..6cb8e071b 100644 --- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java @@ -36,41 +36,34 @@ import javax.persistence.Persistence; import javax.persistence.PersistenceException; import javax.persistence.Query; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.After; +import org.junit.Assert; +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; -import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; -import org.openecomp.policy.pap.xacml.rest.components.ConfigPolicy; -import org.openecomp.policy.pap.xacml.rest.components.Policy; -import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao; -import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDaoTransaction; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao.PolicyDBDaoTestClass; import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.adapter.PolicyRestAdapter; import org.openecomp.policy.rest.jpa.ActionBodyEntity; import org.openecomp.policy.rest.jpa.GroupEntity; import org.openecomp.policy.rest.jpa.PdpEntity; import org.openecomp.policy.rest.jpa.PolicyEntity; import org.openecomp.policy.rest.util.Webapps; - -import com.att.research.xacml.api.pap.PAPException; - import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; import org.openecomp.policy.xacml.std.pap.StdPDPGroup; import org.openecomp.policy.xacml.util.XACMLPolicyWriter; -import com.att.research.xacml.util.XACMLProperties; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -//import org.apache.commons.logging.Log; -//import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.After; -import org.junit.Ignore; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.util.XACMLProperties; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; -import org.junit.Assert; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - @Ignore //only run locally as timing sometimes causes failures on Jenkins public class PolicyDBDaoTest { @@ -96,7 +89,7 @@ public class PolicyDBDaoTest { em.getTransaction().commit(); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); em.getTransaction().rollback(); } em.close(); @@ -104,7 +97,7 @@ public class PolicyDBDaoTest { dbd = PolicyDBDao.getPolicyDBDaoInstance(emf); dbd2 = PolicyDBDao.getPolicyDBDaoInstance(emf); } catch (Exception e) { - //e.printStackTrace(); + //logger.error("Exception Occured"+e); Assert.fail(); } @@ -180,14 +173,14 @@ public class PolicyDBDaoTest { // Assert.fail(); // } String filePath = null; - String xmlFile = "\n\n \n \n \n \n \n 99\n \n \n \n \n \n \n \n \n \n \n PDPAction\n \n \n REST\n \n \n http://localhost:8056/pcd\n \n \n GET\n \n \n $URLaction/com.Action_patbaction7.json\n \n \n \n \n\n"; + String xmlFile = "\n\n \n \n \n \n \n 99\n \n \n \n \n \n \n \n \n \n \n PDPAction\n \n \n REST\n \n \n http://localhost:8056/pcd\n \n \n GET\n \n \n $URLaction/com.Action_patbaction7.json\n \n \n \n \n\n"; String jsonFile = "{\"actionAttribute\":\"Memory\"}"; try{ //policy file InputStream in = new ByteArrayInputStream(xmlFile.getBytes()); String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); - FileUtils.forceMkdir(new File(workspaceDir+"/org/openecomp")); + FileUtils.forceMkdir(new File(workspaceDir+"/com/att")); File outFile = new File(workspaceDir+"/org/openecomp/Action_mypol.xml"); OutputStream out = new FileOutputStream(outFile); IOUtils.copy(in, out); @@ -224,7 +217,7 @@ public class PolicyDBDaoTest { try{ result = (PolicyEntity)getDataQuery.getSingleResult(); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } Assert.assertEquals(xmlFile, result.getPolicyData()); @@ -235,7 +228,7 @@ public class PolicyDBDaoTest { transac = dbd.getNewTransaction(); transac.deletePolicy(filePath); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } Assert.assertTrue(transac.isTransactionOpen()); @@ -253,7 +246,7 @@ public class PolicyDBDaoTest { transac = dbd.getNewTransaction(); transac.deletePolicy(filePath); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } transac.commitTransaction(); @@ -283,7 +276,7 @@ public class PolicyDBDaoTest { } willFail.close(); - fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"org/openecomp/Action_mypol2.xml"); + fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"com/att/Action_mypol2.xml"); willFail = dbd.getNewTransaction(); try{ willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); @@ -319,7 +312,7 @@ public class PolicyDBDaoTest { @Test public void createFromPolicyObject(){ String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); - File parentPath = new File(workspaceDir+"/org/openecomp"); + File parentPath = new File(workspaceDir+"/com/att"); File scope = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); Policy policyObject = new ConfigPolicy(); policyObject.policyAdapter = new PolicyRestAdapter(); @@ -350,7 +343,7 @@ public class PolicyDBDaoTest { try{ result = (PolicyEntity)getDataQuery.getSingleResult(); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } String expectedData; @@ -367,7 +360,7 @@ public class PolicyDBDaoTest { transaction = dbd.getNewTransaction(); transaction.deletePolicy(policyFile.getAbsolutePath()); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } Assert.assertTrue(transaction.isTransactionOpen()); @@ -385,7 +378,7 @@ public class PolicyDBDaoTest { transaction = dbd.getNewTransaction(); transaction.deletePolicy(policyFile.getAbsolutePath()); } catch(Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } //Assert.assertFalse(transaction.isTransactionOpen()); @@ -401,7 +394,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } EntityManager em = emf.createEntityManager(); @@ -423,7 +416,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } em = emf.createEntityManager(); @@ -443,7 +436,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } group = dbd.getNewTransaction(); @@ -452,7 +445,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } em = emf.createEntityManager(); @@ -474,7 +467,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } em = emf.createEntityManager(); @@ -495,7 +488,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } group = dbd.getNewTransaction(); @@ -504,7 +497,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } @@ -514,7 +507,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } group = dbd.getNewTransaction(); @@ -523,7 +516,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } em = emf.createEntityManager(); @@ -543,7 +536,7 @@ public class PolicyDBDaoTest { group.commitTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } em = emf.createEntityManager(); @@ -578,7 +571,7 @@ public class PolicyDBDaoTest { group.rollbackTransaction(); } catch(Exception e){ group.rollbackTransaction(); - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } @@ -592,7 +585,7 @@ public class PolicyDBDaoTest { group.updateGroup(pdpGroup, "testuser"); group.commitTransaction(); }catch (Exception e){ - e.printStackTrace(); + logger.error("Exception Occured"+e); group.rollbackTransaction(); Assert.fail(); } @@ -635,8 +628,7 @@ public class PolicyDBDaoTest { System.out.println("Decrypted password: "+decr); Assert.assertEquals("testpassword", decr); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); } @@ -670,8 +662,7 @@ public class PolicyDBDaoTest { } Thread.sleep(sleepTime); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("Exception Occured"+e); } if(logger.isDebugEnabled()){ Date date= new java.util.Date(); @@ -712,8 +703,7 @@ public class PolicyDBDaoTest { } Thread.sleep(sleepTime); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("Exception Occured"+e); } if(logger.isDebugEnabled()){ Date date= new java.util.Date(); @@ -808,7 +798,7 @@ public class PolicyDBDaoTest { + "\n TimeStamp = " + date.getTime() + "\n\n"); } - e.printStackTrace(); + logger.error("Exception Occured"+e); Assert.fail(); }