diff options
Diffstat (limited to 'models-interactions/model-actors/actor.appc')
8 files changed, 114 insertions, 13 deletions
diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java index f6a204540..76aa828c1 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java @@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory; public class AppcActorServiceProvider extends BidirectionalTopicActor<BidirectionalTopicActorParams> { - private static final String NAME = "APPC"; + public static final String NAME = "APPC"; private static final Logger logger = LoggerFactory.getLogger(AppcActorServiceProvider.class); diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java index 7d4af80ad..dc46f1253 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -67,6 +68,14 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request, } /** + * Starts the GUARD. + */ + @Override + protected CompletableFuture<OperationOutcome> startPreprocessorAsync() { + return startGuardAsync(); + } + + /** * Makes a request, given the target VNF. This is a support function for * {@link #makeRequest(int)}. * @@ -104,10 +113,16 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request, * @param source source from which to get the values * @param target where to place the decoded values */ - private static void convertPayload(Map<String, String> source, Map<String, Object> target) { - for (Entry<String, String> ent : source.entrySet()) { + private static void convertPayload(Map<String, Object> source, Map<String, Object> target) { + for (Entry<String, Object> ent : source.entrySet()) { + Object value = ent.getValue(); + if (value == null) { + target.put(ent.getKey(), null); + continue; + } + try { - target.put(ent.getKey(), coder.decode(ent.getValue(), Object.class)); + target.put(ent.getKey(), coder.decode(value.toString(), Object.class)); } catch (CoderException e) { logger.warn("cannot decode JSON value {}: {}", ent.getKey(), ent.getValue(), e); diff --git a/models-interactions/model-actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/models-interactions/model-actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor index f1002a301..f1002a301 100644 --- a/models-interactions/model-actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor +++ b/models-interactions/model-actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index 218a4e532..8b71b614d 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -63,6 +63,11 @@ public class AppcOperationTest extends BasicAppcOperation { } @Test + public void testStartPreprocessorAsync() { + assertNotNull(oper.startPreprocessorAsync()); + } + + @Test public void testMakeRequest() { Request request = oper.makeRequest(2, MY_VNF); assertEquals(DEFAULT_OPERATION, request.getAction()); @@ -106,7 +111,7 @@ public class AppcOperationTest extends BasicAppcOperation { /* * insert invalid json text into the payload. */ - Map<String, String> payload = new TreeMap<>(params.getPayload()); + Map<String, Object> payload = new TreeMap<>(params.getPayload()); payload.put("invalid-key", "{invalid json"); params = params.toBuilder().payload(payload).build(); @@ -126,6 +131,31 @@ public class AppcOperationTest extends BasicAppcOperation { KEY2, Map.of("output", "world")), request.getPayload()); // @formatter:on + + + /* + * insert null item into the payload. + */ + payload = new TreeMap<>(); + payload.put(KEY1, "abc"); + payload.put(KEY2, null); + payload.put(KEY3, "def"); + params = params.toBuilder().payload(payload).build(); + + oper = new AppcOperation(params, config) { + @Override + protected Request makeRequest(int attempt) { + return oper.makeRequest(attempt, MY_VNF); + } + }; + request = oper.makeRequest(2, MY_VNF); + + payload.put(AppcOperation.VNF_ID_KEY, MY_VNF); + payload.put(KEY1, "abc"); + payload.put(KEY2, null); + payload.put(KEY3, "def"); + + assertEquals(payload, request.getPayload()); } @Test diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index 305c6d7cd..99e9d824a 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -43,6 +43,7 @@ import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actor.test.BasicActor; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; @@ -50,7 +51,7 @@ import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AppcServiceProviderTest { +public class AppcServiceProviderTest extends BasicActor { private static final String GENERIC_VNF_ID = "generic-vnf.vnf-id"; @@ -74,7 +75,8 @@ public class AppcServiceProviderTest { static { /* - * Construct an onset with an AAI subtag containing generic-vnf.vnf-id and a target type of VM. + * Construct an onset with an AAI subtag containing generic-vnf.vnf-id and a + * target type of VM. */ onsetEvent = new VirtualControlLoopEvent(); onsetEvent.setClosedLoopControlName("closedLoopControlName-Test"); @@ -140,6 +142,12 @@ public class AppcServiceProviderTest { } @Test + public void testActorService() { + // verify that it all plugs into the ActorService + verifyActorService(AppcActorServiceProvider.NAME, "service.yaml"); + } + + @Test public void testConstructModifyConfigRequest() { policy.setPayload(new HashMap<>()); policy.getPayload().put(KEY1, VALUE1); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java index ed3e7a7ee..ecba91996 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java @@ -54,6 +54,7 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio protected static final String MY_VNF = "my-vnf"; protected static final String KEY1 = "my-key-A"; protected static final String KEY2 = "my-key-B"; + protected static final String KEY3 = "my-key-C"; protected static final String VALUE1 = "{\"input\":\"hello\"}"; protected static final String VALUE2 = "{\"output\":\"world\"}"; protected static final String RESOURCE_ID = "my-resource"; @@ -162,7 +163,7 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio } @Override - protected Map<String, String> makePayload() { + protected Map<String, Object> makePayload() { return Map.of(KEY1, VALUE1, KEY2, VALUE2); } } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index 5ff789715..460f2c9f0 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -24,11 +24,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; @@ -42,6 +42,7 @@ import org.onap.policy.appc.Request; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; +import org.onap.policy.controlloop.policy.PolicyResult; public class ModifyConfigOperationTest extends BasicAppcOperation { @@ -64,10 +65,11 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { } @Test - public void testStartPreprocessorAsync() { - CompletableFuture<OperationOutcome> future = new CompletableFuture<>(); + public void testStartPreprocessorAsync() throws Exception { + CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>(); context = mock(ControlLoopEventContext.class); - when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(future); + when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(future2); + when(context.getEvent()).thenReturn(event); params = params.toBuilder().context(context).build(); AtomicBoolean guardStarted = new AtomicBoolean(); @@ -80,9 +82,16 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { } }; - assertSame(future, oper.startPreprocessorAsync()); + CompletableFuture<OperationOutcome> future3 = oper.startPreprocessorAsync(); + assertNotNull(future3); assertFalse(future.isDone()); assertTrue(guardStarted.get()); + verify(context).obtain(eq(AaiCqResponse.CONTEXT_KEY), any()); + + future2.complete(params.makeOutcome()); + assertTrue(executor.runAll(100)); + assertTrue(future3.isDone()); + assertEquals(PolicyResult.SUCCESS, future3.get().getResult()); } @Test diff --git a/models-interactions/model-actors/actor.appc/src/test/resources/service.yaml b/models-interactions/model-actors/actor.appc/src/test/resources/service.yaml new file mode 100644 index 000000000..ab9ad98b5 --- /dev/null +++ b/models-interactions/model-actors/actor.appc/src/test/resources/service.yaml @@ -0,0 +1,38 @@ +# +# ============LICENSE_START====================================================== +# ONAP +# =============================================================================== +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# =============================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================== +# +topics: + topicSources: + - topicCommInfrastructure: NOOP + topic: my-source + servers: + - localhost + managed: true + topicSinks: + - topicCommInfrastructure: NOOP + topic: my-sink + servers: + - localhost + managed: true +actors: + APPC: + sinkTopic: my-sink + sourceTopic: my-source + operations: + ModifyConfig: {}
\ No newline at end of file |