Package org.libreplan.business.costcategories.entities

Examples of org.libreplan.business.costcategories.entities.CostCategory


    }

    @Transactional(readOnly = true)
    private CostCategory getFromDB(Long id) {
        try {
            CostCategory result = costCategoryDAO.find(id);
            forceLoadEntities(result);
            return result;
        } catch (InstanceNotFoundException e) {
            throw new RuntimeException(e);
        }
View Full Code Here


    public void testInSpringContainer() {
        assertNotNull(costCategoryDAO);
    }

    private CostCategory createValidCostCategory() {
        CostCategory costCategory = CostCategory.create(UUID.randomUUID().toString());
        return costCategory;
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testSaveCostCategory() {
        CostCategory costCategory = createValidCostCategory();
        costCategoryDAO.save(costCategory);
        assertTrue(costCategory.getId() != null);
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testRemoveCostCategory() throws InstanceNotFoundException {
        CostCategory costCategory = createValidCostCategory();
        costCategoryDAO.save(costCategory);
        costCategoryDAO.remove(costCategory.getId());
        assertFalse(costCategoryDAO.exists(costCategory.getId()));
    }
View Full Code Here

    @Test
    @Transactional
    public void testListCostCategories() {
        int previous = costCategoryDAO.list(CostCategory.class).size();
        CostCategory costCategory = createValidCostCategory();
        costCategoryDAO.save(costCategory);
        List<CostCategory> list = costCategoryDAO.list(CostCategory.class);
        assertEquals(previous + 1, list.size());
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testCanAddHourCost() {
        CostCategory costCategory = createValidCostCategory();
        TypeOfWorkHours type1 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type1.setDefaultPrice(BigDecimal.TEN);
        typeOfWorkHoursDAO.save(type1);
        HourCost hourCost1 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost1.setType(type1);
        hourCost1.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost1);

        HourCost hourCost2 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost2.setType(type1);
        hourCost2.setEndDate(new LocalDate(2009, 11,10));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,11,1));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,11,10));
        hourCost2.setEndDate(new LocalDate(2009,11,10));
        assertFalse(costCategory.canAddHourCost(hourCost2));

        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,10,20));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        TypeOfWorkHours type2 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type2.setDefaultPrice(BigDecimal.TEN);
        typeOfWorkHoursDAO.save(type2);
        hourCost2.setType(type2);
        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(new LocalDate(2009,11,1));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        hourCost2.setType(type1);
        hourCost2.setInitDate(new LocalDate(2009,10,15));
        hourCost2.setEndDate(null);
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setInitDate(new LocalDate(2009,11,9));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setInitDate(new LocalDate(2009,11,11));
        assertTrue(costCategory.canAddHourCost(hourCost2));

        hourCost1.setEndDate(null);
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost2.setEndDate(new LocalDate(2009,11,30));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost1.setEndDate(new LocalDate(2009,11,20));
        assertFalse(costCategory.canAddHourCost(hourCost2));
        hourCost1.setEndDate(new LocalDate(2009,12,1));
        assertTrue(costCategory.canAddHourCost(hourCost2));
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testListHourCosts() {
        CostCategory costCategory = createValidCostCategory();
        HourCost hourCost = HourCost.create(BigDecimal.ONE, new LocalDate(2009,11,1));
        TypeOfWorkHours type =
            TypeOfWorkHours.create(UUID.randomUUID().toString(), UUID.randomUUID().toString());
        hourCost.setType(type);
        int previous = costCategory.getHourCosts().size();

        costCategory.addHourCost(hourCost);
        costCategoryDAO.save(costCategory);
        assertEquals(previous + 1, costCategory.getHourCosts().size());

        costCategory.removeHourCost(hourCost);
        costCategoryDAO.save(costCategory);
        assertEquals(previous, costCategory.getHourCosts().size());
        assertNull(hourCost.getCategory());
    }
View Full Code Here

    }

    @Test(expected=ValidationException.class)
    @Transactional
    public void testHourCostsOverlap() {
        CostCategory costCategory = createValidCostCategory();
        TypeOfWorkHours type1 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type1.setDefaultPrice(BigDecimal.TEN);
        TypeOfWorkHours type2 = TypeOfWorkHours.create(UUID.randomUUID().toString(),
                UUID.randomUUID().toString());
        type2.setDefaultPrice(BigDecimal.TEN);
        //types have to be saved before using them
        //otherwise, the overlapping validation will fail
        typeOfWorkHoursDAO.save(type1);
        typeOfWorkHoursDAO.save(type2);

        HourCost hourCost1 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost1.setType(type1);
        hourCost1.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost1);

        HourCost hourCost2 = HourCost.create(BigDecimal.ONE, new LocalDate(2009, 11,1));
        hourCost2.setType(type2);
        hourCost2.setEndDate(new LocalDate(2009, 11,10));
        costCategory.addHourCost(hourCost2);

        //this save is correct
        costCategoryDAO.save(costCategory);

        hourCost2.setType(type1);
View Full Code Here

        for (HoursGroup hoursGroup : getHoursGroups()) {
            hours = new BigDecimal(hoursGroup.getWorkingHours());

            for (CriterionRequirement crit : hoursGroup
                    .getCriterionRequirements()) {
                CostCategory costcat = crit.getCriterion().getCostCategory();

                if (costcat != null) {

                    IHourCostDAO hourCostDAO = Registry.getHourCostDAO();
                    costPerHour = hourCostDAO.getPriceCostFromCriterionAndType(
View Full Code Here

        assertTrue(costCategoryDAO.existsByCode(cc2.code));
        assertTrue(costCategoryDAO.existsByCode(cc3.code));
        assertFalse(costCategoryDAO.existsByCode(cc4.code));

        try {
            CostCategory costCategory = costCategoryDAO.findByCode(cc3.code);
            assertTrue(costCategory.getHourCosts().size() == 1);
        } catch (InstanceNotFoundException e) {
            assertTrue(false);
        }
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.costcategories.entities.CostCategory

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.