ItEr24S10CUAsignacionCalendarioLaboralRecursoItEr23S13: Testing save a resource with one calendar.
This commit is contained in:
parent
181ce61436
commit
d71d3cdc19
2 changed files with 76 additions and 2 deletions
|
|
@ -17,8 +17,9 @@
|
|||
<one-to-many class="CriterionSatisfaction"/>
|
||||
</set>
|
||||
|
||||
<one-to-one name="calendar" access="field"
|
||||
class="org.navalplanner.business.calendars.entities.ResourceCalendar"/>
|
||||
<many-to-one name="calendar" access="field" cascade="all"
|
||||
class="org.navalplanner.business.calendars.entities.ResourceCalendar"
|
||||
unique="true" />
|
||||
|
||||
<joined-subclass name="org.navalplanner.business.resources.entities.Worker">
|
||||
<key column="WORKER_ID"/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package org.navalplanner.business.test.resources.daos;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test cases for {@link ResourceDAOTest}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class ResourceDAOTest {
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Test
|
||||
public void saveResourceWithCalendar() throws InstanceNotFoundException {
|
||||
Resource resource = givenValidWorker();
|
||||
ResourceCalendar resourceCalendar = givenValidResourceCalendar();
|
||||
|
||||
resource.setCalendar(resourceCalendar);
|
||||
|
||||
resourceDAO.save(resource);
|
||||
resourceDAO.flush();
|
||||
sessionFactory.getCurrentSession().evict(resource);
|
||||
|
||||
Resource foundResource = resourceDAO.find(resource.getId());
|
||||
assertNotSame(resource, foundResource);
|
||||
assertNotNull(foundResource.getCalendar().getId());
|
||||
assertThat(foundResource.getCalendar().getId(),
|
||||
equalTo(resourceCalendar.getId()));
|
||||
}
|
||||
|
||||
private ResourceCalendar givenValidResourceCalendar() {
|
||||
ResourceCalendar resourceCalendar = ResourceCalendar.create();
|
||||
resourceCalendar.setName("Calendar");
|
||||
return resourceCalendar;
|
||||
}
|
||||
|
||||
private Worker givenValidWorker() {
|
||||
Worker worker = Worker.create();
|
||||
worker.setFirstName("First name");
|
||||
worker.setSurname("Surname");
|
||||
worker.setNif("NIF");
|
||||
worker.setDailyHours(8);
|
||||
return worker;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue