Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / SoOperationTest.java
index 6f4ac0e..a2d3925 100644 (file)
@@ -2,8 +2,9 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * 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,10 @@ 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;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.controlloop.ControlLoopOperation;
@@ -48,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();
@@ -124,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());
@@ -139,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());
@@ -205,6 +211,38 @@ public class SoOperationTest extends BasicSoOperation {
         assertTrue(oper.buildConfigurationParameters().isEmpty());
     }
 
+    @Test
+    public void testConstructCloudConfiguration() throws Exception {
+        Tenant tenantItem = new Tenant();
+        tenantItem.setTenantId("my-tenant-id");
+
+        CloudRegion cloudRegionItem = new CloudRegion();
+        cloudRegionItem.setCloudRegionId("my-cloud-id");
+
+        assertThatCode(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem)).doesNotThrowAnyException();
+
+        tenantItem.setTenantId(null);
+        assertThatIllegalArgumentException()
+                        .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+                        .withMessageContaining("missing tenant ID");
+        tenantItem.setTenantId("my-tenant-id");
+
+        cloudRegionItem.setCloudRegionId(null);
+        assertThatIllegalArgumentException()
+                        .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+                        .withMessageContaining("missing cloud region ID");
+        cloudRegionItem.setCloudRegionId("my-cloud-id");
+    }
+
+    @Test
+    public void testGetRequiredText() throws Exception {
+
+        assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException();
+
+        assertThatIllegalArgumentException().isThrownBy(() -> oper.getRequiredText("some value", null))
+                        .withMessageContaining("missing some value");
+    }
+
     @Test
     public void testGetCoder() throws CoderException {
         Coder opcoder = oper.getCoder();