diff options
author | 2023-09-12 15:27:38 +0100 | |
---|---|---|
committer | 2023-09-13 12:47:16 +0100 | |
commit | 281cd97df5d674d2a4168a80e2e0a21b7c21e076 (patch) | |
tree | b486144fa5e56e75bdbabbad0fbb23cdd0ceed2d /controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step | |
parent | b2d624d4655fa4b4e0cebbf7e41dc96b38fa0df5 (diff) |
Upgrade drools-applications to JUnit 5java-17
Issue-ID: POLICY-4819
Change-Id: I33e1f156a1ea0e98cb6386a7d10d06be4dc258d9
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step')
7 files changed, 195 insertions, 252 deletions
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiCqStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiCqStep2Test.java index 3c629591d..1f2d771cb 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiCqStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiCqStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,22 +21,20 @@ package org.onap.policy.drools.apps.controller.usecases.step; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; 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.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.aai.AaiActor; @@ -48,24 +47,16 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.eventmanager.StepContext; -@RunWith(MockitoJUnitRunner.class) -public class AaiCqStep2Test { +class AaiCqStep2Test { private static final UUID REQ_ID = UUID.randomUUID(); - @Mock - private Operator policyOperator; - @Mock - private Operation policyOperation; - @Mock - private Actor policyActor; - @Mock - private ActorService actors; - @Mock - private ControlLoopOperationParams params; - @Mock - private StepContext stepContext; - @Mock - private VirtualControlLoopEvent event; + private final Operator policyOperator = mock(Operator.class); + private final Operation policyOperation = mock(Operation.class); + private final Actor policyActor = mock(Actor.class); + private final ActorService actors = mock(ActorService.class); + private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class); + private final StepContext stepContext = mock(StepContext.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); private CompletableFuture<OperationOutcome> future; private Step2 master; @@ -74,7 +65,7 @@ public class AaiCqStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { future = new CompletableFuture<>(); @@ -92,7 +83,7 @@ public class AaiCqStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(AaiActor.NAME, step.getActorName()); assertEquals(AaiCustomQueryOperation.NAME, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -100,7 +91,7 @@ public class AaiCqStep2Test { } @Test - public void testStart() { + void testStart() { step.init(); assertTrue(step.start(100)); verify(policyOperation).start(); @@ -110,7 +101,7 @@ public class AaiCqStep2Test { * Tests start() when the data has already been retrieved. */ @Test - public void testStartAlreadyHaveData() { + void testStartAlreadyHaveData() { when(stepContext.contains(AaiCqResponse.CONTEXT_KEY)).thenReturn(true); step.init(); @@ -119,9 +110,9 @@ public class AaiCqStep2Test { } @Test - public void testSuccess() { - AaiCqResponse data = new AaiCqResponse("{}"); - OperationOutcome outcome = new OperationOutcome(); + void testSuccess() { + var data = new AaiCqResponse("{}"); + var outcome = new OperationOutcome(); outcome.setResponse(data); step.success(outcome); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetPnfStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetPnfStep2Test.java index 897650fb3..8f2559933 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetPnfStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetPnfStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,22 +21,20 @@ package org.onap.policy.drools.apps.controller.usecases.step; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; 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.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.aai.AaiActor; @@ -49,25 +48,17 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.eventmanager.StepContext; -@RunWith(MockitoJUnitRunner.class) -public class AaiGetPnfStep2Test { +class AaiGetPnfStep2Test { private static final String MY_TARGET = "my-target"; private static final UUID REQ_ID = UUID.randomUUID(); - @Mock - private Operator policyOperator; - @Mock - private Operation policyOperation; - @Mock - private Actor policyActor; - @Mock - private ActorService actors; - @Mock - private ControlLoopOperationParams params; - @Mock - private StepContext stepContext; - @Mock - private VirtualControlLoopEvent event; + private final Operator policyOperator = mock(Operator.class); + private final Operation policyOperation = mock(Operation.class); + private final Actor policyActor = mock(Actor.class); + private final ActorService actors = mock(ActorService.class); + private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class); + private final StepContext stepContext = mock(StepContext.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); private CompletableFuture<OperationOutcome> future; private Step2 master; @@ -76,7 +67,7 @@ public class AaiGetPnfStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { future = new CompletableFuture<>(); @@ -95,7 +86,7 @@ public class AaiGetPnfStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(AaiActor.NAME, step.getActorName()); assertEquals(AaiGetPnfOperation.NAME, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -103,7 +94,7 @@ public class AaiGetPnfStep2Test { } @Test - public void testStart() { + void testStart() { step.init(); assertTrue(step.start(100)); verify(policyOperation).start(); @@ -113,7 +104,7 @@ public class AaiGetPnfStep2Test { * Tests start() when the data has already been retrieved. */ @Test - public void testStartAlreadyHaveData() { + void testStartAlreadyHaveData() { when(stepContext.contains(AaiGetPnfOperation.getKey(MY_TARGET))).thenReturn(true); step.init(); @@ -122,9 +113,9 @@ public class AaiGetPnfStep2Test { } @Test - public void testSuccess() { - StandardCoderObject data = new StandardCoderObject(); - OperationOutcome outcome = new OperationOutcome(); + void testSuccess() { + var data = new StandardCoderObject(); + var outcome = new OperationOutcome(); outcome.setResponse(data); step.success(outcome); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetTenantStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetTenantStep2Test.java index bccfbb3be..9d95b0b68 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetTenantStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/AaiGetTenantStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,12 @@ package org.onap.policy.drools.apps.controller.usecases.step; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,11 +36,8 @@ import static org.mockito.Mockito.when; import java.util.Map; 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.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.aai.AaiActor; @@ -52,25 +51,17 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.eventmanager.StepContext; -@RunWith(MockitoJUnitRunner.class) -public class AaiGetTenantStep2Test { +class AaiGetTenantStep2Test { private static final String MY_VSERVER = "my-vserver"; private static final UUID REQ_ID = UUID.randomUUID(); - @Mock - private Operator policyOperator; - @Mock - private Operation policyOperation; - @Mock - private Actor policyActor; - @Mock - private ActorService actors; - @Mock - private ControlLoopOperationParams params; - @Mock - private StepContext stepContext; - @Mock - private VirtualControlLoopEvent event; + private final Operator policyOperator = mock(Operator.class); + private final Operation policyOperation = mock(Operation.class); + private final Actor policyActor = mock(Actor.class); + private final ActorService actors = mock(ActorService.class); + private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class); + private final StepContext stepContext = mock(StepContext.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); private CompletableFuture<OperationOutcome> future; private Step2 master; @@ -79,7 +70,7 @@ public class AaiGetTenantStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { future = new CompletableFuture<>(); @@ -99,7 +90,7 @@ public class AaiGetTenantStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(AaiActor.NAME, step.getActorName()); assertEquals(AaiGetTenantOperation.NAME, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -117,12 +108,12 @@ public class AaiGetTenantStep2Test { } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { assertThat(step.getPropertyNames()).isEmpty(); } @Test - public void testSetProperties() { + void testSetProperties() { step.init(); step.setProperties(); @@ -131,7 +122,7 @@ public class AaiGetTenantStep2Test { } @Test - public void testStart() { + void testStart() { step.init(); assertTrue(step.start(100)); verify(policyOperation).start(); @@ -141,7 +132,7 @@ public class AaiGetTenantStep2Test { * Tests start() when the data has already been retrieved. */ @Test - public void testStartAlreadyHaveData() { + void testStartAlreadyHaveData() { when(stepContext.contains(AaiGetTenantOperation.getKey(MY_VSERVER))).thenReturn(true); step.init(); @@ -150,9 +141,9 @@ public class AaiGetTenantStep2Test { } @Test - public void testSuccess() { - StandardCoderObject data = new StandardCoderObject(); - OperationOutcome outcome = new OperationOutcome(); + void testSuccess() { + var data = new StandardCoderObject(); + var outcome = new OperationOutcome(); outcome.setResponse(data); step.success(outcome); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GetTargetEntityStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GetTargetEntityStep2Test.java index ff9a38a81..a975e0bb3 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GetTargetEntityStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GetTargetEntityStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,32 +22,25 @@ package org.onap.policy.drools.apps.controller.usecases.step; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.eventmanager.StepContext; import org.onap.policy.drools.apps.controller.usecases.GetTargetEntityOperation2; import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants; -@RunWith(MockitoJUnitRunner.class) -public class GetTargetEntityStep2Test { - @Mock - private ControlLoopOperationParams params; - @Mock - private StepContext stepContext; - @Mock - private VirtualControlLoopEvent event; +class GetTargetEntityStep2Test { + private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class); + private final StepContext stepContext = mock(StepContext.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); private Step2 master; private GetTargetEntityStep2 step; @@ -54,7 +48,7 @@ public class GetTargetEntityStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { when(params.toBuilder()).thenReturn(ControlLoopOperationParams.builder()); @@ -63,7 +57,7 @@ public class GetTargetEntityStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(UsecasesConstants.GET_TARGET_ENTITY_ACTOR, step.getActorName()); assertEquals(UsecasesConstants.GET_TARGET_ENTITY_OPERATION, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -71,13 +65,13 @@ public class GetTargetEntityStep2Test { } @Test - public void testBuildOperation() { - Operation oper = step.buildOperation(); + void testBuildOperation() { + var oper = step.buildOperation(); assertTrue(oper instanceof GetTargetEntityOperation2); } @Test - public void testStart() { + void testStart() { assertThatIllegalStateException().isThrownBy(() -> step.start(200)) .withMessage("step has not been initialized"); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GuardStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GuardStep2Test.java index ffd88d54d..4d158def3 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GuardStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/GuardStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,20 +23,18 @@ package org.onap.policy.drools.apps.controller.usecases.step; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.RelatedToProperty; @@ -55,8 +54,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.eventmanager.StepContext; import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants; -@RunWith(MockitoJUnitRunner.class) -public class GuardStep2Test { +class GuardStep2Test { private static final String SOME_OTHER_VALUE = "some-other-value"; private static final String SOME_OTHER_KEY = "some-other-key"; private static final String CL_NAME = "my-closed-loop"; @@ -72,22 +70,16 @@ public class GuardStep2Test { private static final UUID REQ_ID = UUID.randomUUID(); private static final int VF_COUNT = 10; - @Mock - private StepContext stepContext; - @Mock - private VirtualControlLoopEvent event; - @Mock - private Operation policyOper; - @Mock - private AaiCqResponse customQuery; - @Mock - private GenericVnf genericVnf; - @Mock - private CloudRegion cloudRegion; - @Mock Vserver theVserver; - - TargetType target; - Map<String, String> aai = new HashMap<>(); + private final StepContext stepContext = mock(StepContext.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); + private final Operation policyOper = mock(Operation.class); + private final AaiCqResponse customQuery = mock(AaiCqResponse.class); + private final GenericVnf genericVnf = mock(GenericVnf.class); + private final CloudRegion cloudRegion = mock(CloudRegion.class); + private final Vserver theVserver = mock(Vserver.class); + + private TargetType target; + private Map<String, String> aai = new HashMap<>(); private ControlLoopOperationParams params; private Step2 master; @@ -96,7 +88,7 @@ public class GuardStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { aai.put("vserver.vserver-name", MY_SERVERNAME); when(event.getAai()).thenReturn(aai); @@ -105,19 +97,19 @@ public class GuardStep2Test { when(genericVnf.getVnfType()).thenReturn(MY_TYPE); when(genericVnf.getNfNamingCode()).thenReturn(MY_CODE); - RelationshipList relList = new RelationshipList(); + var relList = new RelationshipList(); when(genericVnf.getRelationshipList()).thenReturn(relList); relList.getRelationship().add(new Relationship()); - Relationship relationship = new Relationship(); + var relationship = new Relationship(); relList.getRelationship().add(relationship); relationship.setRelatedTo("vserver"); relationship.getRelatedToProperty().add(new RelatedToProperty()); // property key mismatch - RelatedToProperty relProp = new RelatedToProperty(); + var relProp = new RelatedToProperty(); relationship.getRelatedToProperty().add(relProp); relProp.setPropertyKey(SOME_OTHER_KEY); relProp.setPropertyValue(MY_NAME); @@ -135,7 +127,7 @@ public class GuardStep2Test { relProp.setPropertyValue(MY_SERVERNAME); // data key mismatch - RelationshipData relData = new RelationshipData(); + var relData = new RelationshipData(); relationship.getRelationshipData().add(relData); relData.setRelationshipKey(SOME_OTHER_KEY); relData.setRelationshipValue(SOME_OTHER_VALUE); @@ -181,7 +173,7 @@ public class GuardStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(XacmlActor.NAME, step.getActorName()); assertEquals(GuardOperation.NAME, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -191,7 +183,7 @@ public class GuardStep2Test { master = new Step2(stepContext, params, event); assertThatIllegalStateException().isThrownBy(() -> new GuardStep2(master, CL_NAME)); - ControlLoopOperationParams params2 = step.getParams(); + var params2 = step.getParams(); // @formatter:off assertThat(params2.getPayload()).isEqualTo(Map.of( @@ -203,13 +195,13 @@ public class GuardStep2Test { } @Test - public void testAcceptsEvent() { + void testAcceptsEvent() { // it should always accept events assertTrue(step.acceptsEvent()); } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { // unmatching property names when(policyOper.getPropertyNames()).thenReturn(List.of("propA", "propB")); assertThat(step.getPropertyNames()) @@ -225,13 +217,13 @@ public class GuardStep2Test { } @Test - public void testLoadTargetEntity() { + void testLoadTargetEntity() { step.loadTargetEntity(OperationProperties.AAI_TARGET_ENTITY); assertThat(step.getParams().getPayload()).containsEntry(GuardStep2.PAYLOAD_KEY_TARGET_ENTITY, MY_TARGET); } @Test - public void testLoadDefaultGenericVnf() { + void testLoadDefaultGenericVnf() { step.loadDefaultGenericVnf(OperationProperties.AAI_VNF); assertThat(step.getParams().getPayload()) .containsEntry(GuardStep2.PAYLOAD_KEY_VNF_ID, MY_TARGET) @@ -242,7 +234,7 @@ public class GuardStep2Test { } @Test - public void testLoadCloudRegion() { + void testLoadCloudRegion() { step.loadCloudRegion(OperationProperties.AAI_DEFAULT_CLOUD_REGION); assertThat(step.getParams().getPayload()).containsEntry(GuardStep2.PAYLOAD_KEY_CLOUD_REGION_ID, MY_REGION); } @@ -251,7 +243,7 @@ public class GuardStep2Test { * Tests loadVfCount() when the policy operation is NOT "VF Module Create". */ @Test - public void testLoadVfCountNotVfModuleCreate() { + void testLoadVfCountNotVfModuleCreate() { // should decrement the count step.loadVfCount(""); assertThat(step.getParams().getPayload()).containsEntry(GuardStep2.PAYLOAD_KEY_VF_COUNT, VF_COUNT - 1); @@ -261,7 +253,7 @@ public class GuardStep2Test { * Tests loadVfCount() when the policy operation is "VF Module Create". */ @Test - public void testLoadVfCountVfModuleCreate() { + void testLoadVfCountVfModuleCreate() { when(policyOper.getName()).thenReturn(VfModuleCreate.NAME); // should increment the count diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/LockStep2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/LockStep2Test.java index fd7efe7bf..29401081e 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/LockStep2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/LockStep2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,20 +21,18 @@ package org.onap.policy.drools.apps.controller.usecases.step; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -42,18 +41,13 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp import org.onap.policy.controlloop.eventmanager.ActorConstants; import org.onap.policy.controlloop.eventmanager.StepContext; -@RunWith(MockitoJUnitRunner.class) -public class LockStep2Test { +class LockStep2Test { private static final String MY_TARGET = "my-target"; - @Mock - private StepContext stepContext; - @Mock - private Operation policyOper; - @Mock - private VirtualControlLoopEvent event; - @Mock - private Consumer<OperationOutcome> callback; + private final StepContext stepContext = mock(StepContext.class); + private final Operation policyOper = mock(Operation.class); + private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class); + private final Consumer<OperationOutcome> callback = mock(); private ControlLoopOperationParams params; private CompletableFuture<OperationOutcome> future; @@ -63,7 +57,7 @@ public class LockStep2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { future = new CompletableFuture<>(); @@ -86,7 +80,7 @@ public class LockStep2Test { } @Test - public void testConstructor() { + void testConstructor() { assertEquals(ActorConstants.LOCK_ACTOR, step.getActorName()); assertEquals(ActorConstants.LOCK_OPERATION, step.getOperationName()); assertSame(stepContext, step.stepContext); @@ -94,20 +88,20 @@ public class LockStep2Test { } @Test - public void testAcceptsEvent() { + void testAcceptsEvent() { // it should always accept events assertTrue(step.acceptsEvent()); } @Test - public void testStart() { + void testStart() { // start the operation step.init(); step.setProperties(); assertTrue(step.start(100)); // complete the operation's future - OperationOutcome outcome = step.makeOutcome(); + var outcome = step.makeOutcome(); outcome.setTarget(MY_TARGET); future.complete(outcome); @@ -120,7 +114,7 @@ public class LockStep2Test { * Tests start when the operation throws an exception. */ @Test - public void testStartNoFuture() { + void testStartNoFuture() { // start the operation step.init(); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java index d80484a2e..7a557c2af 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/step/Step2Test.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +24,10 @@ package org.onap.policy.drools.apps.controller.usecases.step; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -43,11 +44,8 @@ import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.LinkedBlockingQueue; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ModelVer; @@ -70,8 +68,7 @@ import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.eventmanager.StepContext; import org.onap.policy.drools.apps.controller.usecases.UsecasesConstants; -@RunWith(MockitoJUnitRunner.class) -public class Step2Test { +class Step2Test { private static final UUID REQ_ID = UUID.randomUUID(); private static final String POLICY_ACTOR = "my-actor"; private static final String POLICY_OPERATION = "my-operation"; @@ -81,18 +78,12 @@ public class Step2Test { private static final String NO_SLASH = "noslash"; private static final String ONE_SLASH = "/one"; - @Mock - private Operator policyOperator; - @Mock - private Operation policyOperation; - @Mock - private Actor policyActor; - @Mock - private ActorService actors; - @Mock - private StepContext stepContext; - @Mock - private AaiCqResponse aaicq; + private final Operator policyOperator = mock(Operator.class); + private final Operation policyOperation = mock(Operation.class); + private final Actor policyActor = mock(Actor.class); + private final ActorService actors = mock(ActorService.class); + private final StepContext stepContext = mock(StepContext.class); + private final AaiCqResponse aaicq = mock(AaiCqResponse.class); private Map<String, String> payload; private VirtualControlLoopEvent event; @@ -104,7 +95,7 @@ public class Step2Test { /** * Sets up. */ - @Before + @BeforeEach public void setUp() { // configure policy operation when(actors.getActor(POLICY_ACTOR)).thenReturn(policyActor); @@ -136,14 +127,14 @@ public class Step2Test { } @Test - public void testConstructor() { + void testConstructor() { assertSame(stepContext, step.stepContext); assertSame(event, step.event); assertSame(actors, step.getParams().getActorService()); } @Test - public void testConstructorStep2() { + void testConstructorStep2() { step = new Step2(step, "actorB", "operationB"); assertSame(stepContext, step.stepContext); assertSame(event, step.event); @@ -154,7 +145,7 @@ public class Step2Test { } @Test - public void testAcceptsEvent() { + void testAcceptsEvent() { // it's a policy step, thus it accepts events assertTrue(step.acceptsEvent()); @@ -165,12 +156,12 @@ public class Step2Test { } @Test - public void testSuccess() { + void testSuccess() { assertThatCode(() -> step.success(null)).doesNotThrowAnyException(); } @Test - public void testGetPropertyNames() { + void testGetPropertyNames() { // empty property list assertThat(step.getPropertyNames()).isEmpty(); @@ -180,11 +171,11 @@ public class Step2Test { } @Test - public void testSetProperties() { - CloudRegion cloudRegion = new CloudRegion(); + void testSetProperties() { + var cloudRegion = new CloudRegion(); when(aaicq.getDefaultCloudRegion()).thenReturn(cloudRegion); - Tenant tenant = new Tenant(); + var tenant = new Tenant(); when(aaicq.getDefaultTenant()).thenReturn(tenant); when(policyOperation.getPropertyNames()).thenReturn( @@ -202,7 +193,7 @@ public class Step2Test { * Tests setProperties() when the property is unknown. */ @Test - public void testSetPropertiesUnknown() { + void testSetPropertiesUnknown() { when(policyOperation.getPropertyNames()).thenReturn(List.of("unknown-property")); assertThatIllegalArgumentException().isThrownBy(() -> step.setProperties()) @@ -210,8 +201,8 @@ public class Step2Test { } @Test - public void testLoadCloudRegion_testGetCloudRegion() { - CloudRegion data = new CloudRegion(); + void testLoadCloudRegion_testGetCloudRegion() { + var data = new CloudRegion(); when(aaicq.getDefaultCloudRegion()).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_DEFAULT_CLOUD_REGION)); @@ -224,8 +215,8 @@ public class Step2Test { } @Test - public void testLoadTenant_testGetTenant() { - Tenant data = new Tenant(); + void testLoadTenant_testGetTenant() { + var data = new Tenant(); when(aaicq.getDefaultTenant()).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_DEFAULT_TENANT)); @@ -238,8 +229,8 @@ public class Step2Test { } @Test - public void testLoadPnf_testGetPnf() { - StandardCoderObject data = new StandardCoderObject(); + void testLoadPnf_testGetPnf() { + var data = new StandardCoderObject(); when(stepContext.getProperty(OperationProperties.AAI_TARGET_ENTITY)).thenReturn(MY_TARGET); when(stepContext.getProperty(AaiGetPnfOperation.getKey(MY_TARGET))).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_PNF)); @@ -253,9 +244,9 @@ public class Step2Test { } @Test - public void testLoadResourceVnf_testGetResourceVnf() { + void testLoadResourceVnf_testGetResourceVnf() { params.getTargetEntityIds().put(Step2.TARGET_RESOURCE_ID, "my-resource"); - GenericVnf data = new GenericVnf(); + var data = new GenericVnf(); when(aaicq.getGenericVnfByModelInvariantId("my-resource")).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_RESOURCE_VNF)); @@ -280,8 +271,8 @@ public class Step2Test { } @Test - public void testLoadService_testGetService() { - ServiceInstance data = new ServiceInstance(); + void testLoadService_testGetService() { + var data = new ServiceInstance(); when(aaicq.getServiceInstance()).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_SERVICE)); @@ -294,12 +285,12 @@ public class Step2Test { } @Test - public void testLoadServiceModel_testGetServiceModel() { - ServiceInstance service = new ServiceInstance(); + void testLoadServiceModel_testGetServiceModel() { + var service = new ServiceInstance(); service.setModelVersionId("my-service-version"); when(aaicq.getServiceInstance()).thenReturn(service); - ModelVer data = new ModelVer(); + var data = new ModelVer(); when(aaicq.getModelVerByVersionId("my-service-version")).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_SERVICE_MODEL)); @@ -320,8 +311,8 @@ public class Step2Test { } @Test - public void testGetVserver() { - Vserver vserver = new Vserver(); + void testGetVserver() { + var vserver = new Vserver(); when(aaicq.getVserver()).thenReturn(vserver); assertSame(vserver, step.getVServer()); @@ -332,7 +323,7 @@ public class Step2Test { } @Test - public void testGetTargetEntity() { + void testGetTargetEntity() { when(stepContext.getProperty(OperationProperties.AAI_TARGET_ENTITY)).thenReturn(MY_TARGET); assertEquals(MY_TARGET, step.getTargetEntity()); @@ -343,9 +334,9 @@ public class Step2Test { } @Test - public void testLoadVnf_testGetVnf() { + void testLoadVnf_testGetVnf() { params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "my-model-invariant"); - GenericVnf data = new GenericVnf(); + var data = new GenericVnf(); when(aaicq.getGenericVnfByVfModuleModelInvariantId("my-model-invariant")).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_VNF)); @@ -370,13 +361,13 @@ public class Step2Test { } @Test - public void testLoadVnfModel_testGetVnfModel() { + void testLoadVnfModel_testGetVnfModel() { params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "my-model-invariant"); - GenericVnf vnf = new GenericVnf(); + var vnf = new GenericVnf(); when(aaicq.getGenericVnfByVfModuleModelInvariantId("my-model-invariant")).thenReturn(vnf); vnf.setModelVersionId("my-vnf-model-version-id"); - ModelVer data = new ModelVer(); + var data = new ModelVer(); when(aaicq.getModelVerByVersionId("my-vnf-model-version-id")).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.AAI_VNF_MODEL)); @@ -393,10 +384,10 @@ public class Step2Test { } @Test - public void testLoadVserverLink_testGetVserverLink() { + void testLoadVserverLink_testGetVserverLink() { event.setAai(Map.of(Step2.VSERVER_VSERVER_NAME, "vserverB")); - StandardCoderObject tenant = mock(StandardCoderObject.class); + var tenant = mock(StandardCoderObject.class); when(stepContext.getProperty(AaiGetTenantOperation.getKey("vserverB"))).thenReturn(tenant); when(tenant.getString("result-data", 0, "resource-link")).thenReturn("/aai/v7/some/link/bbb"); @@ -428,7 +419,7 @@ public class Step2Test { } @Test - public void testLoadVfCount_testGetVfCount() { + void testLoadVfCount_testGetVfCount() { params.getTargetEntityIds().put(Step2.TARGET_MODEL_CUSTOMIZATION_ID, "vf-count-customization"); params.getTargetEntityIds().put(Step2.TARGET_MODEL_INVARIANT_ID, "vf-count-invariant"); params.getTargetEntityIds().put(Step2.TARGET_MODEL_VERSION_ID, "vf-count-version"); @@ -468,7 +459,7 @@ public class Step2Test { } @Test - public void testLoadEnrichment_testGetEnrichment() { + void testLoadEnrichment_testGetEnrichment() { event.setAai(Map.of("bandwidth", "bandwidth-value")); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.ENRICHMENT_BANDWIDTH)); @@ -481,7 +472,7 @@ public class Step2Test { } @Test - public void testLoadAdditionalEventParams_testGetAdditionalEventParams() { + void testLoadAdditionalEventParams_testGetAdditionalEventParams() { Map<String, String> data = Map.of("addA", "add-valueA", "addB", "add-valueB"); event.setAdditionalEventParams(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.EVENT_ADDITIONAL_PARAMS)); @@ -491,7 +482,7 @@ public class Step2Test { } @Test - public void testLoadEventPayload_testGetEventPayload() { + void testLoadEventPayload_testGetEventPayload() { event.setPayload("some-event-payload"); when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.EVENT_PAYLOAD)); @@ -500,7 +491,7 @@ public class Step2Test { } @Test - public void testLoadOptCdsGrpcAaiProperties() { + void testLoadOptCdsGrpcAaiProperties() { when(policyOperation.getPropertyNames()).thenReturn(List.of(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES)); step.setProperties(); @@ -508,8 +499,8 @@ public class Step2Test { } @Test - public void testLoadDefaultGenericVnf_testGetDefaultGenericVnf() { - GenericVnf data = new GenericVnf(); + void testLoadDefaultGenericVnf_testGetDefaultGenericVnf() { + var data = new GenericVnf(); when(aaicq.getDefaultGenericVnf()).thenReturn(data); when(policyOperation.getPropertyNames()).thenReturn(List.of(UsecasesConstants.AAI_DEFAULT_GENERIC_VNF)); @@ -522,7 +513,7 @@ public class Step2Test { } @Test - public void testGetCustomQueryData() { + void testGetCustomQueryData() { assertSame(aaicq, step.getCustomQueryData()); when(stepContext.getProperty(AaiCqResponse.CONTEXT_KEY)).thenReturn(null); @@ -532,7 +523,7 @@ public class Step2Test { } @Test - public void testVerifyNotNull() { + void testVerifyNotNull() { assertThatCode(() -> step.verifyNotNull("verifyA", "verify-value-A")).doesNotThrowAnyException(); assertThatIllegalArgumentException().isThrownBy(() -> step.verifyNotNull("verifyB", null)) @@ -540,7 +531,7 @@ public class Step2Test { } @Test - public void testStripPrefix() { + void testStripPrefix() { assertEquals(NO_SLASH, Step2.stripPrefix(NO_SLASH, 0)); assertEquals(NO_SLASH, Step2.stripPrefix(NO_SLASH, 1)); assertEquals(NO_SLASH, Step2.stripPrefix(NO_SLASH, 2)); @@ -555,5 +546,4 @@ public class Step2Test { assertEquals("/and/more", Step2.stripPrefix("prefix/three/slashes/and/more", 3)); } - } |