summaryrefslogtreecommitdiffstats
path: root/integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-02-13 09:19:43 -0500
committerJim Hahn <jrh3@att.com>2018-02-13 19:21:55 -0500
commitbf2cc29bf766feabca8ef633926f5fce00a5fe2e (patch)
tree6094d9294378fe7226a3ed7e287dc0381b067fcf /integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java
parent86664073b5a778c56e831d64b3a1883818af0ffe (diff)
Add test coverage to integrity-monitor
Removed "test" from package name. Refactored tests, creating common IntegrityMonitorTestBase. Turned log/print statements into assertEquals in StateTransitionTest. Turned log/print statements into assertEquals in StateManagementTest. Modified AllSeemsWellTest to use IntegrityMonitorTestBase. Modified IntegrityMonitorTest to use IntegrityMonitorTestBase. Added several hooks to IntegrityMonitor to control timers at a finer granularity. Added hooks to IntegrityMonitor to control the FPManager thread. Remove hooks for refresh timer, as property suffices. Added assertException() and assertNoException() methods to IntegrityMonitorTestBase, and then replaced most "try/catch" blocks with calls to those methods. Updated StateManagement to close EntityManagers. Modify pom to remove scope from utils dependency. Fix some comments and remove an unneeded EntityTransaction variable. Change-Id: Ic0789d26f985a40a35f618343fa4e88aa473b2b3 Issue-ID: POLICY-582 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java')
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java173
1 files changed, 173 insertions, 0 deletions
diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java
new file mode 100644
index 00000000..967ca739
--- /dev/null
+++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Integrity Monitor
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.im;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AllSeemsWellTest extends IntegrityMonitorTestBase {
+ private static Logger logger = LoggerFactory.getLogger(AllSeemsWellTest.class);
+
+ private static final long STATE_CYCLE_MS = 3 * CYCLE_INTERVAL_MS;
+
+ private static Properties myProp;
+ private static String resourceName;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ IntegrityMonitorTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + AllSeemsWellTest.class.getSimpleName());
+
+ resourceName = IntegrityMonitorTestBase.siteName + "." + IntegrityMonitorTestBase.nodeType;
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ IntegrityMonitorTestBase.tearDownAfterClass();
+ }
+
+ @Before
+ public void setUp() {
+ super.setUpTest();
+
+ myProp = makeProperties();
+
+ }
+
+ @After
+ public void tearDown() {
+ super.tearDownTest();
+ }
+
+ // Ignore
+ @Test
+ public void testAllSeemsWell() throws Exception {
+ logger.debug("\nIntegrityMonitorTest: Entering testAllSeemsWell\n\n");
+
+ // parameters are passed via a properties file
+ myProp.put(IntegrityMonitorProperties.DEPENDENCY_GROUPS, "");
+ myProp.put(IntegrityMonitorProperties.TEST_VIA_JMX, "false");
+ myProp.put(IntegrityMonitorProperties.REFRESH_STATE_AUDIT_INTERVAL_MS, "-1");
+ myProp.put(IntegrityMonitorProperties.STATE_AUDIT_INTERVAL_MS, "-1");
+ myProp.put(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD, "1");
+ myProp.put(IntegrityMonitorProperties.FP_MONITOR_INTERVAL, "5");
+ myProp.put(IntegrityMonitorProperties.TEST_TRANS_INTERVAL, "1");
+ myProp.put(IntegrityMonitorProperties.WRITE_FPC_INTERVAL, "1");
+
+ IntegrityMonitor.updateProperties(myProp);
+ /*
+ * The monitorInterval is 5 and the failedCounterThreshold is 1 A
+ * forward progress will be stale after 5 seconds.
+ */
+
+ IntegrityMonitor im = IntegrityMonitor.getInstance(resourceName, myProp);
+
+ StateManagement sm = im.getStateManager();
+
+ // Give it time to set the states in the DB
+ Thread.sleep(STATE_CYCLE_MS);
+
+ // Check the state
+ logger.debug(
+ "\n\ntestAllSeemsWell starting im state \nAdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ sm.getAdminState(), sm.getOpState(), sm.getAvailStatus(), sm.getStandbyStatus());
+
+ assertEquals(StateManagement.ENABLED, sm.getOpState());
+
+ // Indicate a failure
+ im.allSeemsWell(this.getClass().getName(), IntegrityMonitorProperties.ALLNOTWELL,
+ "'AllSeemsWellTest - ALLNOTWELL'");
+
+ // Wait for the state to change due to ALLNOTWELL
+ Thread.sleep(STATE_CYCLE_MS);
+ // Check the state
+ logger.debug(
+ "\n\ntestAllSeemsWell after ALLNOTWELL: im state \nAdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ sm.getAdminState(), sm.getOpState(), sm.getAvailStatus(), sm.getStandbyStatus());
+
+ // assertEquals(StateManagement.DISABLED, sm.getOpState());
+
+ Map<String, String> allNotWellMap = im.getAllNotWellMap();
+ for (String key : allNotWellMap.keySet()) {
+ logger.debug("AllSeemsWellTest: allNotWellMap: key = {} msg = {}", key, allNotWellMap.get(key));
+ }
+ // assertEquals(1, allNotWellMap.size());
+
+ Map<String, String> allSeemsWellMap = im.getAllSeemsWellMap();
+ // assertTrue(allSeemsWellMap.isEmpty());
+
+ // Return to normal
+ im.allSeemsWell(this.getClass().getName(), IntegrityMonitorProperties.ALLSEEMSWELL,
+ "'AllSeemsWellTest - ALLSEEMSWELL'");
+
+ // Wait for the state to change due to ALLNOTWELL
+ Thread.sleep(STATE_CYCLE_MS);
+ // Check the state
+ logger.debug(
+ "\n\ntestAllSeemsWell after ALLSEEMSWELL: im state \nAdminState = {}\nOpState() = {}\nAvailStatus = {}\nStandbyStatus = {}\n",
+ sm.getAdminState(), sm.getOpState(), sm.getAvailStatus(), sm.getStandbyStatus());
+
+ // assertEquals(StateManagement.ENABLED, sm.getOpState());
+
+ allNotWellMap = im.getAllNotWellMap();
+ assertTrue(allNotWellMap.isEmpty());
+
+ allSeemsWellMap = im.getAllSeemsWellMap();
+ assertEquals(1, allSeemsWellMap.size());
+ for (String key : allSeemsWellMap.keySet()) {
+ logger.debug("AllSeemsWellTest: allSeemsWellMap: key = {} msg = {}", key, allSeemsWellMap.get(key));
+ }
+
+ // Check for null parameters
+ assertException(im, imx -> {
+ imx.allSeemsWell(null, IntegrityMonitorProperties.ALLSEEMSWELL, "'AllSeemsWellTest - ALLSEEMSWELL'");
+ });
+
+ assertException(im, imx -> {
+ im.allSeemsWell("", IntegrityMonitorProperties.ALLSEEMSWELL, "'AllSeemsWellTest - ALLSEEMSWELL'");
+ });
+
+ assertException(im, imx -> {
+ im.allSeemsWell(this.getClass().getName(), null, "'AllSeemsWellTest - ALLSEEMSWELL'");
+ });
+
+ assertException(im, imx -> {
+ im.allSeemsWell(this.getClass().getName(), IntegrityMonitorProperties.ALLSEEMSWELL, null);
+ });
+
+ assertException(im, imx -> {
+ im.allSeemsWell(this.getClass().getName(), IntegrityMonitorProperties.ALLSEEMSWELL, "");
+ });
+
+ logger.debug("\n\ntestAllSeemsWell: Exit\n\n");
+ }
+
+}