2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oran.dmaapadapter;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.media.Content;
25 import io.swagger.v3.oas.annotations.media.Schema;
26 import io.swagger.v3.oas.annotations.responses.ApiResponse;
27 import io.swagger.v3.oas.annotations.responses.ApiResponses;
28 import io.swagger.v3.oas.annotations.tags.Tag;
30 import java.lang.invoke.MethodHandles;
31 import java.util.Collections;
32 import java.util.LinkedList;
33 import java.util.List;
35 import org.oran.dmaapadapter.controllers.ErrorResponse;
36 import org.oran.dmaapadapter.controllers.VoidResponse;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.MediaType;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.web.bind.annotation.GetMapping;
43 import org.springframework.web.bind.annotation.RestController;
45 @RestController("DmaapSimulatorController")
46 @Tag(name = "DMAAP Simulator (exists only in test)")
47 public class DmaapSimulatorController {
49 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
51 public static final String DMAAP_TOPIC_URL = "/dmaap-topic-1";
53 public static List<String> dmaapResponses = Collections.synchronizedList(new LinkedList<String>());
55 @GetMapping(path = DMAAP_TOPIC_URL, produces = MediaType.APPLICATION_JSON_VALUE)
56 @Operation(summary = "GET from topic",
57 description = "The call is invoked to activate or to modify a data subscription. The endpoint is provided by the Information Producer.")
58 @ApiResponses(value = { //
59 @ApiResponse(responseCode = "200", description = "OK", //
60 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
62 public ResponseEntity<Object> getFromTopic() {
63 if (dmaapResponses.isEmpty()) {
64 return ErrorResponse.create("", HttpStatus.NOT_FOUND);
66 String resp = dmaapResponses.remove(0);
67 logger.info("DMAAP simulator returned: {}", resp);
68 return new ResponseEntity<>(resp, HttpStatus.OK);