Fix broken junits in policy-distribution 35/121535/2
authorJim Hahn <jrh3@att.com>
Tue, 25 May 2021 15:06:41 +0000 (11:06 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 25 May 2021 15:15:49 +0000 (11:15 -0400)
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>
main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java
main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsDistributionRestServer.java
main/src/test/java/org/onap/policy/distribution/main/rest/TestHttpsStatisticDistributionRestServer.java
main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java

index 9d3df3e..ce4cda2 100644 (file)
@@ -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 {
index ef4d1f5..82e40cc 100644 (file)
@@ -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 {
index 9520afb..d47cb52 100644 (file)
@@ -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(() -> {
index b15ef27..6505dfb 100644 (file)
@@ -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");
index 4094bd5..e00c181 100644 (file)
@@ -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");