import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.net.UnknownHostException;
import java.util.Properties;
import org.junit.After;
+import org.junit.Before;
import org.junit.BeforeClass;
-
import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
+import org.onap.policy.pdpx.main.CommonRest;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
* Class to perform unit test of XacmlPdpActivator.
*
*/
-public class TestXacmlPdpActivator {
- private static XacmlPdpActivator activator = null;
+public class TestXacmlPdpActivator extends CommonRest {
+ private static XacmlPdpParameterGroup parGroup;
+ private static Properties props;
+
+ private XacmlPdpActivator activator = null;
/**
- * Setup the tests.
+ * Loads properties.
*/
@BeforeClass
- public static void setup() throws Exception {
+ public static void setUpBeforeClass() throws Exception {
+ CommonRest.setUpBeforeClass();
+
final String[] xacmlPdpConfigParameters =
- {"-c", "parameters/XacmlPdpConfigParameters.json", "-p", "parameters/topic.properties"};
+ {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters);
- final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
+ parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
- Properties props = new Properties();
+ props = new Properties();
String propFile = arguments.getFullPropertyFilePath();
try (FileInputStream stream = new FileInputStream(propFile)) {
props.load(stream);
}
+ // don't want the common "main" running
+ CommonRest.stopMain();
+ }
+
+ /**
+ * Creates the activator.
+ */
+ @Before
+ public void setUp() {
activator = new XacmlPdpActivator(parGroup, props);
}
@Test
- public void testXacmlPdpActivator() throws PolicyXacmlPdpException, TopicSinkClientException, UnknownHostException {
+ public void testXacmlPdpActivator() throws Exception {
assertFalse(activator.isAlive());
activator.start();
assertTrue(activator.isAlive());
@Test
public void testGetCurrent_testSetCurrent() {
+ XacmlPdpActivator.setCurrent(activator);
assertSame(activator, XacmlPdpActivator.getCurrent());
}
@Test
public void testTerminate() throws Exception {
- if (!activator.isAlive()) {
- activator.start();
- }
+ activator.start();
activator.stop();
assertFalse(activator.isAlive());
}