summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2023-01-31 10:41:01 +0000
committerliamfallon <liam.fallon@est.tech>2023-01-31 12:12:05 +0000
commite3938e43b8a1f02f74368ecb75c38530285feac0 (patch)
tree02a042ca672a935fce40fe81120bfffd13cec10f /models-interactions/model-actors/actor.so/src/test
parent8cf623781404f98aeacfc44e1bc8a7f1bf8446ad (diff)
Upgrade and clean up dependencies
- Upgrade Hibernate - Upgrade Mockito - Upgrade Mockserver - Remove Powermock (no longer supported) and replace with spring-test ReflectionTestUtils - Upgrade Spring Framework - Add spring-security to allow authentication on unit tests using MockMVC Minor clean-up - Replace deprecated authorization configuraiton on spring boot applications with SecurityFilterChain bean - Change @LocalPort include on tests to use test include rather than runtime include - Remove unused imports - Remove unused constants and variables - Add deprecation annotations where required Issue-ID: POLICY-4482 Change-Id: Ie8d6ee1e8bcdad282bcef3cad409c5c109e907f1 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/test')
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java17
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyCllTest.java4
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java5
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java12
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java4
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java30
6 files changed, 46 insertions, 26 deletions
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 {