ItEr09S09AdministracionGrupos: version field is increased when adding worker.
This commit is contained in:
parent
f0eeed0ca5
commit
a86f012493
3 changed files with 61 additions and 18 deletions
|
|
@ -29,7 +29,6 @@ public abstract class Resource {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private long version;
|
private long version;
|
||||||
|
|
||||||
private Set<CriterionSatisfaction> criterionSatisfactions = new HashSet<CriterionSatisfaction>();
|
private Set<CriterionSatisfaction> criterionSatisfactions = new HashSet<CriterionSatisfaction>();
|
||||||
|
|
@ -40,6 +39,10 @@ public abstract class Resource {
|
||||||
|
|
||||||
public abstract int getDailyCapacity();
|
public abstract int getDailyCapacity();
|
||||||
|
|
||||||
|
public long getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It removes the resource from the database and updates references. The
|
* It removes the resource from the database and updates references. The
|
||||||
* default implementation removes the resource from the resource group it
|
* default implementation removes the resource from the resource group it
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
package org.navalplanner.business.test.resources.services;
|
package org.navalplanner.business.test.resources.services;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
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.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -28,14 +36,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link CriterionService} <br />
|
* Test cases for {@link CriterionService} <br />
|
||||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||||
|
|
@ -308,12 +308,12 @@ public class CriterionServiceTest {
|
||||||
assertTrue(criterions.contains(one));
|
assertTrue(criterions.contains(one));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICriterionType<Criterion> createTypeThatMatches(
|
public static ICriterionType<Criterion> createTypeThatMatches(
|
||||||
final Criterion criterion) {
|
final Criterion criterion) {
|
||||||
return createTypeThatMatches(false, criterion);
|
return createTypeThatMatches(false, criterion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICriterionType<Criterion> createTypeThatMatches(
|
public static ICriterionType<Criterion> createTypeThatMatches(
|
||||||
final boolean allowMultipleActiveCriterionsPerResource,
|
final boolean allowMultipleActiveCriterionsPerResource,
|
||||||
final Criterion criterion) {
|
final Criterion criterion) {
|
||||||
return new ICriterionType<Criterion>() {
|
return new ICriterionType<Criterion>() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
package org.navalplanner.business.test.resources.services;
|
package org.navalplanner.business.test.resources.services;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
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.validator.ClassValidator;
|
import org.hibernate.validator.ClassValidator;
|
||||||
import org.hibernate.validator.InvalidStateException;
|
import org.hibernate.validator.InvalidStateException;
|
||||||
import org.hibernate.validator.InvalidValue;
|
import org.hibernate.validator.InvalidValue;
|
||||||
|
|
@ -7,10 +17,15 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||||
import org.navalplanner.business.resources.daos.IResourceDao;
|
import org.navalplanner.business.resources.daos.IResourceDao;
|
||||||
|
import org.navalplanner.business.resources.entities.Criterion;
|
||||||
|
import org.navalplanner.business.resources.entities.CriterionWithItsType;
|
||||||
import org.navalplanner.business.resources.entities.ICriterion;
|
import org.navalplanner.business.resources.entities.ICriterion;
|
||||||
|
import org.navalplanner.business.resources.entities.ICriterionType;
|
||||||
import org.navalplanner.business.resources.entities.Resource;
|
import org.navalplanner.business.resources.entities.Resource;
|
||||||
import org.navalplanner.business.resources.entities.Worker;
|
import org.navalplanner.business.resources.entities.Worker;
|
||||||
|
import org.navalplanner.business.resources.services.CriterionService;
|
||||||
import org.navalplanner.business.resources.services.ResourceService;
|
import org.navalplanner.business.resources.services.ResourceService;
|
||||||
|
import org.navalplanner.business.test.resources.daos.CriterionDAOTest;
|
||||||
import org.navalplanner.business.test.resources.entities.CriterionTest;
|
import org.navalplanner.business.test.resources.entities.CriterionTest;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.annotation.NotTransactional;
|
import org.springframework.test.annotation.NotTransactional;
|
||||||
|
|
@ -18,13 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
|
||||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for testing <code>ResourceService</code>. The service and the
|
* A class for testing <code>ResourceService</code>. The service and the
|
||||||
* resource DAOs are autowired.
|
* resource DAOs are autowired.
|
||||||
|
|
@ -42,6 +50,9 @@ public class ResourceServiceTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IResourceDao resourceDao;
|
private IResourceDao resourceDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CriterionService criterionService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveResource() throws InstanceNotFoundException {
|
public void testRemoveResource() throws InstanceNotFoundException {
|
||||||
|
|
||||||
|
|
@ -103,6 +114,35 @@ public class ResourceServiceTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@NotTransactional
|
||||||
|
public void versionIsIncreased() throws Exception {
|
||||||
|
Worker worker1 = new Worker("worker-1", "worker-2-surname",
|
||||||
|
"11111111A", 8);
|
||||||
|
resourceService.saveResource(worker1);
|
||||||
|
long versionValueAfterSave = worker1.getVersion();
|
||||||
|
worker1.setFirstName("blabla");
|
||||||
|
resourceService.saveResource(worker1);
|
||||||
|
assertThat(worker1.getVersion(), not(equalTo(versionValueAfterSave)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@NotTransactional
|
||||||
|
public void versionIsIncreasedWhenAddingSatisfactions()
|
||||||
|
throws Exception {
|
||||||
|
Worker worker1 = new Worker("worker-1", "worker-2-surname",
|
||||||
|
"11111111A", 8);
|
||||||
|
resourceService.saveResource(worker1);
|
||||||
|
long versionValueAfterSave = worker1.getVersion();
|
||||||
|
Criterion criterion = CriterionDAOTest.createValidCriterion();
|
||||||
|
criterionService.save(criterion);
|
||||||
|
ICriterionType<Criterion> type = CriterionServiceTest
|
||||||
|
.createTypeThatMatches(criterion);
|
||||||
|
worker1.activate(new CriterionWithItsType(type, criterion));
|
||||||
|
resourceService.saveResource(worker1);
|
||||||
|
assertThat(worker1.getVersion(), not(equalTo(versionValueAfterSave)));
|
||||||
|
}
|
||||||
|
|
||||||
public void testResourcesSatisfying() {
|
public void testResourcesSatisfying() {
|
||||||
Worker worker1 = new Worker("worker-1", "worker-2-surname",
|
Worker worker1 = new Worker("worker-1", "worker-2-surname",
|
||||||
"11111111A", 8);
|
"11111111A", 8);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue