aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java')
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java127
1 files changed, 91 insertions, 36 deletions
diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java
index 1e194c3b..adb19f54 100644
--- a/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java
+++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* Integrity Monitor
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modificaitons 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.
@@ -24,14 +25,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import jakarta.persistence.EntityTransaction;
+import jakarta.persistence.Query;
+import jakarta.persistence.TemporalType;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Query;
-import javax.persistence.TemporalType;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -40,9 +41,9 @@ import org.junit.Test;
import org.onap.policy.common.im.jpa.ForwardProgressEntity;
import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
import org.onap.policy.common.im.jpa.StateManagementEntity;
-import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
/*
* All JUnits are designed to run in the local development environment
@@ -60,10 +61,17 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
private static final String SITE_B_PAP2 = "siteB_pap2";
private static final String ENABLE_NO_DEPENDENCY_MSG =
- "\n\nsm.enableNoDependency()\nAdminState = {}\nOpState() = {}\n"
- + "AvailStatus = {}\nStandbyStatus = {}\n";
+ """
- private static Logger logger = LoggerFactory.getLogger(IntegrityMonitorTest.class);
+
+ sm.enableNoDependency()
+ AdminState = {}
+ OpState() = {}
+ AvailStatus = {}
+ StandbyStatus = {}
+ """;
+
+ private static final Logger logger = LoggerFactory.getLogger(IntegrityMonitorTest.class);
/**
* Number of monitor cycles it takes between dependency health checks.
@@ -192,7 +200,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
waitCycles(DEPENDENCY_CHECK_CYCLES);
final IntegrityMonitor im2 = im;
- assertThatThrownBy(im2::evaluateSanity);
+ assertThatThrownBy(im2::evaluateSanity).isInstanceOf(IntegrityMonitorException.class);
// undo dependency groups and jmx test properties settings
myProp.put(IntegrityMonitorProperties.DEPENDENCY_GROUPS, "");
@@ -218,8 +226,15 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
im = makeMonitor(resourceName, myProp);
logger.debug(
- "\n\ntestSanityJmx state after creating new im\n"
- + "AdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ """
+
+
+ testSanityJmx state after creating new im
+ AdminState = {}
+ OpState() = {}
+ AvailStatus = {}
+ StandbyStatus = {}
+ """,
im.getStateManager().getAdminState(), im.getStateManager().getOpState(),
im.getStateManager().getAvailStatus(), im.getStateManager().getStandbyStatus());
@@ -244,8 +259,15 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
im = makeMonitor(resourceName, myProp);
sm = im.getStateManager();
logger.debug(
- "\n\ntestSanityJmx restart with AdminState=locked"
- + "\nAdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ """
+
+
+ testSanityJmx restart with AdminState=locked
+ AdminState = {}
+ OpState() = {}
+ AvailStatus = {}
+ StandbyStatus = {}
+ """,
sm.getAdminState(), sm.getOpState(), sm.getAvailStatus(), sm.getStandbyStatus());
assertEquals(StateManagement.LOCKED, sm.getAdminState());
@@ -262,8 +284,15 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
im = makeMonitor(resourceName, myProp);
sm = im.getStateManager();
logger.debug(
- "\n\ntestSanityJmx restart with AdminState=unlocked\n"
- + "AdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ """
+
+
+ testSanityJmx restart with AdminState=unlocked
+ AdminState = {}
+ OpState() = {}
+ AvailStatus = {}
+ StandbyStatus = {}
+ """,
sm.getAdminState(), sm.getOpState(), sm.getAvailStatus(), sm.getStandbyStatus());
assertEquals(StateManagement.UNLOCKED, sm.getAdminState());
@@ -313,7 +342,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
assertEquals(StateManagement.LOCKED, sm.getAdminState());
// test startTransaction. It should fail since it is locked
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
sm.unlock();
logger.debug("\n\nsm.unlock()\nAdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
@@ -374,7 +403,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
assertEquals(StateManagement.HOT_STANDBY, sm.getStandbyStatus());
// test startTransaction. It should fail since it is standby
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
sm.promote();
@@ -400,7 +429,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
// Test startTransaction. Should fail since standby status is cold
// standby
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
sm.enableNoDependency();
@@ -410,7 +439,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
assertEquals(StateManagement.FAILED, sm.getAvailStatus());
// Test startTransaction. Should fail since standby status is cold
// standby
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
sm.disableDependency();
sm.enableNotFailed();
@@ -423,7 +452,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
assertEquals(StateManagement.DEPENDENCY, sm.getAvailStatus());
// Test startTransaction. Should fail since standby status is cold
// standby
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
sm.enableNoDependency();
logger.debug(
@@ -432,7 +461,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
assertEquals(StateManagement.ENABLED, sm.getOpState());
// test startTransaction. It should fail since standby status is hot
// standby
- assertThatThrownBy(im::startTransaction);
+ assertThatThrownBy(im::startTransaction).isInstanceOf(IntegrityMonitorException.class);
logger.debug("\n\ntestIM: Exit\n\n");
}
@@ -490,7 +519,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
// to do it.
logger.debug("\n\nIntegrityMonitor.testSanityState: calling im.dependencyCheck()\n\n");
im.dependencyCheck();
- assertThatThrownBy(im::evaluateSanity);
+ assertThatThrownBy(im::evaluateSanity).isInstanceOf(IntegrityMonitorException.class);
logger.debug("\n\ntestSanityState: Exit\n\n");
}
@@ -539,9 +568,13 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
em.refresh(sme);
logger.debug(
- "??? -- Retrieve StateManagementEntity from database --\nsme.getResourceName() = {}\n"
- + "sme.getAdminState() = {}\nsme.getOpState() = {}\nsme.getAvailStatus() = {}\n"
- + "sme.getStandbyStatus() = {}",
+ """
+ ??? -- Retrieve StateManagementEntity from database --
+ sme.getResourceName() = {}
+ sme.getAdminState() = {}
+ sme.getOpState() = {}
+ sme.getAvailStatus() = {}
+ sme.getStandbyStatus() = {}""",
sme.getResourceName(), sme.getAdminState(), sme.getOpState(), sme.getAvailStatus(),
sme.getStandbyStatus());
@@ -577,9 +610,13 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
sme1 = (StateManagementEntity) resourceList1.get(0);
em.refresh(sme1);
logger.debug(
- "??? -- Retrieve StateManagementEntity from database --\nsme1.getResourceName() = {}\n"
- + "sme1.getAdminState() = {}\nsme1.getOpState() = {}\nsme1.getAvailStatus() = {}\n"
- + "sme1.getStandbyStatus() = {}",
+ """
+ ??? -- Retrieve StateManagementEntity from database --
+ sme1.getResourceName() = {}
+ sme1.getAdminState() = {}
+ sme1.getOpState() = {}
+ sme1.getAvailStatus() = {}
+ sme1.getStandbyStatus() = {}""",
sme1.getResourceName(), sme1.getAdminState(), sme1.getOpState(), sme1.getAvailStatus(),
sme1.getStandbyStatus());
@@ -648,7 +685,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
*/
waitCycles(DEPENDENCY_CHECK_CYCLES);
- assertThatThrownBy(im::evaluateSanity);
+ assertThatThrownBy(im::evaluateSanity).isInstanceOf(IntegrityMonitorException.class);
logger.debug("\n\ntestStateCheck: Exit\n\n");
}
@@ -804,8 +841,14 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
StateManagementEntity tmpSme = (StateManagementEntity) mySme;
em.refresh(tmpSme);
logger.debug(
- "\n ResourceName: {}\n AdminState: {}\n OpState: {}"
- + "\n AvailStatus: {}\n StandbyStatus: {}",
+ """
+
+ ResourceName: {}
+ AdminState: {}
+ OpState: {}
+ AvailStatus: {}
+ StandbyStatus: {}\
+ """,
tmpSme.getResourceName(), tmpSme.getAdminState(), tmpSme.getOpState(), tmpSme.getAvailStatus(),
tmpSme.getStandbyStatus());
}
@@ -827,8 +870,14 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
StateManagementEntity tmpSme = (StateManagementEntity) mySme;
em.refresh(tmpSme);
logger.debug(
- "\n ResourceName: {}" + "\n AdminState: {}" + "\n OpState: {}"
- + "\n AvailStatus: {}" + "\n StandbyStatus: {}",
+ """
+
+ ResourceName: {}
+ AdminState: {}
+ OpState: {}
+ AvailStatus: {}
+ StandbyStatus: {}\
+ """,
tmpSme.getResourceName(), tmpSme.getAdminState(), tmpSme.getOpState(), tmpSme.getAvailStatus(),
tmpSme.getStandbyStatus());
}
@@ -867,8 +916,14 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
em.refresh(tmpSme);
logger.debug(
- "\n (restart4) ResourceName: {}" + "\n AdminState: {}" + "\n OpState: {}"
- + "\n AvailStatus: {}" + "\n StandbyStatus: {}",
+ """
+
+ (restart4) ResourceName: {}
+ AdminState: {}
+ OpState: {}
+ AvailStatus: {}
+ StandbyStatus: {}\
+ """,
tmpSme.getResourceName(), tmpSme.getAdminState(), tmpSme.getOpState(), tmpSme.getAvailStatus(),
tmpSme.getStandbyStatus());
}
@@ -906,7 +961,7 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
}
};
- Whitebox.setInternalState(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
+ ReflectionTestUtils.setField(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
// wait for the monitor thread to start
waitCycles(1);