summaryrefslogtreecommitdiffstats
path: root/models-dao
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-04-09 09:49:48 -0400
committerJim Hahn <jrh3@att.com>2021-04-12 08:59:17 -0400
commit0b7b94b17340406b34817d6088daa97d965d5c2c (patch)
treefaaea701389cf01ab17afa3bbbfea950a863aeae /models-dao
parentf616fc7065ffadf046b1abf0fb479d706fec9464 (diff)
Close DB in junits
Modified some of the junits to close the DB. In addition, one of the junits was apparently dependent on a previous test method adding records to the DB, thus the test methods were actually order dependent, even though no annotations were used to enforce the order. Modified that method to insert the data, itself, so the test methods are no longer order dependent. Issue-ID: POLICY-3171 Change-Id: I778c12796340f2a665b4ba00588c823c925c078c Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-dao')
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
index b40abaedf..bc022be0a 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
@@ -37,6 +37,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.junit.After;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
@@ -63,6 +64,17 @@ public class EntityTest {
private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1613494293).plusSeconds(90);
private PfDao pfDao;
+ /**
+ * Closes the DAO.
+ */
+ @After
+ public void tearDown() {
+ if (pfDao != null) {
+ pfDao.close();
+ pfDao = null;
+ }
+ }
+
@Test
public void testEntityTestSanity() throws PfModelException {
final DaoParameters daoParameters = new DaoParameters();
@@ -92,8 +104,6 @@ public class EntityTest {
assertThatThrownBy(() -> pfDao.create(new PfConceptKey()))
.hasMessage("Policy Framework DAO has not been initialized");
-
- pfDao.close();
}
@Test
@@ -119,8 +129,6 @@ public class EntityTest {
testVersionOps();
testgetFilteredOps();
-
- pfDao.close();
}
@Test
@@ -164,9 +172,8 @@ public class EntityTest {
pfDao.getConcept(PfConceptKey.class, nullKey);
pfDao.getConcept(null, nullRefKey);
pfDao.getConcept(PfReferenceKey.class, nullRefKey);
- pfDao.size(null);
- assertThatCode(() -> pfDao.close()).doesNotThrowAnyException();
+ assertThatCode(() -> pfDao.size(null)).doesNotThrowAnyException();
}
private void testAllOps() {