diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java index 6ec3fa38f..9d0a370df 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java @@ -29,7 +29,6 @@ public abstract class Resource { private Long id; - @SuppressWarnings("unused") private long version; private Set criterionSatisfactions = new HashSet(); @@ -40,6 +39,10 @@ public abstract class Resource { public abstract int getDailyCapacity(); + public long getVersion() { + return version; + } + /** * It removes the resource from the database and updates references. The * default implementation removes the resource from the resource group it diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/CriterionServiceTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/CriterionServiceTest.java index 584b5181c..d7a1d4b86 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/CriterionServiceTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/CriterionServiceTest.java @@ -1,5 +1,13 @@ 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.UUID; @@ -28,14 +36,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 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}
* @author Óscar González Fernández @@ -308,12 +308,12 @@ public class CriterionServiceTest { assertTrue(criterions.contains(one)); } - private ICriterionType createTypeThatMatches( + public static ICriterionType createTypeThatMatches( final Criterion criterion) { return createTypeThatMatches(false, criterion); } - private ICriterionType createTypeThatMatches( + public static ICriterionType createTypeThatMatches( final boolean allowMultipleActiveCriterionsPerResource, final Criterion criterion) { return new ICriterionType() { diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java index b8af91a52..1e9e387b1 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java @@ -1,5 +1,15 @@ 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.InvalidStateException; import org.hibernate.validator.InvalidValue; @@ -7,10 +17,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.navalplanner.business.common.exceptions.InstanceNotFoundException; 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.ICriterionType; import org.navalplanner.business.resources.entities.Resource; 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.test.resources.daos.CriterionDAOTest; import org.navalplanner.business.test.resources.entities.CriterionTest; import org.springframework.beans.factory.annotation.Autowired; 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.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 ResourceService. The service and the * resource DAOs are autowired. @@ -42,6 +50,9 @@ public class ResourceServiceTest { @Autowired private IResourceDao resourceDao; + @Autowired + private CriterionService criterionService; + @Test 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 type = CriterionServiceTest + .createTypeThatMatches(criterion); + worker1.activate(new CriterionWithItsType(type, criterion)); + resourceService.saveResource(worker1); + assertThat(worker1.getVersion(), not(equalTo(versionValueAfterSave))); + } + public void testResourcesSatisfying() { Worker worker1 = new Worker("worker-1", "worker-2-surname", "11111111A", 8);