package org.onap.policy.pdpx.main.startstop;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import java.io.FileInputStream;
+import java.util.Properties;
import org.junit.After;
+import org.junit.Before;
import org.junit.BeforeClass;
-
import org.junit.Test;
+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.
- * @throws PolicyXacmlPdpException when Xacml PDP Exceptional condition occurs
+ * Loads properties.
*/
@BeforeClass
- public static void setup() throws PolicyXacmlPdpException {
- final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"};
+ public static void setUpBeforeClass() throws Exception {
+ CommonRest.setUpBeforeClass();
+ final String[] xacmlPdpConfigParameters =
+ {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters);
+ parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
- final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
+ 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();
+ }
- activator = new XacmlPdpActivator(parGroup);
- activator.initialize();
+ /**
+ * Creates the activator.
+ */
+ @Before
+ public void setUp() {
+ activator = new XacmlPdpActivator(parGroup, props);
}
@Test
- public void testXacmlPdpActivator() throws PolicyXacmlPdpException {
+ public void testXacmlPdpActivator() throws Exception {
+ assertFalse(activator.isAlive());
+ activator.start();
+ assertTrue(activator.isAlive());
assertTrue(activator.getParameterGroup().isValid());
assertEquals(CommonTestData.PDPX_GROUP_NAME, activator.getParameterGroup().getName());
+
}
+ @Test
+ public void testGetCurrent_testSetCurrent() {
+ XacmlPdpActivator.setCurrent(activator);
+ assertSame(activator, XacmlPdpActivator.getCurrent());
+ }
+
+ @Test
+ public void testTerminate() throws Exception {
+ activator.start();
+ activator.stop();
+ assertFalse(activator.isAlive());
+ }
+
+ /**
+ * Teardown tests.
+ * @throws PolicyXacmlPdpException on termination errors
+ */
@After
public void teardown() throws PolicyXacmlPdpException {
- activator.terminate();
+ if (activator != null && activator.isAlive()) {
+ activator.stop();
+ }
}
}