ItEr41S15CUImportacionRecursosProductivosItEr40S20: Resource validations propagaged to CriterionSatisfactions.
@Valid has been specified in Resource::getCriterionSatisfactions. A test case has been added to verify a validation constraint is generated when a resource containing a criterion satisfaction without start date is being imported with the REST service (@Valid annotation is necessary).
This commit is contained in:
parent
746ce17bf1
commit
523aa46263
3 changed files with 45 additions and 0 deletions
|
|
@ -106,6 +106,8 @@ public abstract class Resource extends BaseEntity{
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Valid
|
||||||
public Set<CriterionSatisfaction> getCriterionSatisfactions() {
|
public Set<CriterionSatisfaction> getCriterionSatisfactions() {
|
||||||
Set<CriterionSatisfaction> satisfactionActives =
|
Set<CriterionSatisfaction> satisfactionActives =
|
||||||
new HashSet<CriterionSatisfaction>();
|
new HashSet<CriterionSatisfaction>();
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,39 @@ public class ResourceServiceTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@NotTransactional
|
||||||
|
public void testAddResourceWithCriterionSatisfactionsWithoutStartDate() {
|
||||||
|
|
||||||
|
/* Create a criterion type. */
|
||||||
|
CriterionType ct = createCriterionType();
|
||||||
|
|
||||||
|
/* Create a resource DTO. */
|
||||||
|
MachineDTO machineDTO = new MachineDTO(ct.getName(), "name", "desc");
|
||||||
|
machineDTO.criterionSatisfactions.add(
|
||||||
|
new CriterionSatisfactionDTO(ct.getName() , "c1",
|
||||||
|
null, Calendar.getInstance().getTime())); // Missing start date.
|
||||||
|
|
||||||
|
/* Test. */
|
||||||
|
List<ResourceDTO> resources = new ArrayList<ResourceDTO>();
|
||||||
|
resources.add(machineDTO);
|
||||||
|
|
||||||
|
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList =
|
||||||
|
resourceService.addResources(new ResourceListDTO(resources)).
|
||||||
|
instanceConstraintViolationsList;
|
||||||
|
|
||||||
|
assertTrue(instanceConstraintViolationsList.size() == 1);
|
||||||
|
assertTrue(instanceConstraintViolationsList.get(0).
|
||||||
|
constraintViolations.size() == 1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
findUniqueMachineByCode(machineDTO.code);
|
||||||
|
fail("InstanceNotFoundException expected");
|
||||||
|
} catch (InstanceNotFoundException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@NotTransactional
|
@NotTransactional
|
||||||
public void testAddResourceWithCriterionSatisfactionsWithIncorrectNames() {
|
public void testAddResourceWithCriterionSatisfactionsWithIncorrectNames() {
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,14 @@
|
||||||
<!-- Missing first name, surname, and nif. -->
|
<!-- Missing first name, surname, and nif. -->
|
||||||
<worker first-name="" nif=""/>
|
<worker first-name="" nif=""/>
|
||||||
|
|
||||||
|
<!-- Missing start date in criterion satisfaction. -->
|
||||||
|
<worker first-name="w2-firstName" surname="w2-surname" nif=" w2-nif ">
|
||||||
|
<criterion-satisfaction-list>
|
||||||
|
<criterion-satisfaction
|
||||||
|
criterion-type-name="LEAVE"
|
||||||
|
criterion-name="paternityLeave"
|
||||||
|
finish-date="2009-12-25"/>
|
||||||
|
</criterion-satisfaction-list>
|
||||||
|
</worker>
|
||||||
|
|
||||||
</resource-list>
|
</resource-list>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue