XMLGregorianCalendar endDate = initDate;
final HourCostDTO cc1_1_HourCostDTO = new HourCostDTO(hourCostCode,
new BigDecimal(3), initDate, endDate, typeOfWorkHoursCodeA);
cc1_HourCostDTOs.add(cc1_1_HourCostDTO);
final CostCategoryDTO cc1 = new CostCategoryDTO(costCategoryCode,
"newCC1",
true, cc1_HourCostDTOs);
CostCategoryListDTO costCategoryListDTO = createCostCategoryListDTO(cc1);
List<InstanceConstraintViolationsDTO> instanceConstraintViolationsList = costCategoryService
.addCostCategories(costCategoryListDTO).instanceConstraintViolationsList;
transactionService.runOnTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
costCategoryDAO.flush();
hourCostDAO.flush();
return null;
}
});
/* Test. */
assertTrue(instanceConstraintViolationsList.toString(),
instanceConstraintViolationsList.size() == 0);
transactionService.runOnTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
assertTrue(costCategoryDAO.existsByCode(cc1.code));
return null;
}
});
final CostCategory costCategory = transactionService
.runOnTransaction(new IOnTransaction<CostCategory>() {
@Override
public CostCategory execute() {
CostCategory cost;
try {
cost = costCategoryDAO.findByCode(cc1.code);
cost.getHourCosts().size();
return cost;
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
}
});
assertTrue(costCategory.getHourCosts().size() == 1);
final HourCost hourCost = transactionService
.runOnTransaction(new IOnTransaction<HourCost>() {
@Override
public HourCost execute() {
try {
HourCost cost = hourCostDAO
.findByCode(hourCostCode);
cost.getType().getCode();
return cost;
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
}
});
LocalDate currentDate = LocalDate.fromDateFields(new Date());
assertTrue(hourCost.getInitDate().compareTo(currentDate) == 0);
assertFalse(hourCost.getEndDate() == null);
assertTrue(hourCost.getEndDate().compareTo(hourCost.getInitDate()) == 0);
assertTrue(hourCost.getPriceCost().compareTo(new BigDecimal(3)) == 0);
assertTrue(hourCost.getType().getCode().equalsIgnoreCase(
typeOfWorkHoursCodeA));
transactionService.runOnTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
costCategoryDAO.flush();
sessionFactory.getCurrentSession().evict(costCategory);
return null;
}
});
costCategory.dontPoseAsTransientObjectAnymore();
// Update the previous cost category
Set<HourCostDTO> cc2_HourCostDTOs = new HashSet<HourCostDTO>();
XMLGregorianCalendar initDate2 = DateConverter
.toXMLGregorianCalendar(new Date());
XMLGregorianCalendar endDate2 = DateConverter
.toXMLGregorianCalendar(getNextMonthDate());
HourCostDTO cc2_1_HourCostDTO = new HourCostDTO(hourCostCode,
new BigDecimal(100), initDate2, endDate2, typeOfWorkHoursCodeB);
cc2_HourCostDTOs.add(cc2_1_HourCostDTO);
CostCategoryDTO cc2 = new CostCategoryDTO(costCategoryCode,
"updateCC1", false, cc2_HourCostDTOs);
/* Cost category type list. */
costCategoryListDTO = createCostCategoryListDTO(cc2);