Address sonar issues in models 47/105447/2
authorJim Hahn <jrh3@att.com>
Tue, 7 Apr 2020 17:58:09 +0000 (13:58 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 7 Apr 2020 21:15:07 +0000 (17:15 -0400)
Addressed the following sonar issues:
- use RE2 instead of java.util Pattern for "+" and "*"
- don't use deprecated methods
  - for Date(long), sonar appeared not to parse the argument's
    type correctly.  Modified the code slightly to make sonar happy
- duplicate blocks of code
- either log or throw
- missing assert in junit
  - for SDNR & VFC, eliminated threads, as they are unnecessary
- duplicate code block in different branches
- useless assignments
- redeclaring abstract methods
- cyclomatic complexity
  - used lombok in some cases (e.g., EqualsAndHashCode)
- assert argument order
  - actually deleted ControlLoopTargetType, because it is not needed
    and sonar complains regardless of which order is used
- add private constructor to utility classes
- use StandardCharsets instead of literals

Also:
- added logback-test.xml to SO to eliminate the voluminous output
  from the junit test

Issue-ID: POLICY-2305
Change-Id: I586c331781bedbd54a115a71847d04d293689445
Signed-off-by: Jim Hahn <jrh3@att.com>
41 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java
models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java
models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java
models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java
models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java
models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java
models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java [deleted file]
models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java
models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java
models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java
models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestDetails.java
models-interactions/model-impl/so/src/test/resources/logback-test.xml [new file with mode: 0644]
models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/parameters/DmaapSimParameterHandler.java
models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProviderTest.java
models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java
models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java
models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java
models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorMain.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java

index b949004..97522c4 100644 (file)
@@ -21,6 +21,7 @@
 
 package org.onap.policy.models.base;
 
+import com.google.re2j.Pattern;
 import java.lang.reflect.ParameterizedType;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -73,6 +74,8 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
     implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> {
     private static final long serialVersionUID = -324211738823208318L;
 
+    private static final Pattern KEY_ID_PATTERN = Pattern.compile(PfKey.KEY_ID_REGEXP);
+
     @EmbeddedId
     private PfConceptKey key;
 
@@ -183,7 +186,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
             for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) {
 
                 PfConceptKey conceptKey = new PfConceptKey();
-                if (incomingConceptEntry.getKey().matches(PfKey.KEY_ID_REGEXP)) {
+                if (KEY_ID_PATTERN.matches(incomingConceptEntry.getKey())) {
                     conceptKey = new PfConceptKey(incomingConceptEntry.getKey());
                 } else {
                     conceptKey.setName(incomingConceptEntry.getKey());
index a2f1129..5be9b5f 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -62,7 +63,8 @@ public class PfTimestampKey extends PfKeyImpl {
      */
     public PfTimestampKey(@NonNull final PfTimestampKey copyConcept) {
         super(copyConcept);
-        this.timeStamp = new Date(copyConcept.getTimeStamp().getTime());
+        long millis = copyConcept.getTimeStamp().getTime();
+        this.timeStamp = new Date(millis);
     }
 
     /**
index d612297..d7d1784 100644 (file)
@@ -58,7 +58,7 @@ public class PfDaoFactory {
                         | InvocationTargetException | NoSuchMethodException | SecurityException e) {
             String errorMessage =
                     "Policy Framework DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"";
-            LOGGER.error(errorMessage, e);
+            LOGGER.error(errorMessage);
             throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, e);
         }
 
index d781724..0b32b51 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -120,7 +120,7 @@ public class DefaultPfDao implements PfDao {
         } catch (final Exception ex) {
             String errorMessage = "Creation of Policy Framework persistence unit \""
                     + daoParameters.getPersistenceUnit() + "\" failed";
-            LOGGER.warn(errorMessage, ex);
+            LOGGER.warn(errorMessage);
             throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ex);
         }
         LOGGER.debug("Created Policy Framework persistence unit \"{}\"", daoParameters.getPersistenceUnit());
@@ -362,11 +362,7 @@ public class DefaultPfDao implements PfDao {
 
         try {
             if (filterMap != null) {
-                StringBuilder bld = new StringBuilder(filterQueryString);
-                for (String key : filterMap.keySet()) {
-                    bld.append("c." + key + "= :" + key + AND);
-                }
-                filterQueryString = bld.toString();
+                filterQueryString = buildFilter(filterMap, filterQueryString);
             }
             filterQueryString = addKeyFilterString(filterQueryString, name, startTime, endTime);
             if (getRecordNum > 0) {
@@ -405,42 +401,30 @@ public class DefaultPfDao implements PfDao {
         }
     }
 
+    private String buildFilter(final Map<String, Object> filterMap, String filterQueryString) {
+        StringBuilder bld = new StringBuilder(filterQueryString);
+        for (String key : filterMap.keySet()) {
+            bld.append("c." + key + "= :" + key + AND);
+        }
+        return bld.toString();
+    }
+
     @Override
     public <T extends PfConcept> T get(final Class<T> someClass, final PfConceptKey key) {
-        if (someClass == null) {
-            return null;
-        }
-        final EntityManager mg = getEntityManager();
-        try {
-            final T t = mg.find(someClass, key);
-            if (t != null) {
-                mg.refresh(t);
-            }
-            return checkAndReturn(someClass, t);
-        } finally {
-            mg.close();
-        }
+        return genericGet(someClass, key);
     }
 
     @Override
     public <T extends PfConcept> T get(final Class<T> someClass, final PfReferenceKey key) {
-        if (someClass == null) {
-            return null;
-        }
-        final EntityManager mg = getEntityManager();
-        try {
-            final T t = mg.find(someClass, key);
-            if (t != null) {
-                mg.refresh(t);
-            }
-            return checkAndReturn(someClass, t);
-        } finally {
-            mg.close();
-        }
+        return genericGet(someClass, key);
     }
 
     @Override
     public <T extends PfConcept> T get(final Class<T> someClass, final PfTimestampKey key) {
+        return genericGet(someClass, key);
+    }
+
+    private <T extends PfConcept> T genericGet(final Class<T> someClass, final Object key) {
         if (someClass == null) {
             return null;
         }
@@ -570,7 +554,11 @@ public class DefaultPfDao implements PfDao {
         final EntityManager mg = getEntityManager();
         long size = 0;
         try {
-            size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
+            /*
+             * Concatenation should be safe because the class name should be safe, thus
+             * disabling sonar.
+             */
+            size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)   // NOSONAR
                     .getSingleResult();
         } finally {
             mg.close();
index f5702e6..4331964 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -21,6 +21,7 @@
 
 package org.onap.policy.models.dao;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -166,7 +167,7 @@ public class EntityTest {
         pfDao.getConcept(PfReferenceKey.class, nullRefKey);
         pfDao.size(null);
 
-        pfDao.close();
+        assertThatCode(() -> pfDao.close()).doesNotThrowAnyException();
     }
 
     private void testAllOps() {
index 92af217..1e14e07 100644 (file)
@@ -100,100 +100,115 @@ public class AaiCqResponse implements Serializable {
             resultsArray = (JSONArray) responseObj.get("results");
         }
         for (int i = 0; i < resultsArray.length(); i++) {
-            // Object is a vserver
-            if (resultsArray.getJSONObject(i).has("vserver")) {
+            final JSONObject resultObject = resultsArray.getJSONObject(i);
+
+            extractVserver(resultObject);
+            extractGenericVnf(resultObject);
+            extractServiceInstance(resultObject);
+            extractVfModule(resultObject);
+            extractCloudRegion(resultObject);
+            extractTenant(resultObject);
+            extractModelVer(resultObject);
+        }
+    }
 
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject("vserver").toString()));
+    private void extractVserver(final JSONObject resultObject) {
+        if (resultObject.has("vserver")) {
 
-                // Getting the vserver pojo again from the json
-                Vserver vserver = this.getAaiObject(json, Vserver.class);
-                this.inventoryResponseItems.add(vserver);
-            }
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject("vserver").toString()));
 
-            // Object is a Generic VNF
-            if (resultsArray.getJSONObject(i).has(GENERIC_VNF)) {
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString()));
+            // Getting the vserver pojo again from the json
+            Vserver vserver = this.getAaiObject(json, Vserver.class);
+            this.inventoryResponseItems.add(vserver);
+        }
+    }
 
-                // Getting the generic vnf pojo again from the json
-                GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
+    private void extractGenericVnf(final JSONObject resultObject) {
+        if (resultObject.has(GENERIC_VNF)) {
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject(GENERIC_VNF).toString()));
 
-                this.inventoryResponseItems.add(genericVnf);
-            }
+            // Getting the generic vnf pojo again from the json
+            GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
 
-            // Object is a Service Instance
-            if (resultsArray.getJSONObject(i).has("service-instance")) {
+            this.inventoryResponseItems.add(genericVnf);
+        }
+    }
 
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject("service-instance").toString()));
+    private void extractServiceInstance(final JSONObject resultObject) {
+        if (resultObject.has("service-instance")) {
 
-                // Getting the employee pojo again from the json
-                ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject("service-instance").toString()));
 
-                this.inventoryResponseItems.add(serviceInstance);
-            }
+            // Getting the employee pojo again from the json
+            ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
 
-            // Object is a VF Module
-            if (resultsArray.getJSONObject(i).has(VF_MODULE)) {
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString()));
+            this.inventoryResponseItems.add(serviceInstance);
+        }
+    }
 
-                // Getting the vf module pojo again from the json
-                VfModule vfModule = this.getAaiObject(json, VfModule.class);
+    private void extractVfModule(final JSONObject resultObject) {
+        if (resultObject.has(VF_MODULE)) {
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject(VF_MODULE).toString()));
 
-                this.inventoryResponseItems.add(vfModule);
-            }
+            // Getting the vf module pojo again from the json
+            VfModule vfModule = this.getAaiObject(json, VfModule.class);
 
-            // Object is a CloudRegion
-            if (resultsArray.getJSONObject(i).has("cloud-region")) {
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString()));
+            this.inventoryResponseItems.add(vfModule);
+        }
+    }
 
-                // Getting the cloud region pojo again from the json
-                CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
+    private void extractCloudRegion(final JSONObject resultObject) {
+        if (resultObject.has("cloud-region")) {
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject("cloud-region").toString()));
 
-                this.inventoryResponseItems.add(cloudRegion);
-            }
+            // Getting the cloud region pojo again from the json
+            CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
 
-            // Object is a Tenant
-            if (resultsArray.getJSONObject(i).has("tenant")) {
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject("tenant").toString()));
+            this.inventoryResponseItems.add(cloudRegion);
+        }
+    }
 
-                // Getting the tenant pojo again from the json
-                Tenant tenant = this.getAaiObject(json, Tenant.class);
+    private void extractTenant(final JSONObject resultObject) {
+        if (resultObject.has("tenant")) {
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject("tenant").toString()));
 
-                this.inventoryResponseItems.add(tenant);
-            }
+            // Getting the tenant pojo again from the json
+            Tenant tenant = this.getAaiObject(json, Tenant.class);
 
-            // Object is a ModelVer
-            if (resultsArray.getJSONObject(i).has("model-ver")) {
-                // Create the StreamSource by creating StringReader using the
-                // JSON input
-                StreamSource json = new StreamSource(
-                        new StringReader(resultsArray.getJSONObject(i).getJSONObject("model-ver").toString()));
+            this.inventoryResponseItems.add(tenant);
+        }
+    }
 
-                // Getting the ModelVer pojo again from the json
-                ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
+    private void extractModelVer(final JSONObject resultObject) {
+        if (resultObject.has("model-ver")) {
+            // Create the StreamSource by creating StringReader using the
+            // JSON input
+            StreamSource json = new StreamSource(
+                    new StringReader(resultObject.getJSONObject("model-ver").toString()));
 
-                this.inventoryResponseItems.add(modelVer);
-            }
+            // Getting the ModelVer pojo again from the json
+            ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
 
+            this.inventoryResponseItems.add(modelVer);
         }
-
     }
 
     private <T> T getAaiObject(StreamSource json, final Class<T> classOfResponse) {
index f0419ef..0583234 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * appc
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,12 +29,13 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Map;
 import java.util.UUID;
-
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class CommonHeader implements Serializable {
     private static final long serialVersionUID = -3581658269910980336L;
 
@@ -88,79 +89,4 @@ public class CommonHeader implements Serializable {
                 + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
                 + ", Flags=" + flags + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
-        result = prime * result + ((flags == null) ? 0 : flags.hashCode());
-        result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode());
-        result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
-        result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
-        result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
-        result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        CommonHeader other = (CommonHeader) obj;
-        if (apiVer == null) {
-            if (other.apiVer != null) {
-                return false;
-            }
-        } else if (!apiVer.equals(other.apiVer)) {
-            return false;
-        }
-        if (flags == null) {
-            if (other.flags != null) {
-                return false;
-            }
-        } else if (!flags.equals(other.flags)) {
-            return false;
-        }
-        if (originatorId == null) {
-            if (other.originatorId != null) {
-                return false;
-            }
-        } else if (!originatorId.equals(other.originatorId)) {
-            return false;
-        }
-        if (requestId == null) {
-            if (other.requestId != null) {
-                return false;
-            }
-        } else if (!requestId.equals(other.requestId)) {
-            return false;
-        }
-        if (requestTrack == null) {
-            if (other.requestTrack != null) {
-                return false;
-            }
-        } else if (!requestTrack.equals(other.requestTrack)) {
-            return false;
-        }
-        if (subRequestId == null) {
-            if (other.subRequestId != null) {
-                return false;
-            }
-        } else if (!subRequestId.equals(other.subRequestId)) {
-            return false;
-        }
-        if (timeStamp == null) {
-            return other.timeStamp == null;
-        } else {
-            return timeStamp.equals(other.timeStamp);
-        }
-    }
 }
index e340360..08cc163 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * appc
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,11 +26,13 @@ import com.google.gson.annotations.SerializedName;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class Request implements Serializable {
     private static final long serialVersionUID = -3912323643990646431L;
 
@@ -53,74 +55,6 @@ public class Request implements Serializable {
         // Initiate an empty Request instance
     }
 
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((action == null) ? 0 : action.hashCode());
-        result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
-        result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
-        result = prime * result + ((payload == null) ? 0 : payload.hashCode());
-        result = prime * result + ((targetId == null) ? 0 : targetId.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-
-        Request other = (Request) obj;
-        if (action == null) {
-            if (other.action != null) {
-                return false;
-            }
-        } else if (!action.equals(other.action)) {
-            return false;
-        }
-
-        if (commonHeader == null) {
-            if (other.commonHeader != null) {
-                return false;
-            }
-        } else if (!commonHeader.equals(other.commonHeader)) {
-            return false;
-        }
-
-        if (objectId == null) {
-            if (other.objectId != null) {
-                return false;
-            }
-        } else if (!objectId.equals(other.objectId)) {
-            return false;
-        }
-
-        if (payload == null) {
-            if (other.payload != null) {
-                return false;
-            }
-        } else if (!payload.equals(other.payload)) {
-            return false;
-        }
-
-        if (targetId == null) {
-            if (other.targetId != null) {
-                return false;
-            }
-        } else if (!targetId.equals(other.targetId)) {
-            return false;
-        }
-
-        return true;
-    }
-
     @Override
     public String toString() {
         return "Request [CommonHeader=" + commonHeader + ", Action=" + action + ", TargetId=" + targetId + ", ObjectId="
index fb70151..368876f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * appc
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,11 +26,13 @@ import com.google.gson.annotations.SerializedName;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class Response implements Serializable {
 
     private static final long serialVersionUID = 434953706339865151L;
@@ -71,47 +73,4 @@ public class Response implements Serializable {
     public String toString() {
         return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
-        result = prime * result + ((payload == null) ? 0 : payload.hashCode());
-        result = prime * result + ((status == null) ? 0 : status.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        Response other = (Response) obj;
-        if (commonHeader == null) {
-            if (other.commonHeader != null) {
-                return false;
-            }
-        } else if (!commonHeader.equals(other.commonHeader)) {
-            return false;
-        }
-        if (payload == null) {
-            if (other.payload != null) {
-                return false;
-            }
-        } else if (!payload.equals(other.payload)) {
-            return false;
-        }
-        if (status == null) {
-            return other.status == null;
-        } else {
-            return status.equals(other.status);
-        }
-    }
 }
index 17b4dc5..9d01ec8 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019 Bell Canada.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
@@ -19,6 +19,7 @@
 
 package org.onap.policy.cds.client;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -128,7 +129,7 @@ public class CdsProcessorGrpcClientTest {
 
     @Test
     public void testCdsProcessorGrpcClientConstructor() {
-        new CdsProcessorGrpcClient(listener, props).close();
+        assertThatCode(() -> new CdsProcessorGrpcClient(listener, props).close()).doesNotThrowAnyException();
     }
 
     @Test(expected = IllegalStateException.class)
index b79140a..55c1333 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * controlloop
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,4 +27,8 @@ public class ControlLoopTargetType {
     public static final String VFC = "VFC";
     public static final String VNF = "VNF";
     public static final String PNF = "PNF";
+
+    private ControlLoopTargetType() {
+        // do nothing
+    }
 }
diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java
deleted file mode 100644 (file)
index dcb5d17..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * controlloop
- * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class ControlLoopTargetTypeTest {
-
-    @Test
-    public void test() {
-        assertEquals(ControlLoopTargetType.VM, "VM");
-        assertEquals(ControlLoopTargetType.VF, "VF");
-        assertEquals(ControlLoopTargetType.VFC, "VFC");
-        assertEquals(ControlLoopTargetType.VNF, "VNF");
-        assertEquals(ControlLoopTargetType.PNF, "PNF");
-    }
-}
index dde3aa2..a452c14 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * rest
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@
 
 package org.onap.policy.rest;
 
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.Map.Entry;
 import javax.xml.bind.DatatypeConverter;
@@ -262,6 +262,6 @@ public class RestManager {
         }
 
         String auth = username + ":" + (password == null ? "" : password);
-        return "Basic " + DatatypeConverter.printBase64Binary(auth.getBytes(Charset.forName("ISO-8859-1")));
+        return "Basic " + DatatypeConverter.printBase64Binary(auth.getBytes(StandardCharsets.ISO_8859_1));
     }
 }
index d372f12..3327b78 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * sdc
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,10 @@ public class Service implements Serializable {
 
     private static final long serialVersionUID = -1249276698549996806L;
 
+    /*
+     * Note the field names ending in "UUID" may not be changed without breaking the
+     * interface, due to limitations in the YAML encoder/decoder.
+     */
     private UUID serviceUUID;
     private UUID serviceInvariantUUID;
     private String serviceName;
index b476de2..6eac319 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * sdc
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,10 @@ public class ServiceInstance implements Serializable {
 
     private static final long serialVersionUID = 6285260780966679625L;
 
+    /*
+     * Note the field names ending in "UUID" may not be changed without breaking the
+     * interface, due to limitations in the YAML encoder/decoder.
+     */
     private UUID personaModelUUID;
     private UUID serviceUUID;
     private UUID serviceInstanceUUID;
index 41f07c3..7b5ad46 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * Copyright (C) 2018 Huawei. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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,6 +20,8 @@
 
 package org.onap.policy.sdnc;
 
+import static org.junit.Assert.assertNotNull;
+
 import org.junit.Test;
 import org.onap.policy.sdnc.util.Serialization;
 import org.slf4j.Logger;
@@ -70,5 +72,6 @@ public class DemoTest {
         body = Serialization.gsonPretty.toJson(response);
         logger.info("{}", body);
 
+        assertNotNull(body);
     }
 }
index c069f1c..b962ce8 100644 (file)
@@ -4,7 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Huawei. All rights reserved.
  * ================================================================================
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 package org.onap.policy.sdnc;
 
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyMap;
 import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.endsWith;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.startsWith;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.util.UUID;
@@ -48,7 +49,6 @@ public class SdncManagerTest implements SdncCallback {
     private RestManager   mockedRestManager;
 
     private Pair<Integer, String> httpResponsePutOk;
-    private Pair<Integer, String> httpResponseGetOk;
     private Pair<Integer, String> httpResponseBadResponse;
     private Pair<Integer, String> httpResponseErr;
 
@@ -63,7 +63,6 @@ public class SdncManagerTest implements SdncCallback {
         mockedRestManager   = mock(RestManager.class);
 
         httpResponsePutOk       = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
-        httpResponseGetOk       = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
         httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
         httpResponseErr         = mockedRestManager.new Pair<>(200, null);
     }
@@ -120,14 +119,15 @@ public class SdncManagerTest implements SdncCallback {
         SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Exception");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Exception"), anyMap(),
                         anyString(), anyString())).thenThrow(new RuntimeException("OzException"));
 
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+
+        managerThread.join(1000);
 
-        managerThread.join(100);
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -135,13 +135,12 @@ public class SdncManagerTest implements SdncCallback {
         SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Null");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Null"), anyMap(),
                         anyString(), anyString())).thenReturn(null);
 
-        managerThread.join(100);
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
 
@@ -150,13 +149,12 @@ public class SdncManagerTest implements SdncCallback {
         SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Error0");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Error0"), anyMap(),
                         anyString(), anyString())).thenReturn(httpResponseErr);
 
-        managerThread.join(100);
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -164,13 +162,12 @@ public class SdncManagerTest implements SdncCallback {
         SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "BadResponse");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
                         anyString(), anyString())).thenReturn(httpResponseBadResponse);
 
-        managerThread.join(100);
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -178,17 +175,12 @@ public class SdncManagerTest implements SdncCallback {
         SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "OOK");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
                         anyString(), anyString())).thenReturn(httpResponsePutOk);
 
-        when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
-            .thenReturn(httpResponseGetOk);
-
+        manager.run();
 
-        managerThread.join(100);
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Override
index cdafa68..0b3e987 100644 (file)
@@ -4,7 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
@@ -29,11 +29,13 @@ import java.time.Instant;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class PciCommonHeader implements Serializable {
 
     private static final long serialVersionUID = 5435363539127062114L;
@@ -85,71 +87,4 @@ public class PciCommonHeader implements Serializable {
                    + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack
                    + ", flags=" + flags + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
-        result = prime * result + ((flags == null) ? 0 : flags.hashCode());
-        result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
-        result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
-        result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
-        result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciCommonHeader other = (PciCommonHeader) obj;
-        if (apiVer == null) {
-            if (other.apiVer != null) {
-                return false;
-            }
-        } else if (!apiVer.equals(other.apiVer)) {
-            return false;
-        }
-        if (flags == null) {
-            if (other.flags != null) {
-                return false;
-            }
-        } else if (!flags.equals(other.flags)) {
-            return false;
-        }
-        if (requestTrack == null) {
-            if (other.requestTrack != null) {
-                return false;
-            }
-        } else if (!requestTrack.equals(other.requestTrack)) {
-            return false;
-        }
-        if (requestId == null) {
-            if (other.requestId != null) {
-                return false;
-            }
-        } else if (!requestId.equals(other.requestId)) {
-            return false;
-        }
-        if (subRequestId == null) {
-            if (other.subRequestId != null) {
-                return false;
-            }
-        } else if (!subRequestId.equals(other.subRequestId)) {
-            return false;
-        }
-        if (timeStamp == null) {
-            return other.timeStamp == null;
-        } else {
-            return timeStamp.equals(other.timeStamp);
-        }
-    }
 }
index d1430a7..03fdfc1 100644 (file)
@@ -4,7 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
@@ -25,11 +25,13 @@ package org.onap.policy.sdnr;
 import com.google.gson.annotations.SerializedName;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class PciRequest implements Serializable {
 
     private static final long serialVersionUID = 323235565922846624L;
@@ -99,47 +101,4 @@ public class PciRequest implements Serializable {
     public String toString() {
         return "PciRequest[commonHeader=" + commonHeader + ", action=" + action + ", payload=" + payload + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
-        result = prime * result + ((action == null) ? 0 : action.hashCode());
-        result = prime * result + ((payload == null) ? 0 : payload.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciRequest other = (PciRequest) obj;
-        if (commonHeader == null) {
-            if (other.commonHeader != null) {
-                return false;
-            }
-        } else if (!commonHeader.equals(other.commonHeader)) {
-            return false;
-        }
-        if (action == null) {
-            if (other.action != null) {
-                return false;
-            }
-        } else if (!action.equals(other.action)) {
-            return false;
-        }
-        if (payload == null) {
-            return other.payload == null;
-        } else {
-            return payload.equals(other.payload);
-        }
-    }
 }
index 4de3a0d..b4453ad 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.sdnr;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode(callSuper = true)
 public class PciRequestWrapper extends PciWrapper implements Serializable {
 
     private static final long serialVersionUID = 879766924715980798L;
@@ -45,31 +48,4 @@ public class PciRequestWrapper extends PciWrapper implements Serializable {
     public String toString() {
         return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = super.hashCode();
-        result = prime * result + ((body == null) ? 0 : body.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciRequestWrapper other = (PciRequestWrapper) obj;
-        if (body == null) {
-            return other.body == null;
-        } else {
-            return body.equals(other.body);
-        }
-    }
 }
index 0bc2eb4..5d7697e 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -24,11 +25,13 @@ package org.onap.policy.sdnr;
 import com.google.gson.annotations.SerializedName;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class PciResponse implements Serializable {
 
     private static final long serialVersionUID = 8375708697287669750L;
@@ -62,47 +65,4 @@ public class PciResponse implements Serializable {
         return "PciResponse[CommonHeader=" + commonHeader + ", Status=" + status + ", Payload="
                 + payload + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
-        result = prime * result + ((payload == null) ? 0 : payload.hashCode());
-        result = prime * result + ((status == null) ? 0 : status.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciResponse other = (PciResponse) obj;
-        if (commonHeader == null) {
-            if (other.commonHeader != null) {
-                return false;
-            }
-        } else if (!commonHeader.equals(other.commonHeader)) {
-            return false;
-        }
-        if (payload == null) {
-            if (other.payload != null) {
-                return false;
-            }
-        } else if (!payload.equals(other.payload)) {
-            return false;
-        }
-        if (status == null) {
-            return other.status == null;
-        } else {
-            return status.equals(other.status);
-        }
-    }
 }
index e161364..a41ec90 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.sdnr;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode(callSuper = true)
 public class PciResponseWrapper extends PciWrapper implements Serializable {
 
     private static final long serialVersionUID = 109837814781086802L;
@@ -41,31 +44,4 @@ public class PciResponseWrapper extends PciWrapper implements Serializable {
     public String toString() {
         return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = super.hashCode();
-        result = prime * result + ((body == null) ? 0 : body.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!super.equals(obj)) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciResponseWrapper other = (PciResponseWrapper) obj;
-        if (body == null) {
-            return other.body == null;
-        } else {
-            return body.equals(other.body);
-        }
-    }
 }
index cf0a8a7..a3bffda 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -24,11 +25,13 @@ package org.onap.policy.sdnr;
 import com.google.gson.annotations.SerializedName;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class PciWrapper implements Serializable {
 
     private static final long serialVersionUID = 375215806432396532L;
@@ -55,63 +58,4 @@ public class PciWrapper implements Serializable {
         return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName
             + ", correlationId=" + correlationId + ", type=" + type + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode());
-        result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode());
-        result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode());
-        result = prime * result + ((type == null) ? 0 : type.hashCode());
-        result = prime * result + ((version == null) ? 0 : version.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PciWrapper other = (PciWrapper) obj;
-        if (cambriaPartition == null) {
-            if (other.cambriaPartition != null) {
-                return false;
-            }
-        } else if (!cambriaPartition.equals(other.cambriaPartition)) {
-            return false;
-        }
-        if (correlationId == null) {
-            if (other.correlationId != null) {
-                return false;
-            }
-        } else if (!correlationId.equals(other.correlationId)) {
-            return false;
-        }
-        if (rpcName == null) {
-            if (other.rpcName != null) {
-                return false;
-            }
-        } else if (!rpcName.equals(other.rpcName)) {
-            return false;
-        }
-        if (type == null) {
-            if (other.type != null) {
-                return false;
-            }
-        } else if (!type.equals(other.type)) {
-            return false;
-        }
-        if (version == null) {
-            return other.version == null;
-        } else {
-            return version.equals(other.version);
-        }
-    }
 }
index a8fe379..cdbe9dc 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -24,11 +25,13 @@ package org.onap.policy.sdnr;
 import com.google.gson.annotations.SerializedName;
 
 import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class Status implements Serializable {
 
     private static final long serialVersionUID = 877641506135467199L;
@@ -57,35 +60,4 @@ public class Status implements Serializable {
     public String toString() {
         return "Status [code = " + code + ", value = " + value + "]";
     }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + code;
-        result = prime * result + ((value == null) ? 0 : value.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        Status other = (Status) obj;
-        if (code != other.code) {
-            return false;
-        }
-        if (value == null) {
-            return other.value == null;
-        } else {
-            return value.equals(other.value);
-        }
-    }
 }
index 3fa3332..9c3a4ec 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -25,11 +26,13 @@ import java.io.Serializable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
 
 @Getter
 @Setter
+@EqualsAndHashCode
 public class SoRequestDetails implements Serializable {
 
     private static final long serialVersionUID = -3283942659786236032L;
@@ -59,81 +62,6 @@ public class SoRequestDetails implements Serializable {
         this.subscriberInfo = soRequestDetails.subscriberInfo;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        SoRequestDetails other = (SoRequestDetails) obj;
-        if (cloudConfiguration == null) {
-            if (other.cloudConfiguration != null) {
-                return false;
-            }
-        } else if (!cloudConfiguration.equals(other.cloudConfiguration)) {
-            return false;
-        }
-        if (configurationParameters == null) {
-            if (other.configurationParameters != null) {
-                return false;
-            }
-        } else if (!configurationParameters.equals(other.configurationParameters)) {
-            return false;
-        }
-        if (modelInfo == null) {
-            if (other.modelInfo != null) {
-                return false;
-            }
-        } else if (!modelInfo.equals(other.modelInfo)) {
-            return false;
-        }
-        if (relatedInstanceList == null) {
-            if (other.relatedInstanceList != null) {
-                return false;
-            }
-        } else if (!relatedInstanceList.equals(other.relatedInstanceList)) {
-            return false;
-        }
-        if (requestInfo == null) {
-            if (other.requestInfo != null) {
-                return false;
-            }
-        } else if (!requestInfo.equals(other.requestInfo)) {
-            return false;
-        }
-        if (requestParameters == null) {
-            if (other.requestParameters != null) {
-                return false;
-            }
-        } else if (!requestParameters.equals(other.requestParameters)) {
-            return false;
-        }
-        if (subscriberInfo == null) {
-            return other.subscriberInfo == null;
-        } else {
-            return subscriberInfo.equals(other.subscriberInfo);
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((cloudConfiguration == null) ? 0 : cloudConfiguration.hashCode());
-        result = prime * result + ((configurationParameters == null) ? 0 : configurationParameters.hashCode());
-        result = prime * result + ((modelInfo == null) ? 0 : modelInfo.hashCode());
-        result = prime * result + ((relatedInstanceList == null) ? 0 : relatedInstanceList.hashCode());
-        result = prime * result + ((requestInfo == null) ? 0 : requestInfo.hashCode());
-        result = prime * result + ((requestParameters == null) ? 0 : requestParameters.hashCode());
-        result = prime * result + ((subscriberInfo == null) ? 0 : subscriberInfo.hashCode());
-        return result;
-    }
-
     @Override
     public String toString() {
         return "SORequestDetails [modelInfo=" + modelInfo + ", cloudConfiguration=" + cloudConfiguration
diff --git a/models-interactions/model-impl/so/src/test/resources/logback-test.xml b/models-interactions/model-impl/so/src/test/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..8557063
--- /dev/null
@@ -0,0 +1,38 @@
+<!--
+  ============LICENSE_START=======================================================
+  ONAP
+  ================================================================================
+  Copyright (C) 2020 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.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  ============LICENSE_END=========================================================
+-->
+
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+
+    <contextName>ModelImplSo</contextName>
+    <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+    <property name="LOG_DIR" value="${java.io.tmpdir}/pf_logging/" />
+
+    <!-- USE FOR STD OUT ONLY -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+        </encoder>
+    </appender>
+
+    <root level="warn">
+        <appender-ref ref="STDOUT" />
+    </root>
+
+</configuration>
index 7874d25..8db3438 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * vfc
  * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.. All rights reserved.
  * Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
  * ================================================================================
 package org.onap.policy.vfc;
 
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyMap;
 import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.endsWith;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.startsWith;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
@@ -50,7 +51,6 @@ public class VfcManagerTest implements VfcCallback {
     private RestManager   mockedRestManager;
 
     private Pair<Integer, String> httpResponsePutOk;
-    private Pair<Integer, String> httpResponseGetOk;
     private Pair<Integer, String> httpResponseBadResponse;
     private Pair<Integer, String> httpResponseErr;
 
@@ -65,7 +65,6 @@ public class VfcManagerTest implements VfcCallback {
         mockedRestManager   = mock(RestManager.class);
 
         httpResponsePutOk       = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
-        httpResponseGetOk       = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
         httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
         httpResponseErr         = mockedRestManager.new Pair<>(200, null);
     }
@@ -131,9 +130,6 @@ public class VfcManagerTest implements VfcCallback {
         VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Exception");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(
             startsWith(SOME_URL),
             eq(DOROTHY),
@@ -143,7 +139,9 @@ public class VfcManagerTest implements VfcCallback {
             anyString()))
             .thenThrow(new RuntimeException("OzException"));
 
-        managerThread.join();
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -151,14 +149,13 @@ public class VfcManagerTest implements VfcCallback {
         VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Null");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOME_URL),
                 eq(DOROTHY), eq("Null"), anyMap(), anyString(), anyString()))
                 .thenReturn(null);
 
-        managerThread.join();
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -166,14 +163,13 @@ public class VfcManagerTest implements VfcCallback {
         VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Error0");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOME_URL),
                 eq(DOROTHY), eq("Error0"), anyMap(), anyString(), anyString()))
                 .thenReturn(httpResponseErr);
 
-        managerThread.join();
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -181,14 +177,13 @@ public class VfcManagerTest implements VfcCallback {
         VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "BadResponse");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOME_URL),
                 eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
                 .thenReturn(httpResponseBadResponse);
 
-        managerThread.join();
+        manager.run();
+
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Test
@@ -196,17 +191,13 @@ public class VfcManagerTest implements VfcCallback {
         VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Ok");
         manager.setRestManager(mockedRestManager);
 
-        Thread managerThread = new Thread(manager);
-        managerThread.start();
-
         when(mockedRestManager.post(startsWith(SOME_URL),
                 eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
                 .thenReturn(httpResponsePutOk);
 
-        when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
-            .thenReturn(httpResponseGetOk);
+        manager.run();
 
-        managerThread.join();
+        verify(mockedRestManager).post(any(), any(), any(), any(), any(), any());
     }
 
     @Override
index 7faf197..8f647a4 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -119,10 +119,11 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> {
         }
 
         for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
-            if (matchPolicyTypesExactly && areListsIdentical(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
-                return true;
-            } else if (!matchPolicyTypesExactly
-                    && findSupportedPolicyType(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
+            if (matchPolicyTypesExactly) {
+                if (areListsIdentical(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
+                    return true;
+                }
+            } else if (findSupportedPolicyType(pdpSubGroup.getSupportedPolicyTypes(), typeFilter)) {
                 return true;
             }
         }
@@ -172,9 +173,11 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> {
         }
 
         for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {
-            if (matchPoliciesExactly && areListsIdentical(pdpSubGroup.getPolicies(), policyFilter)) {
-                return true;
-            } else if (!matchPoliciesExactly && findSingleElement(pdpSubGroup.getPolicies(), policyFilter)) {
+            if (matchPoliciesExactly) {
+                if (areListsIdentical(pdpSubGroup.getPolicies(), policyFilter)) {
+                    return true;
+                }
+            } else if (findSingleElement(pdpSubGroup.getPolicies(), policyFilter)) {
                 return true;
             }
         }
index 0df620b..67458cf 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -239,7 +239,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
         }
 
         if (properties != null) {
-            result = validateProperties(result);
+            validateProperties(result);
         }
 
         if (pdpSubGroups == null) {
@@ -257,11 +257,9 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
     /**
      * Validate the properties.
      *
-     * @param resultIn the incoming validation results so far
-     * @return the revalidation results including the property validation results
+     * @param result where to place any new validation results
      */
-    private PfValidationResult validateProperties(PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
+    private void validateProperties(PfValidationResult result) {
 
         for (Entry<String, String> propertyEntry : properties.entrySet()) {
             if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
@@ -273,8 +271,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
                         "a property value may not be null or blank"));
             }
         }
-
-        return result;
     }
 
     @Override
index 4ba70fb..858b614 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.models.provider;
 
 import javax.ws.rs.core.Response;
-
 import lombok.NonNull;
-
 import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.dao.impl.DefaultPfDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,7 +33,7 @@ import org.slf4j.LoggerFactory;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class PolicyModelsProviderFactory {
-    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(PolicyModelsProviderFactory.class);
 
     /**
      * Creates a new PolicyModelsProvider object from its implementation.
@@ -54,7 +51,7 @@ public class PolicyModelsProviderFactory {
         } catch (final Exception exc) {
             String errorMessage = "could not find implementation of the \"PolicyModelsProvider\" interface \""
                     + parameters.getImplementation() + "\"";
-            LOGGER.warn(errorMessage, exc);
+            LOGGER.warn(errorMessage);
             throw new PfModelException(Response.Status.NOT_FOUND, errorMessage, exc);
         }
 
@@ -76,7 +73,7 @@ public class PolicyModelsProviderFactory {
         } catch (Exception exc) {
             String errorMessage =
                     "could not create an instance of PolicyModelsProvider \"" + parameters.getImplementation() + "\"";
-            LOGGER.warn(errorMessage, exc);
+            LOGGER.warn(errorMessage);
             throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc);
         }
     }
index 195b882..f8ff4f3 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -125,7 +125,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     private String getValue(final String value) {
-        if (value != null && value.matches("[$][{].*[}]$")) {
+        if (value != null && value.startsWith("${") && value.endsWith("}")) {
             return System.getenv(value.substring(2, value.length() - 1));
         }
         return value;
index 2520545..0b06de5 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -59,7 +59,7 @@ public class DmaapSimParameterHandler {
         } catch (final CoderException e) {
             final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
                     + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
-            LOGGER.error(errorMessage, e);
+            LOGGER.error(errorMessage);
             throw new DmaapSimException(errorMessage, e);
         }
 
index 4b9549a..6c79ce9 100644 (file)
@@ -18,6 +18,7 @@
 
 package org.onap.policy.models.sim.dmaap.provider;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -242,14 +243,15 @@ public class DmaapSimProviderTest {
         // use a real provider so we can test the real makeTimer() method
         DmaapSimProvider prov2 = new DmaapSimProvider(params);
         prov2.start();
-        prov2.stop();
+        assertThatCode(() -> prov2.stop()).doesNotThrowAnyException();
     }
 
     @Test
     public void testMakeTopicData() {
         // use a real provider so we can test the real makeTopicData() method
         DmaapSimProvider prov2 = new DmaapSimProvider(params);
-        prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0);
+        assertThatCode(() -> prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0))
+                        .doesNotThrowAnyException();
     }
 
     @Test
index b8e285a..7f4e4b1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 package org.onap.policy.sim.dmaap.startstop;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -88,7 +89,7 @@ public class MainTest {
     @Test
     public void testMain_Help() {
         final String[] NormalParameters = {"-h"};
-        Main.main(NormalParameters);
+        assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
     }
 
     @Test
index 2c3f8f7..7c52163 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -55,7 +55,12 @@ public class PdpSimulatorActivator {
     private List<TopicSink> topicSinks;// topics to which pdp sends pdp status
     private List<TopicSource> topicSources; // topics to which pdp listens to for messages from pap.
     private static final String[] MSG_TYPE_NAMES = { "messageName" };
-    private static final Random RANDOM = new Random();
+
+    /*
+     * This simulator is only used for testing. Consequently, it is safe to use a simple
+     * random number generator, thus the sonar is disabled.
+     */
+    private static final Random RANDOM = new Random();      // NOSONAR
 
     /**
      * Listens for messages on the topic, decodes them into a message, and then dispatches them.
index 2bec22a..4916644 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 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,6 +21,8 @@
 
 package org.onap.policy.models.sim.pdp;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
+
 import org.junit.Test;
 import org.powermock.reflect.Whitebox;
 
@@ -32,6 +35,6 @@ public class TestPdpSimulatorConstants {
     @Test
     public void test() throws Exception {
         // verify that constructor does not throw an exception
-        Whitebox.invokeConstructor(PdpSimulatorConstants.class);
+        assertThatCode(() -> Whitebox.invokeConstructor(PdpSimulatorConstants.class)).doesNotThrowAnyException();
     }
 }
index 4b79444..de0181b 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 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,6 +21,7 @@
 
 package org.onap.policy.models.sim.pdp;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -92,7 +94,7 @@ public class TestPdpSimulatorMain {
     @Test
     public void testPdpSimulator_Help() {
         final String[] pdpSimulatorConfigParameters = { "-h" };
-        PdpSimulatorMain.main(pdpSimulatorConfigParameters);
+        assertThatCode(() -> PdpSimulatorMain.main(pdpSimulatorConfigParameters)).doesNotThrowAnyException();
     }
 
     @Test
index 6369f79..7c236e0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,9 +52,6 @@ public abstract class JpaToscaConstraint
         this.fromAuthorative(authorativeConcept);
     }
 
-    @Override
-    public abstract int compareTo(JpaToscaConstraint otherConstraint);
-
     /**
      * Create instances of constraints of various types.
      *
index a44d765..23411ad 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -196,7 +196,7 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
         PfValidationResult result = super.validate(resultIn);
 
         if (constraints != null) {
-            result = validateConstraints(result);
+            validateConstraints(result);
         }
 
         if (properties != null) {
@@ -209,19 +209,15 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
     /**
      * Validate the constraints.
      *
-     * @param result The result of validations up to now
-     * @return the validation result
+     * @param result where to put the validation results
      */
-    private PfValidationResult validateConstraints(@NonNull final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
-
+    private void validateConstraints(@NonNull final PfValidationResult result) {
         for (JpaToscaConstraint constraint : constraints) {
             if (constraint == null) {
                 result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
                         "data type constraint may not be null "));
             }
         }
-        return result;
     }
 
     /**
index cebf63d..1f5c76e 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -274,7 +274,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
         }
 
         if (properties != null) {
-            result = validateProperties(result);
+            validateProperties(result);
         }
 
         if (targets != null) {
@@ -287,11 +287,9 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
     /**
      * Validate the policy properties.
      *
-     * @param result The result of validations up to now
-     * @return the validation result
+     * @param result where to put the validation results
      */
-    private PfValidationResult validateProperties(final PfValidationResult resultIn) {
-        PfValidationResult result = resultIn;
+    private void validateProperties(final PfValidationResult result) {
 
         for (Entry<String, String> propertyEntry : properties.entrySet()) {
             if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
@@ -302,7 +300,6 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
                         "policy property value may not be null "));
             }
         }
-        return result;
     }
 
     /**
index d205794..c1fcf5d 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 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.
@@ -124,7 +124,7 @@ public class JpaToscaDataTypeTest {
 
         assertThatThrownBy(() -> {
             tdt.validate(null);
-        }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+        }).hasMessageMatching("result is marked .*on.*ull but is null");
 
         ToscaDataType dat = new ToscaDataType();
         dat.setName("name");