Merge "policy/engine jdk11 upgrades"
[policy/engine.git] / BRMSGateway / src / test / java / org / onap / policy / brms / BrmsPushTest.java
index 4a1b4f8..994e973 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Engine
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2020 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.
@@ -28,16 +28,48 @@ import java.io.IOException;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
-
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onap.policy.api.PolicyException;
 import org.onap.policy.brms.api.BrmsHandler;
+import org.onap.policy.brms.api.BrmsPush;
 
 public class BrmsPushTest {
 
     private static final String VALID_FILE = "src/test/resources/config.properties";
     private static final String INVALID_FILE = "src/test/resources/failure.properties";
 
+    private static EntityManagerFactory emf;
+
+    /**
+     * Creates the test DB and keeps it open until all tests complete.
+     * 
+     * @throws Exception if an error occurs
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        Properties props = new Properties();
+        try (FileInputStream inp = new FileInputStream(VALID_FILE)) {
+            props.load(inp);
+        }
+        props.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML,
+                        props.getProperty(BrmsPush.BRMSPERSISTENCE));
+
+        emf = Persistence.createEntityManagerFactory("BRMSGW", props);
+    }
+
+    /**
+     * Closes the test DB.
+     */
+    @AfterClass
+    public static void tearDownAfterClass() {
+        emf.close();
+    }
+
     @Test(expected = PolicyException.class)
     public void brmsHandlerFailTest() throws PolicyException {
         new BrmsHandler(null);
@@ -49,7 +81,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest2() throws PolicyException {
+    public void testBrmsHandlerFail2() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "defaultName";
         prop.remove = true;
@@ -60,7 +92,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest3() throws PolicyException {
+    public void testBrmsHandlerFail3() throws PolicyException {
         PropertyChange prop = new PropertyChange();
         prop.key = "repositoryID";
         prop.remove = true;
@@ -75,7 +107,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest4() throws PolicyException {
+    public void testBrmsHandlerFail4() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "repositoryURL";
         prop.remove = true;
@@ -86,7 +118,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest5() throws PolicyException {
+    public void testBrmsHandlerFail5() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "repositoryName";
         prop.remove = true;
@@ -97,7 +129,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest6() throws PolicyException {
+    public void testBrmsHandlerFail6() throws PolicyException {
         PropertyChange prop = new PropertyChange();
         prop.key = "repositoryURL";
         prop.value = "http://nexus:8081/nexus/content/repositories/releases,"
@@ -114,7 +146,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest7() throws PolicyException {
+    public void testBrmsHandlerFail7() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "repositoryPassword";
         prop.remove = true;
@@ -125,7 +157,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest8() throws PolicyException {
+    public void testBrmsHandlerFail8() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "policyKeyID";
         prop.remove = true;
@@ -136,7 +168,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest9() throws PolicyException {
+    public void testBrmsHandlerFail9() throws PolicyException {
         PropertyChange prop = new PropertyChange();
         prop.key = "sync";
         prop.value = "true";
@@ -156,7 +188,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest10() throws PolicyException {
+    public void testBrmsHandlerFail10() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "groupNames";
         prop.value = "";
@@ -168,7 +200,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest11() throws PolicyException {
+    public void testBrmsHandlerFail11() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "default.groupID";
         prop.remove = true;
@@ -179,7 +211,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest12() throws PolicyException {
+    public void testBrmsHandlerFail12() throws PolicyException {
         final PropertyChange prop = new PropertyChange();
         prop.key = "default.artifactID";
         prop.remove = true;
@@ -190,7 +222,7 @@ public class BrmsPushTest {
     }
 
     @Test(expected = PolicyException.class)
-    public void brmsHandlerFailTest13() throws PolicyException {
+    public void testBrmsHandlerFail13() throws PolicyException {
         PropertyChange prop = new PropertyChange();
         prop.key = "NOTIFICATION_TYPE";
         prop.value = "dmaap";