summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-07-19 15:19:22 -0400
committerJim Hahn <jrh3@att.com>2019-07-19 15:35:18 -0400
commit538a204455ca708eaf20785972be3ac1c2a7ed3f (patch)
tree28c3f1f4e740aabe325160c45865e1573970a265 /main/src/test
parentb6037cbe4a1fde65cb91f37b86f9c789d5a3079e (diff)
Modify policy/distribution to use RestServer from common
This also entailed removing the local copy of RestServerParameters. Also added an AafFilter, which was missing from the original code. Change-Id: Ibbdce8c395e0149ab540a3704b3554a9d96b9705 Issue-ID: POLICY-1652 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java31
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java4
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java8
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java6
-rw-r--r--main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt10
-rw-r--r--main/src/test/resources/parameters/RestServerParameters.json6
-rw-r--r--main/src/test/resources/parameters/RestServerParametersEmpty.json2
7 files changed, 43 insertions, 24 deletions
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
index ccd3db6c..19beadb6 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications 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.
@@ -20,11 +21,18 @@
package org.onap.policy.distribution.main.parameters;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
import org.onap.policy.distribution.main.testclasses.DummyPolicyDecoderParameterGroup;
import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
@@ -44,11 +52,6 @@ import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParamet
*/
public class CommonTestData {
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
- private static final String REST_SERVER_USER = "healthcheck";
- private static final int REST_SERVER_PORT = 6969;
- private static final String REST_SERVER_HOST = "0.0.0.0";
- private static final boolean REST_SERVER_HTTPS = false;
public static final String DISTRIBUTION_GROUP_NAME = "SDCDistributionGroup";
public static final String DECODER_TYPE = "DummyDecoder";
public static final String DECODER_CLASS_NAME = "org.onap.policy.distribution.main.testclasses.DummyDecoder";
@@ -73,6 +76,8 @@ public class CommonTestData {
public static final String POLICY_NAME = "SamplePolicy";
public static final String DECODER_CONFIGURATION_PARAMETERS = "dummyDecoderConfiguration";
+ private Coder coder = new StandardCoder();
+
/**
* Returns an instance of ReceptionHandlerParameters for test cases.
*
@@ -80,14 +85,14 @@ public class CommonTestData {
* @return the restServerParameters object
*/
public RestServerParameters getRestServerParameters(final boolean isEmpty) {
- final RestServerParameters restServerParameters;
- if (!isEmpty) {
- restServerParameters = new RestServerParameters(REST_SERVER_HOST, REST_SERVER_PORT, REST_SERVER_USER,
- REST_SERVER_PASSWORD, REST_SERVER_HTTPS);
- } else {
- restServerParameters = new RestServerParameters(null, 0, null, null, REST_SERVER_HTTPS);
+ String fileName = "src/test/resources/parameters/"
+ + (isEmpty ? "RestServerParametersEmpty" : "RestServerParameters") + ".json";
+ try {
+ String text = new String(Files.readAllBytes(new File(fileName).toPath()), StandardCharsets.UTF_8);
+ return coder.decode(text, RestServerParameters.class);
+ } catch (CoderException | IOException e) {
+ throw new RuntimeException("cannot read/decode " + fileName, e);
}
- return restServerParameters;
}
/**
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
index 8a33ac2c..f612c81e 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications 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.
@@ -28,6 +29,7 @@ import static org.junit.Assert.fail;
import java.util.Map;
import org.junit.Test;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup;
@@ -226,7 +228,7 @@ public class TestDistributionParameterGroup {
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.distribution.main.parameters.RestServerParameters\" INVALID, "
+ .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
+ "parameter group has status INVALID"));
}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
index 356a5861..3644864e 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -36,11 +37,12 @@ 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.endpoints.http.server.RestServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
-import org.onap.policy.distribution.main.parameters.RestServerParameters;
import org.onap.policy.distribution.main.startstop.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,13 +79,13 @@ public class TestDistributionRestServer {
final String reportString = "Report [name=Policy SSD, url=self, healthy=false, code=500, message=not alive]";
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
- final DistributionRestServer restServer = new DistributionRestServer(restServerParams);
+ final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class);
try {
restServer.start();
final HealthCheckReport report = performHealthCheck();
validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report);
assertTrue(restServer.isAlive());
- assertTrue(restServer.toString().startsWith("DistributionRestServer [servers="));
+ assertTrue(restServer.toString().startsWith("RestServer [servers="));
restServer.shutdown();
} catch (final Exception exp) {
LOGGER.error("testHealthCheckFailure failed", exp);
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
index 6c95a2a8..0b47bcc3 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionStatistics.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications 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.
@@ -35,10 +36,11 @@ 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.endpoints.http.server.RestServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
-import org.onap.policy.distribution.main.parameters.RestServerParameters;
import org.onap.policy.distribution.main.startstop.Main;
import org.onap.policy.distribution.reception.statistics.DistributionStatisticsManager;
import org.slf4j.Logger;
@@ -75,7 +77,7 @@ public class TestDistributionStatistics {
public void testDistributionStatistics_500() throws InterruptedException {
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
- final DistributionRestServer restServer = new DistributionRestServer(restServerParams);
+ final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class);
try {
restServer.start();
final StatisticsReport report = getDistributionStatistics();
diff --git a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
index ceb195ae..f3152e41 100644
--- a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
+++ b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
@@ -1,7 +1,7 @@
validation error(s) on parameters from "parameters/DistributionConfigParameters_InvalidRestServerParameters.json"
parameter group "SDCDistributionGroup" type "org.onap.policy.distribution.main.parameters.DistributionParameterGroup" INVALID, parameter group has status INVALID
- parameter group "null" type "org.onap.policy.distribution.main.parameters.RestServerParameters" INVALID, parameter group has status INVALID
- field "host" type "java.lang.String" value "" INVALID, must be a non-blank string containing hostname/ipaddress of the distribution rest server
- field "port" type "int" value "-1" INVALID, must be a positive integer containing port of the distribution rest server
- field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string containing userName for distribution rest server credentials
- field "password" type "java.lang.String" value "" INVALID, must be a non-blank string containing password for distribution rest server credentials
+ parameter group "RestServerParameters" type "org.onap.policy.common.endpoints.parameters.RestServerParameters" INVALID, parameter group has status INVALID
+ field "host" type "java.lang.String" value "" INVALID, must be a non-blank string
+ field "port" type "int" value "-1" INVALID, must be >= 1
+ field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string
+ field "password" type "java.lang.String" value "" INVALID, must be a non-blank string \ No newline at end of file
diff --git a/main/src/test/resources/parameters/RestServerParameters.json b/main/src/test/resources/parameters/RestServerParameters.json
new file mode 100644
index 00000000..86aee276
--- /dev/null
+++ b/main/src/test/resources/parameters/RestServerParameters.json
@@ -0,0 +1,6 @@
+{
+ "host": "0.0.0.0",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+}
diff --git a/main/src/test/resources/parameters/RestServerParametersEmpty.json b/main/src/test/resources/parameters/RestServerParametersEmpty.json
new file mode 100644
index 00000000..e02aef27
--- /dev/null
+++ b/main/src/test/resources/parameters/RestServerParametersEmpty.json
@@ -0,0 +1,2 @@
+{
+} \ No newline at end of file