Remove Target and TargetType
[policy/models.git] / models-interactions / model-actors / actor.cds / src / test / java / org / onap / policy / controlloop / actor / cds / GrpcOperationTest.java
index 2e9935f..709e179 100644 (file)
@@ -69,11 +69,10 @@ import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
 import org.onap.policy.controlloop.actorserviceprovider.ActorService;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
 import org.onap.policy.simulators.CdsSimulator;
 import org.onap.policy.simulators.Util;
 
@@ -102,7 +101,8 @@ public class GrpcOperationTest {
     private CdsServerProperties cdsProps;
     private VirtualControlLoopEvent onset;
     private PseudoExecutor executor;
-    private Target target;
+    private TargetType targetType;
+    private Map<String, String> targetEntityIds;
     private ControlLoopOperationParams params;
     private GrpcConfig config;
     private CompletableFuture<OperationOutcome> cqFuture;
@@ -143,17 +143,18 @@ public class GrpcOperationTest {
         // Setup executor
         executor = new PseudoExecutor();
 
-        target = new Target();
-        target.setType(TargetType.VM);
-        target.setResourceID(RESOURCE_ID);
+        targetType = TargetType.VM;
+        targetEntityIds = new HashMap<>();
+        targetEntityIds.put(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID, RESOURCE_ID);
 
         cqFuture = new CompletableFuture<>();
         when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(cqFuture);
         when(context.getEvent()).thenReturn(onset);
 
         params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
-                        .operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
-                        .targetEntity(TARGET_ENTITY).target(target).build();
+                .operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
+                .targetEntity(TARGET_ENTITY).targetType(targetType).targetEntityIds(targetEntityIds)
+                .build();
     }
 
     /**
@@ -166,10 +167,10 @@ public class GrpcOperationTest {
 
         Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
 
-        params = ControlLoopOperationParams.builder()
-                        .actor(CdsActorConstants.CDS_ACTOR).operation("subscribe").context(context)
-                        .actorService(new ActorService()).targetEntity(TARGET_ENTITY).target(target).retry(0)
-                        .timeoutSec(5).executor(blockingExecutor).payload(payload).build();
+        params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR).operation("subscribe")
+                        .context(context).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
+                        .targetType(targetType).targetEntityIds(targetEntityIds)
+                        .retry(0).timeoutSec(5).executor(blockingExecutor).payload(payload).build();
 
         cdsProps.setHost("localhost");
         cdsProps.setPort(sim.getPort());
@@ -181,12 +182,12 @@ public class GrpcOperationTest {
             @Override
             protected CompletableFuture<OperationOutcome> startGuardAsync() {
                 // indicate that guard completed successfully
-                return CompletableFuture.completedFuture(params.makeOutcome());
+                return CompletableFuture.completedFuture(params.makeOutcome(null));
             }
         };
 
         OperationOutcome outcome = operation.start().get();
-        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+        assertEquals(OperationResult.SUCCESS, outcome.getResult());
         assertTrue(outcome.getResponse() instanceof ExecutionServiceOutput);
     }
 
@@ -200,10 +201,10 @@ public class GrpcOperationTest {
 
         Map<String, Object> payload = Map.of("artifact_name", "my_artifact", "artifact_version", "1.0");
 
-        params = ControlLoopOperationParams.builder()
-                        .actor(CdsActorConstants.CDS_ACTOR).operation("subscribe").context(context)
-                        .actorService(new ActorService()).targetEntity(TARGET_ENTITY).target(target).retry(0)
-                        .timeoutSec(5).executor(blockingExecutor).payload(payload).preprocessed(true).build();
+        params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR).operation("subscribe")
+                        .context(context).actorService(new ActorService()).targetEntity(TARGET_ENTITY)
+                        .targetType(targetType).targetEntityIds(targetEntityIds)
+                        .retry(0).timeoutSec(5).executor(blockingExecutor).payload(payload).preprocessed(true).build();
 
         cdsProps.setHost("localhost");
         cdsProps.setPort(sim.getPort());
@@ -217,7 +218,7 @@ public class GrpcOperationTest {
         operation.setProperty(OperationProperties.OPT_CDS_GRPC_AAI_PROPERTIES, Collections.emptyMap());
 
         OperationOutcome outcome = operation.start().get();
-        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+        assertEquals(OperationResult.SUCCESS, outcome.getResult());
         assertTrue(outcome.getResponse() instanceof ExecutionServiceOutput);
     }
 
@@ -241,7 +242,7 @@ public class GrpcOperationTest {
         /*
          * check PNF case
          */
-        target.setType(TargetType.PNF);
+        params = params.toBuilder().targetType(TargetType.PNF).build();
         operation = new GrpcOperation(params, config);
 
         // @formatter:off
@@ -260,8 +261,7 @@ public class GrpcOperationTest {
         operation = new GrpcOperation(params, config);
 
         // in neither property nor context
-        assertThatIllegalArgumentException().isThrownBy(() -> operation.getPnfData())
-                        .withMessage("missing PNF data");
+        assertThatIllegalArgumentException().isThrownBy(() -> operation.getPnfData()).withMessage("missing PNF data");
 
         // only in context
         Pnf pnf = new Pnf();
@@ -335,9 +335,9 @@ public class GrpcOperationTest {
         assertTrue(guardStarted.get());
         verify(context).obtain(eq(AaiCqResponse.CONTEXT_KEY), any());
 
-        cqFuture.complete(params.makeOutcome());
+        cqFuture.complete(params.makeOutcome(null));
         assertTrue(executor.runAll(100));
-        assertEquals(PolicyResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
+        assertEquals(OperationResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
         assertTrue(future3.isDone());
     }
 
@@ -348,7 +348,7 @@ public class GrpcOperationTest {
     public void testStartPreprocessorAsyncPnf() throws InterruptedException, ExecutionException, TimeoutException {
         AtomicBoolean guardStarted = new AtomicBoolean();
 
-        target.setType(TargetType.PNF);
+        params = params.toBuilder().targetType(TargetType.PNF).build();
 
         operation = new GrpcOperation(params, config) {
             @Override
@@ -363,9 +363,9 @@ public class GrpcOperationTest {
         assertTrue(guardStarted.get());
         verify(context).obtain(eq(AaiGetPnfOperation.getKey(TARGET_ENTITY)), any());
 
-        cqFuture.complete(params.makeOutcome());
+        cqFuture.complete(params.makeOutcome(null));
         assertTrue(executor.runAll(100));
-        assertEquals(PolicyResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
+        assertEquals(OperationResult.SUCCESS, future3.get(2, TimeUnit.SECONDS).getResult());
         assertTrue(future3.isDone());
     }
 
@@ -393,7 +393,7 @@ public class GrpcOperationTest {
     @Test
     public void testStartOperationAsyncPnf() throws Exception {
 
-        target.setType(TargetType.PNF);
+        targetType = TargetType.PNF;
 
         ControlLoopEventContext context = new ControlLoopEventContext(onset);
         loadPnfData(context);
@@ -415,7 +415,8 @@ public class GrpcOperationTest {
     @Test
     public void testStartOperationAsyncError() throws Exception {
         operation = new GrpcOperation(params, config);
-        assertThatIllegalArgumentException().isThrownBy(() -> operation.startOperationAsync(1, params.makeOutcome()));
+        assertThatIllegalArgumentException()
+                        .isThrownBy(() -> operation.startOperationAsync(1, params.makeOutcome(null)));
     }
 
     @Test
@@ -449,7 +450,8 @@ public class GrpcOperationTest {
 
         ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
                         .operation(GrpcOperation.NAME).context(context).actorService(new ActorService())
-                        .targetEntity(TARGET_ENTITY).target(target).payload(payloadMap).build();
+                        .targetEntity(TARGET_ENTITY).targetType(targetType).targetEntityIds(targetEntityIds)
+                        .payload(payloadMap).build();
 
         GrpcConfig config = new GrpcConfig(executor, cdsProps);
         operation = new GrpcOperation(params, config);
@@ -457,7 +459,7 @@ public class GrpcOperationTest {
         assertEquals(1000, operation.getTimeoutMs(0));
         assertEquals(2000, operation.getTimeoutMs(2));
         operation.generateSubRequestId(1);
-        CompletableFuture<OperationOutcome> future3 = operation.startOperationAsync(1, params.makeOutcome());
+        CompletableFuture<OperationOutcome> future3 = operation.startOperationAsync(1, params.makeOutcome(null));
         assertNotNull(future3);
     }