For PUT Service, HttpStatus CREATED is returned for new service and
OK for and update one.
Change-Id: I15ae61d33b581f25a3ac2eeb4260d2a086c07382
Issue-ID: NONRTRIC-155
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
@ApiOperation(value = "Register a service")
@ApiResponses(
value = { //
@ApiOperation(value = "Register a service")
@ApiResponses(
value = { //
- @ApiResponse(code = 200, message = "OK", response = String.class),
+ @ApiResponse(code = 200, message = "Service updated", response = String.class),
+ @ApiResponse(code = 201, message = "Service created", response = String.class), //
@ApiResponse(code = 400, message = "Cannot parse the ServiceRegistrationInfo", response = String.class)})
@PutMapping("/service")
public ResponseEntity<String> putService(//
@RequestBody ServiceRegistrationInfo registrationInfo) {
try {
validateRegistrationInfo(registrationInfo);
@ApiResponse(code = 400, message = "Cannot parse the ServiceRegistrationInfo", response = String.class)})
@PutMapping("/service")
public ResponseEntity<String> putService(//
@RequestBody ServiceRegistrationInfo registrationInfo) {
try {
validateRegistrationInfo(registrationInfo);
+ final boolean isCreate = this.services.get(registrationInfo.serviceName) == null;
this.services.put(toService(registrationInfo));
this.services.put(toService(registrationInfo));
- return new ResponseEntity<>("OK", HttpStatus.OK);
+ return new ResponseEntity<>("OK", isCreate ? HttpStatus.CREATED : HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
} catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
+import reactor.util.annotation.Nullable;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Test
public void testPutAndGetService() throws Exception {
// PUT
@Test
public void testPutAndGetService() throws Exception {
// PUT
+ putService("name", 0, HttpStatus.CREATED);
+ putService("name", 0, HttpStatus.OK);
// GET one service
String url = "/services?name=name";
// GET one service
String url = "/services?name=name";
@Test
public void testServiceSupervision() throws Exception {
@Test
public void testServiceSupervision() throws Exception {
- putService("service1", 1);
+ putService("service1", 1, HttpStatus.CREATED);
addPolicyType("type1", "ric1");
String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
addPolicyType("type1", "ric1");
String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
}
private void putService(String name) {
}
private void putService(String name) {
+ putService(name, 0, null);
- private void putService(String name, long keepAliveIntervalSeconds) {
+ private void putService(String name, long keepAliveIntervalSeconds, @Nullable HttpStatus expectedStatus) {
String url = "/service";
String body = createServiceJson(name, keepAliveIntervalSeconds);
String url = "/service";
String body = createServiceJson(name, keepAliveIntervalSeconds);
- restClient().put(url, body).block();
+ ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
+ if (expectedStatus != null) {
+ assertEquals(expectedStatus, resp.getStatusCode(), "");
+ }
}
private String baseUrl() {
}
private String baseUrl() {