summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/test/java/org/onap
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-03-22 23:16:50 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-03-22 23:27:21 +0000
commitc3140f4308f0752153fb279badc88b7d54094171 (patch)
tree12d90d09c774c8f10a02683c88151a47dbc3d187 /ONAP-PAP-REST/src/test/java/org/onap
parentcfb9038e5bca8e3840ebb25d75144abba8343ea6 (diff)
Add database initialization to XACML PDP test
This issue arose due to the order of execution of JUnit tests. The tests in XACMLPAPTest failed becasue the database was not initialized. Up till now, the @Before method in the test class org.onap.policy.pap.ia.DbAuditCompareEntriesTesti initiated the database. THis bug fix adds a similar @Before method to the XACMLPAPTest class to initialize the database. All other classes in the module were tested with both @Before methods commented out to ensure that no other tests will fail due to this issue. Issue-ID: POLICY-707 Change-Id: Ibce5fad5c006f7a92b3ef77bde4dc5ed6f7039ed Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java51
1 files changed, 50 insertions, 1 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
index ca2b6797d..5208ad7a7 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
@@ -35,18 +35,25 @@ import java.util.List;
import java.util.Map;
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.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.policy.common.ia.IntegrityAuditProperties;
import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
import org.onap.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController;
import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController;
@@ -73,8 +80,8 @@ import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import com.mockrunner.mock.web.MockServletInputStream;
-
public class XACMLPAPTest {
+ private static final Log logger = LogFactory.getLog(XACMLPAPTest.class);
private static final String ENVIRONMENT_HEADER = "Environment";
private List<String> headers = new ArrayList<>();
@@ -86,6 +93,48 @@ public class XACMLPAPTest {
private SessionFactory sessionFactory;
private CommonClassDao commonClassDao;
+ private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
+ private static final String DEFAULT_DB_USER = "sa";
+ private static final String DEFAULT_DB_PWD = "";
+
+ @Before
+ public void setUpDB() throws Exception {
+ logger.info("setUpDB: Entering");
+
+ Properties properties = new Properties();
+ properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPAPTest.DEFAULT_DB_DRIVER);
+ properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
+ properties.put(IntegrityAuditProperties.DB_USER, XACMLPAPTest.DEFAULT_DB_USER);
+ properties.put(IntegrityAuditProperties.DB_PWD, XACMLPAPTest.DEFAULT_DB_PWD);
+ properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
+ properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
+
+ //Clean the iaTest DB table for IntegrityAuditEntity entries
+ cleanDb("testPapPU", properties);
+
+ logger.info("setUpDB: Exiting");
+ }
+
+ public void cleanDb(String persistenceUnit, Properties properties){
+ logger.debug("cleanDb: enter");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
+
+ 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("cleanDb: exit");
+ }
+
@Before
public void setUp() throws ServletException {
httpServletRequest = Mockito.mock(HttpServletRequest.class);