aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-monitor/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-11-27 15:15:57 -0500
committerJim Hahn <jrh3@att.com>2018-11-27 15:17:07 -0500
commit1ff3457738007037364a103c28836d582098f764 (patch)
treeb8a9b146aee6178079b7bb60fe6d341fda12e5a7 /integrity-monitor/src/test/java
parentdc569fec077a6d6acce415925685699d5907cd2d (diff)
Remove Factory from IntegrityMonitor
Also removed unneeded method override in junit test. Change-Id: I7186e9f75443f7b8ba8376aa0e00a5cf4c573696 Issue-ID: POLICY-1287 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor/src/test/java')
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/AllSeemsWellTest.java17
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTest.java20
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTestBase.java33
3 files changed, 17 insertions, 53 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
index fe408931..6d67dd1b 100644
--- 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
@@ -31,7 +31,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.common.im.IntegrityMonitor.Factory;
import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,19 +61,21 @@ public class AllSeemsWellTest extends IntegrityMonitorTestBase {
/**
* Set up for test cases.
+ * @throws Exception if an error occurs
*/
@Before
- public void setUp() {
+ public void setUp() throws Exception {
super.setUpTest();
myProp = makeProperties();
monitorSem = new Semaphore(0);
junitSem = new Semaphore(0);
-
- Factory factory = new TestFactory() {
+
+ IntegrityMonitor im = new IntegrityMonitor(resourceName, myProp) {
+
@Override
- public void runStarted() throws InterruptedException {
+ protected void runStarted() throws InterruptedException {
monitorSem.acquire();
junitSem.release();
@@ -82,13 +83,13 @@ public class AllSeemsWellTest extends IntegrityMonitorTestBase {
}
@Override
- public void monitorCompleted() throws InterruptedException {
+ protected void monitorCompleted() throws InterruptedException {
junitSem.release();
monitorSem.acquire();
- }
+ }
};
- Whitebox.setInternalState(IntegrityMonitor.class, FACTORY_FIELD, factory);
+ Whitebox.setInternalState(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
}
@After
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 3c4fba23..862552b8 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
@@ -21,7 +21,6 @@
package org.onap.policy.common.im;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Date;
@@ -37,7 +36,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.common.im.IntegrityMonitor.Factory;
import org.onap.policy.common.im.jpa.ForwardProgressEntity;
import org.onap.policy.common.im.jpa.ResourceRegistrationEntity;
import org.onap.policy.common.im.jpa.StateManagementEntity;
@@ -110,11 +108,6 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
super.tearDownTest();
}
-
- @Test
- public void testFactory() {
- assertNotNull(getSavedFactory());
- }
/*
* The following test verifies the following test cases: New Install New Install - Bad
@@ -917,10 +910,11 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
monitorSem = new Semaphore(0);
junitSem = new Semaphore(0);
-
- Factory factory = new TestFactory() {
+
+ IntegrityMonitor im = new IntegrityMonitor(resourceName, myProp) {
+
@Override
- public void runStarted() throws InterruptedException {
+ protected void runStarted() throws InterruptedException {
monitorSem.acquire();
junitSem.release();
@@ -928,15 +922,13 @@ public class IntegrityMonitorTest extends IntegrityMonitorTestBase {
}
@Override
- public void monitorCompleted() throws InterruptedException {
+ protected void monitorCompleted() throws InterruptedException {
junitSem.release();
monitorSem.acquire();
}
};
-
- Whitebox.setInternalState(IntegrityMonitor.class, FACTORY_FIELD, factory);
- IntegrityMonitor im = IntegrityMonitor.getInstance(resourceName, myProp);
+ Whitebox.setInternalState(IntegrityMonitor.class, IM_INSTANCE_FIELD, im);
// wait for the monitor thread to start
waitCycles(1);
diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTestBase.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTestBase.java
index f3ad1d32..43078432 100644
--- a/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTestBase.java
+++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/IntegrityMonitorTestBase.java
@@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
-import org.onap.policy.common.im.IntegrityMonitor.Factory;
import org.onap.policy.common.utils.jpa.EntityTransCloser;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.CurrentTime;
@@ -53,9 +52,9 @@ public class IntegrityMonitorTestBase {
private static Logger logger = LoggerFactory.getLogger(IntegrityMonitorTestBase.class);
/**
- * Name of the factory field within the IntegrityMonitor class.
+ * Name of the instance field within the IntegrityMonitor class.
*/
- public static final String FACTORY_FIELD = "factory";
+ public static final String IM_INSTANCE_FIELD = "instance";
/**
* Name of the instance field within the MonitorTime class.
@@ -121,11 +120,6 @@ public class IntegrityMonitorTestBase {
private static Object savedJmxPort;
/**
- * Saved factory, to be restored once all tests complete.
- */
- private static Factory savedFactory;
-
- /**
* Saved time accessor, to be restored once all tests complete.
*/
private static CurrentTime savedTime;
@@ -151,14 +145,11 @@ public class IntegrityMonitorTestBase {
IntegrityMonitorTestBase.dbUrl = dbUrl;
// save data that we have to restore at the end of the test
- savedFactory = Whitebox.getInternalState(IntegrityMonitor.class, FACTORY_FIELD);
savedJmxPort = systemProps.get(JMX_PORT_PROP);
savedTime = MonitorTime.getInstance();
systemProps.put(JMX_PORT_PROP, "9797");
- Whitebox.setInternalState(IntegrityMonitor.class, FACTORY_FIELD, new TestFactory());
-
IntegrityMonitor.setUnitTesting(true);
testTime = new TestTime();
@@ -196,7 +187,6 @@ public class IntegrityMonitorTestBase {
}
Whitebox.setInternalState(MonitorTime.class, TIME_INSTANCE_FIELD, savedTime);
- Whitebox.setInternalState(IntegrityMonitor.class, FACTORY_FIELD, savedFactory);
IntegrityMonitor.setUnitTesting(false);
@@ -233,15 +223,6 @@ public class IntegrityMonitorTestBase {
}
/**
- * Get saved factory.
- *
- * @return the original integrity monitor factory
- */
- static Factory getSavedFactory() {
- return savedFactory;
- }
-
- /**
* Stops the IntegrityMonitor instance.
*/
private static void stopMonitor() {
@@ -318,16 +299,6 @@ public class IntegrityMonitorTestBase {
System.out.println("action found expected exception: " + e);
}
}
-
- /**
- * Factory with overrides for junit testing.
- */
- public static class TestFactory extends Factory {
- @Override
- public String getPersistenceUnit() {
- return PERSISTENCE_UNIT;
- }
- }
@FunctionalInterface
protected static interface VoidFunction<T> {