Map<String, RicConfig> newRicConfigs = new HashMap<>();
for (RicConfig newConfig : parserResult.ricConfigs()) {
RicConfig oldConfig = this.ricConfigs.get(newConfig.name());
+ this.ricConfigs.remove(newConfig.name());
if (oldConfig == null) {
newRicConfigs.put(newConfig.name(), newConfig);
modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
- this.ricConfigs.remove(newConfig.name());
} else if (!newConfig.equals(oldConfig)) {
modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
newRicConfigs.put(newConfig.name(), newConfig);
- this.ricConfigs.remove(newConfig.name());
} else {
newRicConfigs.put(oldConfig.name(), oldConfig);
}
if (registrationInfo.serviceName.isEmpty()) {
throw new ServiceException("Missing mandatory parameter 'serviceName'");
}
+ if (registrationInfo.keepAliveIntervalSeconds < 0) {
+ throw new ServiceException("Keepalive interval shoul be greater or equal to 0");
+ }
}
@ApiOperation(value = "Register a service")
value = { //
@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)})
+ @ApiResponse(code = 400, message = "The ServiceRegistrationInfo is not accepted", response = String.class)})
@PutMapping("/service")
public ResponseEntity<String> putService(//
@RequestBody ServiceRegistrationInfo registrationInfo) {
// Keep alive, no registerred service
testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND);
- // PUT servive with crap payload
+ // PUT servive with bad payload
testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
+ testErrorCode(restClient().put("/service", createServiceJson("name", -123)), HttpStatus.BAD_REQUEST);
// GET non existing servive
testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
package org.oransc.policyagent.configuration;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
"Not correct Ric retrieved from configurations.");
+
+ update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).blockFirst();
+ assertNull(update, "Nothing should be updated");
+ assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric should remain.");
+
}
@Test