X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=influxlogger%2Fsrc%2Ftest%2Fjava%2Forg%2Foran%2Fpmlog%2FIcsSimulatorController.java;fp=influxlogger%2Fsrc%2Ftest%2Fjava%2Forg%2Foran%2Fpmlog%2FIcsSimulatorController.java;h=918733ec8d0edefff82f96c290e98e52e485ae99;hb=9e3ded97088f197b335d060e1c9ddf7d6c0ecd89;hp=0000000000000000000000000000000000000000;hpb=7c434fcb459c84543cdb0ad14aa59391c60d16d4;p=nonrtric%2Fplt%2Franpm.git diff --git a/influxlogger/src/test/java/org/oran/pmlog/IcsSimulatorController.java b/influxlogger/src/test/java/org/oran/pmlog/IcsSimulatorController.java new file mode 100644 index 0000000..918733e --- /dev/null +++ b/influxlogger/src/test/java/org/oran/pmlog/IcsSimulatorController.java @@ -0,0 +1,82 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2023 Nordix Foundation + * %% + * 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. + * ========================LICENSE_END=================================== + */ + +package org.oran.pmlog; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import io.swagger.v3.oas.annotations.tags.Tag; + +import java.lang.invoke.MethodHandles; + +import org.oran.pmlog.configuration.ConsumerJobInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController("IcsSimulatorController") +@Tag(name = "Information Coordinator Service Simulator (exists only in test)") +public class IcsSimulatorController { + + private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private final static Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public static class TestResults { + + ConsumerJobInfo createdJob = null; + + public TestResults() {} + + public synchronized void reset() { + createdJob = null; + } + + public void setCreatedJob(ConsumerJobInfo informationJobObject) { + this.createdJob = informationJobObject; + } + } + + final TestResults testResults = new TestResults(); + + @PutMapping(path = "/data-consumer/v1/info-jobs/{infoJobId}", // + produces = MediaType.APPLICATION_JSON_VALUE, // + consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity putIndividualInfoJob( // + @PathVariable("infoJobId") String jobId, // + @RequestBody String body) { + logger.debug("*** added consumer job {}", jobId); + try { + ConsumerJobInfo informationJobObject = gson.fromJson(body, ConsumerJobInfo.class); + testResults.setCreatedJob(informationJobObject); + return new ResponseEntity<>(HttpStatus.OK); + } catch (Exception e) { + logger.error("Received malformed data: {}, {}", body, e.getMessage()); + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + } + +}