diff options
author | rb7147 <rb7147@att.com> | 2017-06-09 15:11:06 -0400 |
---|---|---|
committer | rb7147 <rb7147@att.com> | 2017-06-12 16:59:35 -0400 |
commit | 685ed1545ed28b777a3ba6e7d315b78f355154cb (patch) | |
tree | 1e37d639242c5f1e9cbf5623821f8498542b81dc /ECOMP-PAP-REST/src/test/java/org/openecomp | |
parent | fc5c07705edc4dcb7083b39116a43844bb6a1490 (diff) |
[Policy-20] getConfig & Policy resolved blockers
Change-Id: If08e4c90d419e8d6e1426d817a12dde5b7cafba3
Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PAP-REST/src/test/java/org/openecomp')
3 files changed, 16 insertions, 565 deletions
diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java index d3b5cbbea..3e1ef0469 100644 --- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java @@ -38,7 +38,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.openecomp.policy.common.ia.DbAudit; import org.openecomp.policy.common.ia.DbDAO; @@ -49,7 +48,6 @@ import org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity; import org.openecomp.policy.common.im.jpa.StateManagementEntity; import org.openecomp.policy.jpa.BackUpMonitorEntity; -@Ignore public class DbAuditCompareEntriesTest { private static Log logger = LogFactory.getLog(DbAuditCompareEntriesTest.class); @@ -123,7 +121,6 @@ public class DbAuditCompareEntriesTest { * Tests that a comparison between hashsets is successful if * the entries match */ - //@Ignore @Test public void runAllTests() throws Exception { logger.info("runAllTests: Entering"); @@ -152,7 +149,7 @@ public class DbAuditCompareEntriesTest { //There is only one entry IntegrityAuditEntity, but we will check anyway HashSet<String> classNameSet = dbDAO.getPersistenceClassNames(); for(String c : classNameSet){ - if (c.equals("org.openecomp.policy.common.ia.IntegrityAuditEntity")){ + if (c.equals("org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity")){ className = c; } } diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java deleted file mode 100644 index b87d99059..000000000 --- a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java +++ /dev/null @@ -1,369 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-PAP-REST - * ================================================================================ - * Copyright (C) 2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pap.xacml.rest; - -/*import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; -import javax.servlet.ServletConfig; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import junit.framework.TestCase; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; -import org.openecomp.policy.rest.XACMLRestProperties; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockServletConfig; - -import org.openecomp.policy.common.ia.IntegrityAudit; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - -public class XACMLPapServletTest extends TestCase{ - private static Logger logger = FlexLogger.getLogger(XACMLPapServletTest.class); - - private List<String> headers = new ArrayList<String>(); - - private HttpServletRequest httpServletRequest; - private HttpServletResponse httpServletResponse; - private ServletOutputStream mockOutput; - private ServletConfig servletConfig; - private XACMLPapServlet papServlet; - - - @Before - - public void setUp() throws IOException { - httpServletRequest = Mockito.mock(HttpServletRequest.class); - Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(null); - Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); - Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); - - - mockOutput = Mockito.mock(ServletOutputStream.class); - - //when(httpServletRequest.getPathInfo()).thenReturn("/lineup/world.xml"); - //HttpServletResponse httpResponse = new HttpServletResponse(); - httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); - - - //when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - servletConfig = Mockito.mock(MockServletConfig.class); - //Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); - //servletConfig - Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); - papServlet = new XACMLPapServlet(); - - Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pap.test.properties"); - - System.setProperty("xacml.PAP.papEngineFactory", "com.att.research.xacml.std.pap.StdEngineFactory"); - System.setProperty("xacml.pap.pdps", "pdps"); - System.setProperty("xacml.rest.pap.url", "http://localhost:8070/pap/"); - System.setProperty("xacml.rest.pap.initiate.pdp", "false"); - System.setProperty("xacml.rest.pdp.idfile", "testpdp.properties"); - System.setProperty("xacml.rest.pep.idfile", "client.properties"); - System.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); - System.setProperty("javax.persistence.jdbc.url", "jdbc:h2:file:./sql/xacmlTest"); - System.setProperty("javax.persistence.jdbc.user", "sa"); - System.setProperty("javax.persistence.jdbc.password", ""); - System.setProperty("xacml.rest.pap.jmx.url", "service:jmx:rmi:///jndi/rmi://localhost:9990/jmxrmi"); - System.setProperty("xacml.rest.pap.resource.name", "site_1.pap_1"); - System.setProperty("fp_monitor_interval", "30"); - System.setProperty("failed_counter_threshold", "3"); - System.setProperty("test_trans_interval", "10"); - System.setProperty("write_fpc_interval", "5"); - System.setProperty("com.sun.management.jmxremote.port", "9999"); - System.setProperty("dependency_groups", "site_1.logparser_1;site_1.adminconsole_1;site_1.elk_1"); - System.setProperty("site_name", "site_1"); - System.setProperty("node_type", "pap"); - } - - - * This method initializes and cleans the DB so the XACMLPapServlet will be able to instantiate an - * IntegrityAudit object which will use the DB. - - public void initializeDb(){ - logger.debug("initializeDb: enter"); - Properties cleanProperties = new Properties(); - cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver"); - cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest"); - cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa"); - cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, ""); - EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", cleanProperties); - - EntityManager em = emf.createEntityManager(); - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // Clean up the DB - em.createQuery("Delete from IntegrityAuditEntity").executeUpdate(); - - // commit transaction - et.commit(); - em.close(); - logger.debug("initializeDb: exit"); - } - - @Test - public void testInit() throws Exception{ - System.setProperty("integrity_audit_period_seconds", "0"); - initializeDb(); - try { - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - if(ia.isThreadInitialized()){ - assertTrue(true); - }else{ - fail(); - } - ia.stopAuditThread(); - // Allow time for the thread to stop - Thread.sleep(1000); - if(!ia.isThreadInitialized()){ - assertTrue(true); - }else{ - fail(); - } - } catch (Exception e) { - // TODO Auto-generated catch block - fail(); - } - } - - public void testDoGetPapTest(){ - try{ - Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test"); - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doGet(httpServletRequest, httpServletResponse); - logger.info(httpServletResponse.getStatus()); - - //Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); - }catch (Exception e){ - logger.info("testDoGetPapTest failed with message: " + e.getMessage()); - fail(); - } - assertTrue(true); - } - - - * Need to figure a way to get it to match any message string - * public void testDoGetPapTestFpcFailure(){ - try{ - Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test"); - Mockito.when(httpServletRequest.getHeader("THIS-IS-A-TEST")).thenReturn("FPC"); - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doGet(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, Mockito.anyString()); - }catch (Exception e){ - logger.info("testDoGetPapTestFpcFailure failed with message: " + e.getMessage()); - fail(); - } - assertTrue(true); - } - - public void testDoGetLocal(){ - try{ - Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("localhost"); - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doGet(httpServletRequest, httpServletResponse); - - logger.info(httpServletResponse.getStatus()); - Mockito.verify(httpServletResponse).setHeader("content-type", "application/json"); - Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); - }catch (Exception e){ - fail(); - } - - assertTrue(true); - } - - public void testDoGetNonLocal(){ - //return non-local host remote address, which is invalid - Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("0.0.0.0"); - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doGet(httpServletRequest, httpServletResponse); - logger.info(httpServletResponse.getStatus()); - String message = "Unknown PDP: from 0.0.0.0 us: null"; - - Mockito.verify(httpServletResponse).sendError(401, message); - - }catch (Exception e){ - fail(); - } - } - - public void testDoGetWithGroup() throws Exception{ - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); - //Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn("default"); - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doGet(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); - } - - public void testDoPostWithGroup(){ - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); - Mockito.when(httpServletRequest.getParameter("policyId")).thenReturn("default"); - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doPost(httpServletRequest, httpServletResponse); - //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': java.lang.NullPointerException"); - //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': javax.persistence.PersistenceException: Group policy is being added to does not exist with id default"); - - }catch (Exception e){ - fail(); - } - } - //why is this test trying to send no pdp id and expecting a 200 response? - - public void testDoPost(){ - final ByteArrayOutputStream os = new ByteArrayOutputStream (); - ByteArrayOutputStream multiPartResponse = new ByteArrayOutputStream(); - Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-JMX-PORT")).thenReturn("0"); - - try{ - multiPartResponse.writeTo(os); - final ByteArrayInputStream is = new ByteArrayInputStream (os.toByteArray ()); - Mockito.when(httpServletRequest.getInputStream()).thenReturn(new ServletInputStream() { - @Override - public int read() throws IOException { - return is.read(); - } - }); - - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doPost(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); - }catch (Exception e){ - fail(); - } - } - - - public void testDoPostPDPId(){ - String groupId = "newPDP"; - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(groupId); - Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn(groupId); - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doPut(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'"); - }catch(Exception e){ - fail(); - } - } - - public void testDoPutInvalidAdminConsoleURL(){ - Mockito.when(httpServletRequest.getParameter("adminConsoleURL")).thenReturn("wwww.adminConsole.com"); - //204 - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doPut(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT); - }catch (Exception e){ - fail(); - } - } - - public void testDoPutWithGroupIdAndUnimplimentedPipId(){ - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); - Mockito.when(httpServletRequest.getParameter("pipId")).thenReturn("default"); - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doPut(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); - }catch (Exception e){ - fail(); - } - } - - public void testDoDeleteNoGroup(){ - Mockito.when(httpServletRequest.getParameter("groupdId")).thenReturn(null); - - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doDelete(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId"); - }catch (Exception e){ - fail(); - } - } - - public void testDoDeleteWithDefaultGroup(){ - Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); - - try{ - papServlet.init(servletConfig); - IntegrityAudit ia = papServlet.getIa(); - ia.stopAuditThread(); - papServlet.doDelete(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"You cannot delete the default group."); - }catch(Exception e){ - fail(); - } - } -} -*/
\ No newline at end of file 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 6cb8e071b..9d7fae209 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 @@ -20,12 +20,8 @@ package org.openecomp.policy.pap.xacml.rest.components; -import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.nio.file.Paths; import java.util.Date; import java.util.List; @@ -50,11 +46,9 @@ 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 org.openecomp.policy.xacml.api.pap.EcompPDPGroup; import org.openecomp.policy.xacml.std.pap.StdPDPGroup; import org.openecomp.policy.xacml.util.XACMLPolicyWriter; @@ -64,7 +58,6 @@ import com.att.research.xacml.util.XACMLProperties; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; -@Ignore //only run locally as timing sometimes causes failures on Jenkins public class PolicyDBDaoTest { private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class); @@ -80,14 +73,14 @@ public class PolicyDBDaoTest { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); try{ - em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); - em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); - em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); - em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); - em.createQuery("DELETE FROM PdpEntity").executeUpdate(); - em.createQuery("DELETE FROM GroupEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); + em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); + em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); + em.createQuery("DELETE FROM PdpEntity").executeUpdate(); + em.createQuery("DELETE FROM GroupEntity").executeUpdate(); - em.getTransaction().commit(); + em.getTransaction().commit(); } catch(Exception e){ logger.error("Exception Occured"+e); em.getTransaction().rollback(); @@ -130,21 +123,6 @@ public class PolicyDBDaoTest { } @Test - public void getScopeAndNameAndTypeTest(){ - - String s = d.getGitPath(); - String pathIwantToUse; - if(s.contains("/")){ - pathIwantToUse = "/root/users/" + s + "/org/openecomp/Config_mypolicy.xml"; - } else { - pathIwantToUse = "C:\\root\\users\\" + s + "\\org\\openecomp\\Config_mypolicy.xml"; - } - String[] snt = d.getScopeAndNameAndType(pathIwantToUse); - Assert.assertEquals("Scope was parsed wrong","org.openecomp", snt[0]); - Assert.assertEquals("Policy name was parsed wrong","Config_mypolicy.xml", snt[1]); - Assert.assertEquals("Policy type was parsed wrong","Config", snt[2]); - } - @Test public void computeScopeTest(){ Assert.assertEquals("com",d.computeScope("C:\\Users\\testuser\\admin\\repo\\com\\", "C:\\Users\\testuser\\admin\\repo")); Assert.assertEquals("org.openecomp.policy",d.computeScope("/Users/testuser/admin/repo/org/openecomp/policy", "/Users/testuser/admin/repo")); @@ -160,176 +138,27 @@ public class PolicyDBDaoTest { Assert.assertEquals("org.openecomp.Action_mypolicy.json", configFile); } - @Test - public void transactionTests(){ - - -// try{ -// transac.commitTransaction(); -// Assert.fail(); -// } catch(IllegalStateException e){ -// //worked -// } catch(Exception e2){ -// Assert.fail(); -// } - String filePath = null; - String xmlFile = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<Policy xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" PolicyId=\"urn:com:xacml:policy:id:eaa4bb64-59cf-4517-bb44-b2eeabd50b11\" Version=\"1\" RuleCombiningAlgId=\"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides\">\n <Description></Description>\n <Target>\n <AnyOf>\n <AllOf>\n <Match MatchId=\"org.openecomp.labs.ecomp.function.regex-match\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">99</AttributeValue>\n <AttributeDesignator Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" AttributeId=\"cpu\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\" MustBePresent=\"false\"/>\n </Match>\n </AllOf>\n </AnyOf>\n </Target>\n <Rule RuleId=\"urn:com:xacml:rule:id:3350bf37-43d0-4a94-a317-febec81150d8\" Effect=\"Permit\">\n <Target/>\n <ObligationExpressions>\n <ObligationExpression ObligationId=\"test\" FulfillOn=\"Permit\">\n <AttributeAssignmentExpression AttributeId=\"performer\" Category=\"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">PDPAction</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"type\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">REST</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"url\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">http://localhost:8056/pcd</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"method\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">GET</AttributeValue>\n </AttributeAssignmentExpression>\n <AttributeAssignmentExpression AttributeId=\"body\" Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">\n <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">$URLaction/com.Action_patbaction7.json</AttributeValue>\n </AttributeAssignmentExpression>\n </ObligationExpression>\n </ObligationExpressions>\n </Rule>\n</Policy>\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+"/com/att")); - File outFile = new File(workspaceDir+"/org/openecomp/Action_mypol.xml"); - OutputStream out = new FileOutputStream(outFile); - IOUtils.copy(in, out); - filePath = outFile.getAbsolutePath(); - out.close(); - - //action body file - InputStream actionIn = new ByteArrayInputStream(jsonFile.getBytes()); - String webappDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE); - XACMLProperties.setProperty(XACMLRestProperties.PROP_PAP_WEBAPPS, webappDir); - String actionDir = Webapps.getActionHome(); - FileUtils.forceMkdir(new File(actionDir)); - File actionOutFile = new File(actionDir+"/org.openecomp.Action_mypol.json"); - OutputStream actionOut = new FileOutputStream(actionOutFile); - IOUtils.copy(actionIn, actionOut); - actionOut.close(); - - }catch(Exception e){ - //could not run test - } - PolicyDBDaoTransaction transac = dbd.getNewTransaction(); - if(filePath != null){ - try{ - transac.createPolicy(filePath, "tester"); - transac.commitTransaction(); - } catch(Exception e){ - Assert.fail(); - } - EntityManager getData = emf.createEntityManager(); - Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name"); - getDataQuery.setParameter("scope", "org.openecomp"); - getDataQuery.setParameter("name","Action_mypol.xml"); - PolicyEntity result = null; - try{ - result = (PolicyEntity)getDataQuery.getSingleResult(); - } catch(Exception e){ - logger.error("Exception Occured"+e); - Assert.fail(); - } - Assert.assertEquals(xmlFile, result.getPolicyData()); - getData.close(); - result = null; - xmlFile = null; - try{ - transac = dbd.getNewTransaction(); - transac.deletePolicy(filePath); - } catch(Exception e){ - logger.error("Exception Occured"+e); - Assert.fail(); - } - Assert.assertTrue(transac.isTransactionOpen()); - try{ - transac.deletePolicy(filePath); - Assert.fail(); - } catch(IllegalStateException e){ - //pass - } catch(Exception e){ - Assert.fail(); - } - transac.commitTransaction(); - //Assert.assertFalse(transac.isTransactionOpen()); - try{ - transac = dbd.getNewTransaction(); - transac.deletePolicy(filePath); - } catch(Exception e){ - logger.error("Exception Occured"+e); - Assert.fail(); - } - transac.commitTransaction(); - //Assert.assertFalse(transac.isTransactionOpen()); - String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); - PolicyDBDaoTransaction willFail = dbd.getNewTransaction(); - File fakeFile = new File("directorythatdoesnotexist/"+workspaceDir); - try{ - willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); - Assert.fail(); - } catch(IllegalArgumentException e){ - if(!e.getMessage().equals("The file path could not be parsed")){ - Assert.fail(); - } - } - willFail.close(); - - fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"/Action_mypol2.xml"); - willFail = dbd.getNewTransaction(); - try{ - willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); - Assert.fail(); - } catch(IllegalArgumentException e){ - if(!e.getMessage().equals("The file path could not be parsed")){ - Assert.fail(); - } - } - willFail.close(); - - fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"com/att/Action_mypol2.xml"); - willFail = dbd.getNewTransaction(); - try{ - willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); - Assert.fail(); - } catch(IllegalArgumentException e){ - if(!e.getMessage().equals("The file path does not exist")){ - Assert.fail(); - } - } - willFail.close(); - - emf = Persistence.createEntityManagerFactory("testPU"); - EntityManager aem = emf.createEntityManager(); - Query actionQuery = aem.createQuery("SELECT a FROM ActionBodyEntity a WHERE a.actionBodyName=:actionBodyName"); - actionQuery.setParameter("actionBodyName", "org.openecomp.Action_mypol.json"); - List<?> actionQueryList = actionQuery.getResultList(); - if(actionQueryList.size() < 1){ - Assert.fail("ActionBodyEntity not found with actionBodyName=: org.openecomp.Action_mypol.json" ); - } else if(actionQueryList.size() > 1){ - //something went wrong - Assert.fail("Somehow, more than one ActionBodyEntity with the actionBodyName = org.openecomp.Action_mypol.json"); - } else { - ActionBodyEntity abe = (ActionBodyEntity)actionQueryList.get(0); - logger.debug("\n\nPolicyDBDaoTest.transactionTests() Assert.assertEquals" - + "\n abe.getActionBody() = " + abe.getActionBody() - + "\n jsonFile = " + jsonFile - + "\n\n"); - Assert.assertEquals(abe.getActionBody(),jsonFile); - } - } - } - + @Ignore @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+"/com/att"); - File scope = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + String workspaceDir = "src/test/resources/"; + File parentPath = new File(workspaceDir+"/com"); Policy policyObject = new ConfigPolicy(); policyObject.policyAdapter = new PolicyRestAdapter(); policyObject.policyAdapter.setConfigName("testpolicy1"); policyObject.policyAdapter.setParentPath(parentPath.getAbsolutePath()); - policyObject.policyAdapter.setUserGitPath(scope.getPath()); policyObject.policyAdapter.setPolicyDescription("my description"); policyObject.policyAdapter.setConfigBodyData("this is my test config file"); policyObject.policyAdapter.setPolicyName("testpolicy1"); policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG); policyObject.policyAdapter.setPolicyType("Config"); + policyObject.policyAdapter.setDomainDir("org.openecomp"); PolicyType policyTypeObject = new PolicyType(); policyObject.policyAdapter.setPolicyData(policyTypeObject); PolicyDBDaoTransaction transaction = dbd.getNewTransaction(); try{ - transaction.createPolicy(policyObject, "testuser1"); - transaction.commitTransaction(); + transaction.createPolicy(policyObject, "testuser1"); + transaction.commitTransaction(); } catch(Exception e){ transaction.rollbackTransaction(); Assert.fail(); @@ -385,6 +214,7 @@ public class PolicyDBDaoTest { transaction.commitTransaction(); } + @Ignore @Test public void groupTransactions(){ PolicyDBDaoTransaction group = dbd.getNewTransaction(); @@ -609,13 +439,6 @@ public class PolicyDBDaoTest { Assert.fail(); } em.close(); - //update pdp - - //set group as default - - //move pdp to new group - - } @Test @@ -639,7 +462,7 @@ public class PolicyDBDaoTest { String desc = d.getDescriptionFromXacml("<Description>"+myTestDesc+"</Description>"); Assert.assertEquals(myTestDesc, desc); } - + @Ignore @Test public void threadingStabilityTest(){ if(logger.isDebugEnabled()){ |