diff options
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory')
3 files changed, 45 insertions, 45 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java index a1fd85a23..22cfa643d 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java @@ -23,8 +23,8 @@ package org.onap.policy.controlloop.ophistory; import static org.assertj.core.api.Assertions.assertThatCode; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -40,17 +40,16 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.Mock; +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.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams.OperationHistoryDataManagerParamsBuilder; -public class OperationHistoryDataManagerImplTest { +class OperationHistoryDataManagerImplTest { private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private static final String MY_LOOP_NAME = "my-loop-name"; @@ -81,9 +80,9 @@ public class OperationHistoryDataManagerImplTest { /** * Sets up for all tests. */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { - OperationHistoryDataManagerParams params = makeBuilder().build(); + var params = makeBuilder().build(); // capture the entity manager factory for re-use new OperationHistoryDataManagerImpl(params) { @@ -98,7 +97,7 @@ public class OperationHistoryDataManagerImplTest { /** * Restores the environment after all tests. */ - @AfterClass + @AfterAll public static void tearDownAfterClass() { emf.close(); } @@ -106,7 +105,7 @@ public class OperationHistoryDataManagerImplTest { /** * Sets up for an individual test. */ - @Before + @BeforeEach public void setUp() { event = new VirtualControlLoopEvent(); event.setClosedLoopControlName(MY_LOOP_NAME); @@ -131,13 +130,13 @@ public class OperationHistoryDataManagerImplTest { mgr.start(); } - @After + @AfterEach public void tearDown() { mgr.stop(); } @Test - public void testConstructor() { + void testConstructor() { // use a thread and manager that haven't been started yet thread = mock(Thread.class); mgr = new PseudoThread(); @@ -157,7 +156,7 @@ public class OperationHistoryDataManagerImplTest { } @Test - public void testStart() { + void testStart() { // this should have no effect mgr.start(); @@ -168,7 +167,7 @@ public class OperationHistoryDataManagerImplTest { } @Test - public void testStore_testStop() throws InterruptedException { + void testStore_testStop() throws InterruptedException { // store mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); @@ -181,7 +180,7 @@ public class OperationHistoryDataManagerImplTest { * Tests stop() when the manager isn't running. */ @Test - public void testStopNotRunning() { + void testStopNotRunning() { // use a manager that hasn't been started yet mgr = new PseudoThread(); mgr.stop(); @@ -193,7 +192,7 @@ public class OperationHistoryDataManagerImplTest { * Tests store() when it is already stopped. */ @Test - public void testStoreAlreadyStopped() throws InterruptedException { + void testStoreAlreadyStopped() throws InterruptedException { mgr.stop(); // store @@ -206,7 +205,7 @@ public class OperationHistoryDataManagerImplTest { * Tests store() when when the queue is full. */ @Test - public void testStoreTooManyItems() throws InterruptedException { + void testStoreTooManyItems() throws InterruptedException { final int nextra = 5; for (int nitems = 0; nitems < MAX_QUEUE_LENGTH + nextra; ++nitems) { mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); @@ -218,7 +217,7 @@ public class OperationHistoryDataManagerImplTest { } @Test - public void testRun() throws InterruptedException { + void testRun() throws InterruptedException { // trigger thread shutdown when it completes this batch when(emfSpy.createEntityManager()).thenAnswer(ans -> { @@ -249,8 +248,8 @@ public class OperationHistoryDataManagerImplTest { * Tests run() when the entity manager throws an exception. */ @Test - public void testRunException() throws InterruptedException { - AtomicInteger count = new AtomicInteger(0); + void testRunException() throws InterruptedException { + var count = new AtomicInteger(0); when(emfSpy.createEntityManager()).thenAnswer(ans -> { if (count.incrementAndGet() == 2) { @@ -279,7 +278,7 @@ public class OperationHistoryDataManagerImplTest { * Tests storeRemainingRecords() when the entity manager throws an exception. */ @Test - public void testStoreRemainingRecordsException() throws InterruptedException { + void testStoreRemainingRecordsException() throws InterruptedException { // arrange to throw an exception when(emfSpy.createEntityManager()).thenThrow(EXPECTED_EXCEPTION); @@ -289,7 +288,7 @@ public class OperationHistoryDataManagerImplTest { } @Test - public void testStoreRecord() throws InterruptedException { + void testStoreRecord() throws InterruptedException { /* * Note: we change sub-request ID each time to guarantee that the records are * unique. @@ -330,7 +329,7 @@ public class OperationHistoryDataManagerImplTest { * Tests storeRecord() when records are updated. */ @Test - public void testStoreRecordUpdate() throws InterruptedException { + void testStoreRecordUpdate() throws InterruptedException { /* * Note: we do NOT change sub-request ID, so that records all refer to the same DB * record. @@ -372,7 +371,7 @@ public class OperationHistoryDataManagerImplTest { return; } - Thread thread2 = new Thread(() -> { + var thread2 = new Thread(() -> { threadFunction.accept(emfSpy); finished.countDown(); }); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java index 97f306528..f0159aaff 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 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,17 +22,16 @@ package org.onap.policy.controlloop.ophistory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.function.Consumer; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.common.parameters.ValidationResult; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams.OperationHistoryDataManagerParamsBuilder; -public class OperationHistoryDataManagerParamsTest { +class OperationHistoryDataManagerParamsTest { private static final String CONTAINER = "my-container"; private static final int BATCH_SIZE = 10; private static final int MAX_QUEUE_LENGTH = 20; @@ -44,13 +44,13 @@ public class OperationHistoryDataManagerParamsTest { private OperationHistoryDataManagerParams params; - @Before + @BeforeEach public void setUp() { params = makeBuilder().build(); } @Test - public void test() { + void test() { assertEquals(BATCH_SIZE, params.getBatchSize()); assertEquals(MAX_QUEUE_LENGTH, params.getMaxQueueLength()); assertEquals(MY_PASS, params.getPassword()); @@ -71,7 +71,7 @@ public class OperationHistoryDataManagerParamsTest { } @Test - public void testValidate() { + void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); testValidateField("url", "null", params2 -> params2.setUrl(null)); @@ -103,14 +103,14 @@ public class OperationHistoryDataManagerParamsTest { Consumer<OperationHistoryDataManagerParams> makeInvalid) { // original params should be valid - ValidationResult result = params.validate(CONTAINER); - assertTrue(fieldName, result.isValid()); + var result = params.validate(CONTAINER); + assertTrue(result.isValid()); // make invalid params - OperationHistoryDataManagerParams params2 = makeBuilder().build(); + var params2 = makeBuilder().build(); makeInvalid.accept(params2); result = params2.validate(CONTAINER); - assertFalse(fieldName, result.isValid()); + assertFalse(result.isValid()); assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected); } diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java index 4774af427..d4a5cfdd1 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 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,13 +23,13 @@ package org.onap.policy.controlloop.ophistory; import static org.assertj.core.api.Assertions.assertThatCode; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class OperationHistoryDataManagerStubTest { +class OperationHistoryDataManagerStubTest { @Test - public void test() { - OperationHistoryDataManagerStub mgr = new OperationHistoryDataManagerStub(); + void test() { + var mgr = new OperationHistoryDataManagerStub(); assertThatCode(() -> mgr.store(null, null, null, null, null)).doesNotThrowAnyException(); assertThatCode(() -> mgr.stop()).doesNotThrowAnyException(); |