diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-06-25 16:42:06 +0100 |
---|---|---|
committer | Wayne Dunican <wayne.dunican@est.tech> | 2024-06-27 14:25:16 +0000 |
commit | 61eb8b47308a859a64b9538222445534dda3a34e (patch) | |
tree | a20f35cf2e67fb07d7717435a722cd08d9b0f812 /integrity-audit/src | |
parent | c8daa33cd37f6f046ec2ee4345ed437330f1c11d (diff) |
Convert common to JUnit 5
Review for integrity-audit & integrity-monitor
Issue-ID: POLICY-5043
Change-Id: I9cf896287e8f83559e327dfaa610f454767072f9
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'integrity-audit/src')
10 files changed, 137 insertions, 130 deletions
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java index b5a4eeea..1d47f7d0 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java @@ -3,6 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,16 +21,16 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.common.utils.test.log.logback.ExtractAppender; @@ -39,16 +40,16 @@ import org.onap.policy.common.utils.test.log.logback.ExtractAppender; * where they have write privileges and can execute time-sensitive * tasks. */ -public class AuditPeriodTest extends IntegrityAuditTestBase { +class AuditPeriodTest extends IntegrityAuditTestBase { private static Logger logger = FlexLogger.getLogger(AuditPeriodTest.class); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { IntegrityAuditTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + AuditPeriodTest.class.getSimpleName()); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { IntegrityAuditTestBase.tearDownAfterClass(); } @@ -57,7 +58,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase { * Set up for test case. */ @Override - @Before + @BeforeEach public void setUp() { logger.info("setUp: Entering"); @@ -71,7 +72,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase { * Tear down after test cases. */ @Override - @After + @AfterEach public void tearDown() { logger.info("tearDown: Entering"); @@ -85,7 +86,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase { * suppressed. */ @Test - public void testNegativeAuditPeriod() throws Exception { + void testNegativeAuditPeriod() throws Exception { logger.info("testNegativeAuditPeriod: Entering"); @@ -114,7 +115,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase { * 100ms). */ @Test - public void testZeroAuditPeriod() throws Exception { + void testZeroAuditPeriod() throws Exception { logger.info("testZeroAuditPeriod: Entering"); @@ -154,7 +155,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase { * between the audits. */ @Test - public void testLongAuditPeriod() throws Exception { + void testLongAuditPeriod() throws Exception { logger.info("testLongAuditPeriod: Entering"); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditorTimeTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditorTimeTest.java index b8e4ba5d..9899ca25 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditorTimeTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditorTimeTest.java @@ -3,6 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,19 +21,19 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.time.CurrentTime; /** * Tests the AuditorTime class. */ -public class AuditorTimeTest { +class AuditorTimeTest { @Test - public void testGetInstance() { + void testGetInstance() { CurrentTime inst = AuditorTime.getInstance(); assertNotNull(inst); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java index ad154d33..c9837e03 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java @@ -3,6 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Date; import java.util.HashMap; @@ -30,11 +31,11 @@ import java.util.HashSet; import java.util.Map; import java.util.Properties; import java.util.Set; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.ia.jpa.IaTestEntity; import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; import org.onap.policy.common.ia.jpa.PersonSample; @@ -46,7 +47,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; * where they have write privileges and can execute time-sensitive * tasks. */ -public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { +class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { private static final String ZAPHOD = "Zaphod"; private static Logger logger = FlexLogger.getLogger(DbAuditCompareEntriesTest.class); @@ -54,13 +55,13 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { private DbDao dbDao; private static String resourceName = "pdp1"; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { IntegrityAuditTestBase .setUpBeforeClass(DEFAULT_DB_URL_PREFIX + DbAuditCompareEntriesTest.class.getSimpleName()); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { IntegrityAuditTestBase.tearDownAfterClass(); } @@ -69,7 +70,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { * Set up for test cases. */ @Override - @Before + @BeforeEach public void setUp() { logger.info("setUp: Entering"); @@ -85,7 +86,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { * Clean up DB after each test. */ @Override - @After + @AfterEach public void tearDown() { logger.info("tearDown: Entering"); @@ -101,7 +102,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { */ // @Ignore @Test - public void testSuccessfulComparison() throws Exception { + void testSuccessfulComparison() throws Exception { logger.info("testSuccessfulComparison: Entering"); dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); @@ -171,7 +172,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { */ // @Ignore @Test - public void testComparisonError() throws Exception { + void testComparisonError() throws Exception { logger.info("testComparisonError: Entering"); dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); @@ -231,7 +232,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { */ // @Ignore @Test - public void testCompareMissingEntries() throws Exception { + void testCompareMissingEntries() throws Exception { logger.info("testCompareMissingEntries: Entering"); dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); @@ -317,7 +318,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { */ // @Ignore @Test - public void testCompareAllHashEntities() throws Exception { + void testCompareAllHashEntities() throws Exception { logger.info("testCompareAllHashEntities: Entering"); dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); @@ -418,7 +419,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { * Tests that comparison algorithm works for each entity in the database */ @Test - public void testCompareAllDbEntities() throws Exception { + void testCompareAllDbEntities() throws Exception { logger.info("testCompareAllDbEntities: Entering"); logger.info("Setting up DB"); @@ -482,7 +483,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { */ // @Ignore @Test - public void testEmbeddedClass() throws Exception { + void testEmbeddedClass() throws Exception { logger.info("testEmbeddedClasses: Entering"); dbDao = new DbDao(resourceName, A_SEQ_PU, properties); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java index c48ec0e3..507587b7 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java @@ -3,7 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ package org.onap.policy.common.ia; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import com.google.re2j.Pattern; import jakarta.persistence.EntityManager; @@ -31,11 +31,11 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import java.util.List; import java.util.Properties; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -49,7 +49,7 @@ import org.onap.policy.common.utils.test.log.logback.ExtractAppender; * If any have been ignored (@Ignore) they will not run at the same time * as others. You should run them as JUnits by themselves. */ -public class DbAuditTest extends IntegrityAuditTestBase { +class DbAuditTest extends IntegrityAuditTestBase { private static Logger logger = FlexLogger.getLogger(DbAuditTest.class); @@ -60,13 +60,13 @@ public class DbAuditTest extends IntegrityAuditTestBase { private EntityManager em2; private DbDao dbDao; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { IntegrityAuditTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + DbAuditTest.class.getSimpleName()); IntegrityAuditEntity.setUnitTesting(true); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { IntegrityAuditTestBase.tearDownAfterClass(); IntegrityAuditEntity.setUnitTesting(false); @@ -76,7 +76,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { * Set up for test cases. */ @Override - @Before + @BeforeEach public void setUp() { logger.info("setUp: Entering"); @@ -93,7 +93,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { * Tear down after test cases. */ @Override - @After + @AfterEach public void tearDown() { logger.info("tearDown: Entering"); @@ -130,7 +130,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { * Tests printing an error to the log in the event where there are no entities saved in the database. */ @Test - public void testNoEntities() throws Exception { + void testNoEntities() throws Exception { Properties properties = makeProperties(); logger.info("noEntitiesTest: Entering"); @@ -150,7 +150,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { * Tests the detection of only one entry in the database. */ @Test - public void testOneEntity() throws Exception { + void testOneEntity() throws Exception { Properties properties = makeProperties(); logger.info("oneEntityTest: Entering"); @@ -174,7 +174,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { * Tests reporting mismatches and missing entries using the error log. */ @Test - public void testMismatch() throws Exception { + void testMismatch() throws Exception { logger.info("mismatchTest: Entering"); // use new URLs so we get a completely new DB diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java index 9f2103d7..da6f0bd5 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java @@ -3,7 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.persistence.PersistenceUnitUtil; import jakarta.persistence.Query; @@ -38,11 +38,11 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; import org.onap.policy.common.utils.jpa.EntityTransCloser; import org.onap.policy.common.utils.time.TestTime; @@ -52,7 +52,7 @@ import org.onap.policy.common.utils.time.TestTime; * where they have write privileges and can execute time-sensitive * tasks. */ -public class DbDaoTest extends IntegrityAuditTestBase { +class DbDaoTest extends IntegrityAuditTestBase { private static final String SELECT_ENTITIES = "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"; private static final String SITE_B = "SiteB"; @@ -62,18 +62,18 @@ public class DbDaoTest extends IntegrityAuditTestBase { private DbDao dbDao; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { IntegrityAuditTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + DbDaoTest.class.getSimpleName()); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { IntegrityAuditTestBase.tearDownAfterClass(); } @Override - @Before + @BeforeEach public void setUp() { super.setUp(); dbDao = null; @@ -83,7 +83,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * Tear down after test cases. */ @Override - @After + @AfterEach public void tearDown() { if (dbDao != null) { dbDao.destroy(); @@ -94,7 +94,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests registering a new IntegrityAuditEntity object in the DB */ @Test - public void testNewRegistration() throws Exception { + void testNewRegistration() throws Exception { Properties properties = makeProperties(); try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { @@ -121,7 +121,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * Tests updating an IntegrityAuditEntity if it has already been registered */ @Test - public void testUpdateRegistration() throws Exception { + void testUpdateRegistration() throws Exception { Properties properties = makeProperties(); dbDao = new DbDao(resourceName, A_SEQ_PU, properties); @@ -161,7 +161,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests obtaining all Integrity Audit Entities from a table */ @Test - public void testGetIntegrityAuditEntities() throws Exception { + void testGetIntegrityAuditEntities() throws Exception { Properties properties = makeProperties(); // Add some entries to the DB @@ -178,7 +178,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests retrieving a DbDao instance's IntegrityAuditEntity */ @Test - public void testGetMyIntegrityAuditEntity() throws Exception { + void testGetMyIntegrityAuditEntity() throws Exception { Properties properties = makeProperties(); dbDao = new DbDao(resourceName, A_SEQ_PU, properties); @@ -188,7 +188,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests obtaining an IntegrityAuditEntity by ID */ @Test - public void testGetIntegrityAuditEntity() throws Exception { + void testGetIntegrityAuditEntity() throws Exception { Properties properties = makeProperties(); // Obtain an entry from the database based on ID @@ -224,7 +224,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests setting an IntegrityAuditEntity as the designated node */ @Test - public void testSetDesignated() throws Exception { + void testSetDesignated() throws Exception { Properties properties = makeProperties(); try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { @@ -263,7 +263,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests that the lastUpdated column in the database is updated properly */ @Test - public void testSetLastUpdated() throws Exception { + void testSetLastUpdated() throws Exception { Properties properties = makeProperties(); try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { @@ -311,7 +311,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /* Tests that all the entries from a class can be retrieved */ @Test - public void testGetAllMyEntriesString() throws Exception { + void testGetAllMyEntriesString() throws Exception { Properties properties = makeProperties(); // create entries for the IntegrityAuditEntity table @@ -330,7 +330,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * Tests retrieving all entities in a Persistence Unit using the class name and a hashset of IDs */ @Test - public void testGetAllMyEntriesStringHashSet() throws Exception { + void testGetAllMyEntriesStringHashSet() throws Exception { Properties properties = makeProperties(); // create entries for the IntegrityAuditEntity table @@ -365,7 +365,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * and class name */ @Test - public void testGetAllEntriesStringPropertiesString() throws Exception { + void testGetAllEntriesStringPropertiesString() throws Exception { Properties properties = makeProperties(); // create entries for the IntegrityAuditEntity table @@ -386,7 +386,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * class name, and a hashset of IDs */ @Test - public void testGetAllEntriesStringPropertiesStringHashSet() throws Exception { + void testGetAllEntriesStringPropertiesStringHashSet() throws Exception { Properties properties = makeProperties(); // create entries for the IntegrityAuditEntity table @@ -421,7 +421,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { * className */ @Test - public void testGetAllEntries() throws Exception { + void testGetAllEntries() throws Exception { Properties properties = makeProperties(); // create entries for the IntegrityAuditEntity table @@ -440,7 +440,7 @@ public class DbDaoTest extends IntegrityAuditTestBase { /** * Tests obtaining all class names of persisted classes. */ - public void testGetPersistenceClassNames() throws Exception { + void testGetPersistenceClassNames() throws Exception { Properties properties = makeProperties(); dbDao = new DbDao(resourceName, A_SEQ_PU, properties); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java index 5944443e..d35260dd 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DefaultLoggingPatternTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +26,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.Logger; import org.slf4j.MDC; @@ -37,7 +38,7 @@ import org.slf4j.ext.XLoggerFactory; * Test the default logging pattern. * */ -public class DefaultLoggingPatternTest { +class DefaultLoggingPatternTest { // XLogger for this class private static final XLogger XLOGGER = XLoggerFactory.getXLogger(DefaultLoggingPatternTest.class); @@ -47,7 +48,7 @@ public class DefaultLoggingPatternTest { /** * Delete logging file after test. */ - @AfterClass + @AfterAll public static void deleteLogFile() { new File("testingLogs/common-modules/integrity-audit/logging-pattern-test.log").deleteOnExit(); } @@ -58,7 +59,7 @@ public class DefaultLoggingPatternTest { * @throws IOException on errors */ @Test - public void testDefaultLoggingPatternXLogger() throws IOException { + void testDefaultLoggingPatternXLogger() throws IOException { testDefaultLoggingPattern(XLOGGER, "xlogger"); } @@ -68,7 +69,7 @@ public class DefaultLoggingPatternTest { * @throws IOException on errors */ @Test - public void testDefaultLoggingPatternLogger() throws IOException { + void testDefaultLoggingPatternLogger() throws IOException { testDefaultLoggingPattern(LOGGER, "logger"); } @@ -77,7 +78,7 @@ public class DefaultLoggingPatternTest { * * @throws IOException on errors */ - public void testDefaultLoggingPattern(final Logger logger, final String loggerString) throws IOException { + void testDefaultLoggingPattern(final Logger logger, final String loggerString) throws IOException { MDC.put("requestId", "TheRequestId"); MDC.put("serviceInstanceId", "TheServiceInstanceId"); MDC.put("serverName", "TheServerName"); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java index 40f7a738..988d875d 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java @@ -3,6 +3,7 @@ * Integrity Monitor * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,33 +21,33 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.test.ExceptionsTester; /** * Tests various Exception subclasses. */ -public class ExceptionsTest extends ExceptionsTester { +class ExceptionsTest extends ExceptionsTester { @Test - public void testDbAuditException() { + void testDbAuditException() { assertEquals(4, test(DbAuditException.class)); } @Test - public void testDbDaoTransactionException() { + void testDbDaoTransactionException() { assertEquals(4, test(DbDaoTransactionException.class)); } @Test - public void testIntegrityAuditException() { + void testIntegrityAuditException() { assertEquals(4, test(IntegrityAuditException.class)); } @Test - public void testIntegrityAuditPropertiesException() { + void testIntegrityAuditPropertiesException() { assertEquals(4, test(IntegrityAuditPropertiesException.class)); } } diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java index 084c648d..499d29a0 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java @@ -3,6 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +21,11 @@ package org.onap.policy.common.ia; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.common.utils.test.log.logback.ExtractAppender; @@ -40,7 +41,7 @@ import org.onap.policy.common.utils.test.log.logback.ExtractAppender; * * <p>These tests use a temporary, in-memory DB, which is dropped once the tests complete. */ -public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { +class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { private static Logger logger = FlexLogger.getLogger(IntegrityAuditDesignationTest.class); @@ -55,13 +56,13 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { */ private static final String START_AUDIT_RE_PREFIX = "Running audit for persistenceUnit=\\w+ on resourceName=("; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { IntegrityAuditTestBase .setUpBeforeClass(DEFAULT_DB_URL_PREFIX + IntegrityAuditDesignationTest.class.getSimpleName()); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { IntegrityAuditTestBase.tearDownAfterClass(); } @@ -70,7 +71,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Set up before test cases. */ @Override - @Before + @BeforeEach public void setUp() { logger.info("setUp: Entering"); @@ -83,7 +84,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Tear down after test cases. */ @Override - @After + @AfterEach public void tearDown() { logger.info("tearDown: Entering"); @@ -100,7 +101,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testOneResource() throws Exception { + void testOneResource() throws Exception { logger.info("testOneResource: Entering"); @@ -155,7 +156,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testTwoResources() throws Exception { + void testTwoResources() throws Exception { logger.info("testTwoResources: Entering"); @@ -202,7 +203,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testTwoResourcesDifferentPus() throws Exception { + void testTwoResourcesDifferentPus() throws Exception { logger.info("testTwoResourcesDifferentPus: Entering"); @@ -247,7 +248,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testTwoResourcesOneDead() throws Exception { + void testTwoResourcesOneDead() throws Exception { logger.info("testTwoResourcesOneDead: Entering"); @@ -288,7 +289,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testThreeResources() throws Exception { + void testThreeResources() throws Exception { logger.info("testThreeResources: Entering"); @@ -345,7 +346,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testFourResourcesDifferentPus() throws Exception { + void testFourResourcesDifferentPus() throws Exception { logger.info("testFourResourcesDifferentPus: Entering"); @@ -412,7 +413,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testFourResourcesOneDead() throws Exception { + void testFourResourcesOneDead() throws Exception { logger.info("testFourResourcesOneDead: Entering"); @@ -479,7 +480,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testFourResourcesThreeDead() throws Exception { + void testFourResourcesThreeDead() throws Exception { logger.info("testFourResourcesThreeDead: Entering"); @@ -531,7 +532,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { * Note: console.log must be examined to ascertain whether or not this test was successful. */ @Test - public void testDesignatedNodeDead() throws Exception { + void testDesignatedNodeDead() throws Exception { logger.info("testDesignatedNodeDead: Entering"); final ExtractAppender logA = watch(debugLogger, START_AUDIT_RE); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java index 9550017e..bd0aad55 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java @@ -3,6 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +21,14 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class IntegrityAuditTest { +class IntegrityAuditTest { private static final String PROPERTIES = "properties"; private static final String RESOURCE_NAME = "resourceName"; private static final String SOMETHING = "something"; @@ -36,7 +37,7 @@ public class IntegrityAuditTest { * Test if we can access the updated bad params outside of the parmsAreBad method. */ @Test - public void testParmsAreBad() { + void testParmsAreBad() { // Try with 2 null params StringBuilder badParams = new StringBuilder(); IntegrityAudit.parmsAreBad(null, SOMETHING, null, badParams); diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java index f5a32777..e0c22a1e 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java @@ -3,7 +3,7 @@ * Integrity Audit * ================================================================================ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ package org.onap.policy.common.ia; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; @@ -61,7 +61,7 @@ import org.springframework.test.util.ReflectionTestUtils; * * <p>These tests use a temporary, in-memory DB, which is dropped once the tests complete. */ -public class IntegrityAuditTestBase { +class IntegrityAuditTestBase { /** * Root of the debug logger, as defined in the logback-test.xml. @@ -284,7 +284,7 @@ public class IntegrityAuditTestBase { * @param persistenceUnit the persistence unit * @param tableName the name of the table */ - public void truncateTable(Properties properties, String persistenceUnit, String tableName) { + void truncateTable(Properties properties, String persistenceUnit, String tableName) { try (EntityMgrFactoryCloser emfc = new EntityMgrFactoryCloser(Persistence.createEntityManagerFactory(persistenceUnit, properties)); @@ -338,7 +338,7 @@ public class IntegrityAuditTestBase { } List<String> remaining = getRemaining(expected, it); - assertTrue("missing items " + remaining, remaining.isEmpty()); + assertTrue(remaining.isEmpty(), "missing items " + remaining); } /** @@ -496,7 +496,7 @@ public class IntegrityAuditTestBase { appender.start(); } - public void detach() { + void detach() { logger.detachAppender(appender); } } @@ -554,14 +554,14 @@ public class IntegrityAuditTestBase { * @param sleepMs time to sleep * @throws InterruptedException can be interrupted */ - public void sleep(long sleepMs) throws InterruptedException { + void sleep(long sleepMs) throws InterruptedException { myTime.sleep(sleepMs); } /** * Interrupts the AuditThread. */ - public void interrupt() { + void interrupt() { super.stopAuditThread(); } |