aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
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/java
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/java')
-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
4 files changed, 30 insertions, 19 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();