diff options
author | Jim Hahn <jrh3@att.com> | 2020-03-20 15:53:47 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-03-20 16:23:28 -0400 |
commit | f3fe0b63bc3bf7efdfce815bf17034291f8ff265 (patch) | |
tree | 880c0c685b750443b26c40260c7ea7716bbc6279 /models-interactions | |
parent | bc02433cc5292c5272dc084db8044bb4c8140135 (diff) |
Bug fixes in models simulators
Fixed these issues:
- topics weren't started
- appc topics were reversed
- prevent appc simulator from responding to a response (i.e., infinite
loop)
Issue-ID: POLICY-2434
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I1f43be72d35f874fec98f48f1a112c055c00eee5
Diffstat (limited to 'models-interactions')
5 files changed, 55 insertions, 3 deletions
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLegacyTopicServer.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLegacyTopicServer.java index 5ebd3bd2a..0c259783d 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLegacyTopicServer.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLegacyTopicServer.java @@ -36,6 +36,15 @@ public class AppcLegacyTopicServer extends TopicServer<Request> { @Override protected String process(Request request) { + /* + * The request and response are on the same topic, thus this may be invoked with a + * request or with a response object. If the "action" is null, then we know it's a + * response. + */ + if (request.getAction() == null) { + return null; + } + String response = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appc/appc.legacy.success.json"); return response.replace("${replaceMe}", request.getCommonHeader().getSubRequestId()); } diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/TopicServer.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/TopicServer.java index 0abe5f421..4c01511da 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/TopicServer.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/TopicServer.java @@ -65,8 +65,17 @@ public abstract class TopicServer<Q> implements TopicListener { throw new IllegalArgumentException("cannot decode request from " + source.getTopic()); } - sink.send(process(req)); + String resp = process(req); + if (resp != null) { + sink.send(resp); + } } + /** + * Processes a request. + * + * @param request request to be processed + * @return the response, or {@code null} if no response is to be sent + */ protected abstract String process(Q request); } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java index 57d574a0b..c3c3195df 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/AppcLegacyTopicServerTest.java @@ -22,6 +22,8 @@ package org.onap.policy.simulators; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import org.junit.Before; @@ -55,7 +57,7 @@ public class AppcLegacyTopicServerTest { } @Test - public void testProcessAppcLcmDmaapWrapper() { + public void testProcess() { String request = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appc/appc.legacy.request.json"); assertNotNull(request); @@ -66,4 +68,18 @@ public class AppcLegacyTopicServerTest { assertThat(respCaptor.getValue()).contains("111be3d2").doesNotContain("replaceMe"); } + + /** + * Tests process() when the message is a response. + */ + @Test + public void testProcessNoResponse() { + // NOTE: this json file is a RESPONSE, not a request + String request = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appc/appc.legacy.success.json"); + assertNotNull(request); + + server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, request); + + verify(sink, never()).send(any()); + } } diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java index 6e176423e..11a5e3f81 100644 --- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java +++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/TopicServerTest.java @@ -85,6 +85,23 @@ public class TopicServerTest { verify(sink, never()).send(any()); } + /** + * Tests onTopicEvent() when there is no response. + */ + @Test + public void testOnTopicEventNoResponse() { + server = new MyServer() { + @Override + protected String process(MyRequest request) { + return null; + } + }; + + server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, "{\"text\": \"bye-bye\"}"); + + verify(sink, never()).send(any()); + } + private class MyRequest { private String text; diff --git a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/appc/appc.legacy.request.json b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/appc/appc.legacy.request.json index 8b3b73a88..61c2647cd 100644 --- a/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/appc/appc.legacy.request.json +++ b/models-interactions/model-simulators/src/test/resources/org/onap/policy/simulators/appc/appc.legacy.request.json @@ -6,5 +6,6 @@ "SubRequestID": "111be3d2-6c12-4f4b-a3e7-c349acced200", "RequestTrack": [], "Flags": [] - } + }, + "Action": "ModifyConfig" } |