aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-05-25 11:06:41 -0400
committerJim Hahn <jrh3@att.com>2021-05-25 11:15:49 -0400
commit6e2e640ea348fb4e98552a8d2672c216ce806a71 (patch)
tree6040916b0b611389ad3b990da9ebbafcd9d61ead /main/src/test
parenta96bfe9b7b62404278d107ef068f8ae5ddf82913 (diff)
Fix broken junits in policy-distribution
Changes in policy-common broke some junits in policy-distribution. Some issues were due to the use of lombok ToString annotations, while others appear to be due to parameter groups being previously registered - don't really know the issue there, though probably the parameter group name is now being set, while it wasn't before. In any event, fixed the junits. Issue-ID: POLICY-3298 Change-Id: Iaca9b2ec2c42582e9083ad5825c84cdc8ebc9d6c 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/rest/TestDistributionRestServer.java43
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java22
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java7
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java9
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java9
5 files changed, 61 insertions, 29 deletions
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 9d3df3e7..ce4cda24 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,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@
package org.onap.policy.distribution.main.rest;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -35,11 +36,13 @@ 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.Test;
import org.mockito.internal.util.reflection.Whitebox;
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.parameters.ParameterService;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
@@ -59,34 +62,36 @@ public class TestDistributionRestServer {
private int port;
+ @Before
+ public void setUp() {
+ ParameterService.clear();
+ }
+
@Test
- public void testHealthCheckSuccess() {
- final String reportString = "Report [name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive]";
- assertThatCode(() -> {
- final Main main = startDistributionService();
- final HealthCheckReport report = performHealthCheck();
- validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
- stopDistributionService(main);
- }).doesNotThrowAnyException();
+ public void testHealthCheckSuccess() throws IOException, InterruptedException {
+ final String reportString =
+ "HealthCheckReport(name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive)";
+ final Main main = startDistributionService();
+ final HealthCheckReport report = performHealthCheck();
+ validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
+ assertThatCode(() -> stopDistributionService(main)).doesNotThrowAnyException();
}
@Test
- public void testHealthCheckFailure() throws IOException {
+ public void testHealthCheckFailure() throws IOException, InterruptedException {
port = NetworkUtil.allocPort();
final String reportString =
- "Report [name=Policy SSD, url=" + SELF + ", healthy=false, code=500, message=not alive]";
+ "HealthCheckReport(name=Policy SSD, url=" + SELF + ", healthy=false, code=500, message=not alive)";
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
Whitebox.setInternalState(restServerParams, "port", port);
restServerParams.setName(CommonTestData.DISTRIBUTION_GROUP_NAME);
final RestServer restServer = new RestServer(restServerParams, null, DistributionRestController.class);
- assertThatCode(() -> {
- restServer.start();
- final HealthCheckReport report = performHealthCheck();
- validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report);
- assertTrue(restServer.isAlive());
- assertTrue(restServer.toString().startsWith("RestServer [servers="));
- restServer.shutdown();
- }).doesNotThrowAnyException();
+ restServer.start();
+ final HealthCheckReport report = performHealthCheck();
+ validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report);
+ assertTrue(restServer.isAlive());
+ assertThat(restServer.toString()).startsWith("RestServer(servers=");
+ assertThatCode(restServer::shutdown).doesNotThrowAnyException();
}
private Main startDistributionService() throws IOException {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
index ef4d1f5b..82e40ccd 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
@@ -36,8 +36,10 @@ import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
import org.onap.policy.distribution.main.PolicyDistributionException;
@@ -57,15 +59,19 @@ public class TestHttpsDistributionRestServer {
private int port;
+ @Before
+ public void setUp() {
+ ParameterService.clear();
+ }
+
@Test
- public void testHttpsHealthCheckSuccess() {
- final String reportString = "Report [name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive]";
- assertThatCode(() -> {
- final Main main = startDistributionService();
- final HealthCheckReport report = performHealthCheck();
- validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
- stopDistributionService(main);
- }).doesNotThrowAnyException();
+ public void testHttpsHealthCheckSuccess() throws Exception {
+ final String reportString =
+ "HealthCheckReport(name=Policy SSD, url=" + SELF + ", healthy=true, code=200, message=alive)";
+ final Main main = startDistributionService();
+ final HealthCheckReport report = performHealthCheck();
+ validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
+ assertThatCode(() -> stopDistributionService(main)).doesNotThrowAnyException();
}
private Main startDistributionService() throws IOException, InterruptedException {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
index 9520afb6..d47cb52d 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
@@ -37,7 +37,9 @@ import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
import org.onap.policy.distribution.main.PolicyDistributionException;
@@ -53,6 +55,11 @@ public class TestHttpsStatisticDistributionRestServer {
private int port;
+ @Before
+ public void setUp() {
+ ParameterService.clear();
+ }
+
@Test
public void testHttpsDistributionStatistic() {
assertThatCode(() -> {
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
index b15ef273..6505dfbe 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 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.
@@ -26,7 +26,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
@@ -40,6 +42,11 @@ import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParamet
*/
public class TestDistributionActivator {
+ @Before
+ public void setUp() {
+ ParameterService.clear();
+ }
+
@Test
public void testDistributionActivator() throws PolicyDistributionException, IOException {
CommonTestData.makeConfigFile("parameters/DistributionConfigParameters.json");
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
index 4094bd53..e00c1810 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 AT&T Inc.
+ * Modifications Copyright (C) 2020-2021 AT&T Inc.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.resources.MessageConstants;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.PolicyDistributionRuntimeException;
@@ -41,6 +43,11 @@ import org.onap.policy.distribution.main.parameters.CommonTestData;
*/
public class TestMain {
+ @Before
+ public void setUp() {
+ ParameterService.clear();
+ }
+
@Test
public void testMain() throws PolicyDistributionException, IOException {
CommonTestData.makeConfigFile("parameters/DistributionConfigParameters.json");