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:
Melanie Retter
2016-08-23 11:29:24 +02:00
parent 3650b31c9e
commit d2693e2f49
2 changed files with 19 additions and 0 deletions

View File

@@ -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));

View File

@@ -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.")