diff options
66 files changed, 370 insertions, 673 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java index 394eb89f2..2357ec00d 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ public abstract class PfConcept extends Validated implements Serializable, Compa /** * Default constructor. */ - public PfConcept() { + protected PfConcept() { // Default Constructor } @@ -45,7 +45,7 @@ public abstract class PfConcept extends Validated implements Serializable, Compa * * @param copyConcept the concept to copy from */ - public PfConcept(@NonNull final PfConcept copyConcept) { + protected PfConcept(@NonNull final PfConcept copyConcept) { // nothing else to do (other than @NonNull check) } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java index d2015eb7e..e7cab460e 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,6 +72,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> { private static final long serialVersionUID = -324211738823208318L; + private static final String VALUE_FIELD = "value"; private static final Pattern KEY_ID_PATTERN = Pattern.compile(PfKey.KEY_ID_REGEXP); @EmbeddedId @@ -268,14 +269,14 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex addResult(result, "key on concept entry", conceptEntry.getKey(), IS_A_NULL_KEY); } else if (conceptEntry.getValue() == null) { result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey()); - addResult(result2, "value", conceptEntry.getValue(), IS_NULL); + addResult(result2, VALUE_FIELD, conceptEntry.getValue(), IS_NULL); } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey()); - addResult(result2, "value", conceptEntry.getValue(), "does not equal concept key"); - result2.addResult(conceptEntry.getValue().validate("value")); + addResult(result2, VALUE_FIELD, conceptEntry.getValue(), "does not equal concept key"); + result2.addResult(conceptEntry.getValue().validate(VALUE_FIELD)); } else { result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey()); - result2.addResult(conceptEntry.getValue().validate("value")); + result2.addResult(conceptEntry.getValue().validate(VALUE_FIELD)); } result.addResult(result2); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java index f38689a04..4b7f8cf95 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +70,7 @@ public abstract class PfKey extends PfConcept { /** * Default constructor. */ - public PfKey() { + protected PfKey() { super(); } @@ -78,7 +79,7 @@ public abstract class PfKey extends PfConcept { * * @param copyConcept the concept to copy from */ - public PfKey(final PfKey copyConcept) { + protected PfKey(final PfKey copyConcept) { super(copyConcept); } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java index bfeb870c1..b6d12198c 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * 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,7 @@ public abstract class PfKeyImpl extends PfKey { /** * The default constructor creates a null concept key. */ - public PfKeyImpl() { + protected PfKeyImpl() { this(NULL_KEY_NAME, NULL_KEY_VERSION); } @@ -51,7 +51,7 @@ public abstract class PfKeyImpl extends PfKey { * * @param copyConcept the concept to copy from */ - public PfKeyImpl(final PfKeyImpl copyConcept) { + protected PfKeyImpl(final PfKeyImpl copyConcept) { super(copyConcept); setName(copyConcept.getName()); setVersion(copyConcept.getVersion()); @@ -63,7 +63,7 @@ public abstract class PfKeyImpl extends PfKey { * @param name the key name * @param version the key version */ - public PfKeyImpl(@NonNull final String name, @NonNull final String version) { + protected PfKeyImpl(@NonNull final String name, @NonNull final String version) { super(); setName(name); setVersion(version); @@ -74,7 +74,7 @@ public abstract class PfKeyImpl extends PfKey { * * @param id the key ID in a format that respects the KEY_ID_REGEXP */ - public PfKeyImpl(@NonNull final String id) { + protected PfKeyImpl(@NonNull final String id) { // Check the incoming ID is valid Assertions.validateStringParameter("id", id, getKeyIdRegEx()); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java index bdd652a92..8cdcb90b7 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java @@ -72,7 +72,7 @@ public abstract class PfModel extends PfConcept { /** * The Default Constructor creates this concept with a NULL artifact key. */ - public PfModel() { + protected PfModel() { this(new PfConceptKey()); } @@ -81,7 +81,7 @@ public abstract class PfModel extends PfConcept { * * @param key the key of this concept */ - public PfModel(@NonNull final PfConceptKey key) { + protected PfModel(@NonNull final PfConceptKey key) { super(); Assertions.argumentNotNull(key, "key may not be null"); @@ -93,7 +93,7 @@ public abstract class PfModel extends PfConcept { * * @param copyConcept the concept to copy from */ - public PfModel(@NonNull final PfModel copyConcept) { + protected PfModel(@NonNull final PfModel copyConcept) { super(copyConcept); this.key = new PfConceptKey(copyConcept.key); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java index 91fa301f9..8fa757a00 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java @@ -110,7 +110,8 @@ public class ValidatedTest { BeanValidationResult result2 = new BeanValidationResult("", this); // null parameter tests - assertThatThrownBy(() -> Validated.validateKeyNotNull(result2, null, new PfConceptKey())) + PfConceptKey conceptKey = new PfConceptKey(); + assertThatThrownBy(() -> Validated.validateKeyNotNull(result2, null, conceptKey)) .isInstanceOf(NullPointerException.class); assertThatCode(() -> Validated.validateKeyNotNull(result2, MY_FIELD, null)).doesNotThrowAnyException(); @@ -131,7 +132,8 @@ public class ValidatedTest { assertThat(result.getResult()).contains(MY_FIELD).contains("version").contains(Validated.IS_NULL); BeanValidationResult result2 = new BeanValidationResult("", this); - assertThatThrownBy(() -> Validated.validateKeyVersionNotNull(result2, null, new PfConceptKey())) + PfConceptKey conceptKey = new PfConceptKey(); + assertThatThrownBy(() -> Validated.validateKeyVersionNotNull(result2, null, conceptKey)) .isInstanceOf(NullPointerException.class); assertThatCode(() -> Validated.validateKeyVersionNotNull(result2, MY_FIELD, null)).doesNotThrowAnyException(); diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java index 89d5c4f2f..31b4aec6e 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request, * @param config configuration for this operation * @param propertyNames names of properties required by this operation */ - public AppcOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config, + protected AppcOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config, List<String> propertyNames) { super(params, config, Response.class, propertyNames); } diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java index 07a05e6b8..456b10fdf 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcActorServiceManagerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,13 +31,15 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; -import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType; import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.OperationResult; +@RunWith(MockitoJUnitRunner.class) public class GrpcActorServiceManagerTest { CdsActorServiceManager manager; @@ -49,7 +51,6 @@ public class GrpcActorServiceManagerTest { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); future = new CompletableFuture<>(); manager = new CdsActorServiceManager(new OperationOutcome(), future); } diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java index 9291a3adb..0809291ad 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.util.Collections; import java.util.HashMap; @@ -34,17 +31,16 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput; import org.onap.policy.cds.client.CdsProcessorGrpcClient; import org.onap.policy.cds.properties.CdsServerProperties; @@ -63,6 +59,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.simulators.CdsSimulator; import org.onap.policy.simulators.Util; +@RunWith(MockitoJUnitRunner.class) public class GrpcOperationTest { private static final String MY_VNF = "my-vnf"; private static final String MY_SVC_ID = "my-service-instance-id"; @@ -104,8 +101,6 @@ public class GrpcOperationTest { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - // Setup the CDS properties cdsProps = new CdsServerProperties(); cdsProps.setHost("10.10.10.10"); @@ -114,9 +109,6 @@ public class GrpcOperationTest { cdsProps.setPassword("testPassword"); cdsProps.setTimeout(1); - // Setup cdsClient - when(cdsClient.sendRequest(any(ExecutionServiceInput.class))).thenReturn(mock(CountDownLatch.class)); - // Setup executor executor = new PseudoExecutor(); diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java index 3e3b1f573..aa11d7efd 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperatorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,8 @@ import java.util.Map; import java.util.UUID; import org.junit.Before; import org.junit.Test; -import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.cds.properties.CdsServerProperties; import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -36,6 +37,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; +@RunWith(MockitoJUnitRunner.class) public class GrpcOperatorTest { GrpcOperator operation; @@ -47,7 +49,6 @@ public class GrpcOperatorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); operation = new GrpcOperator(CdsActorConstants.CDS_ACTOR, GrpcOperation.NAME, GrpcOperation::new); CdsServerProperties props = new CdsServerProperties(); diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/DecisionOperatorTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/DecisionOperatorTest.java index 170bcdf7e..76b784101 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/DecisionOperatorTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/DecisionOperatorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,15 @@ import static org.mockito.Mockito.when; import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; +@RunWith(MockitoJUnitRunner.class) public class DecisionOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-name"; @@ -61,8 +63,6 @@ public class DecisionOperatorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(CLIENT)).thenReturn(client); oper = new MyOperator(); diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java index d30c71172..2d929d544 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,12 +29,14 @@ import static org.mockito.Mockito.when; import java.util.concurrent.Executor; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.models.decisions.concepts.DecisionRequest; +@RunWith(MockitoJUnitRunner.class) public class GuardConfigTest { private static final String MY_CLIENT = "my-client"; private static final String PATH = "my-path"; @@ -59,8 +61,6 @@ public class GuardConfigTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(MY_CLIENT)).thenReturn(client); params = GuardParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST) diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java index d235fb2c8..f3d6f1daf 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> { * @param config configuration for this operation * @param propertyNames names of properties required by this operation */ - public SdncOperation(ControlLoopOperationParams params, HttpConfig config, List<String> propertyNames) { + protected SdncOperation(ControlLoopOperationParams params, HttpConfig config, List<String> propertyNames) { super(params, config, SdncResponse.class, propertyNames); } diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java index fc4545966..f30802c32 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ public abstract class BasicBidirectionalTopicOperation<Q> extends BasicOperation /** * Constructs the object using a default actor and operation name. */ - public BasicBidirectionalTopicOperation() { + protected BasicBidirectionalTopicOperation() { super(); } @@ -91,7 +91,7 @@ public abstract class BasicBidirectionalTopicOperation<Q> extends BasicOperation * @param actor actor name * @param operation operation name */ - public BasicBidirectionalTopicOperation(String actor, String operation) { + protected BasicBidirectionalTopicOperation(String actor, String operation) { super(actor, operation); } diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java index 539202c4a..766e0fb2d 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,7 @@ public class BasicOperation { * Initializes mocks and sets up. */ public void setUpBasic() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); future = new CompletableFuture<>(); diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java index ef9b37ba6..65ab0bbb3 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicActorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.test; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.io.FileNotFoundException; import org.junit.Test; public class BasicActorTest extends BasicActor { @@ -42,6 +43,8 @@ public class BasicActorTest extends BasicActor { .isThrownBy(() -> verifyActorService(DummyActor.NAME, "serviceMissingActors.yaml")); // config file not found - assertThatThrownBy(() -> verifyActorService(DummyActor.NAME, "file-not-found.yaml")); + assertThatThrownBy(() -> verifyActorService(DummyActor.NAME, "file-not-found.yaml")) + .isInstanceOf(IllegalArgumentException.class) + .hasCauseInstanceOf(FileNotFoundException.class); } } diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java index 6cccc5cb7..c708a17cd 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,14 +33,16 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.simulators.TopicServer; +@RunWith(MockitoJUnitRunner.class) public class BasicBidirectionalTopicOperationTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-operation"; @@ -66,8 +68,6 @@ public class BasicBidirectionalTopicOperationTest { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - oper = new MyOperation(ACTOR, OPERATION); oper.setUpBasic(); } diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java index 65c7318ff..2d6dc5802 100644 --- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java +++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ public abstract class VfcOperation extends HttpOperation<VfcResponse> { * @param params operation parameters * @param config configuration for this operation */ - public VfcOperation(ControlLoopOperationParams params, HttpConfig config) { + protected VfcOperation(ControlLoopOperationParams params, HttpConfig config) { super(params, config, VfcResponse.class, PROPERTY_NAMES); setUsePolling(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index e02e59239..b0ad38eff 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,7 +78,7 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial * @param clazz response class * @param propertyNames names of properties required by this operation */ - public BidirectionalTopicOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config, + protected BidirectionalTopicOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config, Class<S> clazz, List<String> propertyNames) { super(params, config, propertyNames); this.config = config; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java index c75ca1d4f..a4b48d432 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,7 @@ public abstract class HttpOperation<T> extends OperationPartial { * @param clazz response class * @param propertyNames names of properties required by this operation */ - public HttpOperation(ControlLoopOperationParams params, HttpConfig config, Class<T> clazz, + protected HttpOperation(ControlLoopOperationParams params, HttpConfig config, Class<T> clazz, List<String> propertyNames) { super(params, config, propertyNames); this.config = config; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index 6874c5edd..7ad0cd82e 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,7 +118,7 @@ public abstract class OperationPartial implements Operation { * @param config configuration for this operation * @param propertyNames names of properties required by this operation */ - public OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List<String> propertyNames) { + protected OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List<String> propertyNames) { this.params = params; this.config = config; this.fullName = params.getActor() + "." + params.getOperation(); @@ -518,7 +518,7 @@ public abstract class OperationPartial implements Operation { return futures[0]; } - CompletableFuture.anyOf(futures).thenApply(outcome -> (OperationOutcome) outcome) + CompletableFuture.anyOf(futures).thenApply(OperationOutcome.class::cast) .whenCompleteAsync(controller.delayedComplete(), params.getExecutor()); return controller; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java index 8007c24f9..e75e99eaa 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperatorPartial.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public abstract class OperatorPartial extends StartConfigPartial<Map<String, Obj * @param actorName name of the actor with which this operator is associated * @param name operation name */ - public OperatorPartial(String actorName, String name) { + protected OperatorPartial(String actorName, String name) { super(actorName + "." + name); this.actorName = actorName; this.name = name; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartial.java index 6c883f1b5..1cf611a61 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/StartConfigPartial.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public abstract class StartConfigPartial<T> implements Startable, Configurable<T * * @param fullName full name of this object, used for logging and exception purposes */ - public StartConfigPartial(String fullName) { + protected StartConfigPartial(String fullName) { this.fullName = fullName; } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java index 937776926..55bdab9ad 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/TypedOperator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public abstract class TypedOperator<C, T extends Operation> extends OperatorPart * @param name operation name * @param operationMaker function to make an operation */ - public TypedOperator(String actorName, String name, OperationMaker<C, T> operationMaker) { + protected TypedOperator(String actorName, String name, OperationMaker<C, T> operationMaker) { super(actorName, name); this.operationMaker = operationMaker; } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java index 605a7330c..6f667bb76 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,10 +112,10 @@ public class OperationOutcomeTest { outcome.setOperation(OPERATION); // null actor argument - assertThatThrownBy(() -> outcome.isFor(null, OPERATION)); + assertThatThrownBy(() -> outcome.isFor(null, OPERATION)).isInstanceOf(NullPointerException.class); // null operation argument - assertThatThrownBy(() -> outcome.isFor(ACTOR, null)); + assertThatThrownBy(() -> outcome.isFor(ACTOR, null)).isInstanceOf(NullPointerException.class); // true case assertTrue(OperationOutcome.isFor(outcome, ACTOR, OPERATION)); @@ -126,7 +126,7 @@ public class OperationOutcomeTest { outcome.setResult(OperationResult.FAILURE_EXCEPTION); assertEquals(OperationResult.FAILURE_EXCEPTION, outcome.getResult()); - assertThatThrownBy(() -> outcome.setResult(null)); + assertThatThrownBy(() -> outcome.setResult(null)).isInstanceOf(NullPointerException.class); } private void setAll() { diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java index 6a8813cc6..64d530d77 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,9 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.client.BidirectionalTopicClientException; import org.onap.policy.controlloop.actorserviceprovider.Util; @@ -47,6 +48,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.Bidirectional import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; +@RunWith(MockitoJUnitRunner.class) public class BidirectionalTopicActorTest { private static final String ACTOR = "my-actor"; @@ -90,8 +92,6 @@ public class BidirectionalTopicActorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - actor = new MyActor(); actor.configure(Util.translateToMap(ACTOR, makeParams())); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 08d4adfd2..662f864c7 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,10 +44,11 @@ import lombok.Getter; import lombok.Setter; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -61,6 +62,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; +@RunWith(MockitoJUnitRunner.class) public class BidirectionalTopicOperationTest { private static final CommInfrastructure SINK_INFRA = CommInfrastructure.NOOP; private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); @@ -98,8 +100,6 @@ public class BidirectionalTopicOperationTest { */ @Before public void setUp() throws CoderException { - MockitoAnnotations.initMocks(this); - when(config.getTopicHandler()).thenReturn(handler); when(config.getForwarder()).thenReturn(forwarder); when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS); @@ -166,7 +166,7 @@ public class BidirectionalTopicOperationTest { assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertEquals(response, outcome.getResponse()); - verify(forwarder).unregister(eq(Arrays.asList(REQ_ID)), eq(listenerCaptor.getValue())); + verify(forwarder).unregister(Arrays.asList(REQ_ID), listenerCaptor.getValue()); } /** @@ -194,7 +194,7 @@ public class BidirectionalTopicOperationTest { assertTrue(executor.runAll(MAX_REQUESTS)); assertTrue(future.isCompletedExceptionally()); - verify(forwarder).unregister(eq(Arrays.asList(REQ_ID)), eq(listenerCaptor.getValue())); + verify(forwarder).unregister(Arrays.asList(REQ_ID), listenerCaptor.getValue()); } /** @@ -210,7 +210,7 @@ public class BidirectionalTopicOperationTest { verify(forwarder).register(eq(Arrays.asList(REQ_ID)), listenerCaptor.capture()); // must still unregister - verify(forwarder).unregister(eq(Arrays.asList(REQ_ID)), eq(listenerCaptor.getValue())); + verify(forwarder).unregister(Arrays.asList(REQ_ID), listenerCaptor.getValue()); } @Test diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java index d0dc0a759..4d19782c2 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperatorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,9 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; @@ -45,6 +46,7 @@ import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopic import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; +@RunWith(MockitoJUnitRunner.class) public class BidirectionalTopicOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-operation"; @@ -70,8 +72,6 @@ public class BidirectionalTopicOperatorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - keys = List.of(new SelectorKey("")); when(mgr.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(handler); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index 82aa091c1..117b4097b 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,8 +62,9 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.TopicParamsBuilder; @@ -83,6 +84,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; +@RunWith(MockitoJUnitRunner.class) public class HttpOperationTest { private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); @@ -169,8 +171,6 @@ public class HttpOperationTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - rejectRequest = false; nget = 0; npost = 0; diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java index af8f1aaab..35cf08227 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperatorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,9 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -46,6 +47,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; +@RunWith(MockitoJUnitRunner.class) public class HttpOperatorTest { private static final String ACTOR = "my-actor"; @@ -68,8 +70,6 @@ public class HttpOperatorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(HTTP_CLIENT)).thenReturn(client); oper = new MyOperator(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java index 45ef29321..bd44663fd 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperationTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,9 @@ import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -52,6 +53,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo /** * Tests HttpOperation when polling is enabled. */ +@RunWith(MockitoJUnitRunner.class) public class HttpPollingOperationTest { private static final String BASE_URI = "http://my-host:6969/base-uri/"; private static final String MY_PATH = "my-path"; @@ -84,12 +86,9 @@ public class HttpPollingOperationTest { */ @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - when(client.getBaseUrl()).thenReturn(BASE_URI); when(config.getClient()).thenReturn(client); - when(config.getPath()).thenReturn(MY_PATH); when(config.getMaxPolls()).thenReturn(MAX_POLLS); when(config.getPollPath()).thenReturn(POLL_PATH); when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC); @@ -120,8 +119,6 @@ public class HttpPollingOperationTest { // should throw an exception if we pass a plain HttpConfig HttpConfig config2 = mock(HttpConfig.class); - when(config2.getClient()).thenReturn(client); - when(config2.getPath()).thenReturn(MY_PATH); assertThatIllegalStateException().isThrownBy(() -> new MyOper(params, config2).setUsePolling()); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java index 413667b20..f340f1972 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpPollingOperatorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,9 @@ import java.util.Collections; import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.controlloop.actorserviceprovider.Util; @@ -41,6 +42,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException; +@RunWith(MockitoJUnitRunner.class) public class HttpPollingOperatorTest { private static final String ACTOR = "my-actor"; private static final String OPERATION = "my-name"; @@ -64,8 +66,6 @@ public class HttpPollingOperatorTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(CLIENT)).thenReturn(client); oper = new MyOperator(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index f6dbcd85f..d617a72ee 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; import ch.qos.logback.classic.Logger; import java.time.Instant; @@ -59,8 +57,9 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.Coder; @@ -80,6 +79,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfi import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.slf4j.LoggerFactory; +@RunWith(MockitoJUnitRunner.class) public class OperationPartialTest { private static final CommInfrastructure SINK_INFRA = CommInfrastructure.NOOP; private static final CommInfrastructure SOURCE_INFRA = CommInfrastructure.UEB; @@ -160,18 +160,12 @@ public class OperationPartialTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); executor = new PseudoExecutor(); params = ControlLoopOperationParams.builder().completeCallback(this::completer).requestId(REQ_ID) .executor(executor).actorService(service).actor(ACTOR).operation(OPERATION).timeoutSec(TIMEOUT) .startCallback(this::starter).build(); - when(service.getActor(OperationPartial.GUARD_ACTOR_NAME)).thenReturn(guardActor); - when(guardActor.getOperator(OperationPartial.GUARD_OPERATION_NAME)).thenReturn(guardOperator); - when(guardOperator.buildOperation(any())).thenReturn(guardOperation); - when(guardOperation.start()).thenReturn(CompletableFuture.completedFuture(makeSuccess())); - config = new OperatorConfig(executor); oper = new MyOper(); @@ -1048,13 +1042,6 @@ public class OperationPartialTest { }; } - private OperationOutcome makeSuccess() { - OperationOutcome outcome = params.makeOutcome(); - outcome.setResult(OperationResult.SUCCESS); - - return outcome; - } - /** * Verifies a run. * diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java index 7c6a98fde..7b44333f9 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicConfigTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,13 +29,15 @@ import java.util.List; import java.util.concurrent.Executor; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey; +@RunWith(MockitoJUnitRunner.class) public class BidirectionalTopicConfigTest { private static final String MY_SINK = "my-sink"; private static final String MY_SOURCE = "my-source"; @@ -57,8 +59,6 @@ public class BidirectionalTopicConfigTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - List<SelectorKey> keys = Arrays.asList(new SelectorKey("")); when(topicManager.getTopicHandler(MY_SINK, MY_SOURCE)).thenReturn(topicHandler); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java index 33904517b..bdf6b307a 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,9 @@ import java.util.function.Consumer; import java.util.function.Function; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.controlloop.actorserviceprovider.ActorService; import org.onap.policy.controlloop.actorserviceprovider.Operation; @@ -56,6 +57,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams.ControlLoopOperationParamsBuilder; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; +@RunWith(MockitoJUnitRunner.class) public class ControlLoopOperationParamsTest { private static final String NULL_MSG = "null"; private static final String EXPECTED_EXCEPTION = "expected exception"; @@ -100,8 +102,6 @@ public class ControlLoopOperationParamsTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(actorService.getActor(ACTOR)).thenReturn(actor); when(actor.getOperator(OPERATION)).thenReturn(operator); when(operator.buildOperation(any())).thenReturn(operation); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java index 309b30fd5..181e0ba67 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpConfigTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,13 @@ import static org.mockito.Mockito.when; import java.util.concurrent.Executor; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; +@RunWith(MockitoJUnitRunner.class) public class HttpConfigTest { private static final String MY_CLIENT = "my-client"; private static final String MY_PATH = "my-path"; @@ -51,8 +53,6 @@ public class HttpConfigTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(MY_CLIENT)).thenReturn(client); HttpParams params = HttpParams.builder().clientName(MY_CLIENT).path(MY_PATH).timeoutSec(TIMEOUT_SEC).build(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java index 53be6c711..65fd308fe 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpPollingConfigTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,13 @@ import static org.mockito.Mockito.when; import java.util.concurrent.Executor; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; +@RunWith(MockitoJUnitRunner.class) public class HttpPollingConfigTest { private static final String MY_CLIENT = "my-client"; private static final String MY_PATH = "my-path"; @@ -55,8 +57,6 @@ public class HttpPollingConfigTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(factory.get(MY_CLIENT)).thenReturn(client); params = HttpPollingParams.builder().maxPolls(MAX_POLLS).pollPath(POLL_PATH).pollWaitSec(WAIT_SEC) diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java index de1cf0f8d..eff3dbb18 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/FutureManagerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,11 @@ import static org.mockito.Mockito.when; import java.util.concurrent.Future; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class FutureManagerTest { private static final String EXPECTED_EXCEPTION = "expected exception"; @@ -53,8 +55,6 @@ public class FutureManagerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - mgr = new FutureManager(); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java index 4a882d422..bbd82cbd1 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/ListenerManagerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,11 @@ import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class ListenerManagerTest { private static final String EXPECTED_EXCEPTION = "expected exception"; @@ -51,8 +53,6 @@ public class ListenerManagerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - mgr = new ListenerManager(); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java index 4a00c065e..44c9e20af 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineControllerFutureTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,10 +43,12 @@ import java.util.function.BiConsumer; import java.util.function.Function; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class PipelineControllerFutureTest { private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception"); private static final String TEXT = "some text"; @@ -77,8 +79,6 @@ public class PipelineControllerFutureTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - compFuture = spy(new CompletableFuture<>()); controller = new PipelineControllerFuture<>(); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java index 54d56de53..f96fc0fdc 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/BidirectionalTopicHandlerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,21 +26,22 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.event.comm.client.BidirectionalTopicClientException; +@RunWith(MockitoJUnitRunner.class) public class BidirectionalTopicHandlerTest { private static final String UNKNOWN = "unknown"; private static final String MY_SOURCE = "my-source"; @@ -65,10 +66,8 @@ public class BidirectionalTopicHandlerTest { */ @Before public void setUp() throws BidirectionalTopicClientException { - MockitoAnnotations.initMocks(this); - when(mgr.getTopicSinks(MY_SINK)).thenReturn(Arrays.asList(publisher)); - when(mgr.getTopicSources(eq(Arrays.asList(MY_SOURCE)))).thenReturn(Arrays.asList(subscriber)); + when(mgr.getTopicSources(Arrays.asList(MY_SOURCE))).thenReturn(Arrays.asList(subscriber)); when(publisher.getTopicCommInfrastructure()).thenReturn(CommInfrastructure.NOOP); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java index a01159bc2..3b368e225 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/ForwarderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +32,13 @@ import java.util.Map; import java.util.function.BiConsumer; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.Util; +@RunWith(MockitoJUnitRunner.class) public class ForwarderTest { private static final String TEXT = "some text"; @@ -75,7 +77,6 @@ public class ForwarderTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); forwarder = new Forwarder(Arrays.asList(new SelectorKey(KEY1), new SelectorKey(KEY2, SUBKEY))); forwarder.register(Arrays.asList(VALUEA_REQID, VALUEA_SUBREQID), listener1); @@ -159,9 +160,6 @@ public class ForwarderTest { verify(listener1b, times(2)).accept(any(), any()); verify(listener2).accept(any(), any()); verify(listener3).accept(any(), any()); - - // listener throws an exception - doThrow(new IllegalStateException("expected exception")).when(listener1).accept(any(), any()); } /* diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java index 3012ff6af..9e3b476e9 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/topic/TopicListenerImplTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,13 +33,15 @@ import java.util.Map; import java.util.function.BiConsumer; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; +@RunWith(MockitoJUnitRunner.class) public class TopicListenerImplTest { private static final StandardCoder coder = new StandardCoder(); private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; @@ -72,8 +74,6 @@ public class TopicListenerImplTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - topic = new TopicListenerImpl(); forwarder1 = topic.addForwarder(new SelectorKey(KEY1)); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java index 30d4ed910..686e6a416 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.function.BiConsumer; import org.junit.Test; public class CommonHeaderTest { @@ -94,67 +95,28 @@ public class CommonHeaderTest { assertEquals(commonHeader, clonedCommonHeader); - commonHeader.setApiVer(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setApiVer(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setApiVer(KANSAS); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setApiVer(KANSAS); - assertEquals(commonHeader, copiedCommonHeader); + checkField(KANSAS, CommonHeader::setApiVer); + checkField(flagSet, CommonHeader::setFlags); + checkField(DOROTHY, CommonHeader::setOriginatorId); + checkField(requestId, CommonHeader::setRequestId); + checkField(requestTrackSet, CommonHeader::setRequestTrack); + checkField(CAN_I_GO_HOME, CommonHeader::setSubRequestId); + checkField(timestamp, CommonHeader::setTimeStamp); + } - commonHeader.setFlags(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setFlags(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setFlags(flagSet); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setFlags(flagSet); - assertEquals(commonHeader, copiedCommonHeader); + private <T> void checkField(T value, BiConsumer<CommonHeader, T> setter) { + CommonHeader header1 = new CommonHeader(); + CommonHeader header2 = new CommonHeader(header1); - commonHeader.setOriginatorId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setOriginatorId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setOriginatorId(DOROTHY); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setOriginatorId(DOROTHY); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header2, null); - commonHeader.setRequestId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setRequestId(requestId); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestId(requestId); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header1, value); + assertNotEquals(header1, header2); - commonHeader.setRequestTrack(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestTrack(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setRequestTrack(requestTrackSet); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestTrack(requestTrackSet); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header2, value); + assertEquals(header1, header2); - commonHeader.setSubRequestId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setSubRequestId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setSubRequestId(CAN_I_GO_HOME); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setSubRequestId(CAN_I_GO_HOME); - assertEquals(commonHeader, copiedCommonHeader); - - commonHeader.setTimeStamp(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setTimeStamp(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setTimeStamp(timestamp); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setTimeStamp(timestamp); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header1, null); + assertNotEquals(header1, header2); } } diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java index 43686a747..5bff56b78 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull; import java.util.HashMap; import java.util.Map; +import java.util.function.BiConsumer; import org.junit.Test; public class RequestTest { @@ -77,49 +78,26 @@ public class RequestTest { assertNotEquals(request, null); assertNotEquals(request, (Object) "Hello"); - request.setCommonHeader(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setCommonHeader(null); - assertEquals(request, copiedRequest); - request.setCommonHeader(commonHeader); - assertNotEquals(request, copiedRequest); - copiedRequest.setCommonHeader(commonHeader); - assertEquals(request, copiedRequest); + checkField(commonHeader, Request::setCommonHeader); + checkField(GO_TO_OZ, Request::setAction); + checkField(WIZARD, Request::setObjectId); + checkField("Oz", Request::setTargetId); + checkField(payload, Request::setPayload); + } - request.setAction(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setAction(null); - assertEquals(request, copiedRequest); - request.setAction(GO_TO_OZ); - assertNotEquals(request, copiedRequest); - copiedRequest.setAction(GO_TO_OZ); - assertEquals(request, copiedRequest); + private <T> void checkField(T value, BiConsumer<Request, T> setter) { + Request request1 = new Request(); + Request request2 = new Request(); - request.setObjectId(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setObjectId(null); - assertEquals(request, copiedRequest); - request.setObjectId(WIZARD); - assertNotEquals(request, copiedRequest); - copiedRequest.setObjectId(WIZARD); - assertEquals(request, copiedRequest); + setter.accept(request2, null); - request.setTargetId(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setTargetId(null); - assertEquals(request, copiedRequest); - request.setTargetId("Oz"); - assertNotEquals(request, copiedRequest); - copiedRequest.setTargetId("Oz"); - assertEquals(request, copiedRequest); + setter.accept(request1, value); + assertNotEquals(request1, request2); - request.setPayload(new HashMap<>()); - assertNotEquals(request, copiedRequest); - copiedRequest.setPayload(new HashMap<>()); - assertEquals(request, copiedRequest); - request.setPayload(payload); - assertNotEquals(request, copiedRequest); - copiedRequest.setPayload(payload); - assertEquals(request, copiedRequest); + setter.accept(request2, value); + assertEquals(request1, request2); + + setter.accept(request1, null); + assertNotEquals(request1, request2); } } diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java index 3106e3909..4f0dbf730 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * controlloop * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,7 +54,7 @@ public abstract class ControlLoopEvent implements Serializable { * * @param event the existing instance */ - public ControlLoopEvent(ControlLoopEvent event) { + protected ControlLoopEvent(ControlLoopEvent event) { if (event == null) { return; } diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java index c4c46d30a..890fb083a 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * controlloop * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,7 +57,7 @@ public abstract class ControlLoopNotification implements Serializable { * * @param event the event */ - public ControlLoopNotification(ControlLoopEvent event) { + protected ControlLoopNotification(ControlLoopEvent event) { if (event == null) { return; } diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java index 21df853f4..e5a887429 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * rest * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -145,60 +145,39 @@ public class RestTest { RestManager mgr = new RestManager(); Pair<Integer, String> result = mgr.get(getUri, null, null, null); - - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.getRight()); + checkResult(result, "GOT: " + EXPECT_STRING); result = mgr.delete(deleteUri, null, null, null, null, null); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); + checkResult(result, "DELETE: " + EXPECT_STRING); result = mgr.delete(deleteUri, null, null, null); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); + checkResult(result, "DELETE: " + EXPECT_STRING); result = mgr.put(putUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING); result = mgr.put(putUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING); result = mgr.post(postUri, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING); result = mgr.post(postUriBlank, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + RETURN_STRING); result = mgr.patch(patchUri, null, null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING); result = mgr.patch(patchUriBlank, null, null, null, PAYLOAD); + checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING); + + } + + private void checkResult(Pair<Integer, String> result, String expectedText) { assertEquals((Integer) 200, result.getLeft()); assertNotNull(result.getRight()); assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); - + assertEquals(expectedText, result.getRight()); } @Test @@ -206,53 +185,28 @@ public class RestTest { RestManager mgr = new RestManager(); Pair<Integer, String> result = mgr.get(getUri, "", null, null); - - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.getRight()); + checkResult(result, "GOT: " + EXPECT_STRING); result = mgr.delete(deleteUri, "", null, null, null, null); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); + checkResult(result, "DELETE: " + EXPECT_STRING); result = mgr.put(putUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING); result = mgr.put(putUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING); result = mgr.post(postUri, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING); result = mgr.post(postUriBlank, "", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + RETURN_STRING); result = mgr.patch(patchUri, "", null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING); result = mgr.patch(patchUriBlank, "", null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING); } @@ -261,53 +215,28 @@ public class RestTest { RestManager mgr = new RestManager(); Pair<Integer, String> result = mgr.get(getUri, "user", null, null); - - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("GOT: " + EXPECT_STRING, result.getRight()); + checkResult(result, "GOT: " + EXPECT_STRING); result = mgr.delete(deleteUri, "user", null, null, null, null); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("DELETE: " + EXPECT_STRING, result.getRight()); + checkResult(result, "DELETE: " + EXPECT_STRING); result = mgr.put(putUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + EXPECT_STRING); result = mgr.put(putUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING); result = mgr.post(postUri, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + EXPECT_STRING); result = mgr.post(postUriBlank, "user", null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "POST: " + PAYLOAD + RETURN_STRING); result = mgr.patch(patchUri, "user", null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + EXPECT_STRING, result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + EXPECT_STRING); result = mgr.patch(patchUriBlank, "user", null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING, result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING); } @@ -338,37 +267,21 @@ public class RestTest { RestManager mgr = new RestManager(); Pair<Integer, String> result = mgr.get(baseUri + "RestTest/GetHello/" + NAME_PARAM, null, null, null); - - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("GOT: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + checkResult(result, "GOT: " + RETURN_STRING + NAME_PARAM + " aged 90"); result = mgr.delete(baseUri + "RestTest/DeleteHello/" + NAME_PARAM, null, null, null, null, null); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + checkResult(result, "DELETE: " + RETURN_STRING + NAME_PARAM + " aged 90"); result = mgr.put(baseUri + "RestTest/PutHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + checkResult(result, "PUT: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90"); result = mgr.post(baseUri + "RestTest/PostHello/" + NAME_PARAM, null, null, null, MediaType.TEXT_PLAIN, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + checkResult(result, "POST: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90"); result = mgr.patch(baseUri + "RestTest/PatchHello/" + NAME_PARAM, null, null, null, PAYLOAD); - assertEquals((Integer) 200, result.getLeft()); - assertNotNull(result.getRight()); - assertTrue(result.getRight().length() > 0); - assertEquals("PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90", result.getRight()); + checkResult(result, "PATCH: " + PAYLOAD + RETURN_STRING + NAME_PARAM + " aged 90"); } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java index f4c0bf32d..9d497602f 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.function.BiConsumer; import org.junit.Test; public class PciCommonHeaderTest { @@ -88,59 +89,27 @@ public class PciCommonHeaderTest { assertEquals(commonHeader, clonedPciCommonHeader); - commonHeader.setApiVer(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setApiVer(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setApiVer(KANSAS); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setApiVer(KANSAS); - assertEquals(commonHeader, copiedPciCommonHeader); - - commonHeader.setFlags(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setFlags(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setFlags(flagMap); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setFlags(flagMap); - assertEquals(commonHeader, copiedPciCommonHeader); + checkField(KANSAS, PciCommonHeader::setApiVer); + checkField(flagMap, PciCommonHeader::setFlags); + checkField(requestMap, PciCommonHeader::setRequestTrack); + checkField(requestId, PciCommonHeader::setRequestId); + checkField(CAN_I_GO_HOME, PciCommonHeader::setSubRequestId); + checkField(timestamp, PciCommonHeader::setTimeStamp); + } - commonHeader.setRequestTrack(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setRequestTrack(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setRequestTrack(requestMap); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setRequestTrack(requestMap); - assertEquals(commonHeader, copiedPciCommonHeader); + private <T> void checkField(T value, BiConsumer<PciCommonHeader, T> setter) { + PciCommonHeader details1 = new PciCommonHeader(); + PciCommonHeader details2 = new PciCommonHeader(details1); + setter.accept(details2, null); - commonHeader.setRequestId(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setRequestId(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setRequestId(requestId); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setRequestId(requestId); - assertEquals(commonHeader, copiedPciCommonHeader); + setter.accept(details1, value); + assertNotEquals(details1, details2); - commonHeader.setSubRequestId(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setSubRequestId(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setSubRequestId(CAN_I_GO_HOME); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setSubRequestId(CAN_I_GO_HOME); - assertEquals(commonHeader, copiedPciCommonHeader); + setter.accept(details2, value); + assertEquals(details1, details2); - commonHeader.setTimeStamp(null); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setTimeStamp(null); - assertEquals(commonHeader, copiedPciCommonHeader); - commonHeader.setTimeStamp(timestamp); - assertNotEquals(commonHeader, copiedPciCommonHeader); - copiedPciCommonHeader.setTimeStamp(timestamp); - assertEquals(commonHeader, copiedPciCommonHeader); + setter.accept(details1, null); + assertNotEquals(details1, details2); } } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java index 914974691..91d42a3bf 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import java.util.function.BiConsumer; import org.junit.Test; public class PciWrapperTest { @@ -73,49 +74,26 @@ public class PciWrapperTest { assertNotEquals(wrapper, null); assertNotEquals(wrapper, (Object) "Hello"); - wrapper.setVersion(null); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setVersion(null); - assertEquals(wrapper, copiedPciWrapper); - wrapper.setVersion(VERSION_19); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setVersion(VERSION_19); - assertEquals(wrapper, copiedPciWrapper); + checkField(VERSION_19, PciWrapper::setVersion); + checkField(THE_EMERALD_CITY, PciWrapper::setCambriaPartition); + checkField(TORNADO, PciWrapper::setRpcName); + checkField(YELLOW_BRICK_ROAD, PciWrapper::setCorrelationId); + checkField(MUNCHKIN, PciWrapper::setType); + } - wrapper.setCambriaPartition(null); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setCambriaPartition(null); - assertEquals(wrapper, copiedPciWrapper); - wrapper.setCambriaPartition(THE_EMERALD_CITY); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setCambriaPartition(THE_EMERALD_CITY); - assertEquals(wrapper, copiedPciWrapper); + private <T> void checkField(T value, BiConsumer<PciWrapper, T> setter) { + PciWrapper details1 = new PciWrapper(); + PciWrapper details2 = new PciWrapper(); - wrapper.setRpcName(null); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setRpcName(null); - assertEquals(wrapper, copiedPciWrapper); - wrapper.setRpcName(TORNADO); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setRpcName(TORNADO); - assertEquals(wrapper, copiedPciWrapper); + setter.accept(details2, null); - wrapper.setCorrelationId(null); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setCorrelationId(null); - assertEquals(wrapper, copiedPciWrapper); - wrapper.setCorrelationId(YELLOW_BRICK_ROAD); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setCorrelationId(YELLOW_BRICK_ROAD); - assertEquals(wrapper, copiedPciWrapper); + setter.accept(details1, value); + assertNotEquals(details1, details2); - wrapper.setType(null); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setType(null); - assertEquals(wrapper, copiedPciWrapper); - wrapper.setType(MUNCHKIN); - assertNotEquals(wrapper, copiedPciWrapper); - copiedPciWrapper.setType(MUNCHKIN); - assertEquals(wrapper, copiedPciWrapper); + setter.accept(details2, value); + assertEquals(details1, details2); + + setter.accept(details1, null); + assertNotEquals(details1, details2); } } diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java index 43d5cd38a..66de1b2cd 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java @@ -3,8 +3,7 @@ * so * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +29,7 @@ import static org.junit.Assert.assertNull; import java.util.ArrayList; import java.util.List; +import java.util.function.BiConsumer; import org.junit.Test; public class SoRequestDetailsTest { @@ -118,58 +118,27 @@ public class SoRequestDetailsTest { assertNotEquals(details, null); assertNotEquals(details, (Object) "Hello"); - details.setCloudConfiguration(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setCloudConfiguration(null); - assertEquals(details, copiedDetails); - details.setCloudConfiguration(cloudConfiguration); - assertNotEquals(details, copiedDetails); - copiedDetails.setCloudConfiguration(cloudConfiguration); - assertEquals(details, copiedDetails); + checkField(cloudConfiguration, SoRequestDetails::setCloudConfiguration); + checkField(modelInfo, SoRequestDetails::setModelInfo); + checkField(requestInfo, SoRequestDetails::setRequestInfo); + checkField(requestParameters, SoRequestDetails::setRequestParameters); + checkField(subscriberInfo, SoRequestDetails::setSubscriberInfo); + checkField(relatedInstanceList, SoRequestDetails::setRelatedInstanceList); + } - details.setModelInfo(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setModelInfo(null); - assertEquals(details, copiedDetails); - details.setModelInfo(modelInfo); - assertNotEquals(details, copiedDetails); - copiedDetails.setModelInfo(modelInfo); - assertEquals(details, copiedDetails); + private <T> void checkField(T value, BiConsumer<SoRequestDetails, T> setter) { + SoRequestDetails details1 = new SoRequestDetails(); + SoRequestDetails details2 = new SoRequestDetails(details1); - details.setRequestInfo(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setRequestInfo(null); - assertEquals(details, copiedDetails); - details.setRequestInfo(requestInfo); - assertNotEquals(details, copiedDetails); - copiedDetails.setRequestInfo(requestInfo); - assertEquals(details, copiedDetails); + setter.accept(details2, null); - details.setRequestParameters(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setRequestParameters(null); - assertEquals(details, copiedDetails); - details.setRequestParameters(requestParameters); - assertNotEquals(details, copiedDetails); - copiedDetails.setRequestParameters(requestParameters); - assertEquals(details, copiedDetails); + setter.accept(details1, value); + assertNotEquals(details1, details2); - details.setSubscriberInfo(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setSubscriberInfo(null); - assertEquals(details, copiedDetails); - details.setSubscriberInfo(subscriberInfo); - assertNotEquals(details, copiedDetails); - copiedDetails.setSubscriberInfo(subscriberInfo); - assertEquals(details, copiedDetails); + setter.accept(details2, value); + assertEquals(details1, details2); - details.setRelatedInstanceList(null); - assertNotEquals(details, copiedDetails); - copiedDetails.setRelatedInstanceList(null); - assertEquals(details, copiedDetails); - details.setRelatedInstanceList(relatedInstanceList); - assertNotEquals(details, copiedDetails); - copiedDetails.setRelatedInstanceList(relatedInstanceList); - assertEquals(details, copiedDetails); + setter.accept(details1, null); + assertNotEquals(details1, details2); } } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLcmTopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLcmTopicServerTest.java index f3f546a41..9560658a8 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLcmTopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLcmTopicServerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,14 +28,16 @@ import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.resources.ResourceUtils; +@RunWith(MockitoJUnitRunner.class) public class AppcLcmTopicServerTest { private static final String MY_TOPIC = "my-topic"; @@ -51,8 +53,6 @@ public class AppcLcmTopicServerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - server = new AppcLcmTopicServer(sink, source); } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java index c3c3195df..25cba30bd 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,14 +28,16 @@ import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.resources.ResourceUtils; +@RunWith(MockitoJUnitRunner.class) public class AppcLegacyTopicServerTest { private static final String MY_TOPIC = "my-topic"; @@ -51,8 +53,6 @@ public class AppcLegacyTopicServerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - server = new AppcLegacyTopicServer(sink, source); } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SdnrTopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SdnrTopicServerTest.java index d8f6d1150..96ea9fbcc 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SdnrTopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/SdnrTopicServerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,14 +28,16 @@ import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.resources.ResourceUtils; +@RunWith(MockitoJUnitRunner.class) public class SdnrTopicServerTest { private static final String MY_TOPIC = "my-topic"; @@ -51,8 +53,6 @@ public class SdnrTopicServerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - server = new SdnrTopicServer(sink, source); } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java index 11a5e3f81..972769ddd 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,15 @@ import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.StandardCoder; +@RunWith(MockitoJUnitRunner.class) public class TopicServerTest { private static final String MY_TOPIC = "my-topic"; private static final String TEXT = "hello"; @@ -52,8 +54,6 @@ public class TopicServerTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - server = new MyServer(); } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 596f9fa0d..4f574906a 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -299,7 +299,7 @@ public class DatabasePolicyModelsProviderTest { assertTrue(databaseProvider.getPolicyTypeList(NAME, VERSION_100).isEmpty()); assertThatThrownBy( - () -> databaseProvider.getFilteredPolicyTypes(ToscaEntityFilter.<ToscaPolicyType>builder().build())) + () -> databaseProvider.getFilteredPolicyTypes(ToscaEntityFilter.<ToscaPolicyType>builder().build())) .hasMessage("service template not found in database"); assertTrue(databaseProvider.getFilteredPolicyTypeList(ToscaEntityFilter.<ToscaPolicyType>builder().build()) @@ -322,7 +322,7 @@ public class DatabasePolicyModelsProviderTest { assertTrue(databaseProvider.getPolicyList(NAME, VERSION_100).isEmpty()); assertThatThrownBy( - () -> databaseProvider.getFilteredPolicies(ToscaTypedEntityFilter.<ToscaPolicy>builder().build())) + () -> databaseProvider.getFilteredPolicies(ToscaTypedEntityFilter.<ToscaPolicy>builder().build())) .hasMessage("service template not found in database"); assertTrue(databaseProvider.getFilteredPolicyList(ToscaTypedEntityFilter.<ToscaPolicy>builder().build()) diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProviderTest.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProviderTest.java index 6c79ce9f8..3d72f2e4c 100644 --- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProviderTest.java +++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,15 +44,17 @@ import javax.ws.rs.core.Response.Status; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup; +@RunWith(MockitoJUnitRunner.class) public class DmaapSimProviderTest { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final long SWEEP_SEC = 10L; @@ -86,8 +88,6 @@ public class DmaapSimProviderTest { */ @Before public void setUp() { - MockitoAnnotations.initMocks(this); - when(params.getTopicSweepSec()).thenReturn(SWEEP_SEC); prov = new MyProvider(params); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java index ef0b6b183..d6f3a6815 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +56,7 @@ public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter< // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java index b6ff86b3c..749873a23 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java @@ -67,7 +67,7 @@ public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFi // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java index 4dfbae74d..f3dbeb030 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,7 +46,7 @@ public abstract class JpaToscaConstraint * * @param authorativeConcept the authorative concept to copy from */ - public JpaToscaConstraint(final ToscaConstraint authorativeConcept) { + protected JpaToscaConstraint(final ToscaConstraint authorativeConcept) { this.fromAuthorative(authorativeConcept); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java index 893cdbe84..2416bab69 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; @@ -61,12 +60,8 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme // @formatter:off @Column - @AttributeOverrides({ - @AttributeOverride(name = "name", - column = @Column(name = "derived_from_name")), - @AttributeOverride(name = "version", - column = @Column(name = "derived_from_version")) - }) + @AttributeOverride(name = "name", column = @Column(name = "derived_from_name")) + @AttributeOverride(name = "version", column = @Column(name = "derived_from_version")) @VerifyKey private PfConceptKey derivedFrom; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java index 9a07ea187..c28a1aefb 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java @@ -33,7 +33,6 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.Lob; import javax.persistence.OneToOne; import javax.persistence.Table; @@ -81,14 +80,14 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate> // formatter:off @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"), - @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")}) + @JoinColumn(name = "requirementsName", referencedColumnName = "name") + @JoinColumn(name = "requirementsVersion", referencedColumnName = "version") @Valid private JpaToscaRequirements requirements; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns({@JoinColumn(name = "capabilitiesName", referencedColumnName = "name"), - @JoinColumn(name = "capabilitiesVersion", referencedColumnName = "version")}) + @JoinColumn(name = "capabilitiesName", referencedColumnName = "name") + @JoinColumn(name = "capabilitiesVersion", referencedColumnName = "version") @Valid private JpaToscaCapabilityAssignments capabilities; // @formatter:on diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java index 5ea21ed77..86be4b318 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java @@ -35,7 +35,6 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.Lob; import javax.persistence.OneToOne; import javax.persistence.Table; @@ -76,8 +75,8 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen // formatter:off @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"), - @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")}) + @JoinColumn(name = "requirementsName", referencedColumnName = "name") + @JoinColumn(name = "requirementsVersion", referencedColumnName = "version") // @formatter:on @Valid private JpaToscaRequirements requirements; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 0be04353f..11f1199c0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -27,7 +27,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -76,12 +75,8 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P // @formatter:off @Column - @AttributeOverrides({ - @AttributeOverride(name = "name", - column = @Column(name = "type_name")), - @AttributeOverride(name = "version", - column = @Column(name = "type_version")) - }) + @AttributeOverride(name = "name", column = @Column(name = "type_name")) + @AttributeOverride(name = "version", column = @Column(name = "type_version")) @VerifyKey @NotNull private PfConceptKey type; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index 594a5c348..0d9060d33 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.OneToOne; import javax.persistence.Table; import lombok.Data; @@ -49,11 +48,6 @@ import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** @@ -84,69 +78,45 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp private String toscaDefinitionsVersion; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "dataTypesName", referencedColumnName = "name"), - @JoinColumn(name = "dataTypesVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "dataTypesName", referencedColumnName = "name") + @JoinColumn(name = "dataTypesVersion", referencedColumnName = "version") @SerializedName("data_types") @Valid private JpaToscaDataTypes dataTypes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "capabilityTypesName", referencedColumnName = "name"), - @JoinColumn(name = "capabilityTypesVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "capabilityTypesName", referencedColumnName = "name") + @JoinColumn(name = "capabilityTypesVersion", referencedColumnName = "version") @SerializedName("capability_types") @Valid private JpaToscaCapabilityTypes capabilityTypes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "relationshipTypesName", referencedColumnName = "name"), - @JoinColumn(name = "relationshipTypesVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "relationshipTypesName", referencedColumnName = "name") + @JoinColumn(name = "relationshipTypesVersion", referencedColumnName = "version") @SerializedName("relationship_types") @Valid private JpaToscaRelationshipTypes relationshipTypes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "nodeTypesName", referencedColumnName = "name"), - @JoinColumn(name = "nodeTypesVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "nodeTypesName", referencedColumnName = "name") + @JoinColumn(name = "nodeTypesVersion", referencedColumnName = "version") @SerializedName("node_types") @Valid private JpaToscaNodeTypes nodeTypes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "policyTypesName", referencedColumnName = "name"), - @JoinColumn(name = "policyTypesVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "policyTypesName", referencedColumnName = "name") + @JoinColumn(name = "policyTypesVersion", referencedColumnName = "version") @SerializedName("policy_types") @Valid private JpaToscaPolicyTypes policyTypes; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "topologyTemplateParentKeyName", referencedColumnName = "parentKeyName"), - @JoinColumn(name = "topologyTemplateParentKeyVersion", referencedColumnName = "parentKeyVersion"), - @JoinColumn(name = "topologyTemplateParentLocalName", referencedColumnName = "parentLocalName"), - @JoinColumn(name = "topologyTemplateLocalName", referencedColumnName = "localName") - } - ) + @JoinColumn(name = "topologyTemplateParentKeyName", referencedColumnName = "parentKeyName") + @JoinColumn(name = "topologyTemplateParentKeyVersion", referencedColumnName = "parentKeyVersion") + @JoinColumn(name = "topologyTemplateParentLocalName", referencedColumnName = "parentLocalName") + @JoinColumn(name = "topologyTemplateLocalName", referencedColumnName = "localName") @SerializedName("topology_template") @Valid private JpaToscaTopologyTemplate topologyTemplate; @@ -219,43 +189,23 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion); if (dataTypes != null) { - toscaServiceTemplate.setDataTypes(new LinkedHashMap<>()); - List<Map<String, ToscaDataType>> dataTypeMapList = dataTypes.toAuthorative(); - for (Map<String, ToscaDataType> dataTypeMap : dataTypeMapList) { - toscaServiceTemplate.getDataTypes().putAll(dataTypeMap); - } + toscaServiceTemplate.setDataTypes(flattenMap(dataTypes.toAuthorative())); } if (capabilityTypes != null) { - toscaServiceTemplate.setCapabilityTypes(new LinkedHashMap<>()); - List<Map<String, ToscaCapabilityType>> capabilityTypeMapList = capabilityTypes.toAuthorative(); - for (Map<String, ToscaCapabilityType> capabilityTypeMap : capabilityTypeMapList) { - toscaServiceTemplate.getCapabilityTypes().putAll(capabilityTypeMap); - } + toscaServiceTemplate.setCapabilityTypes(flattenMap(capabilityTypes.toAuthorative())); } if (relationshipTypes != null) { - toscaServiceTemplate.setRelationshipTypes(new LinkedHashMap<>()); - List<Map<String, ToscaRelationshipType>> relationshipTypeMapList = relationshipTypes.toAuthorative(); - for (Map<String, ToscaRelationshipType> relationshipTypeMap : relationshipTypeMapList) { - toscaServiceTemplate.getRelationshipTypes().putAll(relationshipTypeMap); - } + toscaServiceTemplate.setRelationshipTypes(flattenMap(relationshipTypes.toAuthorative())); } if (nodeTypes != null) { - toscaServiceTemplate.setNodeTypes(new LinkedHashMap<>()); - List<Map<String, ToscaNodeType>> nodeTypeMapList = nodeTypes.toAuthorative(); - for (Map<String, ToscaNodeType> nodeTypeMap : nodeTypeMapList) { - toscaServiceTemplate.getNodeTypes().putAll(nodeTypeMap); - } + toscaServiceTemplate.setNodeTypes(flattenMap(nodeTypes.toAuthorative())); } if (policyTypes != null) { - toscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>()); - List<Map<String, ToscaPolicyType>> policyTypeMapList = policyTypes.toAuthorative(); - for (Map<String, ToscaPolicyType> policyTypeMap : policyTypeMapList) { - toscaServiceTemplate.getPolicyTypes().putAll(policyTypeMap); - } + toscaServiceTemplate.setPolicyTypes(flattenMap(policyTypes.toAuthorative())); } if (topologyTemplate != null) { @@ -265,6 +215,22 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp return toscaServiceTemplate; } + /** + * Takes a list of maps and flattens it into a single map. + * + * @param list list to be be flattened + * @return a map containing all of the elements from the list of maps + */ + private <V> Map<String, V> flattenMap(List<Map<String, V>> list) { + Map<String, V> result = new LinkedHashMap<>(); + + for (Map<String, V> map : list) { + result.putAll(map); + } + + return result; + } + @Override public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) { super.fromAuthorative(toscaServiceTemplate); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java index 86add360a..b00b14a9e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java @@ -35,7 +35,6 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.Lob; import javax.persistence.OneToOne; import javax.persistence.Table; @@ -87,23 +86,15 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative private Map<@NotNull String, @NotNull @Valid JpaToscaParameter> inputs; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"), - @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name") + @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version") @SerializedName("data_types") @Valid private JpaToscaNodeTemplates nodeTemplates; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumns( - { - @JoinColumn(name = "policyName", referencedColumnName = "name"), - @JoinColumn(name = "policyVersion", referencedColumnName = "version") - } - ) + @JoinColumn(name = "policyName", referencedColumnName = "name") + @JoinColumn(name = "policyVersion", referencedColumnName = "version") // @formatter:on @Valid private JpaToscaPolicies policies; |