diff options
Diffstat (limited to 'main/src/test')
6 files changed, 86 insertions, 24 deletions
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 fe307e4f..c93ba6f7 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 @@ -29,7 +29,6 @@ import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.HashMap; import java.util.Map; - import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; @@ -38,7 +37,6 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; - import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.AfterClass; @@ -119,7 +117,8 @@ public class TestDecision { } private static Main startXacmlPdpService() { - final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"}; + final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json", "-p", + "parameters/topic.properties"}; return new Main(XacmlPdpConfigParameters); } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java index fc3edd73..0deab9d0 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java @@ -46,6 +46,7 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException; import org.onap.policy.common.endpoints.report.HealthCheckReport; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; @@ -113,7 +114,7 @@ public class TestXacmlPdpRestServer { } @Test - public void testHealthCheckSuccess() throws IOException, InterruptedException { + public void testHealthCheckSuccess() throws IOException, InterruptedException, TopicSinkClientException { main = startXacmlPdpService(true); final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT); final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); @@ -142,7 +143,7 @@ public class TestXacmlPdpRestServer { } @Test - public void testStatistics_200() throws IOException, InterruptedException { + public void testStatistics_200() throws IOException, InterruptedException, TopicSinkClientException { main = startXacmlPdpService(true); Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT); StatisticsReport report = invocationBuilder.get(StatisticsReport.class); @@ -188,11 +189,13 @@ public class TestXacmlPdpRestServer { } } - private Main startXacmlPdpService(final boolean http) { - final String[] xacmlPdpConfigParameters = new String[2]; + private Main startXacmlPdpService(final boolean http) throws TopicSinkClientException { + final String[] xacmlPdpConfigParameters = new String[4]; if (http) { xacmlPdpConfigParameters[0] = "-c"; xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters.json"; + xacmlPdpConfigParameters[2] = "-p"; + xacmlPdpConfigParameters[3] = "parameters/topic.properties"; } else { final Properties systemProps = System.getProperties(); systemProps.put("javax.net.ssl.keyStore", KEYSTORE); @@ -200,6 +203,8 @@ public class TestXacmlPdpRestServer { System.setProperties(systemProps); xacmlPdpConfigParameters[0] = "-c"; xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters_Https.json"; + xacmlPdpConfigParameters[2] = "-p"; + xacmlPdpConfigParameters[3] = "parameters/topic.properties"; } return new Main(xacmlPdpConfigParameters); } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java index 8d2f7ce4..5b08aa80 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java @@ -34,11 +34,11 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; @@ -111,8 +111,9 @@ public class TestXacmlPdpStatistics { } - private Main startXacmlPdpService() { - final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"}; + private Main startXacmlPdpService() throws TopicSinkClientException { + final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json", "-p", + "parameters/topic.properties"}; return new Main(XacmlPdpConfigParameters); } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java index 8c37acb7..80ee95f6 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; @@ -47,7 +48,7 @@ public class TestMain { } @Test - public void testMain() throws PolicyXacmlPdpException { + public void testMain() throws PolicyXacmlPdpException, TopicSinkClientException { final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"}; final Main main = new Main(xacmlPdpConfigParameters); assertTrue(main.getParameters().isValid()); @@ -56,7 +57,7 @@ public class TestMain { } @Test - public void testMain_NoArguments() throws PolicyXacmlPdpException { + public void testMain_NoArguments() throws PolicyXacmlPdpException, TopicSinkClientException { final String[] xacmlPdpConfigParameters = {}; final Main main = new Main(xacmlPdpConfigParameters); assertNull(main.getParameters()); @@ -64,14 +65,14 @@ public class TestMain { } @Test - public void testMain_InvalidArguments() { + public void testMain_InvalidArguments() throws TopicSinkClientException { final String[] xacmlPdpConfigParameters = {"parameters/XacmlPdpConfigParameters.json"}; final Main main = new Main(xacmlPdpConfigParameters); assertNull(main.getParameters()); } @Test - public void testMain_Help() { + public void testMain_Help() throws TopicSinkClientException { final String[] xacmlPdpConfigParameters = {"-h"}; final Main main = new Main(xacmlPdpConfigParameters); final String message = "-h,--help outputs the usage of this command"; @@ -80,7 +81,7 @@ public class TestMain { } @Test - public void testMain_InvalidParameters() { + public void testMain_InvalidParameters() throws TopicSinkClientException { final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidName.json"}; final Main main = new Main(xacmlPdpConfigParameters); assertNull(main.getParameters()); 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 7a514f70..51f737a0 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 @@ -21,12 +21,19 @@ 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.io.FileNotFoundException; +import java.net.UnknownHostException; +import java.util.Properties; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup; @@ -42,28 +49,55 @@ public class TestXacmlPdpActivator { /** * Setup the tests. - * @throws PolicyXacmlPdpException when Xacml PDP Exceptional condition occurs */ @BeforeClass - public static void setup() throws PolicyXacmlPdpException { - final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"}; - + public static void setup() throws Exception { + final String[] xacmlPdpConfigParameters = + {"-c", "parameters/XacmlPdpConfigParameters.json", "-p", "parameters/topic.properties"}; final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters); - final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments); - activator = new XacmlPdpActivator(parGroup); - activator.initialize(); + Properties props = new Properties(); + String propFile = arguments.getFullPropertyFilePath(); + try (FileInputStream stream = new FileInputStream(propFile)) { + props.load(stream); + } + + activator = new XacmlPdpActivator(parGroup, props); } @Test - public void testXacmlPdpActivator() throws PolicyXacmlPdpException { + public void testXacmlPdpActivator() throws PolicyXacmlPdpException, TopicSinkClientException, UnknownHostException { + 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() { + assertSame(activator, XacmlPdpActivator.getCurrent()); + } + + @Test + public void testTerminate() throws Exception { + if (!activator.isAlive()) { + 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(); + } } } diff --git a/main/src/test/resources/parameters/topic.properties b/main/src/test/resources/parameters/topic.properties new file mode 100644 index 00000000..11c17dac --- /dev/null +++ b/main/src/test/resources/parameters/topic.properties @@ -0,0 +1,22 @@ +# ============LICENSE_START======================================================= +# ONAP PAP +# ================================================================================ +# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= + +noop.sink.topics=POLICY-PDP-PAP +noop.sink.topics.POLICY-PDP-PAP.servers=anyserver +noop.source.topics=POLICY-PDP-PAP +noop.source.topics.POLICY-PDP-PAP.servers=anyserver |