Author: bleny Date: 2013-04-18 16:46:51 +0200 (Thu, 18 Apr 2013) New Revision: 116 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: checks that affectation are well managed Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-04-18 14:46:31 UTC (rev 115) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-04-18 14:46:51 UTC (rev 116) @@ -259,10 +259,20 @@ log.info("no order to execute found: there is something to do but driver license is required"); } - findOrderToExecuteResult.setDriverLicenseRequired(driverLicenseRequired); + if (somethingIsAvailable) { - findOrderToExecuteResult.setEverythingUnavailable( ! somethingIsAvailable); + Preconditions.checkState(driverLicenseRequired); + findOrderToExecuteResult.setDriverLicenseRequired(driverLicenseRequired); + + } else { + + Preconditions.checkState( ! driverLicenseRequired); + + findOrderToExecuteResult.setEverythingUnavailable(true); + + } + } } Modified: trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java =================================================================== --- trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java 2013-04-18 14:46:31 UTC (rev 115) +++ trunk/magalie-services/src/test/java/com/franciaflex/magalie/services/service/RequestedArticleServiceTest.java 2013-04-18 14:46:51 UTC (rev 116) @@ -4,6 +4,7 @@ import com.franciaflex.magalie.persistence.entity.MagalieUser; import com.franciaflex.magalie.persistence.entity.RequestedArticle; import com.franciaflex.magalie.services.AbstractMagalieServiceTest; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -150,4 +151,53 @@ } + @Test + public void testFindOrderAffectations() { + + FindOrderToExecuteResult orderToExecute; + + // user is affected to first list, must know new affectation + { + orderToExecute = service.findOrderToExecute(magalieUser, building); + Preconditions.checkState(orderToExecute.isSuccess()); + + Assert.assertNull(orderToExecute.getOldAffectation()); + Assert.assertNotNull(orderToExecute.getNewAffectation()); + + } + + // continuing first list, user affectation not changed + { + orderToExecute = service.findOrderToExecute(magalieUser, building); + Preconditions.checkState(orderToExecute.isSuccess()); + + Assert.assertNull(orderToExecute.getOldAffectation()); + Assert.assertNull(orderToExecute.getNewAffectation()); + + } + + // first list is finished, must know old affectation and new affectation + { + orderToExecute = service.findOrderToExecute(magalieUser, building); + Preconditions.checkState(orderToExecute.isSuccess()); + + Assert.assertNotNull(orderToExecute.getOldAffectation()); + Assert.assertNotNull(orderToExecute.getNewAffectation()); + Assert.assertNotEquals( + orderToExecute.getOldAffectation().getRequestedList(), + orderToExecute.getNewAffectation().getRequestedList()); + + } + + { + orderToExecute = service.findOrderToExecute(magalieUser, building); + Preconditions.checkState(orderToExecute.isSuccess()); + + Assert.assertNull(orderToExecute.getOldAffectation()); + Assert.assertNull(orderToExecute.getNewAffectation()); + + } + + } + }