diff options
Diffstat (limited to 'models-interactions/model-actors/actor.sdnr')
2 files changed, 36 insertions, 3 deletions
diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java index f88f3c300..4511cc3c5 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java @@ -46,7 +46,7 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe */ public static final String NAME = "any"; - private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_VSERVER_LINK); + private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.EVENT_PAYLOAD); /** * Keys used to match the response with the request listener. The sub request ID is a @@ -156,7 +156,7 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe requestCommonHeader.setSubRequestId(subRequestId); sdnrRequest.setCommonHeader(requestCommonHeader); - sdnrRequest.setPayload(params.getContext().getEvent().getPayload()); + sdnrRequest.setPayload(getEventPayload()); sdnrRequest.setAction(params.getOperation()); /* @@ -169,4 +169,18 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe /* Return the request to be sent through dmaap. */ return dmaapRequest; } + + /** + * Gets the event payload, first checking for it in the properties and then in the + * event. + * + * @return the event payload + */ + protected String getEventPayload() { + if (containsProperty(OperationProperties.EVENT_PAYLOAD)) { + return getProperty(OperationProperties.EVENT_PAYLOAD); + } + + return params.getContext().getEvent().getPayload(); + } } diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java index 8ec1e4a20..abce2104e 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java @@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; 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.mock; @@ -90,7 +91,7 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testGetPropertyNames() { - assertThat(operation.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_VSERVER_LINK)); + assertThat(operation.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD)); } @Test @@ -235,6 +236,24 @@ public class SdnrOperationTest extends BasicSdnrOperation { checkOutcome(); } + @Test + public void testGetEventPayload() { + // in neither property nor event + assertNull(operation.getEventPayload()); + + // only in event + event.setPayload("valueA2"); + assertEquals("valueA2", operation.getEventPayload()); + + // both - should choose the property + operation.setProperty(OperationProperties.EVENT_PAYLOAD, "valueB"); + assertEquals("valueB", operation.getEventPayload()); + + // both - should choose the property, even if it's null + operation.setProperty(OperationProperties.EVENT_PAYLOAD, null); + assertNull(operation.getEventPayload()); + } + protected void checkOutcome() { assertSame(outcome, operation.setOutcome(outcome, PolicyResult.SUCCESS, response)); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); |