From ff2e2c5b0cc81d544e02f8fa32c2f81b29513e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Wed, 2 Dec 2009 20:58:44 +0100 Subject: [PATCH] ItEr37S12CUAdministracionCategoriaCosteItEr36S14: basic implementation of the entity ResourcesCostCategoryAssignment Implemented the entity, its DAO and a basic test. --- .../IResourcesCostCategoryAssignmentDAO.java | 31 +++++++ .../ResourcesCostCategoryAssignmentDAO.java | 37 ++++++++ .../ResourcesCostCategoryAssignment.java | 61 ++++++++++++ .../entities/CostCategories.hbm.xml | 13 +++ ...esourcesCostCategoryAssignmentDAOTest.java | 92 +++++++++++++++++++ 5 files changed, 234 insertions(+) create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/IResourcesCostCategoryAssignmentDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/ResourcesCostCategoryAssignmentDAO.java create mode 100644 navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/ResourcesCostCategoryAssignment.java create mode 100644 navalplanner-business/src/test/java/org/navalplanner/business/test/costcategories/daos/ResourcesCostCategoryAssignmentDAOTest.java diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/IResourcesCostCategoryAssignmentDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/IResourcesCostCategoryAssignmentDAO.java new file mode 100644 index 000000000..e4a7589bc --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/IResourcesCostCategoryAssignmentDAO.java @@ -0,0 +1,31 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.business.costcategories.daos; + +import org.navalplanner.business.common.daos.IGenericDAO; +import org.navalplanner.business.costcategories.entities.ResourcesCostCategoryAssignment; + +/** + * @author Jacobo Aragunde Perez + */ +public interface IResourcesCostCategoryAssignmentDAO extends IGenericDAO { + +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/ResourcesCostCategoryAssignmentDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/ResourcesCostCategoryAssignmentDAO.java new file mode 100644 index 000000000..3dfb8e998 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/daos/ResourcesCostCategoryAssignmentDAO.java @@ -0,0 +1,37 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.business.costcategories.daos; + +import org.navalplanner.business.common.daos.GenericDAOHibernate; +import org.navalplanner.business.costcategories.entities.ResourcesCostCategoryAssignment; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; + +/** + * @author Jacobo Aragunde Perez + */ +@Repository +@Scope(BeanDefinition.SCOPE_SINGLETON) +public class ResourcesCostCategoryAssignmentDAO extends + GenericDAOHibernate implements + IResourcesCostCategoryAssignmentDAO { +} diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/ResourcesCostCategoryAssignment.java b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/ResourcesCostCategoryAssignment.java new file mode 100644 index 000000000..7d32d4588 --- /dev/null +++ b/navalplanner-business/src/main/java/org/navalplanner/business/costcategories/entities/ResourcesCostCategoryAssignment.java @@ -0,0 +1,61 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.business.costcategories.entities; + +import org.hibernate.validator.NotNull; +import org.joda.time.LocalDate; +import org.navalplanner.business.common.BaseEntity; + +/** + * @author Jacobo Aragunde Perez + */ +public class ResourcesCostCategoryAssignment extends BaseEntity { + + @NotNull + private LocalDate initDate; + + private LocalDate endDate; + + // Default constructor, needed by Hibernate + protected ResourcesCostCategoryAssignment() { + + } + + public static ResourcesCostCategoryAssignment create() { + return (ResourcesCostCategoryAssignment) create(new ResourcesCostCategoryAssignment()); + } + + public LocalDate getInitDate() { + return initDate; + } + + public void setInitDate(LocalDate initDate) { + this.initDate = initDate; + } + + public LocalDate getEndDate() { + return endDate; + } + + public void setEndDate(LocalDate endDate) { + this.endDate = endDate; + } +} diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml index 24bcf3826..079c81572 100644 --- a/navalplanner-business/src/main/resources/org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml +++ b/navalplanner-business/src/main/resources/org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml @@ -61,4 +61,17 @@ + + + + + 100 + + + + + + + + diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/costcategories/daos/ResourcesCostCategoryAssignmentDAOTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/costcategories/daos/ResourcesCostCategoryAssignmentDAOTest.java new file mode 100644 index 000000000..f4d1d1903 --- /dev/null +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/costcategories/daos/ResourcesCostCategoryAssignmentDAOTest.java @@ -0,0 +1,92 @@ +/* + * This file is part of ###PROJECT_NAME### + * + * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e + * Desenvolvemento Tecnolóxico de Galicia + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.business.test.costcategories.daos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE; +import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE; + +import java.util.List; + +import org.joda.time.LocalDate; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.navalplanner.business.common.exceptions.InstanceNotFoundException; +import org.navalplanner.business.costcategories.daos.IResourcesCostCategoryAssignmentDAO; +import org.navalplanner.business.costcategories.entities.ResourcesCostCategoryAssignment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, + BUSINESS_SPRING_CONFIG_TEST_FILE }) +/** + * Test for {@ResourcesCostCategoryDAO} + * + * @author Jacobo Aragunde Perez + * + */ +@Transactional +public class ResourcesCostCategoryAssignmentDAOTest { + + @Autowired + IResourcesCostCategoryAssignmentDAO resourcesCostCategoryAssignmentDAO; + + @Test + public void testInSpringContainer() { + assertNotNull(resourcesCostCategoryAssignmentDAO); + } + + private ResourcesCostCategoryAssignment createValidResourcesCostCategoryAssignment() { + ResourcesCostCategoryAssignment assignment = ResourcesCostCategoryAssignment.create(); + assignment.setInitDate(new LocalDate()); + return assignment; + } + + @Test + public void testSaveResourcesCostCategoryAssignment() { + ResourcesCostCategoryAssignment assignment = createValidResourcesCostCategoryAssignment(); + resourcesCostCategoryAssignmentDAO.save(assignment); + assertTrue(assignment.getId() != null); + } + + @Test + public void testRemoveResourcesCostCategoryAssignment() throws InstanceNotFoundException { + ResourcesCostCategoryAssignment assignment = createValidResourcesCostCategoryAssignment(); + resourcesCostCategoryAssignmentDAO.save(assignment); + resourcesCostCategoryAssignmentDAO.remove(assignment.getId()); + assertFalse(resourcesCostCategoryAssignmentDAO.exists(assignment.getId())); + } + + @Test + public void testListResourcesCostCategoryAssignments() { + int previous = resourcesCostCategoryAssignmentDAO.list(ResourcesCostCategoryAssignment.class).size(); + ResourcesCostCategoryAssignment assignment = createValidResourcesCostCategoryAssignment(); + resourcesCostCategoryAssignmentDAO.save(assignment); + List list = resourcesCostCategoryAssignmentDAO.list(ResourcesCostCategoryAssignment.class); + assertEquals(previous + 1, list.size()); + } +}