From 0b7b94b17340406b34817d6088daa97d965d5c2c Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 9 Apr 2021 09:49:48 -0400 Subject: 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 --- .../java/org/onap/policy/models/dao/EntityTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'models-dao') 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() { -- cgit 1.2.3-korg