2 * ========================LICENSE_START=================================
5 * Copyright (C) 2023 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.pmlog;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
26 import io.swagger.v3.oas.annotations.tags.Tag;
28 import java.lang.invoke.MethodHandles;
30 import org.oran.pmlog.configuration.ConsumerJobInfo;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.http.HttpStatus;
34 import org.springframework.http.MediaType;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.PathVariable;
37 import org.springframework.web.bind.annotation.PutMapping;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RestController;
41 @RestController("IcsSimulatorController")
42 @Tag(name = "Information Coordinator Service Simulator (exists only in test)")
43 public class IcsSimulatorController {
45 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
46 private final static Gson gson = new GsonBuilder().disableHtmlEscaping().create();
48 public static class TestResults {
50 ConsumerJobInfo createdJob = null;
52 public TestResults() {}
54 public synchronized void reset() {
58 public void setCreatedJob(ConsumerJobInfo informationJobObject) {
59 this.createdJob = informationJobObject;
63 final TestResults testResults = new TestResults();
65 @PutMapping(path = "/data-consumer/v1/info-jobs/{infoJobId}", //
66 produces = MediaType.APPLICATION_JSON_VALUE, //
67 consumes = MediaType.APPLICATION_JSON_VALUE)
68 public ResponseEntity<Object> putIndividualInfoJob( //
69 @PathVariable("infoJobId") String jobId, //
70 @RequestBody String body) {
71 logger.debug("*** added consumer job {}", jobId);
72 ConsumerJobInfo informationJobObject = gson.fromJson(body, ConsumerJobInfo.class);
73 testResults.setCreatedJob(informationJobObject);
74 return new ResponseEntity<>(HttpStatus.OK);