diff options
author | Michael Mokry <michael.mokry@att.com> | 2019-02-13 10:34:48 -0600 |
---|---|---|
committer | Michael Mokry <michael.mokry@att.com> | 2019-02-13 10:38:31 -0600 |
commit | ab1824d122b50d29e000bb58521d8dace9cba2b6 (patch) | |
tree | 609f95d0b9df7d0386c3b50846e8a99674cd4486 /main/src/test/java/org/onap | |
parent | f239a66e5dd52f4f0149a307789909c5ffc2b704 (diff) |
Package and Create Docker Image for Xacml PDP
- Creates docker image of policy xacml-pdp
- Creates zip package of policy xacml-pdp
- Also committed changes from Healthcheck/Statitics review that were
allowed to be deferred
Change-Id: Ia5fb72be05a30a341692453fe4ff32c7b112e861
Issue-ID: POLICY-1436
Signed-off-by: Michael Mokry <michael.mokry@att.com>
Diffstat (limited to 'main/src/test/java/org/onap')
3 files changed, 72 insertions, 52 deletions
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 ce0671a6..d9a0e9b0 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 @@ -23,7 +23,9 @@ package org.onap.policy.pdpx.main.rest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.IOException; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation; @@ -33,6 +35,7 @@ import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.Test; import org.onap.policy.common.endpoints.report.HealthCheckReport; +import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; import org.onap.policy.pdpx.main.parameters.RestServerParameters; @@ -56,10 +59,16 @@ public class TestXacmlPdpRestServer { @Test public void testHealthCheckSuccess() throws PolicyXacmlPdpException, InterruptedException { final String reportString = "Report [name=Policy Xacml PDP, url=self, healthy=true, code=200, message=alive]"; - final Main main = startXacmlPdpService(); - final HealthCheckReport report = performHealthCheck(); - validateReport(NAME, SELF, true, 200, ALIVE, reportString, report); - stopXacmlPdpService(main); + try { + final Main main = startXacmlPdpService(); + final HealthCheckReport report = performHealthCheck(); + validateReport(NAME, SELF, true, 200, ALIVE, reportString, report); + stopXacmlPdpService(main); + } catch (final Exception e) { + LOGGER.error("testHealthCheckSuccess failed", e); + fail("Test should not throw an exception"); + } + } @Test @@ -69,12 +78,18 @@ public class TestXacmlPdpRestServer { final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false); restServerParams.setName(CommonTestData.PDPX_GROUP_NAME); final XacmlPdpRestServer restServer = new XacmlPdpRestServer(restServerParams); - restServer.start(); - final HealthCheckReport report = performHealthCheck(); - validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report); - assertTrue(restServer.isAlive()); - assertTrue(restServer.toString().startsWith("XacmlPdpRestServer [servers=")); - restServer.shutdown(); + + try { + restServer.start(); + final HealthCheckReport report = performHealthCheck(); + validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report); + assertTrue(restServer.isAlive()); + assertTrue(restServer.toString().startsWith("XacmlPdpRestServer [servers=")); + restServer.shutdown(); + } catch (final Exception e) { + LOGGER.error("testHealthCheckSuccess failed", e); + fail("Test should not throw an exception"); + } } private Main startXacmlPdpService() { @@ -86,8 +101,8 @@ public class TestXacmlPdpRestServer { main.shutdown(); } - private HealthCheckReport performHealthCheck() throws InterruptedException { - HealthCheckReport response = null; + private HealthCheckReport performHealthCheck() throws InterruptedException, IOException { + final ClientConfig clientConfig = new ClientConfig(); final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"); @@ -98,15 +113,11 @@ public class TestXacmlPdpRestServer { final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); - final long startTime = System.currentTimeMillis(); - while (response == null && (System.currentTimeMillis() - startTime) < 120000) { - try { - response = invocationBuilder.get(HealthCheckReport.class); - } catch (final Exception exp) { - LOGGER.info("the server is not started yet. We will retry again"); - } + if (!NetworkUtil.isTcpPortOpen("localhost", 6969, 6, 10000L)) { + throw new IllegalStateException("Cannot connect to port 6969"); } - return response; + + return invocationBuilder.get(HealthCheckReport.class); } private void validateReport(final String name, final String url, final boolean healthy, final int code, 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 303a3cfe..b38e92d2 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 @@ -22,17 +22,18 @@ package org.onap.policy.pdpx.main.rest; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import java.io.IOException; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation; 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.Test; - +import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; import org.onap.policy.pdpx.main.parameters.RestServerParameters; @@ -49,38 +50,44 @@ public class TestXacmlPdpStatistics { private static final Logger LOGGER = LoggerFactory.getLogger(TestXacmlPdpStatistics.class); - @Test public void testXacmlPdpStatistics_200() throws PolicyXacmlPdpException, InterruptedException { - final Main main = startXacmlPdpService(); - StatisticsReport report = getXacmlPdpStatistics(); - - validateReport(report, 0, 200); - updateXacmlPdpStatistics(); - report = getXacmlPdpStatistics(); - validateReport(report, 1, 200); - stopXacmlPdpService(main); - XacmlPdpStatisticsManager.resetAllStatistics(); + try { + final Main main = startXacmlPdpService(); + StatisticsReport report = getXacmlPdpStatistics(); + validateReport(report, 0, 200); + updateXacmlPdpStatistics(); + report = getXacmlPdpStatistics(); + validateReport(report, 1, 200); + stopXacmlPdpService(main); + XacmlPdpStatisticsManager.resetAllStatistics(); + } catch (final Exception e) { + LOGGER.error("testApiStatistics_200 failed", e); + fail("Test should not throw an exception"); + } } @Test public void testXacmlPdpStatistics_500() throws InterruptedException { final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false); restServerParams.setName(CommonTestData.PDPX_GROUP_NAME); - final XacmlPdpRestServer restServer = new XacmlPdpRestServer(restServerParams); - restServer.start(); - final StatisticsReport report = getXacmlPdpStatistics(); - validateReport(report, 0, 500); - restServer.shutdown(); - XacmlPdpStatisticsManager.resetAllStatistics(); + try { + restServer.start(); + final StatisticsReport report = getXacmlPdpStatistics(); + validateReport(report, 0, 500); + restServer.shutdown(); + XacmlPdpStatisticsManager.resetAllStatistics(); + } catch (final Exception e) { + LOGGER.error("testApiStatistics_500 failed", e); + fail("Test should not throw an exception"); + } } private Main startXacmlPdpService() { - final String[] XacmlPdpConfigParameters = - { "-c", "parameters/XacmlPdpConfigParameters.json" }; + final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"}; return new Main(XacmlPdpConfigParameters); } @@ -88,8 +95,8 @@ public class TestXacmlPdpStatistics { main.shutdown(); } - private StatisticsReport getXacmlPdpStatistics() throws InterruptedException { - StatisticsReport response = null; + private StatisticsReport getXacmlPdpStatistics() throws InterruptedException, IOException { + final ClientConfig clientConfig = new ClientConfig(); final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"); @@ -99,15 +106,12 @@ public class TestXacmlPdpStatistics { final WebTarget webTarget = client.target("http://localhost:6969/statistics"); final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); - final long startTime = System.currentTimeMillis(); - while (response == null && (System.currentTimeMillis() - startTime) < 120000) { - try { - response = invocationBuilder.get(StatisticsReport.class); - } catch (final Exception exp) { - LOGGER.info("the server is not started yet. We will retry again"); - } + + if (!NetworkUtil.isTcpPortOpen("localhost", 6969, 6, 10000L)) { + throw new IllegalStateException("Cannot connect to port 6969"); } - return response; + + return invocationBuilder.get(StatisticsReport.class); } private void updateXacmlPdpStatistics() { 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 8178343c..bfc8a2a4 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 @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.junit.Assert; import org.junit.Test; import org.onap.policy.pdpx.main.PolicyXacmlPdpException; import org.onap.policy.pdpx.main.parameters.CommonTestData; @@ -44,10 +45,11 @@ public class TestMain { } @Test - public void testMain_NoArguments() { + public void testMain_NoArguments() throws PolicyXacmlPdpException { final String[] xacmlPdpConfigParameters = {}; final Main main = new Main(xacmlPdpConfigParameters); assertNull(main.getParameters()); + main.shutdown(); } @Test @@ -60,7 +62,10 @@ public class TestMain { @Test public void testMain_Help() { final String[] xacmlPdpConfigParameters = {"-h"}; - Main.main(xacmlPdpConfigParameters); + final Main main = new Main(xacmlPdpConfigParameters); + final String message = "-h,--help outputs the usage of this command"; + Assert.assertTrue(main.getArgumentMessage().contains(message)); + } @Test |