X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fenrichment%2Fcontroller%2FProducerSimulatorController.java;h=cc61d21d8c6e3adf0f9fe5494450a5881c1e4868;hb=530fa60a49e8f870cea442a338b148783fbe2ab7;hp=b6b8bc34d1a5bc19e7f40df979757abea71c38fe;hpb=a41966b2da6d7f74d4f486bc1492a5cbb5866583;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java index b6b8bc34..cc61d21d 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 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 @@ -32,30 +32,39 @@ import java.util.List; import lombok.Getter; -import org.oransc.enrichment.clients.ProducerJobInfo; import org.oransc.enrichment.controllers.ErrorResponse; +import org.oransc.enrichment.controllers.VoidResponse; +import org.oransc.enrichment.controllers.producer.ProducerJobInfo; 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.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @RestController("ProducerSimulatorController") -@Api(tags = {"Producer Simulator"}) +@Api(tags = {"Producer Callbacks"}) public class ProducerSimulatorController { private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public static final String JOB_CREATED_URL = "/producer_simulator/job_created"; public static final String JOB_DELETED_URL = "/producer_simulator/job_deleted"; + public static final String JOB_CREATED_ERROR_URL = "/producer_simulator/job_created_error"; + public static final String JOB_DELETED_ERROR_URL = "/producer_simulator/job_deleted_error"; + + public static final String SUPERVISION_URL = "/producer_simulator/supervision"; + public static final String SUPERVISION_ERROR_URL = "/producer_simulator/supervision_error"; public static class TestResults { public List jobsStarted = Collections.synchronizedList(new ArrayList()); public List jobsStopped = Collections.synchronizedList(new ArrayList()); + public int noOfRejectedCreate = 0; + public int noOfRejectedDelete = 0; public boolean errorFound = false; public TestResults() { @@ -65,6 +74,8 @@ public class ProducerSimulatorController { jobsStarted.clear(); jobsStopped.clear(); this.errorFound = false; + this.noOfRejectedCreate = 0; + this.noOfRejectedDelete = 0; } } @@ -75,7 +86,7 @@ public class ProducerSimulatorController { @ApiOperation(value = "Callback for EI job creation", notes = "") @ApiResponses( value = { // - @ApiResponse(code = 200, message = "OK", response = void.class)}// + @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)}// ) public ResponseEntity jobCreatedCallback( // @RequestBody ProducerJobInfo request) { @@ -96,7 +107,7 @@ public class ProducerSimulatorController { @ApiOperation(value = "Callback for EI job deletion", notes = "") @ApiResponses( value = { // - @ApiResponse(code = 200, message = "OK", response = void.class)}// + @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)}// ) public ResponseEntity jobDeletedCallback( // @RequestBody ProducerJobInfo request) { @@ -109,4 +120,52 @@ public class ProducerSimulatorController { } } + @PostMapping(path = JOB_CREATED_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "Callback for EI job creation, returns error", notes = "", hidden = true) + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)}// + ) + public ResponseEntity jobCreatedCallbackReturnError( // + @RequestBody ProducerJobInfo request) { + logger.info("Job created (returning error) callback {}", request.id); + this.testResults.noOfRejectedCreate += 1; + return ErrorResponse.create("Producer returns error on create job", HttpStatus.NOT_FOUND); + } + + @PostMapping(path = JOB_DELETED_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "Callback for EI job creation, returns error", notes = "", hidden = true) + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)}// + ) + public ResponseEntity jobDeletedCallbackReturnError( // + @RequestBody ProducerJobInfo request) { + logger.info("Job created (returning error) callback {}", request.id); + this.testResults.noOfRejectedDelete += 1; + return ErrorResponse.create("Producer returns error on delete job", HttpStatus.NOT_FOUND); + } + + @GetMapping(path = SUPERVISION_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "Producer supervision", notes = "") + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "OK", response = String.class)}// + ) + public ResponseEntity producerSupervision() { + logger.info("Producer supervision"); + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping(path = SUPERVISION_ERROR_URL, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "Producer supervision error", notes = "", hidden = true) + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "OK", response = String.class)}// + ) + public ResponseEntity producerSupervisionError() { + logger.info("Producer supervision error"); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + }