Also removed unneeded method override in junit test.
Change-Id: I7186e9f75443f7b8ba8376aa0e00a5cf4c573696
Issue-ID: POLICY-1287
Signed-off-by: Jim Hahn <jrh3@att.com>
*/
private static final String QUERY_STRING = "Select f from ForwardProgressEntity f where f.resourceName=:rn";
- // may be changed by junit tests
- private static Factory factory = new Factory();
-
private static String resourceName = null;
boolean alarmExists = false;
//
// Create the entity manager factory
//
- emf = Persistence.createEntityManagerFactory(factory.getPersistenceUnit(), properties);
+ emf = Persistence.createEntityManagerFactory(getPersistenceUnit(), properties);
//
// Did it get created?
//
if (emf == null) {
- logger.error("Error creating IM entity manager factory with persistence unit: {}",
- factory.getPersistenceUnit());
+ logger.error("Error creating IM entity manager factory with persistence unit: {}",
+ getPersistenceUnit());
throw new IntegrityMonitorException("Unable to create IM Entity Manager Factory");
}
logger.debug("FPManager thread running");
try {
- factory.runStarted();
+ runStarted();
while (!stopRequested) {
MonitorTime.getInstance().sleep(CYCLE_INTERVAL_MILLIS);
-
- this.runOnce();
- factory.monitorCompleted();
+
+ runOnce();
+ monitorCompleted();
}
} catch (InterruptedException e) {
public Map<String, String> getAllNotWellMap() {
return allNotWellMap;
}
+
+ // these methods may be overridden by junit tests
/**
- * Wrapper used to access various objects. Overridden by junit tests.
+ * Indicates that the {@link FpManager#run()} method has started. This method
+ * simply returns.
+ *
+ * @throws InterruptedException can be interrupted
*/
- public static class Factory {
-
- /**
- * Indicates that the {@link FpManager#run()} method has started. This method simply returns.
- *
- * @throws InterruptedException can be interrupted
- */
- public void runStarted() throws InterruptedException {
- // does nothing
- }
+ protected void runStarted() throws InterruptedException {
+ // does nothing
+ }
- /**
- * Indicates that a monitor activity has completed. This method simply returns.
- *
- * @throws InterruptedException can be interrupted
- */
- public void monitorCompleted() throws InterruptedException {
- // does nothing
- }
+ /**
+ * Indicates that a monitor activity has completed. This method simply returns.
+ *
+ * @throws InterruptedException can be interrupted
+ */
+ protected void monitorCompleted() throws InterruptedException {
+ // does nothing
+ }
- /**
- * Get persistence unit.
- *
- * @return the persistence unit to be used
- */
- public String getPersistenceUnit() {
- return PERSISTENCE_UNIT;
- }
+ /**
+ * Get persistence unit.
+ *
+ * @return the persistence unit to be used
+ */
+ protected String getPersistenceUnit() {
+ return PERSISTENCE_UNIT;
}
/*
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;
/**
* 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();
}
@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
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;
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;
super.tearDownTest();
}
-
- @Test
- public void testFactory() {
- assertNotNull(getSavedFactory());
- }
/*
* The following test verifies the following test cases: New Install New Install - Bad
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();
}
@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);
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;
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.
*/
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.
*/
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();
}
Whitebox.setInternalState(MonitorTime.class, TIME_INSTANCE_FIELD, savedTime);
- Whitebox.setInternalState(IntegrityMonitor.class, FACTORY_FIELD, savedFactory);
IntegrityMonitor.setUnitTesting(false);
stopMonitor();
}
- /**
- * Get saved factory.
- *
- * @return the original integrity monitor factory
- */
- static Factory getSavedFactory() {
- return savedFactory;
- }
-
/**
* Stops the IntegrityMonitor instance.
*/
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> {