// check out the resource
Worker worker = givenSavedValidWorker();
// add line 1 with a resource
LocalDate today = new LocalDate();
ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 1", today,
orderElement);
line1.setResource(worker);
line1.setExpenseSheet(expense);
expense.add(line1);
// add line 2 without resource
LocalDate tomorrow = new LocalDate().plusDays(1);
ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 2", tomorrow,
orderElement);
line2.setExpenseSheet(expense);
expense.add(line2);
try {
expenseSheetDAO.save(expense);
expenseSheetDAO.flush();
} catch (ValidationException e) {
fail("it must not throw a exception");
}
assertThat(expenseSheetDAO.getAll().size(), equalTo(previousExpenses + 1));
// check out the expense sheet
ExpenseSheet expenseSheet = expenseSheetDAO.getAll().get(previousExpenses);
assertNotNull(expenseSheet.getCode());
assertThat(expenseSheet.getCode(), equalTo("code-expense-sheet-1"));
assertThat(expenseSheet.getTotal(), equalTo(new BigDecimal(2)));
assertThat(expenseSheet.getFirstExpense(), equalTo(today));
assertThat(expenseSheet.getLastExpense(), equalTo(tomorrow));
assertThat(expenseSheet.getExpenseSheetLines().size(), equalTo(2));
// check out the expense sheet lines
ExpenseSheetLine savedLine1 = expenseSheet.getExpenseSheetLines().last();
ExpenseSheetLine savedLine2 = expenseSheet.getExpenseSheetLines().first();
assertThat(savedLine1.getConcept(), equalTo("concept 1"));
assertThat(savedLine1.getDate(), equalTo(today));
assertThat(savedLine1.getValue(), equalTo(BigDecimal.ONE));
assertNotNull(savedLine1.getOrderElement());
assertNotNull(savedLine1.getResource());
assertNotNull(savedLine1.getCode());
assertThat(savedLine2.getConcept(), equalTo("concept 2"));
assertThat(savedLine2.getDate(), equalTo(tomorrow));
assertThat(savedLine2.getValue(), equalTo(BigDecimal.ONE));
assertNotNull(savedLine2.getOrderElement());
assertNotNull(savedLine2.getCode());
}