ItEr43S08CUImportacionRecursosProductivosItEr42S12: checkConstraintPositiveTimeInterval added to CriterionSatisfaction.
This constraint checks that interval of a CriterionSatisfaction is positive. A test case has also been provided.
This commit is contained in:
parent
53d8cc7dbf
commit
56337460f9
3 changed files with 61 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ import java.util.Date;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
|
|
@ -274,17 +275,41 @@ public class CriterionSatisfaction extends BaseEntity {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* IMPORTANT: This method currently redefines BaseEntity::validate avoiding
|
||||
* Hibernate Validator to run. This should be fixed in a future.
|
||||
*/
|
||||
public void validate(){
|
||||
Validate.notNull(resource);
|
||||
Validate.notNull(startDate);
|
||||
Validate.notNull(criterion);
|
||||
Validate.isTrue(finishDate == null || finishDate.after(startDate));
|
||||
Validate.isTrue(finishDate == null || startDate.equals(finishDate)
|
||||
|| startDate.before(finishDate));
|
||||
Validate.isTrue(checkConstraintPositiveTimeInterval());
|
||||
}
|
||||
|
||||
public ResourceEnum getResourceType() {
|
||||
return criterion.getType().getResource();
|
||||
}
|
||||
|
||||
@AssertTrue(message="criterion satisfaction with end date less than start " +
|
||||
"date")
|
||||
public boolean checkConstraintPositiveTimeInterval() {
|
||||
|
||||
/* Check if it makes sense to check the constraint .*/
|
||||
if (!isStartDateSpecified()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check the constraint. */
|
||||
if (finishDate == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (finishDate.after(startDate) || startDate.equals(finishDate));
|
||||
|
||||
}
|
||||
|
||||
public boolean isStartDateSpecified() {
|
||||
return startDate != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ public class ResourceServiceTest {
|
|||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void testAddResourceWithCriterionSatisfactionsWithoutStartDate() {
|
||||
public void testAddResourceWithCriterionSatisfactionWithoutStartDate() {
|
||||
|
||||
/* Create a criterion type. */
|
||||
CriterionType ct = createCriterionType();
|
||||
|
|
@ -310,6 +310,27 @@ public class ResourceServiceTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void testAddResourceWithCriterionSatisfactionWithNegativeInterval() {
|
||||
|
||||
/* Create a criterion type. */
|
||||
CriterionType ct = createCriterionType();
|
||||
|
||||
/* Create a machine DTO. */
|
||||
MachineDTO machineDTO = new MachineDTO(getUniqueName(), "name", "desc");
|
||||
machineDTO.criterionSatisfactions.add(
|
||||
new CriterionSatisfactionDTO(ct.getName() , "c1",
|
||||
getDate(2000, 2, 1), getDate(2000, 1, 1)));
|
||||
|
||||
/* Test. */
|
||||
assertOneConstraintViolation(
|
||||
resourceService.addResources(createResourceListDTO(machineDTO)));
|
||||
assertFalse(machineDAO.existsMachineWithCodeInAnotherTransaction(
|
||||
machineDTO.code));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@NotTransactional
|
||||
public void testAddResourcesWithCriterionSatisfactionsWithIncorrectType() {
|
||||
|
|
|
|||
|
|
@ -186,4 +186,15 @@
|
|||
</resources-cost-category-assignment-list>
|
||||
</worker>
|
||||
|
||||
<!-- Missing start date in criterion satisfaction. -->
|
||||
<worker first-name="w10-firstName" surname="w10-surname" nif="w10-nif">
|
||||
<criterion-satisfaction-list>
|
||||
<criterion-satisfaction
|
||||
criterion-type-name="LEAVE"
|
||||
criterion-name="paternityLeave"
|
||||
start-date="2000-02-01"
|
||||
end-date="2000-01-01"/>
|
||||
</criterion-satisfaction-list>
|
||||
</worker>
|
||||
|
||||
</resource-list>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue