diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2021-08-30 17:28:37 -0400 |
---|---|---|
committer | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2021-08-31 09:06:27 -0400 |
commit | 263f2bd07273cef4bc103f5198fa36e1e04297e5 (patch) | |
tree | 5c3126f5f1999bce698fc431cc73f0c277eaaac3 | |
parent | 62c469dc0045e81979ac14aecb105f2150592c3a (diff) |
Add topics end point to dmaap sim
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>
4 files changed, 75 insertions, 3 deletions
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 index 000000000..1f05976f7 --- /dev/null +++ b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapGetTopicResponse.java @@ -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; +} diff --git a/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProvider.java b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProvider.java index c954ab8dc..2119a6521 100644 --- a/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProvider.java +++ b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/provider/DmaapSimProvider.java @@ -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. @@ -142,6 +143,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. */ private class SweeperTask implements Runnable { diff --git a/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1.java b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1.java index f6e14d2b0..17b7529f6 100644 --- a/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1.java +++ b/models-sim/models-sim-dmaap/src/main/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1.java @@ -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(); + } } diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1Test.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1Test.java index 7b84d543d..dd938d310 100644 --- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1Test.java +++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/DmaapSimRestControllerV1Test.java @@ -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) { |