diff options
Diffstat (limited to 'models-interactions/model-actors/actor.so')
7 files changed, 49 insertions, 29 deletions
diff --git a/models-interactions/model-actors/actor.so/pom.xml b/models-interactions/model-actors/actor.so/pom.xml index fab1b2a52..7a0800397 100644 --- a/models-interactions/model-actors/actor.so/pom.xml +++ b/models-interactions/model-actors/actor.so/pom.xml @@ -2,7 +2,7 @@ <!-- ============LICENSE_START======================================================= Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - Modifications Copyright (C) 2019 Nordix Foundation. + Modifications Copyright (C) 2019,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. @@ -85,8 +85,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito2</artifactId> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java index 4b05daa23..1e38861e2 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 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,7 +21,7 @@ package org.onap.policy.controlloop.actor.so; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.lenient; import java.util.Collections; import java.util.HashMap; @@ -124,8 +125,8 @@ public abstract class BasicSoOperation extends BasicHttpOperation { response.setRequestReferences(ref); ref.setRequestId(REQ_ID.toString()); - when(rawResponse.getStatus()).thenReturn(200); - when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response)); + lenient().when(rawResponse.getStatus()).thenReturn(200); + lenient().when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response)); initConfig(); } @@ -133,11 +134,11 @@ public abstract class BasicSoOperation extends BasicHttpOperation { @Override protected void initConfig() { super.initConfig(); - 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); + lenient().when(config.getClient()).thenReturn(client); + lenient().when(config.getPath()).thenReturn(MY_PATH); + lenient().when(config.getMaxPolls()).thenReturn(MAX_POLLS); + lenient().when(config.getPollPath()).thenReturn(POLL_PATH); + lenient().when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC); } @Override diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java index 1c8920368..f7a59201d 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2022 CTC, Inc. and others. 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. @@ -32,6 +33,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; @@ -40,6 +43,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.so.SoResponse; +@RunWith(MockitoJUnitRunner.class) public class ModifyCllTest extends BasicSoOperation { private ModifyCll oper; diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java index 29a7d082a..8a31f2c93 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2020 Wipro Limited. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020,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. @@ -34,6 +34,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; @@ -42,6 +44,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingCo import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams; import org.onap.policy.so.SoResponse; +@RunWith(MockitoJUnitRunner.class) public class ModifyNssiTest extends BasicSoOperation { private ModifyNssi oper; diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index 50bbfee2b..a2d392510 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +29,7 @@ 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.Mockito.when; +import static org.mockito.Mockito.lenient; import java.time.LocalDateTime; import java.time.Month; @@ -37,6 +38,8 @@ import java.util.List; import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.Tenant; import org.onap.policy.common.utils.coder.Coder; @@ -50,6 +53,7 @@ import org.onap.policy.so.SoRequestInfo; import org.onap.policy.so.SoRequestStatus; import org.onap.policy.so.SoResponse; +@RunWith(MockitoJUnitRunner.class) public class SoOperationTest extends BasicSoOperation { private static final List<String> PROP_NAMES = Collections.emptyList(); @@ -126,14 +130,14 @@ public class SoOperationTest extends BasicSoOperation { assertTrue(oper.isSuccess(rawResponse, response)); - when(rawResponse.getStatus()).thenReturn(500); + lenient().when(rawResponse.getStatus()).thenReturn(500); assertTrue(oper.isSuccess(rawResponse, response)); } @Test public void testSetOutcome() { // success case - when(rawResponse.getStatus()).thenReturn(200); + lenient().when(rawResponse.getStatus()).thenReturn(200); assertSame(outcome, oper.setOutcome(outcome, OperationResult.SUCCESS, rawResponse, response)); assertEquals(OperationResult.SUCCESS, outcome.getResult()); @@ -141,7 +145,7 @@ public class SoOperationTest extends BasicSoOperation { assertSame(response, outcome.getResponse()); // failure case - when(rawResponse.getStatus()).thenReturn(500); + lenient().when(rawResponse.getStatus()).thenReturn(500); assertSame(outcome, oper.setOutcome(outcome, OperationResult.FAILURE, rawResponse, response)); assertEquals(OperationResult.FAILURE, outcome.getResult()); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index 7168ec449..ad242c0dc 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +39,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ModelVer; @@ -53,6 +56,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingPa import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; +@RunWith(MockitoJUnitRunner.class) public class VfModuleCreateTest extends BasicSoOperation { diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index cc11f952d..8c35e236f 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Wipro Limited. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +29,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; 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.net.http.HttpHeaders; import java.net.http.HttpRequest; @@ -53,8 +54,10 @@ 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.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; @@ -70,6 +73,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingPa import org.onap.policy.so.SoRequest; import org.onap.policy.so.SoResponse; +@RunWith(MockitoJUnitRunner.class) public class VfModuleDeleteTest extends BasicSoOperation { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String SVC_INSTANCE_ID = "my-service-instance-id"; @@ -203,8 +207,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { // indicate that the response was incomplete configureResponse(coder.encode(response).replace("COMPLETE", "incomplete")); - when(rawResponse.getStatus()).thenReturn(500, 500, 500, 200, 200); - when(client.get(any(), any(), any())).thenAnswer(provideResponse(rawResponse)); + lenient().when(rawResponse.getStatus()).thenReturn(500, 500, 500, 200, 200); + lenient().when(client.get(any(), any(), any())).thenAnswer(provideResponse(rawResponse)); // use a real executor params = params.toBuilder().executor(ForkJoinPool.commonPool()).build(); @@ -277,7 +281,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { // need a new future, with an exception javaFuture = CompletableFuture.failedFuture(thrown); - when(javaClient.sendAsync(any(), any(BodyHandlers.ofString().getClass()))).thenReturn(javaFuture); + lenient().when(javaClient.sendAsync(any(), any(BodyHandlers.ofString().getClass()))).thenReturn(javaFuture); SoRequest req = new SoRequest(); req.setRequestId(REQ_ID); @@ -300,8 +304,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { @Test public void testAddAuthHeader() { Builder builder = mock(Builder.class); - when(client.getUserName()).thenReturn("the-user"); - when(client.getPassword()).thenReturn("the-password"); + lenient().when(client.getUserName()).thenReturn("the-user"); + lenient().when(client.getPassword()).thenReturn("the-password"); oper.addAuthHeader(builder); ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class); @@ -321,12 +325,12 @@ public class VfModuleDeleteTest extends BasicSoOperation { @Test public void testAddAuthHeaderNoUser() { Builder builder = mock(Builder.class); - when(client.getPassword()).thenReturn("world"); + lenient().when(client.getPassword()).thenReturn("world"); oper.addAuthHeader(builder); verify(builder, never()).header(any(), any()); // repeat with empty username - when(client.getUserName()).thenReturn(""); + lenient().when(client.getUserName()).thenReturn(""); oper.addAuthHeader(builder); verify(builder, never()).header(any(), any()); } @@ -337,7 +341,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { @Test public void testAddAuthHeaderUserOnly() { Builder builder = mock(Builder.class); - when(client.getUserName()).thenReturn("my-user"); + lenient().when(client.getUserName()).thenReturn("my-user"); oper.addAuthHeader(builder); ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class); @@ -372,17 +376,17 @@ public class VfModuleDeleteTest extends BasicSoOperation { } private void initHostPort() { - when(client.getBaseUrl()).thenReturn("http://my-host:6969/"); + lenient().when(client.getBaseUrl()).thenReturn("http://my-host:6969/"); } @SuppressWarnings("unchecked") private void configureResponse(String responseText) throws CoderException { // indicate that the response was completed - when(javaResp.statusCode()).thenReturn(200); - when(javaResp.body()).thenReturn(responseText); + lenient().when(javaResp.statusCode()).thenReturn(200); + lenient().when(javaResp.body()).thenReturn(responseText); javaFuture = CompletableFuture.completedFuture(javaResp); - when(javaClient.sendAsync(any(), any(BodyHandlers.ofString().getClass()))).thenReturn(javaFuture); + lenient().when(javaClient.sendAsync(any(), any(BodyHandlers.ofString().getClass()))).thenReturn(javaFuture); } private class MyOperation extends VfModuleDelete { |