Enhance toString methods in factory classes 04/121504/1
authorJim Hahn <jrh3@att.com>
Fri, 21 May 2021 16:19:44 +0000 (12:19 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 21 May 2021 17:08:54 +0000 (13:08 -0400)
The factory classes in policy-endpoints have toString() methods that
return "[]" for their list contents.  Updated the code to provide a list
of the keys rather than just an empty list.
Also replaced some toString() methods with lombok.
Also replace StringBuilder with concatenation in some cases.

Issue-ID: POLICY-3298
Change-Id: I64fca21a4b009f7e09fcc482b5d156753fb7e680
Signed-off-by: Jim Hahn <jrh3@att.com>
28 files changed:
common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java
gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java
gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java
gson/src/test/java/org/onap/policy/common/gson/JacksonHandlerTest.java
gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java
gson/src/test/java/org/onap/policy/common/gson/internal/DataAdapterFactory.java
gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java
integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementTest.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedDmaapTopicSinkFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedDmaapTopicSourceFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedUebTopicSinkFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/IndexedUebTopicSourceFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSink.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyJerseyServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/report/HealthCheckReport.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoReqResp.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlJacksonHandlerTest.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/YamlMessageBodyHandlerTest.java
utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
utils/pom.xml
utils/src/main/java/org/onap/policy/common/utils/resources/TextFileUtils.java
utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java

index b68c62e..7e56230 100644 (file)
@@ -157,21 +157,13 @@ public class ParameterValidationResult implements ValidationResult {
             return null;
         }
 
-        var validationResultBuilder = new StringBuilder();
-
-        validationResultBuilder.append(initialIndentation);
-        validationResultBuilder.append("field \"");
-        validationResultBuilder.append(getName());
-        validationResultBuilder.append("\" type \"");
-        validationResultBuilder.append(field.getType().getName());
-        validationResultBuilder.append("\" value \"");
-        validationResultBuilder.append(parameterValue);
-        validationResultBuilder.append("\" ");
-        validationResultBuilder.append(getStatus());
-        validationResultBuilder.append(", ");
-        validationResultBuilder.append(message);
-        validationResultBuilder.append('\n');
-
-        return validationResultBuilder.toString();
+        return initialIndentation
+            + "field \"" + getName()
+            + "\" type \"" + field.getType().getName()
+            + "\" value \"" + parameterValue
+            + "\" " + getStatus()
+            + ", "
+            + message
+            + '\n';
     }
 }
index c05a1e5..eee0c14 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -196,6 +196,7 @@ public class GsonMessageBodyHandlerTest {
     }
 
 
+    @ToString
     public static class MyObject {
         private int id;
 
@@ -206,11 +207,6 @@ public class GsonMessageBodyHandlerTest {
         public MyObject(int id) {
             this.id = id;
         }
-
-        @Override
-        public String toString() {
-            return "MyObject [id=" + id + "]";
-        }
     }
 
     private static class MyMap {
index 3d7c29d..41933bc 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -31,6 +31,7 @@ import com.google.gson.JsonElement;
 import java.lang.reflect.GenericArrayType;
 import java.util.LinkedList;
 import java.util.TreeMap;
+import lombok.ToString;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -102,6 +103,7 @@ public class JacksonExclusionStrategyTest {
     /**
      * Used to verify that no fields are exposed.
      */
+    @ToString
     public static class Data {
         private int id;
         public String text;
@@ -121,13 +123,9 @@ public class JacksonExclusionStrategyTest {
         public void setText(String text) {
             this.text = text;
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", text=" + text + "]";
-        }
     }
 
+    @ToString(callSuper = true)
     public static class Derived extends Data {
         protected String value;
 
@@ -138,11 +136,6 @@ public class JacksonExclusionStrategyTest {
         public void setValue(String value) {
             this.value = value;
         }
-
-        @Override
-        public String toString() {
-            return "Derived [value=" + value + ", " + super.toString() + "]";
-        }
     }
 
     /**
index bbeb1e2..dc62186 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -31,6 +31,7 @@ import com.google.gson.JsonElement;
 import com.google.gson.reflect.TypeToken;
 import java.util.ArrayList;
 import java.util.List;
+import lombok.ToString;
 import org.junit.Test;
 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
@@ -137,6 +138,7 @@ public class JacksonFieldAdapterFactoryTest {
         return text.replaceFirst("@\\w+", "@");
     }
 
+    @ToString
     private static class Data {
         @GsonJsonProperty("my-id")
         private int id;
@@ -155,21 +157,12 @@ public class JacksonFieldAdapterFactoryTest {
         public void setId(int id) {
             this.id = id;
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", text=" + text + "]";
-        }
     }
 
+    @ToString(callSuper = true)
     private static class Derived extends Data {
         // not serialized
         private String unserialized;
-
-        @Override
-        public String toString() {
-            return "Derived [unserialized=" + unserialized + ", toString()=" + super.toString() + "]";
-        }
     }
 
     private static class DataList {
index 18a6fc7..891c4d3 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -33,6 +33,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 import javax.ws.rs.core.MediaType;
+import lombok.ToString;
 import org.junit.Test;
 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
@@ -109,6 +110,7 @@ public class JacksonHandlerTest {
     /**
      * This class includes all policy-specific gson annotations.
      */
+    @ToString
     public static class Data {
         protected int id;
 
@@ -147,11 +149,6 @@ public class JacksonHandlerTest {
 
             props.put(name, value);
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", value=" + value + ", props=" + props + "]";
-        }
     }
 
     private static class MyMap {
index 6377420..7afb0e5 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -32,6 +32,7 @@ import com.google.gson.JsonElement;
 import com.google.gson.reflect.TypeToken;
 import java.util.Map;
 import java.util.TreeMap;
+import lombok.ToString;
 import org.junit.Test;
 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
@@ -117,6 +118,7 @@ public class JacksonMethodAdapterFactoryTest {
         assertEquals("{'id':500,'nested':{'value':'bye bye'}}".replace('\'', '"'), result);
     }
 
+    @ToString
     protected static class Data {
         private int id;
         private String text;
@@ -142,13 +144,9 @@ public class JacksonMethodAdapterFactoryTest {
         public void unused(String text) {
             // do nothing
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", text=" + text + "]";
-        }
     }
 
+    @ToString(callSuper = true)
     protected static class Derived extends Data {
 
         // overrides private field from Data
@@ -174,11 +172,6 @@ public class JacksonMethodAdapterFactoryTest {
 
             map.put(key, value);
         }
-
-        @Override
-        public String toString() {
-            return "Derived [text=" + text + ", map=" + map + ", toString()=" + super.toString() + "]";
-        }
     }
 
     /**
@@ -258,6 +251,7 @@ public class JacksonMethodAdapterFactoryTest {
     /**
      * Used to test serialization of non-static nested classes.
      */
+    @ToString
     protected static class Container {
         private int id;
         private Nested nested;
@@ -283,12 +277,8 @@ public class JacksonMethodAdapterFactoryTest {
             return nested;
         }
 
-        @Override
-        public String toString() {
-            return "Container [id=" + id + ", nested=" + nested + "]";
-        }
-
 
+        @ToString
         protected class Nested {
             private String value;
 
@@ -299,11 +289,6 @@ public class JacksonMethodAdapterFactoryTest {
             public String getValue() {
                 return value;
             }
-
-            @Override
-            public String toString() {
-                return "Nested [value=" + value + "]";
-            }
         }
     }
 }
index 2799d8b..d2cdf7f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -35,6 +35,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import lombok.ToString;
 
 /**
  * Factory used with test Data.
@@ -54,6 +55,7 @@ public class DataAdapterFactory implements TypeAdapterFactory {
     /**
      * Object handled by this factory.
      */
+    @ToString
     public static class Data {
         private int id;
 
@@ -72,16 +74,12 @@ public class DataAdapterFactory implements TypeAdapterFactory {
         public void setId(int id) {
             this.id = id;
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + "]";
-        }
     }
 
     /**
      * Object derived from Data.
      */
+    @ToString(callSuper = true)
     public static class DerivedData extends Data {
         private String text;
 
@@ -101,11 +99,6 @@ public class DataAdapterFactory implements TypeAdapterFactory {
         public void setText(String text) {
             this.text = text;
         }
-
-        @Override
-        public String toString() {
-            return "DerivedData [text=" + text + ", toString()=" + super.toString() + "]";
-        }
     }
 
     /**
index 6be4e59..5e73d06 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -33,6 +33,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
+import lombok.ToString;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -138,6 +139,7 @@ public class JacksonTypeAdapterTest {
         assertEquals("read text", data);
     }
 
+    @ToString
     private static class Data {
         private String id;
         private String value;
@@ -155,11 +157,6 @@ public class JacksonTypeAdapterTest {
             this.id = id;
             this.value = value;
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", value=" + value + "]";
-        }
     }
 
     private abstract static class NamedSer implements Serializer {
index fb1df8c..b1d7d5b 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * Integrity Monitor
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -287,16 +287,9 @@ public class StateManagementTest extends IntegrityMonitorTestBase {
             return null;
         }
 
-        final StringBuilder b = new StringBuilder();
-
-        b.append(sm.getAdminState());
-        b.append(',');
-        b.append(sm.getOpState());
-        b.append(',');
-        b.append(sm.getAvailStatus());
-        b.append(',');
-        b.append(sm.getStandbyStatus());
-
-        return b.toString();
+        return sm.getAdminState()
+            + ',' + sm.getOpState()
+            + ',' + sm.getAvailStatus()
+            + ',' + sm.getStandbyStatus();
     }
 }
index 9d38aac..dfdadd1 100644 (file)
@@ -190,7 +190,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
 
     @Override
     public String toString() {
-        return "IndexedDmaapTopicSinkFactory []";
+        return "IndexedDmaapTopicSinkFactory " + dmaapTopicWriters.keySet();
     }
 
 }
index b63fe03..66960b1 100644 (file)
@@ -208,7 +208,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
 
     @Override
     public String toString() {
-        return "IndexedDmaapTopicSourceFactory []";
+        return "IndexedDmaapTopicSourceFactory " + dmaapTopicSources.keySet();
     }
 
 }
index 17446a9..b04fc07 100644 (file)
@@ -196,7 +196,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory {
 
     @Override
     public String toString() {
-        return "IndexedUebTopicSinkFactory []";
+        return "IndexedUebTopicSinkFactory " + uebTopicSinks.keySet();
     }
 
 }
index edaf473..0950097 100644 (file)
@@ -211,6 +211,6 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory {
 
     @Override
     public String toString() {
-        return "IndexedUebTopicSourceFactory []";
+        return "IndexedUebTopicSourceFactory " + uebTopicSources.keySet();
     }
 }
index ea22af8..f905bd7 100644 (file)
@@ -74,10 +74,8 @@ public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSi
 
     @Override
     public String toString() {
-        var builder = new StringBuilder();
-        builder.append("InlineUebTopicSink [getTopicCommInfrastructure()=").append(getTopicCommInfrastructure())
-                .append(", toString()=").append(super.toString()).append("]");
-        return builder.toString();
+        return "InlineUebTopicSink [getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()="
+                        + super.toString() + "]";
     }
 
     @Override
index 1c3d89d..09ce526 100644 (file)
@@ -128,12 +128,10 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
 
     @Override
     public String toString() {
-        var builder = new StringBuilder();
-        builder.append("SingleThreadedDmaapTopicSource [userName=").append(userName).append(", password=")
-                .append((password == null || password.isEmpty()) ? "-" : password.length())
-                .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=")
-                .append(super.toString()).append("]");
-        return builder.toString();
+        return "SingleThreadedDmaapTopicSource [userName=" + userName
+            + ", password=" + (password == null || password.isEmpty() ? "-" : password.length())
+            + ", getTopicCommInfrastructure()=" + getTopicCommInfrastructure()
+            + ", toString()=" + super.toString() + "]";
     }
 
 
index 496c38f..d8703c4 100644 (file)
@@ -66,10 +66,8 @@ public class SingleThreadedUebTopicSource extends SingleThreadedBusTopicSource i
 
     @Override
     public String toString() {
-        var builder = new StringBuilder();
-        builder.append("SingleThreadedUebTopicSource [getTopicCommInfrastructure()=")
-                .append(getTopicCommInfrastructure()).append(", toString()=").append(super.toString()).append("]");
-        return builder.toString();
+        return "SingleThreadedUebTopicSource [getTopicCommInfrastructure()=" + getTopicCommInfrastructure()
+            + ", toString()=" + super.toString() + "]";
     }
 
 }
index b83bf29..709b148 100644 (file)
@@ -38,6 +38,7 @@ import javax.ws.rs.client.Invocation.Builder;
 import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Response;
+import lombok.ToString;
 import org.apache.commons.lang3.StringUtils;
 import org.glassfish.jersey.client.ClientProperties;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
@@ -51,6 +52,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Http Client implementation using a Jersey Client.
  */
+@ToString
 public class JerseyClient implements HttpClient {
     private static final Pattern COMMA_PAT = Pattern.compile(",");
 
@@ -310,35 +312,6 @@ public class JerseyClient implements HttpClient {
         return baseUrl;
     }
 
-    @Override
-    public String toString() {
-        var builder = new StringBuilder();
-        builder.append("JerseyClient [name=");
-        builder.append(name);
-        builder.append(", https=");
-        builder.append(https);
-        builder.append(", selfSignedCerts=");
-        builder.append(selfSignedCerts);
-        builder.append(", hostname=");
-        builder.append(hostname);
-        builder.append(", port=");
-        builder.append(port);
-        builder.append(", basePath=");
-        builder.append(basePath);
-        builder.append(", userName=");
-        builder.append(userName);
-        builder.append(", password=");
-        builder.append(password);
-        builder.append(", client=");
-        builder.append(client);
-        builder.append(", baseUrl=");
-        builder.append(baseUrl);
-        builder.append(", alive=");
-        builder.append(alive);
-        builder.append("]");
-        return builder.toString();
-    }
-
     private Builder getBuilder(String path, Map<String, Object> headers) {
         var builder = getWebTarget().path(path).request();
         for (Entry<String, Object> header : headers.entrySet()) {
index 3258810..70d4511 100644 (file)
 
 package org.onap.policy.common.endpoints.http.server;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
+import java.util.stream.Collectors;
+import lombok.ToString;
 import org.onap.policy.common.endpoints.http.server.aaf.AafAuthFilter;
 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
@@ -34,6 +37,7 @@ import org.onap.policy.common.utils.services.ServiceManagerContainer;
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ToString
 public class RestServer extends ServiceManagerContainer {
 
     /**
@@ -111,17 +115,7 @@ public class RestServer extends ServiceManagerContainer {
      * @return the provider class names
      */
     private String getProviderClassNames(Class<?>[] jaxrsProviders) {
-        var names = new StringBuilder();
-
-        for (Class<?> prov : jaxrsProviders) {
-            if (names.length() > 0) {
-                names.append(',');
-            }
-
-            names.append(prov.getName());
-        }
-
-        return names.toString();
+        return String.join(",", Arrays.stream(jaxrsProviders).map(Class::getName).collect(Collectors.toList()));
     }
 
     private String getValue(final String value) {
@@ -131,11 +125,6 @@ public class RestServer extends ServiceManagerContainer {
         return value;
     }
 
-    @Override
-    public String toString() {
-        return "RestServer [servers=" + servers + "]";
-    }
-
     /**
      * Factory used to access objects.
      */
index afa37a6..467fd86 100644 (file)
@@ -258,9 +258,9 @@ public class JettyJerseyServer extends JettyServletServer {
 
     @Override
     public String toString() {
-        var builder = new StringBuilder();
-        builder.append("JettyJerseyServer [Jerseyservlets=").append(servlets).append(", swaggerId=").append(swaggerId)
-                .append(", toString()=").append(super.toString()).append("]");
-        return builder.toString();
+        return "JettyJerseyServer [Jerseyservlets=" + servlets
+            + ", swaggerId=" + swaggerId
+            + ", toString()=" + super.toString()
+            + "]";
     }
 }
index 48dc811..4afe2c0 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.policy.common.endpoints.http.server.internal;
 
 import java.util.EnumSet;
 import javax.servlet.DispatcherType;
+import lombok.ToString;
 import org.eclipse.jetty.security.ConstraintMapping;
 import org.eclipse.jetty.security.ConstraintSecurityHandler;
 import org.eclipse.jetty.security.HashLoginService;
@@ -50,6 +51,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Http Server implementation using Embedded Jetty.
  */
+@ToString
 public abstract class JettyServletServer implements HttpServletServer, Runnable {
 
     /**
@@ -120,6 +122,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable
     /**
      * Start condition.
      */
+    @ToString.Exclude
     protected Object startCondition = new Object();
 
     /**
@@ -521,15 +524,4 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable
         throw new UnsupportedOperationException("addServletResource()" + NOT_SUPPORTED);
     }
 
-    @Override
-    public String toString() {
-        var builder = new StringBuilder();
-        builder.append("JettyServer [name=").append(name).append(", host=").append(host).append(", port=").append(port)
-                .append(", user=").append(user).append(", password=").append(password != null).append(", contextPath=")
-                .append(contextPath).append(", jettyServer=").append(jettyServer).append(", context=")
-                .append(this.context).append(", connector=").append(connector).append(", jettyThread=")
-                .append(jettyThread).append("]");
-        return builder.toString();
-    }
-
 }
index 2caa922..c214c91 100644 (file)
 
 package org.onap.policy.common.endpoints.report;
 
+import lombok.ToString;
+
 /**
  * Class to represent health check report of a service.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
  */
+@ToString
 public class HealthCheckReport {
 
     private String name;
@@ -123,21 +126,4 @@ public class HealthCheckReport {
     public void setMessage(final String message) {
         this.message = message;
     }
-
-    @Override
-    public String toString() {
-        final var builder = new StringBuilder();
-        builder.append("Report [name=");
-        builder.append(getName());
-        builder.append(", url=");
-        builder.append(getUrl());
-        builder.append(", healthy=");
-        builder.append(isHealthy());
-        builder.append(", code=");
-        builder.append(getCode());
-        builder.append(", message=");
-        builder.append(getMessage());
-        builder.append("]");
-        return builder.toString();
-    }
 }
index 2a3e244..2748fad 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
 package org.onap.policy.common.endpoints.http.server.test;
 
 import com.google.gson.annotations.SerializedName;
+import lombok.ToString;
 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
 
 /**
  * "ECHO" request and response supporting serialization and de-serialization via
  * both jackson and gson.
  */
+@ToString
 public class RestEchoReqResp {
     @GsonJsonProperty("reqId")
     @SerializedName("reqId")
@@ -51,9 +53,4 @@ public class RestEchoReqResp {
     public void setText(String text) {
         this.text = text;
     }
-
-    @Override
-    public String toString() {
-        return "RestEchoReqResp [requestId=" + requestId + ", text=" + text + "]";
-    }
 }
index 7ca131e..8d65bbd 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
@@ -31,6 +31,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.TreeMap;
 import javax.ws.rs.core.MediaType;
+import lombok.ToString;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.http.server.YamlJacksonHandler;
 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
@@ -106,6 +107,7 @@ public class YamlJacksonHandlerTest {
     /**
      * This class includes all policy-specific gson annotations.
      */
+    @ToString
     public static class Data {
         protected int id;
 
@@ -144,11 +146,6 @@ public class YamlJacksonHandlerTest {
 
             props.put(name, value);
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", value=" + value + ", props=" + props + "]";
-        }
     }
 
     private static class MyMap {
index 4f2eb31..c0927aa 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -33,6 +33,7 @@ import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import javax.ws.rs.core.MediaType;
+import lombok.ToString;
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
@@ -212,6 +213,7 @@ public class YamlMessageBodyHandlerTest {
         }
     }
 
+    @ToString
     public static class MyObject {
         private int id;
 
@@ -222,11 +224,6 @@ public class YamlMessageBodyHandlerTest {
         public MyObject(int id) {
             this.id = id;
         }
-
-        @Override
-        public String toString() {
-            return "MyObject [id=" + id + "]";
-        }
     }
 
     private static class MyMap {
index f16764c..907b778 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -34,6 +34,7 @@ import com.google.gson.JsonParseException;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import lombok.ToString;
 import org.apache.commons.jexl3.JexlException;
 import org.junit.Before;
 import org.junit.Test;
@@ -225,6 +226,7 @@ public class GsonTestUtilsTest {
         assertEquals("[300,{'objE':true,'objEStr':'obj-e-string'},false]".replace('\'', '"'), jsonEl.toString());
     }
 
+    @ToString
     public static class Data {
         private int id;
         private String text;
@@ -244,10 +246,5 @@ public class GsonTestUtilsTest {
         public void setText(String text) {
             this.text = text;
         }
-
-        @Override
-        public String toString() {
-            return "Data [id=" + id + ", text=" + text + "]";
-        }
     }
 }
index 75173a2..03cc766 100644 (file)
             <groupId>commons-cli</groupId>
             <artifactId>commons-cli</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
     </dependencies>
 </project>
index 6039e08..7cd09fa 100644 (file)
@@ -28,6 +28,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import org.apache.commons.io.IOUtils;
 
 /**
  * The Class TextFileUtils is class that provides useful functions for handling text files. Functions to read and write
@@ -36,7 +37,6 @@ import java.nio.file.Files;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public abstract class TextFileUtils {
-    private static final int READER_CHAR_BUFFER_SIZE_4096 = 4096;
 
     private TextFileUtils() {
         // This class cannot be initialized
@@ -100,15 +100,6 @@ public abstract class TextFileUtils {
      * @throws IOException on errors reading text from the file
      */
     public static String getReaderAsString(final Reader textReader) throws IOException {
-        final var builder = new StringBuilder();
-        int charsRead = -1;
-        final var chars = new char[READER_CHAR_BUFFER_SIZE_4096];
-        do {
-            charsRead = textReader.read(chars);
-            if (charsRead > 0) {
-                builder.append(chars, 0, charsRead);
-            }
-        } while (charsRead > 0);
-        return builder.toString();
+        return IOUtils.toString(textReader);
     }
 }
index a468f0b..33c7331 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -52,6 +52,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
+import lombok.ToString;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -358,13 +359,9 @@ public class StandardCoderTest {
     }
 
 
+    @ToString
     private static class MyObject {
         private String abc;
-
-        @Override
-        public String toString() {
-            return "MyObject [abc=" + abc + "]";
-        }
     }
 
     public static class MyMap {