diff --git a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java index 1a2c44ca0..39a9906ea 100644 --- a/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java +++ b/navalplanner-webapp/src/test/java/org/navalplanner/web/test/ws/resources/api/ResourceServiceTest.java @@ -165,6 +165,54 @@ public class ResourceServiceTest { } + @Test + @NotTransactional + public void AddResourceWithCriterionSatisfactionsWithIncorrectNames() { + + /* Create a criterion type. */ + CriterionType ct = createCriterionType(); + + /* Create a machine DTO. */ + MachineDTO machineDTO = new MachineDTO(getUniqueName(), "name", "desc"); + + /* Test. */ + machineDTO.criterionSatisfactions.add( // Non-existent criterion type. + new CriterionSatisfactionDTO(ct.getName() + 'X' , "c1", + Calendar.getInstance().getTime(), null)); + assertOneConstraintViolation( + resourceService.addResources(createResourceListDTO(machineDTO))); + assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction( + machineDTO.code)); + + machineDTO.criterionSatisfactions.clear(); + machineDTO.criterionSatisfactions.add( // Non-existent criterion. + new CriterionSatisfactionDTO(ct.getName() , "c1" + 'X', + Calendar.getInstance().getTime(), null)); + assertOneConstraintViolation( + resourceService.addResources(createResourceListDTO(machineDTO))); + assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction( + machineDTO.code)); + + machineDTO.criterionSatisfactions.clear(); + machineDTO.criterionSatisfactions.add( // Criterion type null. + new CriterionSatisfactionDTO(null , "c1", + Calendar.getInstance().getTime(), null)); + assertOneConstraintViolation( + resourceService.addResources(createResourceListDTO(machineDTO))); + assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction( + machineDTO.code)); + + machineDTO.criterionSatisfactions.clear(); + machineDTO.criterionSatisfactions.add( // Criterion null. + new CriterionSatisfactionDTO(ct.getName() , null, + Calendar.getInstance().getTime(), null)); + assertOneConstraintViolation( + resourceService.addResources(createResourceListDTO(machineDTO))); + assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction( + machineDTO.code)); + + } + @Test @NotTransactional public void testAddResourceWithCriterionSatisfactionsWithoutStartDate() { diff --git a/scripts/rest-clients/resources-sample.xml b/scripts/rest-clients/resources-sample.xml index 2e532f355..c793c1937 100644 --- a/scripts/rest-clients/resources-sample.xml +++ b/scripts/rest-clients/resources-sample.xml @@ -14,8 +14,8 @@ @@ -52,4 +52,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +