summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorAli Hockla <ah999m@att.com>2019-11-05 08:15:20 -0600
committerAli Hockla <ah999m@att.com>2019-11-05 13:46:33 -0600
commitdd69ccf79236b5268cc8cac2638fcd07f373bd4d (patch)
tree35db5821e4078d6a7dbed48c0a3adf700ca0a416 /main/src/test
parentda6120bf874de49a4b998b705e6b5cc0ee69bd03 (diff)
Added support for 'Active' and 'Passive' states.
Removed the rest server start/stop from the Activator because the engine starts in PASSIVE state. Added code to start/stop the rest server when a pdp state change occurs. Issue-ID: POLICY-2154 Change-Id: Iec6fcc990dc3dde702a911eb4f90d29e25c395a2 Signed-off-by: Ali Hockla <ah999m@att.com>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java3
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java11
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java2
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java2
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java10
5 files changed, 28 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
index a32bc6fd..d2379e09 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
@@ -120,6 +120,9 @@ public class CommonRest {
final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE};
main = new Main(xacmlPdpConfigParameters);
+ // start xacml rest controller
+ XacmlPdpActivator.getCurrent().startXacmlRestController();
+
if (!NetworkUtil.isTcpPortOpen("localhost", port, 20, 1000L)) {
throw new IllegalStateException("server is not listening on port " + port);
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index 20136bf0..eef1f1be 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
@@ -135,6 +136,16 @@ public class XacmlStateTest {
// ensure info was saved
status = state.genHeartbeat();
assertEquals(PdpState.SAFE, status.getState());
+
+ req.setState(PdpState.ACTIVE);
+ status = state.updateInternalState(req);
+ assertEquals(PdpState.ACTIVE, status.getState());
+ verify(act).startXacmlRestController();
+
+ req.setState(PdpState.PASSIVE);
+ status = state.updateInternalState(req);
+ assertEquals(PdpState.PASSIVE, status.getState());
+ verify(act).stopXacmlRestController();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
index 37a669d2..d416cd3b 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
@@ -67,6 +67,7 @@ import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
import org.onap.policy.pdpx.main.startstop.Main;
+import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
import org.onap.policy.xacml.pdp.application.monitoring.MonitoringPdpApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -130,6 +131,7 @@ public class TestAbbreviateDecisionResults {
// Start the service
//
main = startXacmlPdpService(fileParams);
+ XacmlPdpActivator.getCurrent().startXacmlRestController();
//
// Make sure it is running
//
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
index 042180b4..6c6e35b9 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
@@ -61,6 +61,7 @@ import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
import org.onap.policy.pdpx.main.startstop.Main;
+import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -116,6 +117,7 @@ public class TestDecision {
// Start the service
//
main = startXacmlPdpService(fileParams);
+ XacmlPdpActivator.getCurrent().startXacmlRestController();
//
// Make sure it is running
//
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
index cd4b78d9..5223bcd8 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
@@ -64,6 +64,7 @@ public class TestXacmlPdpActivator extends CommonRest {
/**
* Creates the activator.
*/
+ @Override
@Before
public void setUp() {
activator = new XacmlPdpActivator(parGroup);
@@ -72,11 +73,20 @@ public class TestXacmlPdpActivator extends CommonRest {
@Test
public void testXacmlPdpActivator() throws Exception {
assertFalse(activator.isAlive());
+ assertFalse(activator.isXacmlRestControllerAlive());
activator.start();
assertTrue(activator.isAlive());
+
+ // XacmlPdp starts in PASSIVE state so the rest controller should not be alive
+ assertFalse(activator.isXacmlRestControllerAlive());
assertTrue(activator.getParameterGroup().isValid());
assertEquals(CommonTestData.PDPX_GROUP_NAME, activator.getParameterGroup().getName());
+ activator.startXacmlRestController();
+ assertTrue(activator.isXacmlRestControllerAlive());
+
+ activator.stopXacmlRestController();
+ assertFalse(activator.isXacmlRestControllerAlive());
}
@Test