<commit_before>package org.navalplanner.business.test.planner.daos;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.planner.daos.IDayAssigmentDAO;
import org.navalplanner.business.planner.entities.DayAssigment;
import org.navalplanner.business.planner.entities.GenericDayAssigment;
import org.navalplanner.business.planner.entities.SpecificDayAssigment;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
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 })
/**
 * @author <NAME> <<EMAIL>>
 */
@Transactional
public class DayAssigmentDAOTest {

    @Autowired
    private IDayAssigmentDAO dayAssigmentDAO;

    @Autowired
    private IResourceDAO resourceDAO;

    private SpecificDayAssigment createValidSpecificDayAssigment() {
        return SpecificDayAssigment.create(new LocalDate(2009, 1, 2), 8,
                createValidResource());
    }

    private Resource createValidResource() {
        Worker worker = Worker.create("first", "surname", "1221332132A", 5);
        resourceDAO.save(worker);
        return worker;
    }

    private GenericDayAssigment createValidGenericDayAssigment() {
        return GenericDayAssigment.create(new LocalDate(2009, 1, 2), 8,
                createValidResource());
    }

    @Test
    public void testInSpringContainer() {
        assertTrue(dayAssigmentDAO != null);
    }

    @Test
    public void testSaveSpecificResourceAllocation() {
        SpecificDayAssigment dayAssigment = createValidSpecificDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        assertTrue(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test
    public void testSaveGenericResourceAllocation() {
        GenericDayAssigment dayAssigment = createValidGenericDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        assertTrue(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test
    public void testRemoveSpecificResourceAllocation()
            throws InstanceNotFoundException {
        SpecificDayAssigment dayAssigment = createValidSpecificDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        dayAssigmentDAO.remove(dayAssigment.getId());
        assertFalse(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test
    public void testRemoveGenericResourceAllocation()
            throws InstanceNotFoundException {
        GenericDayAssigment dayAssigment = createValidGenericDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        dayAssigmentDAO.remove(dayAssigment.getId());<commit_msg> ItEr25S07CUAsignacionGrupoRecursosAPlanificacionItEr24S08: Testing that the related resource must exist prior saving a DayAssignment<commit_after>package org.navalplanner.business.test.planner.daos;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.planner.daos.IDayAssigmentDAO;
import org.navalplanner.business.planner.entities.DayAssigment;
import org.navalplanner.business.planner.entities.GenericDayAssigment;
import org.navalplanner.business.planner.entities.SpecificDayAssigment;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
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 })
/**
 * @author <NAME> <<EMAIL>>
 */
@Transactional
public class DayAssigmentDAOTest {

    @Autowired
    private IDayAssigmentDAO dayAssigmentDAO;

    @Autowired
    private IResourceDAO resourceDAO;

    private SpecificDayAssigment createValidSpecificDayAssigment() {
        return SpecificDayAssigment.create(new LocalDate(2009, 1, 2), 8,
                createValidResource());
    }

    private Resource createValidResource() {
        Worker worker = Worker.create("first", "surname", "1221332132A", 5);
        resourceDAO.save(worker);
        return worker;
    }

    private GenericDayAssigment createValidGenericDayAssigment() {
        return GenericDayAssigment.create(new LocalDate(2009, 1, 2), 8,
                createValidResource());
    }

    @Test
    public void testInSpringContainer() {
        assertTrue(dayAssigmentDAO != null);
    }

    @Test
    public void testSaveSpecificResourceAllocation() {
        SpecificDayAssigment dayAssigment = createValidSpecificDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        assertTrue(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test
    public void testSaveGenericResourceAllocation() {
        GenericDayAssigment dayAssigment = createValidGenericDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        assertTrue(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test(expected = DataIntegrityViolationException.class)
    public void theRelatedResourceMustExistInOrderToSave() {
        Worker transientWorker = Worker.create("first", "surname", "1221332132A", 5);
        SpecificDayAssigment dayAssigment = SpecificDayAssigment.create(
                new LocalDate(2009, 1, 2), 8, transientWorker);
        dayAssigmentDAO.save(dayAssigment);
    }

    @Test
    public void testRemoveSpecificResourceAllocation()
            throws InstanceNotFoundException {
        SpecificDayAssigment dayAssigment = createValidSpecificDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        dayAssigmentDAO.remove(dayAssigment.getId());
        assertFalse(dayAssigmentDAO.exists(dayAssigment.getId()));
    }

    @Test
    public void testRemoveGenericResourceAllocation()
            throws InstanceNotFoundException {
        GenericDayAssigment dayAssigment = createValidGenericDayAssigment();
        dayAssigmentDAO.save(dayAssigment);
        dayAssigmentDAO.remove(dayAssigment.getId());
{'fraction_non_alphanumeric': 0.08576714682172591, 'fraction_numerical': 0.01083652702524118, 'mean_word_length': 4.694507148231753, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837266', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2222, 'n_words': 328}