e04655d5d10a4449356f5d7e8b1c61543feba536
[nonrtric.git] / pmlog / src / test / java / org / oran / pmlog / IcsSimulatorController.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2023 Nordix Foundation
6  * %%
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.oran.pmlog;
22
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
25
26 import io.swagger.v3.oas.annotations.tags.Tag;
27
28 import java.lang.invoke.MethodHandles;
29
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;
40
41 @RestController("IcsSimulatorController")
42 @Tag(name = "Information Coordinator Service Simulator (exists only in test)")
43 public class IcsSimulatorController {
44
45     private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
46     private final static Gson gson = new GsonBuilder().disableHtmlEscaping().create();
47
48     public static class TestResults {
49
50         ConsumerJobInfo createdJob = null;
51
52         public TestResults() {}
53
54         public synchronized void reset() {
55             createdJob = null;
56         }
57
58         public void setCreatedJob(ConsumerJobInfo informationJobObject) {
59             this.createdJob = informationJobObject;
60         }
61     }
62
63     final TestResults testResults = new TestResults();
64
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);
75     }
76
77 }