Improve code coverage and sonar fixes 44/138644/8
authorwaynedunican <wayne.dunican@est.tech>
Tue, 23 Jul 2024 08:23:51 +0000 (09:23 +0100)
committerwaynedunican <wayne.dunican@est.tech>
Tue, 13 Aug 2024 07:49:10 +0000 (08:49 +0100)
Increased code coverage to 90%
SONAR - Removed TODO comments
SONAR - Added NOSONAR where appropriate
SONAR - Replaced stream.Collect() with stream.toList() where applicable
SONAR - Made variables serializable or transient to comply with sonar rules

Issue-ID: POLICY-5069
Change-Id: Ife256eaf4e6f427fe40b138bacc6f112dc5bcea4
Signed-off-by: waynedunican <wayne.dunican@est.tech>
110 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
models-base/src/main/java/org/onap/policy/models/base/PfModel.java
models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
models-base/src/main/java/org/onap/policy/models/base/PfValidator.java
models-base/src/main/java/org/onap/policy/models/base/Validated.java
models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java
models-dao/pom.xml
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/ProxyDao.java
models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java [new file with mode: 0644]
models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java [new file with mode: 0644]
models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java [new file with mode: 0644]
models-decisions/pom.xml
models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java [new file with mode: 0644]
models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java [new file with mode: 0644]
models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java [new file with mode: 0644]
models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java [new file with mode: 0644]
models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/A1pOperationTest.java
models-interactions/model-actors/actor.a1p/src/test/java/org/onap/policy/controlloop/actor/a1p/BasicA1pOperation.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java
models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java
models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java
models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/RestManagerResponse.java
models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleDelete.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java
models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java
models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java
models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicOperationTest.java
models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java
models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java
models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java
models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java
models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java
models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java
models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java
models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java
models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.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/ControlLoopEvent.java
models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java
models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java
models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java
models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/CdsSimulatorTest.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParameters.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpFilterParametersTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java
models-provider/pom.xml
models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/TestPdpSimulatorConstants.java
models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/Main.java
models-tosca/pom.xml
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java

index df6141b..f97d7b4 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2020, 2024 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,7 +54,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> {
                 .filter(filterStringPred(name, PfConcept::getName))
                 .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion))
                 .filter(filterPrefixPred(versionPrefix, PfConcept::getVersion))
-                .collect(Collectors.toList());
+                .collect(Collectors.toList()); //NOSONAR
         // @formatter:off
 
         if (LATEST_VERSION.equals(version)) {
index 1caa632..0beeb01 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019, 2023 Nordix Foundation.
+ *  Copyright (C) 2019, 2023-2024 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -123,10 +123,10 @@ public abstract class PfModel extends PfConcept {
 
         for (final PfKey pfKey : this.getKeys()) {
             // Check for the two type of keys we have
-            if (pfKey instanceof PfConceptKey) {
-                validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result);
-            } else if (pfKey instanceof PfReferenceKey) {
-                validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result);
+            if (pfKey instanceof PfConceptKey pfConceptKey) {
+                validateArtifactKeyInModel(pfConceptKey, artifactKeySet, result);
+            } else if (pfKey instanceof PfReferenceKey pfReferenceKey) {
+                validateReferenceKeyInModel(pfReferenceKey, referenceKeySet, result);
             } else {
                 // It must be a PfKeyUse, nothing else is legal
                 usedKeySet.add((PfKeyUse) pfKey);
index 51054ee..f7e6b5a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ *  Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -114,7 +114,7 @@ public final class PfUtils {
             return defaultValue;
         }
 
-        return source.stream().map(mapFunc).collect(Collectors.toList());
+        return source.stream().map(mapFunc).collect(Collectors.toList()); //NOSONAR
     }
 
     /**
index c2eb2b6..e9c8591 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -67,8 +67,8 @@ public class PfValidator extends BeanValidator {
      */
     @Override
     public boolean verCascade(BeanValidationResult result, String fieldName, Object value) {
-        if (value instanceof Validated) {
-            ValidationResult result2 = ((Validated) value).validate(fieldName);
+        if (value instanceof Validated validated) {
+            ValidationResult result2 = validated.validate(fieldName);
             if (result2 == null) {
                 return true;
             }
@@ -129,6 +129,6 @@ public class PfValidator extends BeanValidator {
 
     @Override
     public Object xlate(Object value) {
-        return (value instanceof PfKey ? ((PfKey) value).getId() : value);
+        return (value instanceof PfKey pfKey ? pfKey.getId() : value);
     }
 }
index 711dd7b..0c4f360 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2024 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -119,6 +120,6 @@ public class Validated {
      * @return the value's ID, if it's a key, the original value otherwise
      */
     private static Object getKeyId(Object value) {
-        return (value instanceof PfKey ? ((PfKey) value).getId() : value);
+        return (value instanceof PfKey pfKey ? pfKey.getId() : value);
     }
 }
index d605645..35535e7 100644 (file)
@@ -130,7 +130,7 @@ class PfReferenceKeyTest {
         assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN")));
         assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN")));
 
-        assertNotEquals(testReferenceKey, null);
+        assertNotNull(testReferenceKey);
 
         assertThatThrownBy(() -> new PfReferenceKey((PfReferenceKey) null)).isInstanceOf(NullPointerException.class);
 
index 2fea439..9d142bf 100644 (file)
@@ -48,7 +48,7 @@ class PfUtilsTest {
         assertEquals(0, PfUtils.compareObjects(null, null));
         assertEquals(-1, PfUtils.compareObjects(HELLO, null));
         assertEquals(1, PfUtils.compareObjects(null, HELLO));
-        assertNotEquals(PfUtils.compareObjects(HELLO, "goodbye"), 0);
+        assertNotEquals(0, PfUtils.compareObjects(HELLO, "goodbye"));
         assertEquals(0, PfUtils.compareObjects(HELLO, HELLO));
     }
 
index 594528b..4b3d9e8 100644 (file)
@@ -102,7 +102,6 @@ public class DummyPfKey extends PfKey {
 
     @Override
     public boolean isNewerThan(@NonNull PfKey otherKey) {
-        // TODO Auto-generated method stub
         return false;
     }
 
index 4892628..3f0199a 100644 (file)
@@ -33,7 +33,6 @@ import org.onap.policy.models.base.PfObjectFilter;
 public class DummyPfObjectFilter implements PfObjectFilter<DummyPfObject> {
     @Override
     public List<DummyPfObject> filter(List<DummyPfObject> originalList) {
-        // TODO Auto-generated method stub
         return null;
     }
 }
index 1a33715..da32f25 100644 (file)
             <groupId>org.hibernate.orm</groupId>
             <artifactId>hibernate-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+        </dependency>
     </dependencies>
 </project>
index c6faf21..6b1409a 100644 (file)
@@ -455,7 +455,7 @@ public class DefaultPfDao implements PfDao {
              * The invoking code only passes well-known classes into this method, thus
              * disabling the sonar about SQL injection.
              */
-            size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) // NOSONAR
+            size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
                 .getSingleResult();
         }
         return size;
index ec0c357..e48fe16 100644 (file)
@@ -367,7 +367,7 @@ public class ProxyDao implements PfDao {
          * The invoking code only passes well-known classes into this method, thus
          * disabling the sonar about SQL injection.
          */
-        size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) // NOSONAR
+        size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class)
                 .getSingleResult();
         return size;
     }
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/PfFilterParametersTest.java
new file mode 100644 (file)
index 0000000..ec864a5
--- /dev/null
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class PfFilterParametersTest {
+
+    @Mock
+    private Map<String, Object> mockFilterMap;
+
+    private PfFilterParameters pfFilterParametersUnderTest;
+
+    @BeforeEach
+    void setUp() {
+        pfFilterParametersUnderTest = new PfFilterParameters("name", "version",
+            LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC),
+            LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC), mockFilterMap, 0, "sortOrder");
+    }
+
+    @Test
+    void testGetName() {
+        assertThat(pfFilterParametersUnderTest.getName()).isEqualTo("name");
+    }
+
+    @Test
+    void testGetVersion() {
+        assertThat(pfFilterParametersUnderTest.getVersion()).isEqualTo("version");
+    }
+
+    @Test
+    void testGetStartTime() {
+        assertThat(pfFilterParametersUnderTest.getStartTime())
+            .isEqualTo(LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC));
+    }
+
+    @Test
+    void testGetEndTime() {
+        assertThat(pfFilterParametersUnderTest.getEndTime())
+            .isEqualTo(LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC));
+    }
+
+    @Test
+    void testGetFilterMap() {
+        assertThat(pfFilterParametersUnderTest.getFilterMap()).isEqualTo(mockFilterMap);
+    }
+
+    @Test
+    void testGetRecordNum() {
+        assertThat(pfFilterParametersUnderTest.getRecordNum()).isZero();
+    }
+
+    @Test
+    void testGetSortOrder() {
+        assertThat(pfFilterParametersUnderTest.getSortOrder()).isEqualTo("sortOrder");
+    }
+
+    @Test
+    void testBuilder() {
+        assertThatCode(PfFilterParameters::builder).doesNotThrowAnyException();
+    }
+}
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilterTest.java
new file mode 100644 (file)
index 0000000..faab76b
--- /dev/null
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao.impl;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+
+class PfNonTimestampKeyFilterTest {
+
+    static PfNonTimestampKeyFilter filter;
+
+    @Test
+    void testPfNonTimestampKeyFilter() {
+        filter = new PfNonTimestampKeyFilter();
+        assertNotNull(filter);
+    }
+}
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/impl/ProxyDaoTest.java
new file mode 100644 (file)
index 0000000..e2fe1d9
--- /dev/null
@@ -0,0 +1,548 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.TypedQuery;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfReferenceTimestampKey;
+import org.onap.policy.models.base.PfTimestampKey;
+import org.onap.policy.models.dao.DaoParameters;
+import org.onap.policy.models.dao.PfFilterParameters;
+
+@ExtendWith(MockitoExtension.class)
+class ProxyDaoTest {
+
+    @Mock
+    private EntityManager mockMg;
+
+    @Mock
+    private TypedQuery mockQuery;
+
+    private ProxyDao proxyDaoUnderTest;
+
+    @BeforeEach
+    void setUp() {
+        proxyDaoUnderTest = new ProxyDao(mockMg);
+    }
+
+    @Test
+    void testInit() {
+        assertThatCode(() -> proxyDaoUnderTest.init(new DaoParameters())).doesNotThrowAnyException();
+    }
+
+    @Test
+    void testClose() {
+        assertThatCode((() -> proxyDaoUnderTest.close())).doesNotThrowAnyException();
+    }
+
+    @Test
+    void testCreate_Null() {
+        final PfConcept obj = null;
+
+        proxyDaoUnderTest.create(obj);
+
+        verify(mockMg, never()).merge(null);
+        verify(mockMg, never()).flush();
+    }
+
+    @Test
+    void testCreate() {
+        final PfConceptKey obj = new PfConceptKey("name", "1.0.0");
+
+        proxyDaoUnderTest.create(obj);
+
+        verify(mockMg).merge(obj);
+        verify(mockMg).flush();
+    }
+
+    @Test
+    void testDelete1_Null() {
+        final PfConcept obj = null;
+
+        proxyDaoUnderTest.delete(obj);
+
+        verify(mockMg, never()).remove(null);
+    }
+
+    @Test
+    void testDelete1() {
+        final PfConceptKey obj = new PfConceptKey("name", "1.0.0");
+
+        when(mockMg.contains(obj)).thenReturn(false);
+        when(mockMg.merge(obj)).thenReturn(obj);
+
+        proxyDaoUnderTest.delete(obj);
+
+        verify(mockMg).remove(obj);
+    }
+
+    @Test
+    void testDelete2WithNullKey() {
+        proxyDaoUnderTest.delete(PfConceptKey.class, (PfConceptKey) null);
+        // Verify that no interactions with mg are made when key is null
+        verify(mockMg, never()).createQuery(anyString(), any());
+    }
+
+    @Test
+    void testDelete2WithValidKey() {
+        PfConceptKey key = new PfConceptKey("name", "1.0.0");
+
+        when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery);
+        when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+
+        proxyDaoUnderTest.delete(PfConceptKey.class, key);
+
+        ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
+        verify(mockMg).createQuery(queryCaptor.capture(), eq(PfConceptKey.class));
+        verify(mockQuery).setParameter("name", key.getName());
+        verify(mockQuery).setParameter("version", key.getVersion());
+        verify(mockQuery).executeUpdate();
+
+        assertEquals("DELETE FROM PfConceptKey c WHERE c.key.name = :name "
+            + "AND c.key.version = :version", queryCaptor.getValue());
+    }
+
+    @Test
+    void testDelete3WithNullKey() {
+        proxyDaoUnderTest.delete(PfReferenceKey.class, (PfReferenceKey) null);
+        // Verify that no interactions with mg are made when key is null
+        verify(mockMg, never()).createQuery(anyString(), any());
+    }
+
+    @Test
+    void testDelete3WithValidKey() {
+        PfReferenceKey key = new PfReferenceKey("name", "1.0.0", "localName");
+
+        when(mockMg.createQuery(anyString(), eq(PfReferenceKey.class))).thenReturn(mockQuery);
+        when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+
+        proxyDaoUnderTest.delete(PfReferenceKey.class, key);
+
+        ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
+        verify(mockMg).createQuery(queryCaptor.capture(), eq(PfReferenceKey.class));
+        verify(mockQuery).setParameter("parentname", key.getParentKeyName());
+        verify(mockQuery).setParameter("parentversion", key.getParentKeyVersion());
+        verify(mockQuery).setParameter("localname", key.getLocalName());
+        verify(mockQuery).executeUpdate();
+
+        assertEquals("DELETE FROM PfReferenceKey c WHERE c.key.parentKeyName = :parentname"
+            + " AND c.key.parentKeyVersion = :parentversion"
+            + " AND c.key.localName = :localname", queryCaptor.getValue());
+    }
+
+    @Test
+    void testDelete4WithNullKey() {
+        proxyDaoUnderTest.delete(PfTimestampKey.class, (PfTimestampKey) null);
+        // Verify that no interactions with mg are made when key is null
+        verify(mockMg, never()).createQuery(anyString(), any());
+    }
+
+    @Test
+    void testDelete4WithValidKey() {
+        final PfTimestampKey key = new PfTimestampKey("name", "1.0.0", LocalDateTime.of(2020,
+            1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC));
+
+        when(mockMg.createQuery(anyString(), eq(PfTimestampKey.class))).thenReturn(mockQuery);
+        when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+
+        proxyDaoUnderTest.delete(PfTimestampKey.class, key);
+
+        ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
+        verify(mockMg).createQuery(queryCaptor.capture(), eq(PfTimestampKey.class));
+        verify(mockQuery).setParameter("name", key.getName());
+        verify(mockQuery).setParameter("version", key.getVersion());
+        verify(mockQuery).setParameter("timeStamp", key.getTimeStamp());
+        verify(mockQuery).executeUpdate();
+
+        assertEquals("DELETE FROM PfTimestampKey c WHERE c.key.name = :name AND c.key.version = :version "
+            + "AND c.key.timeStamp = :timeStamp", queryCaptor.getValue());
+    }
+
+    @Test
+    void testCreateCollectionWithNull() {
+        proxyDaoUnderTest.createCollection(null);
+
+        verify(mockMg, never()).merge(null);
+    }
+
+    @Test
+    void testCreateCollection() {
+        List<PfConceptKey> list = List.of(new PfConceptKey("name", "1.0.0"),
+            new PfConceptKey("name2", "1.0.1"));
+
+        proxyDaoUnderTest.createCollection(list);
+
+        for (final Object ck : list) {
+            verify(mockMg).merge(ck);
+        }
+    }
+
+    @Test
+    void testCreateCollectionWithIsEmpty() {
+        proxyDaoUnderTest.createCollection(List.of());
+
+        verify(mockMg, never()).merge(null);
+    }
+
+    @Test
+    void testDeleteCollection() {
+        final Collection<PfConceptKey> list = List.of(
+            new PfConceptKey("name", "1.0.0"),
+                new PfConceptKey("name2", "1.0.1"));
+        for (final Object o : list) {
+            lenient().when(mockMg.contains(o)).thenReturn(true);
+        }
+
+        proxyDaoUnderTest.deleteCollection(list);
+
+        for (final Object o : list) {
+            verify(mockMg).remove(o);
+        }
+    }
+
+    @Test
+    void testDeleteCollection_EntityManagerContainsReturnsFalse() {
+        final Collection<PfConceptKey> list = List.of(
+            new PfConceptKey("name", "1.0.0"),
+                new PfConceptKey("name2", "1.0.1"));
+        for (final Object o : list) {
+            lenient().when(mockMg.contains(o)).thenReturn(false);
+            lenient().when(mockMg.merge(o)).thenReturn(o);
+        }
+
+        proxyDaoUnderTest.deleteCollection(list);
+
+        for (final Object o : list) {
+            verify(mockMg).remove(o);
+        }
+    }
+
+    @Test
+    void testDeleteByConceptKey() {
+        final Collection<PfConceptKey> keys = List.of(new PfConceptKey("name", "1.0.0"));
+        when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery);
+        when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+        when(mockQuery.executeUpdate()).thenReturn(1);
+
+        final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, keys);
+
+        assertThat(result).isEqualTo(1);
+    }
+
+    @Test
+    void testDeleteByConceptKeyWithNull() {
+        final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, null);
+        assertThat(result).isZero();
+    }
+
+    @Test
+    void testDeleteByConceptKeyWithEmpty() {
+        final int result = proxyDaoUnderTest.deleteByConceptKey(PfConceptKey.class, List.of());
+        assertThat(result).isZero();
+    }
+
+    @Test
+    void testDeleteByReferenceKey() {
+        // Setup
+        final Collection<PfReferenceKey> keys = List.of(
+            new PfReferenceKey("parentkeyname", "1.0.0", "parentlocalname"));
+        when(mockMg.createQuery(anyString(), eq(PfReferenceKey.class))).thenReturn(mockQuery);
+        when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+        when(mockQuery.executeUpdate()).thenReturn(1);
+
+        final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, keys);
+
+        assertThat(result).isEqualTo(1);
+    }
+
+    @Test
+    void testDeleteByReferenceKeyWithNull() {
+        final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, null);
+        assertThat(result).isZero();
+    }
+
+    @Test
+    void testDeleteByReferenceKeyWithIsEmpty() {
+        final int result = proxyDaoUnderTest.deleteByReferenceKey(PfReferenceKey.class, List.of());
+        assertThat(result).isZero();
+    }
+
+    @Test
+    void testDeleteAll() {
+        when(mockMg.createQuery(anyString(), eq(PfConceptKey.class))).thenReturn(mockQuery);
+        proxyDaoUnderTest.deleteAll(PfConceptKey.class);
+        verify(mockQuery).executeUpdate();
+    }
+
+    @Test
+    void testGetFiltered1() {
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey());
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        for (final PfConcept ck : expectedResult) {
+            lenient().when(mockMg.find(eq(
+                PfConcept.class), any(Object.class))).thenReturn(ck);
+        }
+
+        final List<PfConcept> result = proxyDaoUnderTest.getFiltered(PfConcept.class, "name", "1.0.0");
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGenericGetNull() {
+        assertEquals(null, proxyDaoUnderTest.get(null, new PfConceptKey(
+            "name", "1.0.0")));
+    }
+
+    @Test
+    void testGetAllNull() {
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null));
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null,
+            new PfConceptKey("name", "1.0.0")));
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest.getAll(null,
+            "name", 1));
+
+    }
+
+    @Test
+    void testGetAllVersionsByParentNull() {
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest
+            .getAllVersionsByParent(null, "name"));
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest
+            .getAllVersionsByParent(PfConcept.class, null));
+    }
+
+    @Test
+    void testGetAllVersionsNull() {
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest
+            .getAllVersions(null, "conceptName"));
+        assertEquals(Collections.emptyList(), proxyDaoUnderTest
+            .getAllVersions(PfConcept.class, null));
+    }
+
+    @Test
+    void testGetConceptNull() {
+        assertNull(proxyDaoUnderTest.getConcept(null,
+            new PfConceptKey("name", "1.0.0")));
+        assertNull(proxyDaoUnderTest.getConcept(PfConcept.class, (PfConceptKey) null));
+        assertNull(proxyDaoUnderTest.getConcept(null,
+            new PfReferenceKey("name", "1.0.0", "localName")));
+        assertNull(proxyDaoUnderTest.getConcept(PfConcept.class, (PfReferenceKey) null));
+
+    }
+
+    @Test
+    void testGetFiltered2() {
+        List<PfConceptKey> list = List.of(new PfConceptKey("name", "1.0.0"),
+            new PfConceptKey("name2", "1.0.1"));
+
+        proxyDaoUnderTest.createCollection(list);
+
+        final PfFilterParameters filterParams = PfFilterParameters.builder()
+            .name("name")
+            .version("1.0.0")
+            .build();
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0"));
+
+        when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        when(mockQuery.getResultList()).thenReturn(expectedResult);
+
+        final List<PfConcept> result = proxyDaoUnderTest.getFiltered(PfConcept.class, filterParams);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGet1() {
+        final PfConceptKey key = new PfConceptKey("name", "1.0.0");
+        final PfConcept expectedResult = new PfConceptKey(key);
+        when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key);
+
+        final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGet2() {
+        final PfReferenceKey key =
+            new PfReferenceKey("parentKeyName", "1.0.0", "parentLocalName", "localName");
+        final PfConcept expectedResult = new PfReferenceKey(key);
+        when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key);
+
+        final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGet3() {
+        final PfTimestampKey key =
+            new PfTimestampKey("name", "1.0.0", LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC));
+        final PfConcept expectedResult = new PfTimestampKey(key);
+        when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key);
+
+        final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGet4() {
+        final PfReferenceTimestampKey key =
+            new PfReferenceTimestampKey("parentKeyName", "1.0.0", "parentLocalName", "localName",
+                LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0).toInstant(ZoneOffset.UTC));
+        final PfConcept expectedResult = new PfReferenceTimestampKey(key);
+        when(mockMg.find(eq(PfConcept.class), any(Object.class))).thenReturn(key);
+
+        final PfConcept result = proxyDaoUnderTest.get(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetAll1() {
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0"));
+
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList()).thenReturn(expectedResult);
+        final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetAll2() {
+        final PfConceptKey parentKey = new PfConceptKey("name", "1.0.0");
+        final List<PfConcept> expectedResult = List.of(parentKey);
+
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setParameter(anyString(), any())).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList()).thenReturn(expectedResult);
+
+        final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class, parentKey);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetAll3() {
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0"));
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setMaxResults(1)).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList())
+            .thenReturn(List.of(new PfConceptKey("name", "1.0.0")));
+
+        final List<PfConcept> result = proxyDaoUnderTest.getAll(PfConcept.class, "name", 1);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetAllVersionsByParent() {
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0"));
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList())
+            .thenReturn(List.of(new PfConceptKey("name", "1.0.0")));
+
+        final List<PfConcept> result = proxyDaoUnderTest.getAllVersionsByParent(PfConcept.class, "name");
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetAllVersions() {
+        final List<PfConcept> expectedResult = List.of(new PfConceptKey("name", "1.0.0"));
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList())
+            .thenReturn(List.of(new PfConceptKey("name", "1.0.0")));
+
+        final List<PfConcept> result = proxyDaoUnderTest.getAllVersions(PfConcept.class, "name");
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetConcept1() {
+        final PfConceptKey key = new PfConceptKey("name", "1.0.0");
+        final PfConcept expectedResult = key;
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList()).thenReturn(List.of(key));
+
+        final PfConcept result = proxyDaoUnderTest.getConcept(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testGetConcept2() {
+        final PfReferenceKey key = new PfReferenceKey();
+        final PfConcept expectedResult = key;
+        lenient().when(mockMg.createQuery(anyString(), eq(PfConcept.class))).thenReturn(mockQuery);
+        lenient().when(mockQuery.setParameter(anyString(), anyString())).thenReturn(mockQuery);
+        lenient().when(mockQuery.getResultList()).thenReturn(List.of(key));
+
+        final PfConcept result = proxyDaoUnderTest.getConcept(PfConcept.class, key);
+
+        assertThat(result).isEqualTo(expectedResult);
+    }
+
+    @Test
+    void testUpdate() {
+        final PfConcept obj = null;
+        final PfConcept expectedResult = null;
+        when(mockMg.merge(null)).thenReturn(null);
+
+        final PfConcept result = proxyDaoUnderTest.update(obj);
+
+        assertThat(result).isEqualTo(expectedResult);
+        verify(mockMg).flush();
+    }
+}
index 7c71d2f..a69e0d4 100644 (file)
@@ -55,5 +55,9 @@
             <artifactId>openpojo</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionException.java
new file mode 100644 (file)
index 0000000..5123f71
--- /dev/null
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Decision Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.decisions.concepts;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import jakarta.ws.rs.core.Response;
+import org.junit.jupiter.api.Test;
+
+class TestDecisionException {
+
+    @Test
+    void testException() {
+        Response.Status status = Response.Status.NOT_ACCEPTABLE;
+        String message = "Test exception thrown";
+
+        DecisionException exception = new DecisionException(status, message);
+
+        assertNotNull(exception);
+        assertEquals(status, exception.getErrorResponse().getResponseCode());
+        assertEquals(message, exception.getMessage());
+
+        assertThrows(DecisionException.class, () -> {
+            throw exception;
+        });
+    }
+}
diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/concepts/TestDecisionRequest.java
new file mode 100644 (file)
index 0000000..2d4acfb
--- /dev/null
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Decision Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.decisions.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+class TestDecisionRequest {
+
+    private DecisionRequest request1;
+
+    @BeforeEach
+    void setUp() {
+        request1 = new DecisionRequest();
+    }
+
+    @Test
+    void testConstructor() {
+        DecisionRequest request2 = new DecisionRequest(request1);
+        assertEquals(request1, request2);
+    }
+
+    @Test
+    void testConstructorContextNotNull() {
+        Map testMap = new HashMap<String, Object>();
+        testMap.put("entry1", "test");
+        request1.setContext(testMap);
+        DecisionRequest request2 = new DecisionRequest(request1);
+        assertThat(request2.toString()).contains("context={entry1=test}");
+    }
+
+    @Test
+    void testConstructorResourceNotNull() {
+        Map testMap = new HashMap<String, Object>();
+        testMap.put("resourceEntry1", "test");
+        request1.setResource(testMap);
+        DecisionRequest request2 = new DecisionRequest(request1);
+        assertThat(request2.toString()).contains("resource={resourceEntry1=test}");
+    }
+}
diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionRequestMessageBodyHandler.java
new file mode 100644 (file)
index 0000000..3bd4168
--- /dev/null
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Decision Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.decisions.serialization;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import com.google.gson.GsonBuilder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class TestDecisionRequestMessageBodyHandler {
+
+    DecisionRequestMessageBodyHandler handler;
+
+    @BeforeEach
+    void setUp() {
+        handler = new DecisionRequestMessageBodyHandler();
+    }
+
+    @Test
+    void testDecisionRequestMessageBodyHandlerConstructor() {
+        GsonBuilder builder = new GsonBuilder();
+        DecisionRequestMessageBodyHandler handler2 =
+            new DecisionRequestMessageBodyHandler(builder);
+        assertNotNull(handler);
+        assertNotNull(handler2);
+    }
+}
diff --git a/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java b/models-decisions/src/test/java/org/onap/policy/models/decisions/serialization/TestDecisionResponseMessageBodyHandler.java
new file mode 100644 (file)
index 0000000..93e39df
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Decision Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.decisions.serialization;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import com.google.gson.GsonBuilder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class TestDecisionResponseMessageBodyHandler {
+
+    DecisionResponseMessageBodyHandler handler;
+
+    @BeforeEach
+    void setUp() {
+        handler = new DecisionResponseMessageBodyHandler();
+    }
+
+    @Test
+    void testDecisionResponseMessageBodyHandler() {
+        GsonBuilder builder = new GsonBuilder();
+        DecisionResponseMessageBodyHandler handler2 = new DecisionResponseMessageBodyHandler(builder);
+        assertNotNull(handler);
+        assertNotNull(handler2);
+    }
+}
index 930888d..7ab5d47 100644 (file)
@@ -59,7 +59,7 @@ import org.onap.policy.sdnr.util.StatusCodeEnum;
      */
     @BeforeEach
     @Override
-     void setUp() throws Exception {
+     void setUp() {
         super.setUp();
 
         operation = new A1pOperation(params, config);
index 3620b0c..6a254a4 100644 (file)
@@ -69,7 +69,7 @@ public abstract class BasicA1pOperation extends BasicBidirectionalTopicOperation
     /**
      * Initializes mocks and sets up.
      */
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
 
         response = new PciMessage();
index 8768aec..7a101cb 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 20232024 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation {
      * Sets up.
      */
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
 
         oper = new AaiCustomQueryOperation(params, config);
@@ -166,7 +166,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation {
     }
 
     @Test
-    void testGetVserverLink() throws Exception {
+    void testGetVserverLink() {
         oper.setProperty(OperationProperties.AAI_VSERVER_LINK, MY_LINK);
         assertEquals(MY_LINK, oper.getVserverLink());
     }
@@ -194,7 +194,7 @@ class AaiCustomQueryOperationTest extends BasicAaiOperation {
 
 
     private OperationResult getResult(CompletableFuture<OperationOutcome> future2)
-                    throws InterruptedException, ExecutionException, TimeoutException {
+                    throws InterruptedException, ExecutionException {
 
         executor.runAll(100);
         assertTrue(future2.isDone());
index e9890b7..831edcc 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 20232024 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ class AaiGetOperationTest extends BasicAaiOperation {
      * Sets up.
      */
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
         oper = new AaiGetOperation(params, config);
     }
index cf2bb1b..bed847a 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 20232024 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ class AaiGetPnfOperationTest extends BasicAaiOperation {
      * Sets up.
      */
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
         oper = new AaiGetPnfOperation(params, config);
         oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
@@ -174,7 +174,7 @@ class AaiGetPnfOperationTest extends BasicAaiOperation {
      * Tests startOperationAsync() when a property is missing.
      */
     @Test
-    void testStartOperationAsyncMissingProperty() throws Exception {
+    void testStartOperationAsyncMissingProperty() {
         oper = new AaiGetPnfOperation(params, config);
 
         oper.generateSubRequestId(1);
index 65d3fe8..e3beb52 100644 (file)
@@ -75,7 +75,7 @@ class AaiGetTenantOperationTest extends BasicAaiOperation {
      * Sets up.
      */
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
         oper = new AaiGetTenantOperation(params, config);
         oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
@@ -174,7 +174,7 @@ class AaiGetTenantOperationTest extends BasicAaiOperation {
      * Tests startOperationAsync() when a property is missing.
      */
     @Test
-    void testStartOperationAsyncMissingProperty() throws Exception {
+    void testStartOperationAsyncMissingProperty() {
         oper = new AaiGetTenantOperation(params, config);
 
         oper.generateSubRequestId(1);
index caa190f..94efe0a 100644 (file)
@@ -66,7 +66,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
      */
     @BeforeEach
     @Override
-     void setUp() throws Exception {
+     void setUp() {
         super.setUp();
 
         oper = new MyOper(params, config);
index b934d86..45d64db 100644 (file)
@@ -86,7 +86,7 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio
     /**
      * Initializes mocks and sets up.
      */
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
 
         response = new Response();
index fad5044..2e0926e 100644 (file)
@@ -62,7 +62,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional
 
     @BeforeEach
     @Override
-     void setUp() throws Exception {
+     void setUp() {
         super.setUp();
 
         oper = new ModifyConfigOperation(params, config);
@@ -90,8 +90,6 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional
         oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf);
 
         outcome = oper.start().get();
-        // assertEquals(OperationResult.SUCCESS, outcome.getResult());
-        // assertTrue(outcome.getResponse() instanceof Response);
         assertNotNull(outcome);
     }
 
index 8fa165f..53677c7 100644 (file)
@@ -126,8 +126,6 @@ import org.onap.policy.simulators.TopicServer;
         oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
 
         outcome = oper.start().get();
-        // assertEquals(OperationResult.SUCCESS, outcome.getResult());
-        // assertTrue(outcome.getResponse() instanceof AppcLcmMessageWrapper);
         assertNotNull(outcome);
     }
 
@@ -167,7 +165,7 @@ import org.onap.policy.simulators.TopicServer;
      * Tests makeRequest() when a property is missing.
      */
     @Test
-     void testMakeRequestMissingProperty() throws Exception {
+     void testMakeRequestMissingProperty() {
         oper = new AppcLcmOperation(params, config);
         oper.generateSubRequestId(1);
 
index dc7fcf4..e3ad6be 100644 (file)
@@ -51,7 +51,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
      * Sets up the fields.
      */
     @BeforeEach
-     void setUp() throws Exception {
+     void setUp() {
         future = new CompletableFuture<>();
         manager = new CdsActorServiceManager(new OperationOutcome(), future);
     }
@@ -68,7 +68,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
     }
 
     @Test
-     void testOnMessageProcessing() throws InterruptedException, ExecutionException, TimeoutException {
+     void testOnMessageProcessing() {
 
         Status status = Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_PROCESSING).build();
         output = ExecutionServiceOutput.newBuilder().setStatus(status).build();
@@ -89,7 +89,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
     }
 
     @Test
-     void testOnError() throws InterruptedException, ExecutionException, TimeoutException {
+     void testOnError() {
 
         Exception exception = new Exception("something failed");
         manager.onError(exception);
index 3510c4a..09ca684 100644 (file)
@@ -129,7 +129,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation {
      */
 
     @Test
-     void testMakeRequestMissingBandwidth() throws Exception {
+     void testMakeRequestMissingBandwidth() {
         oper = new BandwidthOnDemandOperation(params, config);
         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
@@ -143,7 +143,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation {
     }
 
     @Test
-     void testMakeRequestMissingBandwidthChangeTime() throws Exception {
+     void testMakeRequestMissingBandwidthChangeTime() {
         oper = new BandwidthOnDemandOperation(params, config);
         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
@@ -157,7 +157,7 @@ class BandwidthOnDemandOperationTest extends BasicSdncOperation {
     }
 
     @Test
-     void testMakeRequestMissingVnfId() throws Exception {
+     void testMakeRequestMissingVnfId() {
         oper = new BandwidthOnDemandOperation(params, config);
         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
index cfdec98..5dee02f 100644 (file)
@@ -112,7 +112,7 @@ abstract class BasicSdncOperation extends BasicHttpOperation {
      * @return the request that was posted
      */
     protected SdncRequest verifyOperation(SdncOperation operation)
-                    throws InterruptedException, ExecutionException, TimeoutException, CoderException {
+                    throws InterruptedException, ExecutionException, CoderException {
 
         CompletableFuture<OperationOutcome> future2 = operation.start();
         executor.runAll(100);
index ee9a3a1..bd67f7f 100644 (file)
@@ -70,7 +70,7 @@ abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation<PciMe
     /**
      * Initializes mocks and sets up.
      */
-    void setUp() throws Exception {
+    void setUp() {
         super.setUpBasic();
 
         response = new PciMessage();
@@ -102,7 +102,7 @@ abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation<PciMe
      * @param operation operation to run
      */
     protected void verifyOperation(SdnrOperation operation)
-        throws InterruptedException, ExecutionException, TimeoutException {
+        throws InterruptedException, ExecutionException {
 
         CompletableFuture<OperationOutcome> future2 = operation.start();
         executor.runAll(100);
index e16ad11..f7dd9b9 100644 (file)
@@ -66,7 +66,7 @@ import org.onap.policy.sdnr.util.StatusCodeEnum;
      */
     @BeforeEach
     @Override
-     void setUp() throws Exception {
+     void setUp() {
         super.setUp();
 
         operation = new SdnrOperation(params, config);
@@ -148,8 +148,6 @@ import org.onap.policy.sdnr.util.StatusCodeEnum;
         operation.setProperty(OperationProperties.EVENT_PAYLOAD, "my payload");
 
         outcome = operation.start().get();
-        // assertEquals(OperationResult.SUCCESS, outcome.getResult());
-        // assertTrue(outcome.getResponse() instanceof PciMessage);
         assertNotNull(outcome);
     }
 
index 8076fbc..4ef0a7b 100644 (file)
@@ -4,7 +4,7 @@
  * ================================================================================
  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020 Wipro Limited.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -121,7 +121,6 @@ public class VfModuleDelete extends SoOperation {
      */
     protected CompletableFuture<Response> delete(String uri, Map<String, Object> headers, String contentType,
                     String request, InvocationCallback<Response> callback) {
-        // TODO move to HttpOperation
 
         final String url = getClient().getBaseUrl() + uri;
 
@@ -163,7 +162,6 @@ public class VfModuleDelete extends SoOperation {
      * @return the builder
      */
     protected Builder addAuthHeader(Builder builder) {
-        // TODO move to HttpOperation
         final HttpClient client = getClient();
         String username = client.getUserName();
         if (StringUtils.isBlank(username)) {
@@ -229,11 +227,6 @@ public class VfModuleDelete extends SoOperation {
         // requestInfo
         details.setRequestInfo(constructRequestInfo());
 
-        /*
-         * TODO the legacy SO code always passes null for the last argument, though it
-         * should be passing the vfModuleInstanceId
-         */
-
         // compute the path
         String svcId = getRequiredText("service instance ID", vnfServiceItem.getServiceInstanceId());
         String path = PATH_PREFIX + svcId + "/vnfs/" + vnfItem.getVnfId() + "/vfModules/null";
index ff1a93b..0edc7d3 100644 (file)
@@ -110,7 +110,7 @@ class ModifyCllTest extends BasicSoOperation {
      * Tests makeRequest() when a property is missing.
      */
     @Test
-     void testMakeRequestMissingProperty() throws Exception {
+     void testMakeRequestMissingProperty() {
         oper = new ModifyCll(params, config);
 
         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
index c5c1832..4db3ca3 100644 (file)
@@ -110,7 +110,7 @@ class ModifyNssiTest extends BasicSoOperation {
      * Tests makeRequest() when a property is missing.
      */
     @Test
-     void testMakeRequestMissingProperty() throws Exception {
+     void testMakeRequestMissingProperty() {
         oper = new ModifyNssi(params, config);
 
         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
index fe88a23..f047082 100644 (file)
@@ -212,7 +212,7 @@ import org.onap.policy.so.SoResponse;
     }
 
     @Test
-     void testConstructCloudConfiguration() throws Exception {
+     void testConstructCloudConfiguration() {
         Tenant tenantItem = new Tenant();
         tenantItem.setTenantId("my-tenant-id");
 
@@ -235,7 +235,7 @@ import org.onap.policy.so.SoResponse;
     }
 
     @Test
-     void testGetRequiredText() throws Exception {
+     void testGetRequiredText() {
 
         assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException();
 
index 721cb6a..d1b2c07 100644 (file)
@@ -221,7 +221,7 @@ class VfModuleCreateTest extends BasicSoOperation {
      * Tests makeRequest() when a property is missing.
      */
     @Test
-    void testMakeRequestMissingProperty() throws Exception {
+    void testMakeRequestMissingProperty() {
         loadProperties();
 
         ServiceInstance instance = new ServiceInstance();
index 5ece196..208db3f 100644 (file)
@@ -277,7 +277,7 @@ class VfModuleDeleteTest extends BasicSoOperation {
      */
     @Test
     @SuppressWarnings("unchecked")
-    void testDeleteException() throws Exception {
+    void testDeleteException() {
         Throwable thrown = new IllegalStateException(EXPECTED_EXCEPTION);
 
         // need a new future, with an exception
@@ -360,7 +360,7 @@ class VfModuleDeleteTest extends BasicSoOperation {
      * Tests makeRequest() when a property is missing.
      */
     @Test
-    void testMakeRequestMissingProperty() throws Exception {
+    void testMakeRequestMissingProperty() {
         loadProperties();
 
         ServiceInstance instance = new ServiceInstance();
@@ -381,7 +381,7 @@ class VfModuleDeleteTest extends BasicSoOperation {
     }
 
     @SuppressWarnings("unchecked")
-    private void configureResponse(String responseText) throws CoderException {
+    private void configureResponse(String responseText) {
         // indicate that the response was completed
         lenient().when(javaResp.statusCode()).thenReturn(200);
         lenient().when(javaResp.body()).thenReturn(responseText);
index 48ee9dc..4727de0 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.policy.controlloop.actor.test;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import jakarta.ws.rs.core.Response;
+import java.util.Collections;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
@@ -122,7 +123,7 @@ public class BasicOperation {
      * @return payload data
      */
     protected Map<String, Object> makePayload() {
-        return null;
+        return Collections.emptyMap();
     }
 
     /**
index c795f9c..0d04e58 100644 (file)
@@ -37,7 +37,6 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -71,7 +70,7 @@ class BasicBidirectionalTopicOperationTest {
      * Sets up.
      */
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         oper.setUpBasic();
     }
 
index 58392b9..9078029 100644 (file)
@@ -43,7 +43,7 @@ class BasicHttpOperationTest {
 
 
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         oper = new BasicHttpOperation(ACTOR, OPERATION);
         oper.setUpBasic();
     }
@@ -62,7 +62,7 @@ class BasicHttpOperationTest {
     }
 
     @Test
-    void testSetUp() throws Exception {
+    void testSetUp() {
         assertNotNull(oper.client);
         assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT));
         assertEquals(200, oper.rawResponse.getStatus());
@@ -73,7 +73,7 @@ class BasicHttpOperationTest {
     }
 
     @Test
-    void testInitOperator() throws Exception {
+    void testInitOperator() {
         oper.initConfig();
 
         assertSame(oper.client, oper.config.getClient());
index b2afce2..cf61e19 100644 (file)
@@ -23,9 +23,9 @@ package org.onap.policy.controlloop.actor.test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 
+import java.util.Collections;
 import java.util.Map;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -44,7 +44,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
 
 
     @BeforeEach
-     void setUp() throws Exception {
+     void setUp() {
         oper = new BasicHttpOperation(ACTOR, OPERATION);
         oper.setUpBasic();
     }
@@ -63,7 +63,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
     }
 
     @Test
-     void testSetUp() throws Exception {
+     void testSetUp() {
         assertNotNull(oper.future);
         assertNotNull(oper.outcome);
         assertNotNull(oper.executor);
@@ -82,7 +82,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
 
     @Test
      void testMakePayload() {
-        assertNull(oper.makePayload());
+        assertEquals(Collections.emptyMap(), oper.makePayload());
     }
 
     @Test
index 920e799..e0fd18b 100644 (file)
@@ -76,7 +76,6 @@ import org.onap.policy.vfc.VfcResponseDescriptor;
         VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
 
-        // TODO use actual request state value
         Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
         assertNotNull(oper.getRequestState(mockResponse));
     }
index ee9d28c..fa81836 100644 (file)
@@ -94,7 +94,7 @@ import org.onap.policy.simulators.XacmlSimulatorJaxRs;
      * Sets up.
      */
     @BeforeEach
-     void setUp() throws Exception {
+     void setUp() {
         super.setUpBasic();
 
         guardConfig = mock(DecisionConfig.class);
index a4187b5..f8b53e8 100644 (file)
@@ -28,7 +28,6 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import java.util.Map;
 import java.util.TreeMap;
@@ -86,7 +85,7 @@ import org.onap.policy.simulators.XacmlSimulatorJaxRs;
      * Sets up.
      */
     @BeforeEach
-     void setUp() throws Exception {
+     void setUp() {
         super.setUpBasic();
 
         guardConfig = mock(DecisionConfig.class);
index 3f0e528..81c9464 100644 (file)
@@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.xacml;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Arrays;
 import java.util.stream.Collectors;
index 5765f35..8f2199f 100644 (file)
@@ -95,7 +95,6 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial
      */
     @Override
     protected long getTimeoutMs(Integer timeoutSec) {
-        // TODO move this method to the superclass
         return (timeoutSec == null || timeoutSec == 0 ? getTimeoutMs() : super.getTimeoutMs(timeoutSec));
     }
 
index 5ecebd6..7e4543e 100644 (file)
@@ -98,7 +98,7 @@ class BidirectionalTopicActorTest {
     }
 
     @Test
-    void testDoStart() throws BidirectionalTopicClientException {
+    void testDoStart() {
         // allocate some handlers
         actor.getTopicHandler(MY_SINK, MY_SOURCE1);
         actor.getTopicHandler(MY_SINK, MY_SOURCE2);
@@ -117,7 +117,7 @@ class BidirectionalTopicActorTest {
     }
 
     @Test
-    void testDoStop() throws BidirectionalTopicClientException {
+    void testDoStop() {
         // allocate some handlers
         actor.getTopicHandler(MY_SINK, MY_SOURCE1);
         actor.getTopicHandler(MY_SINK, MY_SOURCE2);
@@ -136,7 +136,7 @@ class BidirectionalTopicActorTest {
     }
 
     @Test
-    void testDoShutdown() throws BidirectionalTopicClientException {
+    void testDoShutdown() {
 
         // allocate some handlers
         actor.getTopicHandler(MY_SINK, MY_SOURCE1);
@@ -187,7 +187,7 @@ class BidirectionalTopicActorTest {
     }
 
     @Test
-     void testGetTopicHandler() throws BidirectionalTopicClientException {
+     void testGetTopicHandler() {
         assertSame(handler1, actor.getTopicHandler(MY_SINK, MY_SOURCE1));
         assertSame(handler2, actor.getTopicHandler(MY_SINK, MY_SOURCE2));
 
@@ -195,7 +195,7 @@ class BidirectionalTopicActorTest {
     }
 
     @Test
-     void testMakeTopicHandler() throws BidirectionalTopicClientException {
+     void testMakeTopicHandler() {
         // use a real actor
         actor = new BidirectionalTopicActor<>(ACTOR, BidirectionalTopicActorParams.class);
 
index 1fc8cc1..67283f5 100644 (file)
@@ -174,7 +174,7 @@ class BidirectionalTopicOperationTest {
      * Tests startOperationAsync() when processResponse() throws an exception.
      */
     @Test
-    void testStartOperationAsyncProcException() throws Exception {
+    void testStartOperationAsyncProcException() {
         oper = new MyOperation(params, config) {
             @Override
             protected OperationOutcome processResponse(OperationOutcome outcome, String rawResponse,
@@ -202,7 +202,7 @@ class BidirectionalTopicOperationTest {
      * Tests startOperationAsync() when the publisher throws an exception.
      */
     @Test
-     void testStartOperationAsyncPubException() throws Exception {
+     void testStartOperationAsyncPubException() {
         // indicate that nothing was published
         when(handler.send(any())).thenReturn(false);
 
@@ -302,7 +302,7 @@ class BidirectionalTopicOperationTest {
      * Tests processResponse() when the decoder succeeds.
      */
     @Test
-     void testProcessResponseDecodeOk() throws CoderException {
+     void testProcessResponseDecodeOk() {
         assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse));
         assertEquals(OperationResult.SUCCESS, outcome.getResult());
         assertEquals(response, outcome.getResponse());
@@ -312,7 +312,7 @@ class BidirectionalTopicOperationTest {
      * Tests processResponse() when the decoder throws an exception.
      */
     @Test
-     void testProcessResponseDecodeExcept() throws CoderException {
+     void testProcessResponseDecodeExcept() {
         assertThatIllegalArgumentException().isThrownBy(
             () -> oper.processResponse(outcome, "{invalid json", stdResponse));
     }
index 9813d1b..8e1a878 100644 (file)
@@ -260,7 +260,7 @@ class HttpOperationTest {
      * Tests handleResponse() when it fails.
      */
     @Test
-   void testHandleResponseFailed() throws Exception {
+   void testHandleResponseFailed() {
         CompletableFuture<OperationOutcome> future2 = oper.handleResponse(outcome, PATH, cb -> {
             callback.set(cb);
             return future;
@@ -322,7 +322,7 @@ class HttpOperationTest {
      * Tests processResponse() when the decoder throws an exception.
      */
     @Test
-    void testProcessResponseDecodeExcept() throws CoderException {
+    void testProcessResponseDecodeExcept() {
         MyGetOperation<Integer> oper2 = new MyGetOperation<>(Integer.class);
 
         assertThatIllegalArgumentException().isThrownBy(() -> oper2.processResponse(outcome, PATH, response));
index 27b841a..d2ca7db 100644 (file)
@@ -137,7 +137,7 @@ class OperationPartialTest {
      * Attaches the appender to the logger.
      */
     @BeforeAll
-    static void setUpBeforeClass() throws Exception {
+    static void setUpBeforeClass() {
         /*
          * Attach appender to the logger.
          */
@@ -565,7 +565,7 @@ class OperationPartialTest {
      */
     @Test
     @SuppressWarnings("unchecked")
-     void testAnyOfEdge() throws Exception {
+     void testAnyOfEdge() {
         List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>();
 
         // zero items: check both using a list and using an array
@@ -651,7 +651,7 @@ class OperationPartialTest {
      */
     @Test
     @SuppressWarnings("unchecked")
-     void testAllOfEdge() throws Exception {
+     void testAllOfEdge() {
         List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>();
 
         // zero items: check both using a list and using an array
@@ -667,7 +667,7 @@ class OperationPartialTest {
     }
 
     @Test
-     void testAttachFutures() throws Exception {
+     void testAttachFutures() {
         List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>();
 
         // third task throws an exception during construction
@@ -770,7 +770,7 @@ class OperationPartialTest {
      */
     @Test
     @SuppressWarnings("unchecked")
-     void testSequenceEdge() throws Exception {
+     void testSequenceEdge() {
         List<Supplier<CompletableFuture<OperationOutcome>>> tasks = new LinkedList<>();
 
         // zero items: check both using a list and using an array
index c0d3a0d..2c82759 100644 (file)
@@ -157,7 +157,7 @@ class PipelineControllerFutureTest {
      * Tests completeAsync(executor) when canceled before execution.
      */
     @Test
-     void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() throws Exception {
+     void testCompleteAsyncSupplierOfQextendsTExecutorCanceled() {
         CompletableFuture<String> future = controller.completeAsync(() -> TEXT, executor);
 
         assertTrue(future.cancel(false));
@@ -181,7 +181,7 @@ class PipelineControllerFutureTest {
      * Tests completeAsync() when canceled.
      */
     @Test
-     void testCompleteAsyncSupplierOfQextendsTCanceled() throws Exception {
+     void testCompleteAsyncSupplierOfQextendsTCanceled() {
         CountDownLatch canceled = new CountDownLatch(1);
 
         // run async, but await until canceled
@@ -210,7 +210,7 @@ class PipelineControllerFutureTest {
     @Test
      void testCompleteOnTimeoutTLongTimeUnit() throws Exception {
         CountDownLatch stopped = new CountDownLatch(1);
-        controller.add(() -> stopped.countDown());
+        controller.add(stopped::countDown);
 
         CompletableFuture<String> future = controller.completeOnTimeout(TEXT, 1, TimeUnit.MILLISECONDS);
 
@@ -288,7 +288,7 @@ class PipelineControllerFutureTest {
      * Tests delayedComplete() when an exception is generated.
      */
     @Test
-     void testDelayedCompleteWithException() throws Exception {
+     void testDelayedCompleteWithException() {
         controller.add(runnable1);
 
         BiConsumer<String, Throwable> stopper = controller.delayedComplete();
@@ -314,7 +314,7 @@ class PipelineControllerFutureTest {
     }
 
     @Test
-     void testDelayedRemoveFutureOfF() throws Exception {
+     void testDelayedRemoveFutureOfF() {
         BiConsumer<String, Throwable> remover = controller.delayedRemove(future1);
 
         remover.accept(TEXT, EXPECTED_EXCEPTION);
@@ -331,7 +331,7 @@ class PipelineControllerFutureTest {
     }
 
     @Test
-     void testDelayedRemoveRunnable() throws Exception {
+     void testDelayedRemoveRunnable() {
         BiConsumer<String, Throwable> remover = controller.delayedRemove(runnable1);
 
         remover.accept(TEXT, EXPECTED_EXCEPTION);
@@ -380,7 +380,7 @@ class PipelineControllerFutureTest {
      * Tests wrap(), when the controller is not running.
      */
     @Test
-     void testWrapNotRunning() throws Exception {
+     void testWrapNotRunning() {
         controller.cancel(false);
         controller = spy(controller);
 
@@ -395,7 +395,7 @@ class PipelineControllerFutureTest {
      * Tests wrap(), when the future throws an exception.
      */
     @Test
-     void testWrapException() throws Exception {
+     void testWrapException() {
         controller = spy(controller);
 
         CompletableFuture<String> future = controller.wrap(compFuture);
@@ -428,7 +428,7 @@ class PipelineControllerFutureTest {
      * Tests wrap(Function) when the controller is canceled after the future is added.
      */
     @Test
-     void testWrapFunctionCancel() throws Exception {
+     void testWrapFunctionCancel() {
         Function<String, CompletableFuture<String>> func = controller.wrap(input -> compFuture);
 
         CompletableFuture<String> future = func.apply(TEXT);
index 7a6eb68..ed77525 100644 (file)
@@ -3,7 +3,7 @@
  *
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@ import org.onap.aai.domain.yang.Vserver;
 
 public class AaiCqResponse implements Serializable {
     private static final long serialVersionUID = 1L;
-    public static final String CONTEXT_KEY = AaiConstants.CONTEXT_PREFIX + "AaiCqResponse";
     public static final String OPERATION = "CustomQuery";
     private static final String GENERIC_VNF = "generic-vnf";
     private static final String VF_MODULE = "vf-module";
@@ -50,7 +49,7 @@ public class AaiCqResponse implements Serializable {
     @SerializedName("results")
     private List<Serializable> inventoryResponseItems = new LinkedList<>();
 
-    private final Gson gson;
+    private final transient Gson gson;
 
     /**
      * Constructor creates a custom query response from a valid json string.
index a6a6718..26a3987 100644 (file)
@@ -3,7 +3,7 @@
  * aai
  * ================================================================================
  * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation.
  * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,7 @@ package org.onap.policy.aai;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -48,8 +49,6 @@ import org.slf4j.LoggerFactory;
 @AllArgsConstructor
 public final class AaiManager {
 
-    // TODO remove this class
-
     /** The Constant logger. */
     private static final Logger logger = LoggerFactory.getLogger(AaiManager.class);
 
@@ -246,12 +245,12 @@ public final class AaiManager {
             pnfName = URLEncoder.encode(pnfName, StandardCharsets.UTF_8.toString()) + AAI_DEPTH_SUFFIX;
         } catch (UnsupportedEncodingException e) {
             logger.error("Failed to encode the pnfName: {} using UTF-8", pnfName, e);
-            return null;
+            return Collections.emptyMap();
         }
         var responseGet = getStringQuery(urlGet, username, password, requestId, pnfName);
         if (responseGet == null) {
             logger.error("Null response from AAI for the url: {}.", urlGet);
-            return null;
+            return Collections.emptyMap();
         }
         try {
             @SuppressWarnings("unchecked")
@@ -261,7 +260,7 @@ public final class AaiManager {
                             .collect(Collectors.toMap(e -> "pnf." + e.getKey(), Map.Entry::getValue));
         } catch (CoderException e) {
             logger.error("Failed to fetch PNF from AAI", e);
-            return null;
+            return Collections.emptyMap();
         }
     }
 }
index 72a7814..0a47fcb 100644 (file)
@@ -87,7 +87,7 @@ class CommonHeaderTest {
 
         assertEquals(commonHeader, (Object) commonHeader);
         assertEquals(commonHeader, copiedCommonHeader);
-        assertNotEquals(commonHeader, null);
+        assertNotNull(commonHeader);
         assertNotEquals(commonHeader, (Object) "Hello");
 
         CommonHeader clonedCommonHeader = new CommonHeader(commonHeader);
index 7ab4ae7..67b3d85 100644 (file)
@@ -76,7 +76,7 @@ class RequestTest {
 
         assertEquals(request, (Object) request);
         assertEquals(request, copiedRequest);
-        assertNotEquals(request, null);
+        assertNotNull(request);
         assertNotEquals(request, (Object) "Hello");
 
         checkField(commonHeader, Request::setCommonHeader);
index a13e08f..f095df9 100644 (file)
@@ -58,7 +58,7 @@ class ResponseStatusTest {
 
         assertEquals(status, (Object) status);
         assertEquals(status, copiedStatus);
-        assertNotEquals(status, null);
+        assertNotNull(status);
         assertNotEquals(status, (Object) "Hello");
 
         status.setCode(-1);
index ee0ff37..dffb958 100644 (file)
@@ -70,7 +70,7 @@ class ResponseTest {
 
         assertEquals(response, (Object) response);
         assertEquals(response, copiedResponse);
-        assertNotEquals(response, null);
+        assertNotNull(response);
         assertNotEquals(response, (Object) "Hello");
 
         response.setCommonHeader(null);
index 1a35064..b0a605b 100644 (file)
@@ -152,9 +152,7 @@ class CdsProcessorGrpcClientTest {
     @Test
     void testCdsProcessorGrpcClientConstructorFailure() {
         props.setHost(null);
-        assertThrows(IllegalStateException.class, () -> {
-            new CdsProcessorGrpcClient(listener, props).close();
-        });
+        assertThrows(IllegalStateException.class, () -> new CdsProcessorGrpcClient(listener, props));
     }
 
     @Test
index 4f0dbf7..8ac1c3f 100644 (file)
@@ -3,7 +3,7 @@
  * controlloop
  * ================================================================================
  * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public abstract class ControlLoopEvent implements Serializable {
     protected String policyName;
     protected String policyVersion;
     protected ControlLoopEventStatus closedLoopEventStatus;
-    protected Map<String, String> additionalEventParams;
+    private Map<String, String> additionalEventParams;
 
     /**
      * Construct an instance from an existing instance.
index b7622bd..12900a2 100644 (file)
@@ -3,7 +3,7 @@
  * controlloop
  * ================================================================================
  * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ public class VirtualControlLoopEvent extends ControlLoopEvent {
     private static final long serialVersionUID = -5752405682246066226L;
 
     @SerializedName("AAI")
-    protected Map<String, String> aai = new HashMap<>();
+    private Map<String, String> aai = new HashMap<>();
     protected String payload;
     protected Instant closedLoopAlarmStart;
     protected Instant closedLoopAlarmEnd;
index 4770000..b14df21 100644 (file)
@@ -37,7 +37,7 @@ class ControlLoopOperationTest {
 
         assertEquals(operation, (Object) operation);
         assertNotEquals(operation, (Object) "");
-        assertNotEquals(operation, null);
+        assertNotNull(operation);
 
         assertNotEquals(0, operation.hashCode());
         assertTrue(operation.toString().startsWith("ControlLoopOperation"));
index 23c9cea..5f21633 100644 (file)
@@ -33,6 +33,6 @@ class HttpDeleteWithBodyTest {
     void testGetMethod() {
         HttpDeleteWithBody deleteWithBody = new HttpDeleteWithBody(NO_URI);
         assertEquals("DELETE", deleteWithBody.getMethod());
-        assertEquals(deleteWithBody.getURI().toString(), NO_URI);
+        assertEquals(NO_URI, deleteWithBody.getURI().toString());
     }
 }
\ No newline at end of file
index 28136e6..7a21771 100644 (file)
@@ -107,7 +107,7 @@ public class RestTest {
      * @throws Exception if there is a problem
      */
     @AfterAll
-    public static void tearDown() throws Exception {
+    public static void tearDown() {
         HttpServletServerFactoryInstance.getServerFactory().destroy();
     }
 
index 1885ed1..d852e8b 100644 (file)
@@ -80,7 +80,7 @@ class PciCommonHeaderTest {
 
         assertEquals(commonHeader, (Object) commonHeader);
         assertEquals(commonHeader, copiedPciCommonHeader);
-        assertNotEquals(commonHeader, null);
+        assertNotNull(commonHeader);
         assertNotEquals(commonHeader, (Object) "Hello");
 
         PciCommonHeader clonedPciCommonHeader = new PciCommonHeader(commonHeader);
index 1334fcc..00eb694 100644 (file)
@@ -61,7 +61,7 @@ class PciRequestTest {
 
         assertEquals(request, (Object) request);
         assertEquals(request, copiedPciRequest);
-        assertNotEquals(request, null);
+        assertNotNull(request);
         assertNotEquals(request, (Object) "Hello");
 
         request.setCommonHeader(null);
index 722c081..a4a3e45 100644 (file)
@@ -54,7 +54,7 @@ class PciRequestWrapperTest {
 
         assertEquals(requestWrapper, (Object) requestWrapper);
         assertEquals(requestWrapper, copiedPciRequestWrapper);
-        assertNotEquals(requestWrapper, null);
+        assertNotNull(requestWrapper);
         assertNotEquals(requestWrapper, (Object) "Hello");
 
         requestWrapper.setBody(null);
index 70480b1..d2e28fd 100644 (file)
@@ -67,8 +67,7 @@ class PciResponseTest {
     @Test
     void testEqualsObject() {
         PciResponse response = new PciResponse();
-        assertEquals(response, response);
-        assertNotEquals(response, null);
+        assertNotNull(response);
         assertNotEquals(response, new Object());
 
         PciResponse response2 = new PciResponse();
index 1b02473..a34d65c 100644 (file)
@@ -50,17 +50,13 @@ class PciResponseWrapperTest {
         copiedPciResponseWrapper.setBody(responseWrapper.getBody());
 
         assertEquals(responseWrapper, (Object) responseWrapper);
-        //assertEquals(responseWrapper, copiedPciResponseWrapper);
-        assertNotEquals(responseWrapper, null);
+        assertNotNull(responseWrapper);
         assertNotEquals(responseWrapper, (Object) "Hello");
 
         responseWrapper.setBody(null);
         assertNotEquals(responseWrapper, copiedPciResponseWrapper);
         copiedPciResponseWrapper.setBody(null);
-        //assertEquals(responseWrapper, copiedPciResponseWrapper);
         responseWrapper.setBody(response);
-        //assertNotEquals(responseWrapper, copiedPciResponseWrapper);
         copiedPciResponseWrapper.setBody(response);
-        //assertEquals(responseWrapper, copiedPciResponseWrapper);
     }
 }
index e8f779e..495fc13 100644 (file)
@@ -52,7 +52,7 @@ class PciStatusTest {
 
         assertEquals(status, (Object) status);
         assertEquals(status, copiedStatus);
-        assertNotEquals(status, null);
+        assertNotNull(status);
         assertNotEquals(status, (Object) "Hello");
 
         status.setCode(-1);
index 8e915c3..3c11c09 100644 (file)
@@ -71,7 +71,7 @@ class PciWrapperTest {
 
         assertEquals(wrapper, (Object) wrapper);
         assertEquals(wrapper, copiedPciWrapper);
-        assertNotEquals(wrapper, null);
+        assertNotNull(wrapper);
         assertNotEquals(wrapper, (Object) "Hello");
 
         checkField(VERSION_19, PciWrapper::setVersion);
index 98a8289..64fc4ac 100644 (file)
@@ -115,7 +115,7 @@ class SoRequestDetailsTest {
 
         assertEquals(details, (Object) details);
         assertEquals(details, copiedDetails);
-        assertNotEquals(details, null);
+        assertNotNull(details);
         assertNotEquals(details, (Object) "Hello");
 
         checkField(cloudConfiguration, SoRequestDetails::setCloudConfiguration);
index f33bfd7..3229881 100644 (file)
@@ -74,7 +74,7 @@ class SoResponseWrapperTest {
 
         assertEquals(responseWrapper,  (Object) responseWrapper);
         assertEquals(responseWrapper,  identicalResponseWrapper);
-        assertNotEquals(responseWrapper, null);
+        assertNotNull(responseWrapper);
         assertNotEquals(responseWrapper, (Object) "AString");
 
         assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
index f3d5b3b..d7cfd18 100644 (file)
@@ -127,7 +127,7 @@ class CdsSimulatorTest {
     }
 
     @Test
-    void testGetResponse() throws IOException, CoderException, ParseException {
+    void testGetResponse() throws IOException, CoderException {
         CdsSimulator cdsSimulator = new CdsSimulator(Util.LOCALHOST, sim.getPort());
         String reqstr = ResourceUtils.getResourceAsString(
             "org/onap/policy/simulators/cds/cds.request.json");
index 6ab41dd..583c371 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Models
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
 package org.onap.policy.models.pap.concepts;
 
 import java.util.List;
-import java.util.stream.Collectors;
 import lombok.ToString;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 
@@ -41,7 +40,7 @@ public class PdpDeployPolicies {
      */
     public List<ToscaConceptIdentifierOptVersion> getPolicies() {
         return policies == null ? null
-                : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).collect(Collectors.toList());
+                : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).toList();
     }
 
     /**
@@ -51,6 +50,6 @@ public class PdpDeployPolicies {
      */
     public void setPolicies(final List<ToscaConceptIdentifierOptVersion> policies) {
         this.policies =
-                policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).collect(Collectors.toList());
+                policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).toList();
     }
 }
index 5373ace..d838a1b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Copyright (C) 2019-2021, 2024 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
 package org.onap.policy.models.pdp.concepts;
 
 import java.util.List;
-import java.util.stream.Collectors;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
@@ -76,7 +75,7 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> {
                 .filter(p -> filterOnPolicyTypeList(p, policyTypeList, matchPolicyTypesExactly))
                 .filter(p -> filterOnPolicyList(p, policyList, matchPoliciesExactly))
                 .filter(p -> filterOnPdpState(p, pdpState))
-                .collect(Collectors.toList());
+                .toList();
         // @formatter:on
     }
 
index 6729d7e..6be00bc 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Models
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
@@ -88,7 +87,7 @@ public class PdpGroups {
         if (null == groups) {
             result.setResult(ValidationStatus.INVALID, "is null");
         } else {
-            List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList());
+            List<String> names = groups.stream().map(PdpGroup::getName).toList();
             if (groups.size() != new HashSet<>(names).size()) {
                 result =
                     new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names");
index b962e2b..fed2bbb 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
- *  Modifications Copyright (C) 2021 Nordix Foundation.
+ *  Modifications Copyright (C) 2021, 2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ package org.onap.policy.models.pdp.concepts;
 
 import java.util.LinkedList;
 import java.util.List;
-import java.util.stream.Collectors;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
@@ -88,8 +87,8 @@ public class PdpUpdate extends PdpMessage {
         this.description = source.description;
         this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs;
         this.policiesToBeDeployed = (source.policiesToBeDeployed == null ? null
-                : source.policiesToBeDeployed.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
+                : source.policiesToBeDeployed.stream().map(ToscaPolicy::new).toList());
         this.policiesToBeUndeployed = (source.policiesToBeUndeployed == null ? null
-                : source.policiesToBeUndeployed.stream().map(ToscaConceptIdentifier::new).collect(Collectors.toList()));
+                : source.policiesToBeUndeployed.stream().map(ToscaConceptIdentifier::new).toList());
     }
 }
index 991e823..7771492 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
 package org.onap.policy.models.pdp.persistence.provider;
 
 import java.time.Instant;
+import java.util.Collections;
 import java.util.Map;
 import lombok.Builder;
 import lombok.Getter;
@@ -53,7 +55,7 @@ public class PdpFilterParameters implements PfFilterParametersIntfc {
             return filterMap;
 
         } else if (group == null) {
-            return null;
+            return Collections.emptyMap();
 
         } else if (subGroup == null) {
             filterMap = Map.of("pdpGroupName", group);
index fe46328..291248b 100644 (file)
@@ -33,7 +33,6 @@ import lombok.NonNull;
 import org.onap.policy.common.parameters.BeanValidationResult;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.dao.PfDao;
@@ -293,7 +292,8 @@ public class PdpProvider {
             return Collections.emptyList();
         }
 
-        List<JpaPdpPolicyStatus> jpas = objs.stream().map(JpaPdpPolicyStatus::new).collect(Collectors.toList());
+        List<JpaPdpPolicyStatus> jpas = objs.stream().map(JpaPdpPolicyStatus::new)
+            .collect(Collectors.toList());
 
         // validate the objects
         var result = new BeanValidationResult(fieldName, jpas);
index 998ccf6..acf1f60 100644 (file)
@@ -33,9 +33,9 @@ class PdpFilterParametersTest {
 
     @Test
     void testGetFilterMap() {
-        assertThat(PdpFilterParameters.builder().build().getFilterMap()).isNull();
+        assertThat(PdpFilterParameters.builder().build().getFilterMap()).isEmpty();
 
-        assertThat(PdpFilterParameters.builder().subGroup(SUBGROUP).build().getFilterMap()).isNull();
+        assertThat(PdpFilterParameters.builder().subGroup(SUBGROUP).build().getFilterMap()).isEmpty();
 
         PdpFilterParameters params = PdpFilterParameters.builder().group(GROUP).build();
         Map<String, Object> map = params.getFilterMap();
index 85d68ae..15ea29d 100644 (file)
@@ -38,7 +38,6 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.base.Validated;
 import org.onap.policy.models.dao.DaoParameters;
@@ -66,7 +65,6 @@ import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
  */
 class PdpProviderTest {
     private static final String PDP_GROUPS0_JSON = "testdata/PdpGroups0.json";
-    private static final String PDP_TYPE_IS_NULL = "pdpType is marked .*ull but is null";
     private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked .*ull but is null";
     private static final String GROUP_IS_NULL = "pdpGroupName is marked .*ull but is null";
     private static final String DAO_IS_NULL = "dao is marked .*ull but is null";
@@ -594,7 +592,7 @@ class PdpProviderTest {
         List<PdpPolicyStatus> records = prov.getGroupPolicyStatus(pfDao, GROUP_A);
         assertThat(records).hasSize(2);
 
-        Collections.sort(records, (rec1, rec2) -> rec1.getPdpId().compareTo(rec2.getPdpId()));
+        records.sort((rec1, rec2) -> rec1.getPdpId().compareTo(rec2.getPdpId()));
         assertThat(records.get(0)).isEqualTo(idx);
         assertThat(records.get(1)).isEqualTo(idy);
 
index cc692aa..35e2014 100644 (file)
             <artifactId>openpojo</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index 5fa6e80..6d7a707 100644 (file)
@@ -23,8 +23,13 @@ package org.onap.policy.models.provider;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import jakarta.persistence.EntityManager;
+import lombok.Getter;
+import lombok.Setter;
 import lombok.ToString;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.dao.impl.ProxyDao;
 
 /**
  * Test the {@link PolicyModelsProviderFactory} class.
@@ -34,6 +39,11 @@ import org.junit.jupiter.api.Test;
 @ToString
 class PolicyModelsProviderFactoryTest {
 
+    @Getter
+    @Setter
+    @Mock
+    private EntityManager mgr;
+
     @Test
     void testFactory() {
         PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
@@ -70,5 +80,26 @@ class PolicyModelsProviderFactoryTest {
         }).hasMessage("could not create an instance of PolicyModelsProvider "
                 + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"");
         // @formatter:on
+
+        assertThatThrownBy(() -> {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            ProxyDao dao = new ProxyDao(mgr);
+            factory.createPolicyModelsProvider(dao, pars);
+        }).hasMessageContaining("could not create an instance of PolicyModelsProvider");
+
+        assertThatThrownBy(() -> {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation(null);
+            ProxyDao dao = new ProxyDao(mgr);
+            factory.createPolicyModelsProvider(dao, pars);
+        }).hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"");
+
+        assertThatThrownBy(() -> {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation("java.lang.String");
+            ProxyDao dao = new ProxyDao(mgr);
+            factory.createPolicyModelsProvider(dao, pars);
+        }).hasMessage(
+            "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface");
     }
 }
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/AbstractModelsProviderTest.java
new file mode 100644 (file)
index 0000000..d6aefda
--- /dev/null
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Provider Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.provider.impl;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+
+class AbstractModelsProviderTest {
+
+    @Mock
+    private PolicyModelsProviderParameters mockParameters;
+
+    private AbstractModelsProvider abstractModelsProviderUnderTest;
+
+    private AutoCloseable mockitoCloseable;
+
+    @BeforeEach
+    void setUp() {
+        mockitoCloseable = openMocks(this);
+        abstractModelsProviderUnderTest = new AbstractModelsProvider(mockParameters) {};
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        mockitoCloseable.close();
+    }
+
+    @Test
+    void testInitError() {
+        when(mockParameters.getDatabaseUrl()).thenReturn("invalidParameter");
+        when(mockParameters.getDatabaseDriver()).thenReturn("invalidParameter");
+        when(mockParameters.getDatabaseUser()).thenReturn("invalidParameter");
+        when(mockParameters.getDatabasePassword()).thenReturn("invalidParameter");
+        when(mockParameters.getPersistenceUnit()).thenReturn("invalidParameter");
+
+        assertThrows(PfModelException.class, () -> abstractModelsProviderUnderTest.init());
+    }
+
+    @Test
+    void testClose() {
+        when(mockParameters.getDatabaseUrl()).thenReturn("result");
+        when(mockParameters.getPersistenceUnit()).thenReturn("result");
+
+        assertThatCode(abstractModelsProviderUnderTest::close).doesNotThrowAnyException();
+    }
+}
index 16d4ee4..0db2e0d 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.policy.models.provider.impl;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -44,6 +45,7 @@ import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
@@ -488,6 +490,53 @@ class DatabasePolicyModelsProviderTest {
             databaseProvider.deleteToscaNodeTemplate("invalidName", "1.0.1");
         }).hasMessage("node template invalidName:1.0.1 not found");
 
+        assertThatCode(() -> databaseProvider.getServiceTemplateList(NAME, VERSION_100))
+            .doesNotThrowAnyException();
+
+        assertThatCode(() -> databaseProvider.getFilteredServiceTemplateList(ToscaEntityFilter
+            .<ToscaServiceTemplate>builder().build()))
+            .doesNotThrowAnyException();
+
+
+    }
+
+    @Test
+    void testToscaTemplateMethods() throws PfModelException {
+        databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+        assertThatThrownBy(() -> databaseProvider.createServiceTemplate(new ToscaServiceTemplate()))
+            .hasMessageContaining("\"service template\" INVALID");
+
+        assertThatThrownBy(() -> databaseProvider.updateServiceTemplate(new ToscaServiceTemplate()))
+            .hasMessageContaining("\"service template\" INVALID");
+
+        assertThatThrownBy(() -> databaseProvider.deleteServiceTemplate(NAME, VERSION_100))
+            .hasMessageContaining("service template not found in database");
+
+        assertThatThrownBy(() -> databaseProvider.getToscaNodeTemplate(NAME, VERSION_100))
+            .hasMessageContaining("service template not found in database");
+
+        assertNotNull(databaseProvider.getAllPolicyStatus());
+
+        assertNotNull(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion()));
+
+        assertNotNull(databaseProvider.getGroupPolicyStatus("testGroup"));
+
+        ToscaServiceTemplate serviceTemplate = makeNodeTemplate();
+        databaseProvider.createToscaNodeTemplates(serviceTemplate);
+
+        assertThatCode(() -> databaseProvider.createServiceTemplate(new ToscaServiceTemplate()))
+            .doesNotThrowAnyException();
+        assertThatCode(() -> databaseProvider.getToscaNodeTemplate(serviceTemplate.getName(),
+            serviceTemplate.getVersion())).doesNotThrowAnyException();
+
+        assertThatCode(() -> databaseProvider.updateServiceTemplate(new ToscaServiceTemplate()))
+            .doesNotThrowAnyException();
+        assertThatCode(() -> databaseProvider.deleteServiceTemplate(serviceTemplate.getName(),
+            serviceTemplate.getVersion())).doesNotThrowAnyException();
+
+
+
         databaseProvider.close();
     }
 
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DbPolicyModelsProviderImplTest.java
new file mode 100644 (file)
index 0000000..d14ed8f
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Provider Models
+ * ================================================================================
+ * Copyright (C) 2024 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.models.provider.impl;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.dao.impl.ProxyDao;
+
+class DbPolicyModelsProviderImplTest {
+
+    @Mock
+    private ProxyDao mockPfDao;
+
+    private DbPolicyModelsProviderImpl dbPolicyModelsProviderImplUnderTest;
+
+    private AutoCloseable mockitoCloseable;
+
+    @BeforeEach
+    void setUp() {
+        mockitoCloseable = openMocks(this);
+        dbPolicyModelsProviderImplUnderTest = new DbPolicyModelsProviderImpl(mockPfDao);
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        mockitoCloseable.close();
+    }
+
+    @Test
+    void testInit() {
+        assertThatCode(() -> dbPolicyModelsProviderImplUnderTest.init())
+            .doesNotThrowAnyException();
+    }
+
+    @Test
+    void testClose() {
+        assertThatCode(() -> dbPolicyModelsProviderImplUnderTest.close())
+            .doesNotThrowAnyException();
+    }
+}
index 227f186..e9aedad 100644 (file)
@@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-import java.net.URISyntaxException;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
index ca65623..bd30174 100644 (file)
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
  */
 class TestPdpSimulatorConstants {
     @Test
-    void test() throws Exception {
+    void test() {
         // verify that constructor does not throw an exception
         assertThatCode(() -> {
             Constructor<PdpSimulatorConstants> c = PdpSimulatorConstants.class.getDeclaredConstructor();
index ce32fd4..dd82c84 100644 (file)
@@ -52,6 +52,8 @@ public class Main extends ServiceManagerContainer {
 
     private static final String CANNOT_CONNECT = "cannot connect to port ";
 
+    private static final String FALSE_STRING = "false";
+
     @Getter(AccessLevel.PROTECTED)
     private static Main instance;
 
@@ -185,9 +187,9 @@ public class Main extends ServiceManagerContainer {
                         Boolean.toString(params.isHttps()));
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
                         params.getProviderClass());
-        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false");
-        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false");
-        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, "false");
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, FALSE_STRING);
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, FALSE_STRING);
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, FALSE_STRING);
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
 
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, String.join(",",
index 9fbda40..3397316 100644 (file)
             <artifactId>openpojo</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index d6f3a68..a5a8005 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Copyright (C) 2019-2021, 2024 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import java.util.List;
-import java.util.stream.Collectors;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
@@ -52,7 +51,7 @@ public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<
                 .filter(p -> filterString(p.getName(), name))
                 .filter(p -> LATEST_VERSION.equals(version)
                         || filterString(p.getVersion(), version))
-                .collect(Collectors.toList());
+                .toList();
         // @formatter:off
 
         if (LATEST_VERSION.equals(version)) {
index 749873a..0bb72e5 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Copyright (C) 2019-2021, 2024 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import java.util.List;
-import java.util.stream.Collectors;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
@@ -63,7 +62,7 @@ public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFi
                 .filter(filterPrefixPred(versionPrefix, T::getVersion))
                 .filter(filterStringPred(type, T::getType))
                 .filter(filterStringPred(typeVersion, T::getTypeVersion))
-                .collect(Collectors.toList());
+                .toList();
         // @formatter:off
 
         if (LATEST_VERSION.equals(version)) {
index 3597156..f047658 100644 (file)
@@ -55,7 +55,6 @@ import org.slf4j.LoggerFactory;
 public class AuthorativeToscaProvider {
     private static final Logger LOGGER = LoggerFactory.getLogger(AuthorativeToscaProvider.class);
 
-    // TODO: In next release this locking mechanism should be removed and replaced with proper session handling
     private static final Object providerLockObject = "providerLockObject";
 
     /**
index 14502c6..593d18b 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation.
  * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -110,18 +110,9 @@ public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyT
         super.setToscaEntity(toscaPolicyType);
         super.toAuthorative();
 
-        // TODO need to copy targets & triggers?
-
         return toscaPolicyType;
     }
 
-    @Override
-    public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
-        super.fromAuthorative(toscaPolicyType);
-
-        // TODO need to copy targets & triggers?
-    }
-
     @Override
     public List<PfKey> getKeys() {
         final List<PfKey> keyList = super.getKeys();
index b9ae31b..c1c3f4a 100644 (file)
@@ -146,16 +146,6 @@ class ToscaEntityFilterTest {
         typeList.get(12).setVersion("2.0.0");
         filteredList = filter.filter(typeList);
         assertEquals(19, filteredList.size());
-        //
-        // This seems to change around as to where this policy type
-        // got changed - perhaps we change this test to find a specific name
-        // to test for vs an index which never remains consistent?
-        //
-        // assertEquals("2.0.0", filteredList.get(18).getVersion());
-        //
-        // And now this index changes again??
-        //
-        // assertEquals(VERSION_100, filteredList.get(17).getVersion());
 
         typeList.get(12).setVersion(VERSION_100);
         filteredList = filter.filter(typeList);
index 78058d9..d12e741 100644 (file)
@@ -169,7 +169,7 @@ class AuthorativeToscaProviderGenericTest {
     }
 
     @Test
-    void testNullParameters() throws Exception {
+    void testNullParameters() {
         assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplateList(null, null, null))
             .hasMessageMatching("^dao is marked .*on.*ull but is null$");
 
index b07535e..a993b30 100644 (file)
@@ -423,7 +423,7 @@ class AuthorativeToscaProviderPolicyTypeTest {
     }
 
     @Test
-    void testNullParameters() throws Exception {
+    void testNullParameters() {
         assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(null, null, null))
                 .hasMessageMatching("^dao is marked .*on.*ull but is null$");
     }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentsTest.java
new file mode 100644 (file)
index 0000000..7d54663
--- /dev/null
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
+
+class JpaToscaCapabilityAssignmentsTest {
+
+    @Mock
+    private PfConceptKey mockKey;
+
+    private JpaToscaCapabilityAssignments jpaToscaCapabilityAssignmentsUnderTest;
+
+    @BeforeEach
+    void setUp() {
+        openMocks(this);
+        jpaToscaCapabilityAssignmentsUnderTest = new JpaToscaCapabilityAssignments(mockKey, Map.ofEntries(
+            Map.entry(new PfConceptKey("name", "1.0.0"),
+                new JpaToscaCapabilityAssignment(new PfConceptKey("name", "1.0.0")))));
+    }
+
+    @Test
+    void testConstructors() {
+        JpaToscaCapabilityAssignments assignment = new JpaToscaCapabilityAssignments();
+        assertNotNull(assignment);
+
+        PfConceptKey key = new PfConceptKey();
+        assignment = new JpaToscaCapabilityAssignments(key);
+        assertNotNull(assignment);
+
+        assignment = new JpaToscaCapabilityAssignments(key, new HashMap<>());
+        assertNotNull(assignment);
+
+        JpaToscaCapabilityAssignments assignmentCopy = new JpaToscaCapabilityAssignments(assignment);
+        assertNotNull(assignmentCopy);
+
+        assertThatThrownBy(() -> new JpaToscaCapabilityAssignments(List.of(new HashMap<>())))
+            .hasMessageContaining("An incoming list of concepts must have at least one entry");
+    }
+
+    @Test
+    void testValidate() {
+        BeanValidationResult result = jpaToscaCapabilityAssignmentsUnderTest.validate("fieldName");
+        assertThat(result.getResult()).contains("item has status INVALID");
+
+        assertThatThrownBy(() -> jpaToscaCapabilityAssignmentsUnderTest.validate(null))
+            .hasMessageContaining("fieldName is marked non-null but is null");
+    }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypeTest.java
new file mode 100644 (file)
index 0000000..4f2b401
--- /dev/null
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.Map;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
+
+class JpaToscaCapabilityTypeTest {
+
+    @Mock
+    private PfConceptKey mockKey;
+
+    private JpaToscaCapabilityType jpaToscaCapabilityTypeUnderTest;
+
+    private AutoCloseable mockitoCloseable;
+
+    @BeforeEach
+    void setUp() {
+        mockitoCloseable = openMocks(this);
+        jpaToscaCapabilityTypeUnderTest = new JpaToscaCapabilityType(mockKey);
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        mockitoCloseable.close();
+    }
+
+    @Test
+    void testToAuthorative() {
+        final ToscaCapabilityType expectedResult = new ToscaCapabilityType();
+        expectedResult.setName("name");
+        expectedResult.setVersion("version");
+        expectedResult.setDerivedFrom("name");
+        expectedResult.setMetadata(Map.ofEntries(Map.entry("value", "value")));
+        expectedResult.setDescription("description");
+        final ToscaProperty toscaProperty = new ToscaProperty();
+        expectedResult.setProperties(Map.ofEntries(Map.entry("value", toscaProperty)));
+
+        when(mockKey.getName()).thenReturn("name");
+        when(mockKey.getVersion()).thenReturn("version");
+
+        final ToscaCapabilityType result = jpaToscaCapabilityTypeUnderTest.toAuthorative();
+
+        assertThat(result.toString()).contains(expectedResult.toString());
+    }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java
new file mode 100644 (file)
index 0000000..228a4f8
--- /dev/null
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.List;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfConceptKey;
+
+class JpaToscaRequirementTest {
+
+    @Mock
+    private PfConceptKey mockKey;
+    @Mock
+    private List<Integer> mockOccurrences;
+
+    private JpaToscaRequirement jpaToscaRequirementUnderTest;
+
+    private AutoCloseable mockitoCloseable;
+
+    @BeforeEach
+    void setUp() {
+        mockitoCloseable = openMocks(this);
+        jpaToscaRequirementUnderTest = new JpaToscaRequirement(mockKey);
+        jpaToscaRequirementUnderTest.setOccurrences(mockOccurrences);
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        mockitoCloseable.close();
+    }
+
+    @Test
+    void testCapabilityGetterAndSetter() {
+        final String capability = "capability";
+        jpaToscaRequirementUnderTest.setCapability(capability);
+        assertThat(jpaToscaRequirementUnderTest.getCapability()).isEqualTo(capability);
+
+        final String node = "node";
+        jpaToscaRequirementUnderTest.setNode(node);
+        assertThat(jpaToscaRequirementUnderTest.getNode()).isEqualTo(node);
+
+        final String relationship = "relationship";
+        jpaToscaRequirementUnderTest.setRelationship(relationship);
+        assertThat(jpaToscaRequirementUnderTest.getRelationship()).isEqualTo(relationship);
+
+        assertThat(jpaToscaRequirementUnderTest.getOccurrences()).isEqualTo(mockOccurrences);
+
+        assertThat(jpaToscaRequirementUnderTest.toString())
+            .hasToString("JpaToscaRequirement(capability=capability, node=node, relationship=relationship, "
+                + "occurrences=mockOccurrences)");
+    }
+}
index a789cd5..b26b397 100644 (file)
@@ -531,13 +531,13 @@ class SimpleToscaProviderTest {
     }
 
     @Test
-    void testGetServiceTemplate() throws PfModelException {
+    void testGetServiceTemplate() {
         assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao))
             .hasMessage("service template not found in database");
     }
 
     @Test
-    void testAppendToServiceTemplate() throws PfModelException {
+    void testAppendToServiceTemplate() {
         JpaToscaServiceTemplate serviceTemplateFragment = new JpaToscaServiceTemplate();
         serviceTemplateFragment.setPolicyTypes(new JpaToscaPolicyTypes());
         JpaToscaPolicyType badPt = new JpaToscaPolicyType();
index 4ddae1c..7ee015d 100644 (file)
@@ -173,9 +173,6 @@ class OptimizationPolicyTypeSerializationTest {
 
         assertNotNull(prop, testnm);
 
-        // this line results in a stack overflow
-        // assertEquals(testnm + " name", "geography", prop.getName());
-
         assertEquals("One or more geographic regions", prop.getDescription(), testnm + " description");
         assertEquals("list", prop.getType().getName(), testnm + " description");
         validateMatchable(testnm, prop.getMetadata());