MaxAssignment smaller than 0 is not allowed -> BadRequest Status code
Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
@@ -113,6 +113,12 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
public ResponseEntity<List<MgmtSoftwareModuleType>> createSoftwareModuleTypes(
|
||||
@RequestBody final List<MgmtSoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
|
||||
|
||||
for (final MgmtSoftwareModuleTypeRequestBodyPost softwareModuleType : softwareModuleTypes) {
|
||||
if (softwareModuleType.getMaxAssignments() <= 0) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
final List<SoftwareModuleType> createdSoftwareModules = this.softwareManagement.createSoftwareModuleType(
|
||||
MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
|
||||
|
||||
|
||||
@@ -133,6 +133,19 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
|
||||
.andExpect(jsonPath("$content.[2].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests when max assignment is <= 0")
|
||||
public void createSoftwareModuleTypesInvalidAssignmentBadRequest() throws JSONException, Exception {
|
||||
|
||||
final List<SoftwareModuleType> types = new ArrayList<>();
|
||||
types.add(entityFactory.generateSoftwareModuleType("test1", "TestName1", "Desc1", -1));
|
||||
|
||||
mvc.perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests.")
|
||||
|
||||
Reference in New Issue
Block a user