Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.appclcm / src / test / java / org / onap / policy / controlloop / actor / appclcm / AppcLcmOperationTest.java
index 650c5da..5765e3c 100644 (file)
@@ -2,7 +2,8 @@
  * ============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) 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,6 +23,7 @@ package org.onap.policy.controlloop.actor.appclcm;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+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.assertNotNull;
@@ -40,6 +42,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.appclcm.AppcLcmBody;
 import org.onap.policy.appclcm.AppcLcmCommonHeader;
 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
@@ -61,6 +65,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
 import org.onap.policy.simulators.AppcLcmTopicServer;
 import org.onap.policy.simulators.TopicServer;
 
+@RunWith(MockitoJUnitRunner.class)
 public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcLcmDmaapWrapper> {
 
     private static final String EXPECTED_EXCEPTION = "expected exception";
@@ -94,6 +99,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcL
         response = makeResponse();
 
         oper = new AppcLcmOperation(params, config);
+        oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
     }
 
     @After
@@ -118,6 +124,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcL
         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
 
         oper = new AppcLcmOperation(params, config);
+        oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
 
         outcome = oper.start().get();
         assertEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -156,11 +163,24 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcL
         assertEquals(subreq, request.getBody().getInput().getCommonHeader().getSubRequestId());
     }
 
+    /**
+     * Tests makeRequest() when a property is missing.
+     */
+    @Test
+    public void testMakeRequestMissingProperty() throws Exception {
+        oper = new AppcLcmOperation(params, config);
+        oper.generateSubRequestId(1);
+
+        assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
+                        .withMessageContaining("missing target entity");
+    }
+
     @Test
     public void testConvertPayload() {
         // only builds a payload for ConfigModify
         params = params.toBuilder().operation(AppcLcmConstants.OPERATION_CONFIG_MODIFY).build();
         oper = new AppcLcmOperation(params, config);
+        oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
 
         oper.generateSubRequestId(2);
         AppcLcmDmaapWrapper req = oper.makeRequest(2);
@@ -179,10 +199,11 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcL
             }
         };
 
+        oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, TARGET_ENTITY);
         oper.generateSubRequestId(2);
 
         assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest(2))
-                        .withMessage("Cannot convert payload");
+                        .withMessageContaining("Cannot convert payload");
     }
 
     @Test