Package org.libreplan.business.expensesheet.entities

Examples of org.libreplan.business.expensesheet.entities.ExpenseSheet


    }

    @Test(expected = ValidationException.class)
    @Transactional
    public void invalidExpenseSheetWithoutLines() {
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode("UUID.randomUUID().toString()");

        try {
            expenseSheetDAO.save(expense);
            expenseSheetDAO.flush();
            fail("it must throw a exception because the total is empty");
        } catch (ValidationException e) {
        }

        expense.updateTotal();

        expenseSheetDAO.save(expense);
        expenseSheetDAO.flush();
        fail("it must throw a exception because the expense sheet has not lines");
    }
View Full Code Here


    @Test(expected = ValidationException.class)
    @Transactional
    public void validExpenseSheetWithInvalidExpenseSheetLineData() {
        // check out the expenseSheet without lines
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode("code-expense-sheet-1");

        // order element empty
        OrderElement orderElement = null;

        // a expense sheet with valid value,date but without order element.
        ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ZERO, "concept",
                new LocalDate(), orderElement);

        line1.setExpenseSheet(expense);
        expense.add(line1);

        expenseSheetDAO.save(expense);
        expenseSheetDAO.flush();
        fail("it must throw a exception. The order element not specified");
    }
View Full Code Here

    @Test
    @Transactional
    public void validExpenseSheetWithInvalidValuesInLines() {
        // create the expenseSheet without lines
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode("code-expense-sheet-1");

        // order element empty
        OrderElement orderElement = this.givenOrderElement("order-element-2");

        // a expense sheet with valid date and order element, but invalid value.
        ExpenseSheetLine line1 = ExpenseSheetLine.create(null, "concept", new LocalDate(),
                orderElement);

        // add the line to the expense sheet
        line1.setExpenseSheet(expense);
        expense.add(line1);

        try {
            expenseSheetDAO.save(expense);
            fail("it must throw a exception. The value is not specified in the expense sheet line.");
        } catch (ValidationException e) {
        }

        line1.setValue(new BigDecimal(-3));

        try {
            expenseSheetDAO.save(expense);
            fail("it must throw a exception. The total is invalid because it is less than 0.");
        } catch (ValidationException e) {
        }

        ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.TEN, "concept",
                new LocalDate(), orderElement);

        // add other line to the expense sheet
        line2.setExpenseSheet(expense);
        expense.add(line2);

        try {
            expenseSheetDAO.save(expense);
            fail("it must throw a exception. The value of the line 1 is invalid because it is less than 0.");
        } catch (ValidationException e) {
        }

        // but if you change the value
        line1.setValue(BigDecimal.ONE);

        try {
            expenseSheetDAO.save(expense);
            assertThat(expense.getTotal(), equalTo(new BigDecimal(11)));
        } catch (ValidationException e) {
            fail("it must not throw a exception.");
        }
    }
View Full Code Here

    @Test
    @Transactional
    public void validExpenseSheetWithInvalidDateInLines() {
        // create the expenseSheet without lines
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode("code-expense-sheet-1");

        // order element empty
        OrderElement orderElement = this.givenOrderElement("order-element-2");

        // a expense sheet with valid date and order element, but invalid value.
        ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept", null,
                orderElement);

        // add the line to the expense sheet
        line1.setExpenseSheet(expense);
        expense.add(line1);

        try {
            expenseSheetDAO.save(expense);
            fail("it must throw a exception. The date is not specified in the expense sheet line.");
        } catch (ValidationException e) {
        }

        LocalDate today = new LocalDate();
        line1.setDate(today);

        assertThat(expense.getFirstExpense(), equalTo(today));
        assertThat(expense.getLastExpense(), equalTo(today));

        // add other line with other date
        LocalDate tomorrow = new LocalDate().plusDays(1);
        ExpenseSheetLine line2 = ExpenseSheetLine.create(BigDecimal.ONE, "concept", tomorrow,
                orderElement);
        line2.setExpenseSheet(expense);
        expense.add(line2);

        assertThat(expense.getFirstExpense(), equalTo(today));
        assertThat(expense.getLastExpense(), equalTo(tomorrow));

        try {
            expenseSheetDAO.save(expense);
        } catch (ValidationException e) {
            fail("it must not throw a exception.");
View Full Code Here

    @Test
    @Transactional
    public void validExpenseSheetData() {
        // check out the expenseSheet without lines
        int previousExpenses = expenseSheetDAO.getAll().size();
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode("code-expense-sheet-1");

        // check out the order element
        String orderLineCode = "order-line-code";
        OrderElement orderElement = givenSavedOrderElement(orderLineCode);

        // 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());
View Full Code Here

        // create a valid order element
        String orderLineCode = "order-line-code";
        OrderElement orderElement = givenSavedOrderElement(orderLineCode);

        ExpenseSheet expense = getValidExpenseSheet("code-expense-sheet-1", orderElement);
        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"));

        // create other expense sheet with one line

        ExpenseSheet expense2 = getValidExpenseSheet("code-expense-sheet-1", orderElement);
        try {
            expenseSheetDAO.save(expense2);
            expenseSheetDAO.flush();
            fail("it must throw a exception");
        } catch (Exception e) {
View Full Code Here

        }
    }

    private ExpenseSheet getValidExpenseSheet(String code, OrderElement orderElement) {
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode(code);

        // add line 1
        LocalDate today = new LocalDate();
        ExpenseSheetLine line1 = ExpenseSheetLine.create(BigDecimal.ONE, "concept 1", today,
                orderElement);
        line1.setExpenseSheet(expense);
        expense.add(line1);
        return expense;
    }
View Full Code Here

        // create a valid order element
        String orderLineCode = "order-line-code";
        OrderElement orderElement = givenSavedOrderElement(orderLineCode);

        ExpenseSheet expense = getValidExpenseSheet("code-expense-sheet-1", orderElement);
        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"));

        // create other expense sheet with one line

        ExpenseSheet expense2 = getValidExpenseSheet("code-expense-sheet-2", orderElement);
        try {
            expenseSheetDAO.save(expense2);
            expenseSheetDAO.flush();
        } catch (ValidationException e) {
            fail("it must not throw a exception");
        }

        assertThat(expenseSheetDAO.getAll().size(), equalTo(previousExpenses + 2));

        // check out the expense sheet
        try {
            ExpenseSheet expenseSheet2 = expenseSheetDAO.findByCode("code-expense-sheet-2");
            assertNotNull(expenseSheet2);
            assertThat(expenseSheet2.getExpenseSheetLines().size(), equalTo(1));
        } catch (InstanceNotFoundException e) {
            fail("it must not throw a exception");
        }
    }
View Full Code Here

    }

    @Test(expected = ValidationException.class)
    @Transactional
    public void testSaveExpenseSheetWithoutCode() {
        ExpenseSheet expense = ExpenseSheet.create();
        expense.setCode(null);
        try {
        expenseSheetDAO.save(expense);
        } catch (DataIntegrityViolationException e) {
            throw new ValidationException(e.getMessage());
        }
View Full Code Here

        // create a valid order element
        String orderLineCode = "order-line-code";
        OrderElement orderElement = givenSavedOrderElement(orderLineCode);

        ExpenseSheet expense = getValidExpenseSheet("code-expense-sheet-1", orderElement);
        try {
            expenseSheetDAO.save(expense);
            expenseSheetDAO.flush();
        } catch (ValidationException e) {
            fail("it must not throw a exception");
        }

        assertThat(expenseSheetDAO.getAll().size(), equalTo(previousExpenses + 1));
        assertThat(expenseSheetLineDAO.findAll().size(), equalTo(previousExpenseLines + 1));

        expenseSheetDAO.remove(expense.getId());
        expenseSheetDAO.flush();

        assertThat(expenseSheetDAO.getAll().size(), equalTo(previousExpenses));
        assertThat(expenseSheetLineDAO.findAll().size(), equalTo(previousExpenseLines));
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.expensesheet.entities.ExpenseSheet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.