Add topics end point to dmaap sim 99/123699/3
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Mon, 30 Aug 2021 21:28:37 +0000 (17:28 -0400)
committerRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 31 Aug 2021 13:06:27 +0000 (09:06 -0400)
Add "/topics" end point to dmaap simulator.
It will be used in CSIT tests to verify consolidated health check.

Issue-ID: POLICY-3605
Change-Id: I6814d6dd021e0d98bd99754d4e68f789ef405353
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapGetTopicResponse.java [new file with mode: 0644]
models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProvider.java
models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1.java
models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1Test.java

diff --git a/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapGetTopicResponse.java b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapGetTopicResponse.java
new file mode 100644 (file)
index 0000000..1f05976
--- /dev/null
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Bell Canada. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.sim.dmaap.provider;
+
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Class to capture get topic response from dmaap simulator.
+ */
+@Getter
+@Setter
+@ToString
+public class DmaapGetTopicResponse {
+
+    private List<String> topics;
+}
index c954ab8..2119a65 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -141,6 +142,20 @@ public class DmaapSimProvider extends ServiceManagerContainer {
         }
     }
 
+    /**
+     * Returns the list of default topics.
+     *
+     * @return the topic list
+     */
+    public Response processDmaapTopicsGet() {
+
+        LOGGER.debug("Request for listing DMaaP topics");
+        var response = new DmaapGetTopicResponse();
+        response.setTopics(List.of("POLICY-PDP-PAP", "POLICY-NOTIFICATION", "unauthenticated.DCAE_CL_OUTPUT",
+                        "POLICY-CL-MGT"));
+        return Response.status(Status.OK).entity(response).build();
+    }
+
     /**
      * Task to remove idle consumers from each topic.
      */
index f6e14d2..17b7529 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019,2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -35,7 +36,7 @@ import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
 /**
  * Class to provide REST endpoints for DMaaP simulator component statistics.
  */
-@Path("/events")
+@Path("/")
 @Produces(DmaapSimRestControllerV1.MEDIA_TYPE_APPLICATION_JSON)
 public class DmaapSimRestControllerV1 extends BaseRestControllerV1 {
     public static final String MEDIA_TYPE_APPLICATION_JSON = "application/json";
@@ -50,7 +51,7 @@ public class DmaapSimRestControllerV1 extends BaseRestControllerV1 {
      * @return the message
      */
     @GET
-    @Path("{topicName}/{consumerGroup}/{consumerId}")
+    @Path("events/{topicName}/{consumerGroup}/{consumerId}")
     public Response getDmaapMessage(@PathParam("topicName") final String topicName,
                     @PathParam("consumerGroup") final String consumerGroup,
                     @PathParam("consumerId") final String consumerId,
@@ -68,11 +69,23 @@ public class DmaapSimRestControllerV1 extends BaseRestControllerV1 {
      * @return the response to the post
      */
     @POST
-    @Path("{topicName}")
+    @Path("events/{topicName}")
     @Consumes(value = {CambriaMessageBodyHandler.MEDIA_TYPE_APPLICATION_CAMBRIA,
         TextMessageBodyHandler.MEDIA_TYPE_TEXT_PLAIN, MEDIA_TYPE_APPLICATION_JSON})
     public Response postDmaapMessage(@PathParam("topicName") final String topicName, final Object dmaapMessage) {
 
         return DmaapSimProvider.getInstance().processDmaapMessagePut(topicName, dmaapMessage);
     }
+
+    /**
+     * Get the list of topics configured.
+     *
+     * @return the message
+     */
+    @GET
+    @Path("topics")
+    public Response getDmaapTopics() {
+
+        return DmaapSimProvider.getInstance().processDmaapTopicsGet();
+    }
 }
index 7b84d54..dd938d3 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -18,6 +19,7 @@
 
 package org.onap.policy.models.sim.dmaap.rest;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import java.io.File;
@@ -82,6 +84,11 @@ public class DmaapSimRestControllerV1Test {
         resp = rest.getDmaapMessage(TOPIC, CONSUMER, CONSUMER_ID, LIMIT, 0);
         assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
         assertEquals("[my-message, my-message-B]", resp.getEntity().toString());
+
+        // verify getDmaapTopics
+        resp = rest.getDmaapTopics();
+        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+        assertThat(resp.getEntity().toString()).contains("POLICY-PDP-PAP");
     }
 
     private int getCount(Response resp) {