Author: bleny Date: 2011-06-09 09:35:04 +0000 (Thu, 09 Jun 2011) New Revision: 1327 Log: cleaning in test ; using @Rule ; remove dead code and obsolete tests ; use abstract tests when necessary ; rename tests according to convention Added: trunk/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingTest.java Removed: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java trunk/wao-business/src/test/java/fr/ifremer/wao/business/AbstractBusinessTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFixtures.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/AbstractServiceTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ActivityCalendarImportTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java trunk/wao-business/src/test/resources/log4j.properties Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -149,20 +149,14 @@ loadConfiguration(conf); - printConfiguration(); + if (log.isTraceEnabled()) { + configuration.printConfig(); + } } catch (ArgumentsParserException eee) { treateError(eee, n_("wao.error.context.parse"), DEFAULT_FILENAME); } } - protected void printConfiguration() { - //StringWriter writer = new StringWriter(); -// PrintWriter printWriter = new PrintWriter(new StringWriter()); -// PrintStream stream = new PrintStream(); - configuration.printConfig(); -// stream. - } - protected void loadMigrationConfiguration(ApplicationConfig conf) { // migration configuration String callBackName = null; @@ -243,9 +237,6 @@ @Override public void start(ServiceUser serviceUser) { try { - if (log.isInfoEnabled()) { - log.info("Start Wao"); - } DefaultI18nInitializer defaultI18nInitializer = new DefaultI18nInitializer(getI18nBundle()); I18n.init(defaultI18nInitializer, Locale.FRENCH); setLocale(Locale.FRENCH); @@ -268,11 +259,6 @@ serviceReferential.initialImport(); serviceUser.addTokensToAllProfiles(); - - if (log.isInfoEnabled()) { - log.info("wao is started !"); - } - } catch (Exception eee) { treateError(eee, n_("wao.error.context.start")); } @@ -284,9 +270,6 @@ @Override public void stop() { try { - if (log.isInfoEnabled()) { - log.info("Stop Wao"); - } getTopiaRootContext().closeContext(); // Close Appender from ActivityCalendarAccessLogger if (activityCalendarAccessLogger != null) { Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -409,11 +409,14 @@ result.add(dcfFiveCode); } - if (log.isInfoEnabled()) { - log.info(String.format("line %s will be migrated to", dcf5Code)); + if (log.isDebugEnabled()) { + StringBuilder logMessage = new StringBuilder(); + logMessage.append("line '").append(dcf5Code) + .append("' will be migrated to"); for (String[] code : result) { - log.info(Arrays.toString(code)); + logMessage.append(" ").append(Arrays.toString(code)); } + log.debug(logMessage.toString()); } return result; } Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,159 +0,0 @@ -/* - * #%L - * Wao :: Business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao; - -import fr.ifremer.wao.service.ServiceBoat; -import fr.ifremer.wao.service.ServiceCartography; -import fr.ifremer.wao.service.ServiceChart; -import fr.ifremer.wao.service.ServiceContact; -import fr.ifremer.wao.service.ServiceNews; -import fr.ifremer.wao.service.ServiceReferential; -import fr.ifremer.wao.service.ServiceSampling; -import fr.ifremer.wao.service.ServiceSynthesis; -import fr.ifremer.wao.service.ServiceUser; -import org.junit.Ignore; -import org.nuiton.topia.TopiaException; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.util.DateUtil; -import org.nuiton.util.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Properties; - -/** - * WaoRunnerTest - * - * Created: 23 nov. 2009 - * - * @author fdesbois <fdesbois at codelutin.com> - */ - at Ignore -public class TestManager { - - private static final Logger log = LoggerFactory.getLogger(TestManager.class); - - private WaoContextImpl context; - - public void start() throws WaoException { - if (log.isDebugEnabled()) { - log.debug("## TEST START"); - } - try { - context = new WaoContextImpl(); - ApplicationConfig configuration = new ApplicationConfig(); - configuration.setOptions(loadFileProperties("WaoTest.properties")); - - context.loadConfiguration(configuration); - context.setI18nBundle("wao-business"); - - // Set currentDate to 23/10/2009 - Calendar calendar = new GregorianCalendar(2009, 9, 23); - context.setCurrentDate(calendar.getTime()); - - context.start(getServiceUser()); - } catch (Exception eee) { - context.treateError(eee, "Error during loadConfiguration from " + - "'WaoTest.properties' file"); - } - } - - public void stop() throws WaoException { - if (log.isDebugEnabled()) { - log.debug("TEST STOP : clearContext"); - } - try { - context.getTopiaRootContext().clear(true); - } catch (TopiaException eee) { - context.treateError(eee, "Error during clear database"); - } - } - - public WaoContext getContext() { - return context; - } - - protected Properties loadFileProperties(String filename) - throws URISyntaxException, IOException { - Properties props = new Properties(); - URL url = Resource.getURL(filename); - if (log.isDebugEnabled()) { - log.debug(url.toString()); - } - props.load(url.openStream()); - return props; - } - - public ServiceBoat getServiceBoat() { - return context.getServiceFactory().getServiceBoat(); - } - - public ServiceReferential getServiceReferential() { - return context.getServiceFactory().getServiceReferential(); - } - - public ServiceNews getServiceNews() { - return context.getServiceFactory().getServiceNews(); - } - - public ServiceSampling getServiceSampling() { - return context.getServiceFactory().getServiceSampling(); - } - - public ServiceSynthesis getServiceSynthesis() { - return context.getServiceFactory().getServiceSynthesis(); - } - - public ServiceUser getServiceUser() { - return context.getServiceFactory().getServiceUser(); - } - - public ServiceContact getServiceContact() { - return context.getServiceFactory().getServiceContact(); - } - - public ServiceCartography getServiceCartography() { - return context.getServiceFactory().getServiceCartography(); - } - - public ServiceChart getServiceChart() { - return context.getServiceFactory().getServiceChart(); - } - - public void setCurrentDate(Date date) { - context.setCurrentDate(date); - } - - public void setCurrentDate(int day, int month, int year) { - Date date = DateUtil.createDate(day, month, year); - setCurrentDate(date); - } -} Copied: trunk/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java (from rev 1275, trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java) =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -0,0 +1,144 @@ +/* + * #%L + * Wao :: Business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.wao; + +import fr.ifremer.wao.service.ServiceBoat; +import fr.ifremer.wao.service.ServiceCartography; +import fr.ifremer.wao.service.ServiceChart; +import fr.ifremer.wao.service.ServiceContact; +import fr.ifremer.wao.service.ServiceNews; +import fr.ifremer.wao.service.ServiceReferential; +import fr.ifremer.wao.service.ServiceSampling; +import fr.ifremer.wao.service.ServiceSynthesis; +import fr.ifremer.wao.service.ServiceUser; +import org.apache.commons.io.IOUtils; +import org.junit.Ignore; +import org.junit.rules.ExternalResource; +import org.nuiton.topia.TopiaException; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.Properties; + +/** + * WaoRunnerTest + * + * Created: 23 nov. 2009 + * + * @author fdesbois <fdesbois at codelutin.com> + */ +public class WaoServices extends ExternalResource { + + private static final Logger log = LoggerFactory.getLogger(WaoServices.class); + + private WaoContextImpl context; + + @Override + protected void before() { + InputStream input = null; + ApplicationConfig configuration; + try { + input = getClass().getResourceAsStream("/WaoTest.properties"); + Properties properties = new Properties(); + properties.load(input); + configuration = new ApplicationConfig(properties); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + IOUtils.closeQuietly(input); + } + + context = new WaoContextImpl(); + context.loadConfiguration(configuration); + context.setI18nBundle("wao-business"); + + setCurrentDate(2009, 9, 23); + + context.start(getServiceUser()); + } + + @Override + protected void after() { + try { + context.getTopiaRootContext().clear(true); + } catch (TopiaException eee) { + throw new RuntimeException(eee); + } + } + + public WaoContext getContext() { + return context; + } + + public ServiceBoat getServiceBoat() { + return context.getServiceFactory().getServiceBoat(); + } + + public ServiceReferential getServiceReferential() { + return context.getServiceFactory().getServiceReferential(); + } + + public ServiceNews getServiceNews() { + return context.getServiceFactory().getServiceNews(); + } + + public ServiceSampling getServiceSampling() { + return context.getServiceFactory().getServiceSampling(); + } + + public ServiceSynthesis getServiceSynthesis() { + return context.getServiceFactory().getServiceSynthesis(); + } + + public ServiceUser getServiceUser() { + return context.getServiceFactory().getServiceUser(); + } + + public ServiceContact getServiceContact() { + return context.getServiceFactory().getServiceContact(); + } + + public ServiceCartography getServiceCartography() { + return context.getServiceFactory().getServiceCartography(); + } + + public ServiceChart getServiceChart() { + return context.getServiceFactory().getServiceChart(); + } + + public void setCurrentDate(Date date) { + context.setCurrentDate(date); + } + + public void setCurrentDate(int day, int month, int year) { + Date date = DateUtil.createDate(day, month, year); + setCurrentDate(date); + } +} Property changes on: trunk/wao-business/src/test/java/fr/ifremer/wao/WaoServices.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/business/AbstractBusinessTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/business/AbstractBusinessTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/business/AbstractBusinessTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,6 +1,6 @@ package fr.ifremer.wao.business; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.service.ServiceBoat; import fr.ifremer.wao.service.ServiceContact; import fr.ifremer.wao.service.ServiceReferential; @@ -9,6 +9,7 @@ import fr.ifremer.wao.service.ServiceUser; import org.junit.After; import org.junit.Before; +import org.junit.Rule; /** * Business tests are integration tests that check services implementation @@ -21,7 +22,9 @@ */ public abstract class AbstractBusinessTest { - protected TestManager manager; + @Rule + public WaoServices manager = new WaoServices(); + protected ServiceUser serviceUser; protected ServiceReferential serviceReferential; protected ServiceBoat serviceBoat; @@ -31,9 +34,6 @@ @Before public void before() { - manager = new TestManager(); - manager.start(); - serviceUser = manager.getServiceUser(); serviceReferential = manager.getServiceReferential(); serviceBoat = manager.getServiceBoat(); @@ -42,9 +42,4 @@ serviceSynthesis = manager.getServiceSynthesis(); } - @After - public void after() { - manager.stop(); - } - } Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFixtures.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFixtures.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFixtures.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,6 +1,6 @@ package fr.ifremer.wao.business; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.bean.ConnectedUser; import fr.ifremer.wao.bean.ObsProgram; @@ -18,7 +18,7 @@ public class ObsDebFixtures { - protected TestManager manager; + protected WaoServices manager; protected WaoUser josh; protected Company codeLutin; @@ -28,7 +28,7 @@ protected boolean boatsImported; - public ObsDebFixtures(TestManager manager) { + public ObsDebFixtures(WaoServices manager) { this.manager = manager; } Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -24,23 +24,20 @@ package fr.ifremer.wao.entity; -import fr.ifremer.wao.service.AbstractServiceTest; -import fr.ifremer.wao.TestManager; import fr.ifremer.wao.WaoDAOHelper; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.bean.ConnectedUser; import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.DataReliability; import fr.ifremer.wao.bean.ObsProgram; import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.service.AbstractServiceTest; import fr.ifremer.wao.service.ServiceBoat; import fr.ifremer.wao.service.ServiceContact; import fr.ifremer.wao.service.ServiceSampling; import fr.ifremer.wao.service.ServiceUser; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.util.DateUtil; @@ -60,35 +57,16 @@ */ public class BoatImplTest extends AbstractServiceTest { - private static TestManager manager; + @Rule + public WaoServices manager = new WaoServices(); private static final Logger log = LoggerFactory.getLogger(BoatImplTest.class); - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - manager.start(); - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - /** * Test of canCreateContact method, of class BoatImpl. */ @Test public void testCanCreateContact() throws Exception { - log.info("canCreateContact"); /** PREPARE DATA **/ ServiceUser serviceUser = manager.getServiceUser(); Company company = new CompanyImpl(); @@ -190,8 +168,6 @@ */ @Test public void testGetNbBoarding() throws Exception { - log.info("getNbBoarding"); - /** PREPARE DATA **/ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = manager.getServiceBoat(); Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,75 +0,0 @@ -/* - * #%L - * Wao :: Business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao.entity; - -import fr.ifremer.wao.TestManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * BoatInfosImplTest - * - * Created: 21 déc. 2009 - * - * @author fdesbois <fdesbois at codelutin.com> - */ -public class BoatInfosImplTest { - - private static TestManager manager; - - public BoatInfosImplTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - manager.start(); - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - - /** - * Test of getNbBoardingForCompany method, of class BoatInfosImpl. - */ - @Test - public void testGetNbBoardingForCompany() { - System.out.println("getNbBoardingForCompany"); - } - -} Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -24,23 +24,14 @@ package fr.ifremer.wao.entity; -import fr.ifremer.wao.TestManager; -import fr.ifremer.wao.WaoDAOHelper; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import fr.ifremer.wao.WaoServices; +import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Calendar; import java.util.GregorianCalendar; -import static org.junit.Assert.assertFalse; - /** * SampleRowImplTest * @@ -50,138 +41,18 @@ */ public class SampleRowImplTest { - private static TestManager manager; + // XXX 20110609 bleny it's lame to need to init services (init current date) to make this test works + @Rule + public WaoServices waoServices = new WaoServices(); - private static final Logger log = - LoggerFactory.getLogger(SampleRowImplTest.class); - - public SampleRowImplTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - manager.start(); - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - - private SampleRow prepareData() throws TopiaException { - TopiaContext transaction = manager.getContext().beginTransaction(); - - SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - - SampleRow row = dao.create(); - row.setCode("2010_1"); - - SampleMonthDAO monthDAO = WaoDAOHelper.getSampleMonthDAO(transaction); - - SampleMonth month = monthDAO.create(SampleMonth.PROPERTY_SAMPLE_ROW, row); - Calendar calendar = new GregorianCalendar(2009, 3, 1); - month.setPeriodDate(calendar.getTime()); - row.addSampleMonth(month); - - transaction.commitTransaction(); - SampleRow myRow = dao.findByCode("2010_1"); - myRow.sizeElligibleBoat(); - myRow.sizeSampleMonth(); - transaction.closeContext(); - return myRow; - } - - private SampleRow getRowFromContext() throws TopiaException { - TopiaContext transaction = manager.getContext().beginTransaction(); - SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - SampleRow resultRow = dao.findByCode("2010_1"); - resultRow.sizeElligibleBoat(); - resultRow.sizeSampleMonth(); - transaction.closeContext(); - return resultRow; - } - -// @Test -// public void testAddRealTideTime() throws Exception { -// log.info("addRealTideTime"); -// -// /** PREPARE DATA **/ -// SampleRow row = prepareData(); -// -// Contact contact = new ContactImpl(); -// Date beginDate = DateUtil.createDate(12, 4, 2009); -// Date endDate = DateUtil.createDate(15, 4, 2009); -// contact.setObservationBeginDate(beginDate); -// contact.setObservationEndDate(endDate); -// -// /** EXEC METHOD **/ -// row.addRealTideTime(contact); -// SampleMonth result = getRowFromContext().getSampleMonth(beginDate); -// assertEquals(1, result.getRealTidesValue()); -// -//// // Reinit result for next test -//// result.addRealTideTime(-1); -//// // Test with a more than one day interval dates from contact -//// endDate = DateUtil.createDate(18, 4, 2009); -//// contact.setObservationEndDate(endDate); -//// -//// getRowFromContext().addRealTideTime(contact); -//// result = getRowFromContext().getSampleMonth(beginDate); -//// assertEquals(1, result.getRealTidesValue()); -// } -// -// @Test -// public void testRemoveRealTideTime() throws Exception { -// log.info("addRealTideTime"); -// -// /** PREPARE DATA **/ -// SampleRow row = prepareData(); -// -// Contact contact = new ContactImpl(); -// Date beginDate = DateUtil.createDate(12, 4, 2009); -// Date endDate = DateUtil.createDate(12, 4, 2009); -// contact.setObservationBeginDate(beginDate); -// contact.setObservationEndDate(endDate); -// -// /** EXEC METHOD **/ -// row.removeRealTideTime(contact); -// SampleMonth result = getRowFromContext().getSampleMonth(beginDate); -// // result stay at 0, can't remove 1 tide from 0 -// assertEquals(0, result.getRealTidesValue()); -// -// // Reinit result for next test -// result.addRealTideTime(12); -// -// // Test with a more than one day interval dates from contact : only one tide to remove -// endDate = DateUtil.createDate(18, 4, 2009); -// contact.setObservationEndDate(endDate); -// -// getRowFromContext().removeRealTideTime(contact); -// result = getRowFromContext().getSampleMonth(beginDate); -// assertEquals(11, result.getRealTidesValue()); -// } - @Test public void testIsFinished() throws Exception { - log.info("isFinished()"); - SampleRow row = new SampleRowImpl(); Calendar calendar = new GregorianCalendar(2009, 8, 23); row.setPeriodEnd(calendar.getTime()); // with a gap of one month, the row is not considered as finished - assertFalse(row.isFinished(-1)); - - + Assert.assertFalse(row.isFinished(-1)); } } Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -25,16 +25,14 @@ package fr.ifremer.wao.io; import com.csvreader.CsvReader; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.io.csv.ImportHelper; -import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT; import fr.ifremer.wao.io.csv.WaoCsvHeader.DatedHeader; import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING; import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.nuiton.util.DateUtil; import org.slf4j.Logger; @@ -45,10 +43,7 @@ import java.nio.charset.Charset; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; import static org.junit.Assert.assertEquals; @@ -58,30 +53,16 @@ */ public class ImportHelperTest { - private static TestManager manager; + @Rule + public WaoServices manager = new WaoServices(); - private static final Logger log = LoggerFactory.getLogger(ImportHelperTest.class); + private static final Logger log = + LoggerFactory.getLogger(ImportHelperTest.class); - private CsvReader reader; + protected CsvReader reader; - public ImportHelperTest() { - manager = new TestManager(); - } - - @BeforeClass - public static void setUpClass() throws Exception { - - } - - @AfterClass - public static void tearDownClass() throws Exception { - - } - @Before public void setUp() throws IOException { - manager.start(); - InputStream input = getClass().getResourceAsStream("/import/misc.csv"); reader = new CsvReader(input, Charset.forName("UTF-8")); reader.readHeaders(); @@ -90,50 +71,9 @@ @After public void tearDown() { reader.close(); - - manager.stop(); } /** - * Test of formatContactCode method, of class ImportHelper. - */ - @Test - public void testFormatContactCode() { - log.info("formatContactCode"); - Date createDate = manager.getContext().getCurrentDate(); - Calendar calendar = new GregorianCalendar(Locale.FRENCH); - calendar.setTime(createDate); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MINUTE, 1); - calendar.set(Calendar.SECOND, 50); - calendar.set(Calendar.MILLISECOND, 260); - String expResult = "100150260"; - String result = CONTACT.TIME_FORMAT.format(calendar.getTime()); - assertEquals(expResult, result); - } - - /** - * Test of parseContactCreateDate method, of class ImportHelper. - * @throws Exception all exceptions are thrown - */ - @Test - public void testParseContactCreateDate() throws Exception { - System.out.println("parseContactCreateDate"); - String code = "101250718"; - Date createDate = manager.getContext().getCurrentDate(); - Calendar calendar = new GregorianCalendar(Locale.FRENCH); - calendar.setTime(createDate); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MINUTE, 12); - calendar.set(Calendar.SECOND, 50); - calendar.set(Calendar.MILLISECOND, 718); - Date expResult = calendar.getTime(); - Date date = DateUtil.createDate(23,10,2009); - Date result = ImportHelper.parseContactCreateDate(code, date); - assertEquals(expResult, result); - } - - /** * Test of readSampleRowCode method, of class ImportHelper. * @throws Exception all exceptions are thrown */ Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/AbstractServiceTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/AbstractServiceTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/AbstractServiceTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -21,7 +21,7 @@ package fr.ifremer.wao.service; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.bean.ConnectedUser; @@ -47,6 +47,7 @@ import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.util.DateUtil; @@ -70,7 +71,8 @@ private static final Logger log = LoggerFactory.getLogger(AbstractServiceTest.class); - protected static TestManager manager; + @Rule + public WaoServices manager = new WaoServices(); protected ServiceSamplingImpl serviceSampling; @@ -97,23 +99,13 @@ log.info("tmp dir : " + file + " was created"); } } - manager = new TestManager(); } @Before public void setUp() throws Exception { - if (log.isDebugEnabled()) { - log.debug("Start manager"); - } - manager.start(); serviceSampling = (ServiceSamplingImpl) manager.getServiceSampling(); } - @After - public void tearDown() throws Exception { - manager.stop(); - } - /** * Create a company : <br /> * <ul> Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ActivityCalendarImportTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ActivityCalendarImportTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ActivityCalendarImportTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -24,7 +24,7 @@ package fr.ifremer.wao.service; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoProperty; import org.junit.After; @@ -32,6 +32,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,43 +51,20 @@ * * @author fdesbois <fdesbois at codelutin.com> */ + at Ignore("activity calendars are deprecated") public class ActivityCalendarImportTest { - private static TestManager manager; + public WaoServices manager = new WaoServices(); private static final Logger log = LoggerFactory.getLogger(ActivityCalendarImportTest.class); - public ActivityCalendarImportTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - manager.start(); - } - - @After - public void tearDown() { - manager.stop(); - } - /** * Test of run method, of class ActivityCalendarImport. */ @Test public void testRun() throws IOException, InterruptedException, WaoBusinessException { - log.info("run"); - ServiceBoat serviceBoat = manager.getServiceBoat(); InputStream input = getClass().getResourceAsStream("/import/navires.csv"); serviceBoat.importBoatCsv(input); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -24,7 +24,7 @@ package fr.ifremer.wao.service; -import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoServices; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoProperty; @@ -79,28 +79,15 @@ */ public class ServiceBoatImplTest extends AbstractServiceTest { - private static TestManager manager; - private static final Logger log = LoggerFactory.getLogger(ServiceBoatImplTest.class); private ServiceBoat service; - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - @Before public void setUp() throws Exception { - manager.start(); service = manager.getServiceBoat(); } - @After - public void tearDown() throws Exception { - manager.stop(); - } - /** * Test of getBoatsByFilter method, of class ServiceBoatImpl. * @throws Exception Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -55,11 +55,10 @@ private static final Logger log = LoggerFactory.getLogger(ServiceCartographyImplTest.class); - private ServiceCartography service; + protected ServiceCartography service; @Before public void initialize() { - log.info("initialize ServiceCartographyImplTest"); service = manager.getServiceCartography(); } Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,112 +0,0 @@ -/* - * #%L - * Wao :: Business - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao.service; - -import fr.ifremer.wao.bean.ConnectedUser; -import fr.ifremer.wao.bean.ContactFilter; -import fr.ifremer.wao.bean.ContactFilterImpl; -import fr.ifremer.wao.bean.ObsProgram; -import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.WaoUser; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.TopiaException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -/** - * ServiceContactImplTest - * - * Created: 3 mai 2010 - * - * @author fdesbois - * $Id$ - */ -public class ServiceContactImplTest extends AbstractServiceTest { - - private static final Logger log = - LoggerFactory.getLogger(ServiceContactImplTest.class); - - private ServiceContact service; - - @Before - public void initialize() { - log.info("initialize ServiceContactImplTest"); - service = manager.getServiceContact(); - } - - @Test - public void testGetContactsFilteredByObserver() throws TopiaException { - log.info("getContactsFilteredByObserver"); - - /** PREPARE DATA **/ - Contact contact = createDefaultContact(); - - /** EXEC METHOD **/ - ContactFilter filter = new ContactFilterImpl(); - filter.setObserver(findDefaultObserver()); - - log.info("test 1 : Ok good filter, contact is correctly returned"); - Map<String, Contact> results = service.getContacts(filter); - - Assert.assertEquals(1, results.size()); - Contact contactFind = results.get(contact.getTopiaId()); - Assert.assertEquals(contact, contactFind); - - log.info("test 2 : Bad filter, no contact is returned"); - WaoUser observer2 = createUser("marge", - UserRole.OBSERVER, findDefaultCompany()); - - filter.setObserver(observer2); - - results = service.getContacts(filter); - Assert.assertEquals(0, results.size()); - } - - @Test - public void testSaveContactWithMultipleObservers() throws TopiaException { - Contact contact = createDefaultContact(); - - Company company = createCompany("Boite"); - WaoUser toto = createUser("toto", UserRole.OBSERVER, company); - contact.addSecondaryObservers(toto); - contact.addSecondaryObservers(createUser("titi", UserRole.OBSERVER, company)); - - ConnectedUser connectedUser = getConnectedUser(toto, UserRole.COORDINATOR, ObsProgram.OBSMER); - service.saveContact(connectedUser, contact, false); - - Contact savedContact = service.getContact(contact.getTopiaId()); - Assert.assertEquals(2, savedContact.getSecondaryObservers().size()); - - contact.clearSecondaryObservers(); - service.saveContact(connectedUser, contact, false); - savedContact = service.getContact(contact.getTopiaId()); - Assert.assertEquals(0, savedContact.getSecondaryObservers().size()); - } - - -} Copied: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java (from rev 1321, trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java) =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -0,0 +1,760 @@ +/* + * #%L + * Wao :: Business + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.wao.service; + +import com.csvreader.CsvReader; +import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.WaoDAOHelper; +import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.ContactState; +import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException; +import fr.ifremer.wao.bean.ObsProgram; +import fr.ifremer.wao.bean.SamplingStrategy; +import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.BoatDAO; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyDAO; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactDAO; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleMonthDAO; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowDAO; +import fr.ifremer.wao.entity.UserProfileImpl; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.entity.WaoUserDAO; +import fr.ifremer.wao.io.ContactInput; +import fr.ifremer.wao.io.ImportRefusedException; +import fr.ifremer.wao.io.ImportResults; +import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT; +import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT; +import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.util.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.util.Date; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +/** + * ServiceContactImplTest + * + * Created: 16 avr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ServiceContactImplTest extends AbstractServiceTest { + + private static final Logger log = + LoggerFactory.getLogger(ServiceContactImplTest.class); + + protected ServiceContactImpl service; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + service = (ServiceContactImpl) manager.getServiceContact(); + sampleMonth = null; + sampleRow = null; + boat = null; + company = null; + observer = null; + } + + // Real data + protected SampleRow sampleRow; + protected SampleMonth sampleMonth; + protected Boat boat; + protected Company company; + protected WaoUser observer; + + // Mock data + @Mock + protected Contact contact; + @Mock + protected Contact contactReference; + @Mock + protected ConnectedUser creator; + @Mock + protected CsvReader reader; + + protected void prepareData(boolean needBoat, boolean needObserver) + throws TopiaException { + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + + if (needObserver) { + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + company = companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + + WaoUserDAO userDAO = WaoDAOHelper.getWaoUserDAO(transaction); + observer = userDAO.create( + WaoUser.PROPERTY_COMPANY, company, + WaoUser.PROPERTY_LOGIN, "jmichmuche", + WaoUser.PROPERTY_FIRST_NAME, "Jean", + WaoUser.PROPERTY_LAST_NAME, "Michmuche"); + + when(contact.getMainObserver()).thenReturn(observer); + } + + SampleRowDAO rowDAO = + WaoDAOHelper.getSampleRowDAO(transaction); + log.trace("SampleRow : 2010_0001"); + sampleRow = rowDAO.create(SampleRow.PROPERTY_CODE, "2010_0001", + SampleRow.PROPERTY_COMPANY, company); + + SampleMonthDAO monthDAO = + WaoDAOHelper.getSampleMonthDAO(transaction); + log.trace("SampleMonth : 03/2010 _ row 2010_0001"); + Date monthDate = DateUtil.createDate(1, 3, 2010); + sampleMonth = monthDAO.create(SampleMonth.PROPERTY_SAMPLE_ROW, sampleRow, + SampleMonth.PROPERTY_PERIOD_DATE, monthDate); + monthDate = DateUtil.createDate(1, 4, 2010); + monthDAO.create(SampleMonth.PROPERTY_SAMPLE_ROW, sampleRow, + SampleMonth.PROPERTY_PERIOD_DATE, monthDate); + + Date contactDate = DateUtil.createDate(18, 3, 2010); + when(contact.getObservationBeginDate()).thenReturn(contactDate); + when(contact.getSampleRow()).thenReturn(sampleRow); + + if (needBoat) { + BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction); + boat = boatDAO.create(Boat.PROPERTY_IMMATRICULATION, 175846, Boat.PROPERTY_ACTIVE, true); + when(contact.getBoat()).thenReturn(boat); + } + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + } + + @Test + public void testUpdateSampleMonthTidesValue() throws TopiaException, + NullSampleMonthException { + + /** PREPARE DATA **/ + prepareData(false, false); + Date tideBeginDate = new Date(contact.getObservationBeginDate().getTime()); + when(contactReference.getObservationBeginDate()).thenReturn(tideBeginDate); + when(contactReference.getSampleRow()).thenReturn(sampleRow); + // WARN : by default mockito doesn't initialize Boolean type with null + when(contactReference.getValidationProgram()).thenReturn(null); + when(contact.getValidationProgram()).thenReturn(null); + + /** EXEC METHOD **/ + log.trace("test 1 : ContactState changed from null to OBSERVATION_DONE" + + " -> increment estimated tides value"); + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + when(contact.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + + service.updateSampleMonthTidesValue(transaction, null, + contact, false); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 1 : verification sampleMonth estimated tides = 1 + checkTidesValue(1, false); + + // test 2 : ContactState changed from OBSERVATION_DONE to + // CONTACT_REFUSED -> decrement estimated tides value + transaction = manager.getContext().beginTransaction(); + try { + when(contactReference.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + + when(contact.getContactState()). + thenReturn(ContactState.CONTACT_REFUSED); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, false); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 2 : verification sampleMonth estimated tides = 0 + checkTidesValue(0, false); + + // Reset contactState to OBSERVATION_DONE for next test + when(contact.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + + // test 3 : CompanyValidation changed from null to FALSE -> do nothing + transaction = manager.getContext().beginTransaction(); + try { + when(contactReference.getValidationCompany()).thenReturn(null); + + when(contact.getValidationCompany()).thenReturn(Boolean.FALSE); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 3 : verification sampleMonth real tides = 0 + checkTidesValue(0, true); + + // test 4 : CompanyValidation changed from FALSE to TRUE -> increment + // real tides value + transaction = manager.getContext().beginTransaction(); + try { + when(contactReference.getValidationCompany()). + thenReturn(Boolean.FALSE); + + when(contact.getValidationCompany()).thenReturn(Boolean.TRUE); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 4 : verification sampleMonth real tides = 1 + checkTidesValue(1, true); + + // ContactReference after saving contact will normally have this value : + when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); + + // test 5 : CompanyValidation doesn't changed but ProgramValidation is + // set to FALSE -> decrement real tides + transaction = manager.getContext().beginTransaction(); + try { + when(contact.getValidationProgram()).thenReturn(Boolean.FALSE); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 5 : verification sampleMonth real tides = 0 + checkTidesValue(0, true); + + // test 6 : Prepare data for delete case + // PREPARE DATA : update estimated to 1 and real to 1 + transaction = manager.getContext().beginTransaction(); + try { + // Will update estimatedTides up to 1 + // contact has already OBSERVATION_DONE + when(contactReference.getContactState()). + thenReturn(ContactState.OBSERVATION_EXPECTED); + + // Will update realTides up to 1 + // contact has already validationCompany = TRUE + when(contactReference.getValidationCompany()).thenReturn(null); + when(contact.getValidationProgram()).thenReturn(Boolean.TRUE); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // ContactReference after saving contact will normally have this values + when(contactReference.getValidationProgram()).thenReturn(Boolean.TRUE); + when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); + + // test 6 : Delete contact (new contact is null) -> decrement realTides + // and estimatedTides + transaction = manager.getContext().beginTransaction(); + try { + when(contactReference.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + service.updateSampleMonthTidesValue(transaction, contactReference, + null, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 6 : verification sampleMonth real tides = 0 and estimated tides = 0 + checkTidesValue(0, true); + checkTidesValue(0, false); + + // test 7 : SampleMonth will change from 03/2010 to 04/2010 -> decrement + // estimated tides from oldMonth + transaction = manager.getContext().beginTransaction(); + try { + // contactReference OBSERVATION_DONE, validations true/true + // contact OBSERVATION_DONE, validations true/true + when(contactReference.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + when(contact.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + when(contact.getObservationBeginDate()). + thenReturn(DateUtil.createDate(3, 4, 2010)); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // test 7 : verification old sampleMonth estimated tides = 0 + checkTidesValue(0, false); + + // test 7 : verification new sampleMonth estimated tides = 1 and real + // tides = 1 + transaction = manager.getContext().beginTransaction(); + try { + SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); + + TopiaQuery query = dao.createQuery(); + query.addEquals(SampleMonth.PROPERTY_PERIOD_DATE, DateUtil.createDate(1, 4, 2010)); + + SampleMonth month = dao.findByQuery(query); + + assertEquals(1, month.getEstimatedTidesValue()); + assertEquals(1, month.getRealTidesValue()); + + } finally { + transaction.closeContext(); + } + } + + @Test + public void testDecrementSampleMonthContactRefused() + throws TopiaException, NullSampleMonthException { + + /** PREPARE DATA **/ + prepareData(false, false); + + // contactReference as the same tideBeginDate and sampleRow as contact + Date tideBeginDate = new Date(contact.getObservationBeginDate().getTime()); + when(contactReference.getObservationBeginDate()).thenReturn(tideBeginDate); + when(contactReference.getSampleRow()).thenReturn(sampleRow); + + // Initialize correct old status in contactReference + when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); + when(contactReference.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + when(contactReference.getValidationProgram()).thenReturn(null); + + + // Initialize data in sampleMonth + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); + + sampleMonth.addEstimatedTideTime(1); + sampleMonth.addRealTideTime(1); + + dao.update(sampleMonth); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + // both estimated and real as value = 1 + checkTidesValue(1, false); + checkTidesValue(1, true); + + /** EXEC METHOD **/ + // test 1 : validationProgram null -> FALSE, estimated -1 and real -1 + transaction = manager.getContext().beginTransaction(); + try { + when(contact.getValidationCompany()).thenReturn(Boolean.TRUE); + when(contact.getContactState()). + thenReturn(ContactState.OBSERVATION_DONE); + when(contact.getValidationProgram()).thenReturn(Boolean.FALSE); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + checkTidesValue(0, false); + checkTidesValue(0, true); + + // test 2 : validationProgram FALSE -> null, estimated +1 and real +1 + transaction = manager.getContext().beginTransaction(); + try { + when(contactReference.getValidationProgram()). + thenReturn(Boolean.FALSE); + when(contact.getValidationProgram()).thenReturn(null); + + service.updateSampleMonthTidesValue(transaction, contactReference, + contact, true); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + checkTidesValue(1, false); + checkTidesValue(1, true); + } + + protected void checkTidesValue(int expected, boolean real) + throws TopiaException { + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); + + SampleMonth result = dao.findByTopiaId(sampleMonth.getTopiaId()); + int test = real ? result.getRealTidesValue() : + result.getEstimatedTidesValue(); + assertEquals(expected, test); + } finally { + transaction.closeContext(); + } + } + + @Test + public void testLoadContactCsv() throws TopiaException, + WaoBusinessException, + IOException, + ImportRefusedException, + ParseException { + + /** PREPARE DATA **/ + prepareData(true, true); + + when(reader.get(CONTACT.CONT_ETAT.name())). + thenReturn(ContactState.OBSERVATION_DONE.name()); + when(reader.get(CONTACT.OBSERV_ID.name())). + thenReturn(observer.getLogin()); + when(reader.get(SAMPLING.PLAN_CODE.name())). + thenReturn(sampleRow.getCode()); + when(reader.get(BOAT.NAVS_COD.name())). + thenReturn(String.valueOf(boat.getImmatriculation())); + when(reader.get(CONTACT.CONT_DEBUT_MAREE.name())). + thenReturn("22/03/2010 1:00"); + when(reader.get(CONTACT.CONT_FIN_MAREE.name())). + thenReturn("22/03/10 2:15"); + when(reader.get(CONTACT.CONT_NB_OBSERV.name())). + thenReturn("1"); + when(reader.get(CONTACT.CONT_MAM_CAPT.name())). + thenReturn(""); + when(reader.get(CONTACT.CONT_MAM_OBS.name())). + thenReturn("X"); + when(reader.get(CONTACT.CONT_ALLEGRO.name())). + thenReturn("25/03/2010"); + when(reader.get(CONTACT.CONT_SOCIETE_VALID.name())). + thenReturn("A"); + when(reader.get(CONTACT.CONT_PROGRAM_VALID.name())). + thenReturn(""); + when(reader.get(CONTACT.CONT_CREATION.name())). + thenReturn("18/03/10"); + when(reader.get(CONTACT.CONT_CODE.name())). + thenReturn(""); + String comment = "Commentaire sur le contact\nAutre ligne"; + when(reader.get(CONTACT.CONT_COMMENT.name())). + thenReturn(comment); + when(reader.get(CONTACT.CONT_DATA_RELIABILITY.name())). + thenReturn("DOUBTFUL"); + when(reader.get(CONTACT.CONT_SAMPLING_STRATEGY.name())). + thenReturn(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES.name()); + when(reader.get(CONTACT.CONT_COMPLETE_SAMPLING.name())). + thenReturn("Y"); + + when(creator.getCompany()).thenReturn(company); + when(creator.isAdmin()).thenReturn(false); + when(creator.getLogin()).thenReturn(observer.getLogin()); + + /** EXEC METHOD **/ + + // test 1 : load contact by Creator jmichmuche -> no error + ContactInput result = new ContactInput(); + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + result.initialize(transaction, creator, 1); + service.loadContactCsv(reader, result, false); + Date createDate = DateUtil.createDate(18,3,2010); + assertEquals(createDate, result.getCreationDate()); + assertEquals(ContactState.OBSERVATION_DONE, result.getContactState()); + assertEquals(observer, result.getMainObserver()); + assertEquals(sampleRow, result.getSampleRow()); + assertEquals(boat, result.getBoat()); + + assertEquals(DateUtil.getDifferenceInMinutes(DateUtil.createDate(0,0,1,22,3,2010), result.getObservationBeginDate()), 0); + assertEquals(DateUtil.getDifferenceInMinutes(DateUtil.createDate(0,15,2,22,3,2010), result.getObservationEndDate()), 0); + + assertEquals(1, result.getNbObservants()); + assertFalse(result.getMammalsCapture()); + assertTrue(result.getMammalsObservation()); + assertEquals(comment, result.getComment()); + assertEquals(DateUtil.createDate(25,3,2010), + result.getDataInputDate()); + // No validation update : creator is not an admin + assertNull(result.getValidationCompany()); + assertNull(result.getValidationProgram()); + } finally { + transaction.closeContext(); + } + + // test 2 : Error on boat + when(reader.get(BOAT.NAVS_COD.name())).thenReturn("2222"); + checkImportError(Contact.PROPERTY_BOAT); + // Reinit boat + when(reader.get(BOAT.NAVS_COD.name())). + thenReturn(String.valueOf(boat.getImmatriculation())); + + // test 3 : Error on company + when(creator.getCompany()).thenReturn(null); + checkImportError(WaoUser.PROPERTY_COMPANY); + // Reinit creator company + when(creator.getCompany()).thenReturn(company); + + // test 4 : Error on observer + when(reader.get(CONTACT.OBSERV_ID.name())).thenReturn("FAKE"); + checkImportError(Contact.PROPERTY_MAIN_OBSERVER); + // Reinit observer + when(reader.get(CONTACT.OBSERV_ID.name())). + thenReturn(observer.getLogin()); + + // test 5 : Error on sampleRow + when(reader.get(SAMPLING.PLAN_CODE.name())).thenReturn("FAKE"); + checkImportError(Contact.PROPERTY_SAMPLE_ROW); + // Reinit sampleRow + when(reader.get(SAMPLING.PLAN_CODE.name())). + thenReturn(sampleRow.getCode()); + + // test 6 : Error on state + when(reader.get(CONTACT.CONT_ETAT.name())).thenReturn("FAKE"); + checkImportError(Contact.PROPERTY_STATE); + // Reinit state + when(reader.get(CONTACT.CONT_ETAT.name())). + thenReturn(ContactState.OBSERVATION_DONE.name()); + } + + protected void checkImportError(String field) throws TopiaException { + ContactInput result = new ContactInput(); + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + result.initialize(transaction, creator, 1); + service.loadContactCsv(reader, result, false); + } catch (Exception eee) { + log.error("Error : " + eee.getMessage()); + assertEquals(ImportRefusedException.class, eee.getClass()); + ImportRefusedException ex = (ImportRefusedException)eee; + assertEquals(field, ex.getField()); + } finally { + transaction.closeContext(); + } + } + + @Test + public void testCreateOrUpdateContact() + throws TopiaException, WaoBusinessException { + + /** PREPARE DATA **/ + prepareData(true, true); + + ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); + + // Don't use a mock in this case + Contact newContact = service.newContact(connectedUser, sampleRow, boat); + newContact.setCreationDate(DateUtil.createDate(2, 3, 2010)); + + /** EXEC METHOD **/ + + // test 1 : Create new contact with state CONTACT_START + TopiaContext transaction = null; + String newTopiaId = null; + try { + transaction = manager.getContext().beginTransaction(); + + service.createOrUpdateContact(transaction, null, newContact, false); + transaction.commitTransaction(); + + newTopiaId = newContact.getTopiaId(); + assertNotNull(newTopiaId); + } finally { + if (transaction != null) { + transaction.closeContext(); + } + } + + // test 1 : Check contact existence + try { + transaction = manager.getContext().beginTransaction(); + + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + + Contact existingContact = dao.findByTopiaId(newTopiaId); + assertNotNull(existingContact); + assertEquals(boat, existingContact.getBoat()); + assertEquals(sampleRow, existingContact.getSampleRow()); + assertEquals(observer, existingContact.getMainObserver()); + assertEquals(ContactState.CONTACT_START, + existingContact.getContactState()); + } finally { + if (transaction != null) { + transaction.closeContext(); + } + } + + // test 2 : Update the contact with state OBSERVATION_DONE + // tideBeginDate, tideEndDate and NbObservants + Date tideBeginDate = DateUtil.createDate(18,3,2010); + Date tideEndDate = DateUtil.createDate(19,3,2010); + try { + transaction = manager.getContext().beginTransaction(); + + newContact.setContactState(ContactState.OBSERVATION_DONE); + newContact.setObservationBeginDate(tideBeginDate); + newContact.setObservationEndDate(tideEndDate); + newContact.setNbObservants(1); + + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + Contact oldContact = dao.findByTopiaId(newTopiaId); + + service.createOrUpdateContact(transaction, oldContact, newContact, false); + transaction.commitTransaction(); + } finally { + if (transaction != null) { + transaction.closeContext(); + } + } + + // test 2 : Check update contact + try { + transaction = manager.getContext().beginTransaction(); + + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + + Contact existingContact = dao.findByTopiaId(newTopiaId); + assertNotNull(existingContact); + assertEquals(1, existingContact.getNbObservants()); + assertEquals(tideBeginDate, existingContact.getObservationBeginDate()); + assertEquals(tideEndDate, existingContact.getObservationEndDate()); + assertEquals(ContactState.OBSERVATION_DONE, + existingContact.getContactState()); + + // Will have an update on sampleMonth 03/2010 for estimatedTides + SampleMonthDAO monthDAO = + WaoDAOHelper.getSampleMonthDAO(transaction); + SampleMonth existingMonth = + monthDAO.findByTopiaId(sampleMonth.getTopiaId()); + assertNotNull(existingMonth); + assertEquals(1, existingMonth.getEstimatedTidesValue()); + } finally { + if (transaction != null) { + transaction.closeContext(); + } + } + } + + @Test + public void testImportContactCsv() + throws TopiaException, WaoBusinessException, IOException { + + /** PREPARE DATA **/ + prepareData(true, true); + + when(creator.getCompany()).thenReturn(company); + when(creator.getLogin()).thenReturn(observer.getLogin()); + when(creator.getProfile()).thenReturn(new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true)); + + /** EXEC METHOD **/ + // test 1 : Import new contact with observer creator + InputStream input = + getClass().getResourceAsStream("/import/contacts.csv"); + try { + ImportResults results = service.importContactCsv(creator, input); + assertEquals(0, results.getNbRowsRefused()); + assertEquals(1, results.getNbRowsImported()); + assertTrue(results.getErrors().isEmpty()); + } finally { + input.close(); + } + + // test 1 : Check creation of the contact + TopiaContext transaction = null; + try { + transaction = manager.getContext().beginTransaction(); + + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + + List<Contact> contactsFound = dao.findAll(); + assertEquals(1, contactsFound.size()); + Contact contactFound = contactsFound.get(0); + assertNull(contactFound.getValidationCompany()); + assertNull(contactFound.getValidationProgram()); + } finally { + if (transaction != null) { + transaction.closeContext(); + } + } + + // test 2 : Import new contact with super admin creator + when(creator.getCompany()).thenReturn(company); + when(creator.getLogin()).thenReturn("admin"); + when(creator.getProfile()).thenReturn(new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true)); + + input = getClass().getResourceAsStream("/import/contacts.csv"); + try { + ImportResults results = service.importContactCsv(creator, input); + assertEquals(1, results.getNbRowsImported()); + assertEquals(0, results.getNbRowsRefused()); + assertTrue(results.getErrors().isEmpty()); + } finally { + input.close(); + } + } +} Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,793 +0,0 @@ -/* - * #%L - * Wao :: Business - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao.service; - -import com.csvreader.CsvReader; -import fr.ifremer.wao.TestManager; -import fr.ifremer.wao.WaoBusinessException; -import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.bean.ConnectedUser; -import fr.ifremer.wao.bean.ContactState; -import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException; -import fr.ifremer.wao.bean.ObsProgram; -import fr.ifremer.wao.bean.SamplingStrategy; -import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.BoatDAO; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyDAO; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactDAO; -import fr.ifremer.wao.entity.SampleMonth; -import fr.ifremer.wao.entity.SampleMonthDAO; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowDAO; -import fr.ifremer.wao.entity.UserProfileImpl; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserDAO; -import fr.ifremer.wao.io.ContactInput; -import fr.ifremer.wao.io.ImportRefusedException; -import fr.ifremer.wao.io.ImportResults; -import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT; -import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT; -import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.util.DateUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -/** - * ServiceContactImplTest - * - * Created: 16 avr. 2010 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class ServiceContactInternalTest extends AbstractServiceTest { - - private static TestManager manager; - - private static final Logger log = - LoggerFactory.getLogger(ServiceContactInternalTest.class); - - private ServiceContactImpl service; - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @Before - public void setUp() throws Exception { - manager.start(); - MockitoAnnotations.initMocks(this); - service = (ServiceContactImpl)manager.getServiceContact(); - sampleMonth = null; - sampleRow = null; - boat = null; - company = null; - observer = null; - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - - // Real data - protected SampleRow sampleRow; - protected SampleMonth sampleMonth; - protected Boat boat; - protected Company company; - protected WaoUser observer; - - // Mock data - @Mock - protected Contact contact; - @Mock - protected Contact contactReference; - @Mock - protected ConnectedUser creator; - @Mock - protected CsvReader reader; - - protected void prepareData(boolean needBoat, boolean needObserver) - throws TopiaException { - log.info("Prepare data :"); - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - - if (needObserver) { - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - company = companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - - WaoUserDAO userDAO = WaoDAOHelper.getWaoUserDAO(transaction); - observer = userDAO.create( - WaoUser.PROPERTY_COMPANY, company, - WaoUser.PROPERTY_LOGIN, "jmichmuche", - WaoUser.PROPERTY_FIRST_NAME, "Jean", - WaoUser.PROPERTY_LAST_NAME, "Michmuche"); - - when(contact.getMainObserver()).thenReturn(observer); - } - - SampleRowDAO rowDAO = - WaoDAOHelper.getSampleRowDAO(transaction); - log.info("SampleRow : 2010_0001"); - sampleRow = rowDAO.create(SampleRow.PROPERTY_CODE, "2010_0001", - SampleRow.PROPERTY_COMPANY, company); - - SampleMonthDAO monthDAO = - WaoDAOHelper.getSampleMonthDAO(transaction); - log.info("SampleMonth : 03/2010 _ row 2010_0001"); - Date monthDate = DateUtil.createDate(1, 3, 2010); - sampleMonth = monthDAO.create(SampleMonth.PROPERTY_SAMPLE_ROW, sampleRow, - SampleMonth.PROPERTY_PERIOD_DATE, monthDate); - monthDate = DateUtil.createDate(1, 4, 2010); - monthDAO.create(SampleMonth.PROPERTY_SAMPLE_ROW, sampleRow, - SampleMonth.PROPERTY_PERIOD_DATE, monthDate); - - Date contactDate = DateUtil.createDate(18, 3, 2010); - when(contact.getObservationBeginDate()).thenReturn(contactDate); - when(contact.getSampleRow()).thenReturn(sampleRow); - - if (needBoat) { - BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction); - boat = boatDAO.create(Boat.PROPERTY_IMMATRICULATION, 175846, Boat.PROPERTY_ACTIVE, true); - when(contact.getBoat()).thenReturn(boat); - } - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - } - - @Test - public void testUpdateSampleMonthTidesValue() throws TopiaException, - NullSampleMonthException { - log.info("testUpdateSampleMonthTidesValue"); - - /** PREPARE DATA **/ - prepareData(false, false); - Date tideBeginDate = new Date(contact.getObservationBeginDate().getTime()); - when(contactReference.getObservationBeginDate()).thenReturn(tideBeginDate); - when(contactReference.getSampleRow()).thenReturn(sampleRow); - // WARN : by default mockito doesn't initialize Boolean type with null - when(contactReference.getValidationProgram()).thenReturn(null); - when(contact.getValidationProgram()).thenReturn(null); - - /** EXEC METHOD **/ - log.info("test 1 : ContactState changed from null to OBSERVATION_DONE" + - " -> increment estimated tides value"); - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - when(contact.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - - service.updateSampleMonthTidesValue(transaction, null, - contact, false); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 1 : verification sampleMonth estimated tides = 1"); - checkTidesValue(1, false); - - log.info("test 2 : ContactState changed from OBSERVATION_DONE to " + - "CONTACT_REFUSED -> decrement estimated tides value"); - transaction = manager.getContext().beginTransaction(); - try { - when(contactReference.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - - when(contact.getContactState()). - thenReturn(ContactState.CONTACT_REFUSED); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, false); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 2 : verification sampleMonth estimated tides = 0"); - checkTidesValue(0, false); - - // Reset contactState to OBSERVATION_DONE for next test - when(contact.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - - log.info("test 3 : CompanyValidation changed from null to " + - "FALSE -> do nothing"); - transaction = manager.getContext().beginTransaction(); - try { - when(contactReference.getValidationCompany()).thenReturn(null); - - when(contact.getValidationCompany()).thenReturn(Boolean.FALSE); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 3 : verification sampleMonth real tides = 0"); - checkTidesValue(0, true); - - log.info("test 4 : CompanyValidation changed from FALSE to " + - "TRUE -> increment real tides value"); - transaction = manager.getContext().beginTransaction(); - try { - when(contactReference.getValidationCompany()). - thenReturn(Boolean.FALSE); - - when(contact.getValidationCompany()).thenReturn(Boolean.TRUE); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 4 : verification sampleMonth real tides = 1"); - checkTidesValue(1, true); - - // ContactReference after saving contact will normally have this value : - when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); - - log.info("test 5 : CompanyValidation doesn't changed but " + - "ProgramValidation is set to FALSE -> decrement real tides"); - transaction = manager.getContext().beginTransaction(); - try { - when(contact.getValidationProgram()).thenReturn(Boolean.FALSE); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 5 : verification sampleMonth real tides = 0"); - checkTidesValue(0, true); - - log.info("test 6 : Prepare data for delete case"); - // PREPARE DATA : update estimated to 1 and real to 1 - transaction = manager.getContext().beginTransaction(); - try { - // Will update estimatedTides up to 1 - // contact has already OBSERVATION_DONE - when(contactReference.getContactState()). - thenReturn(ContactState.OBSERVATION_EXPECTED); - - // Will update realTides up to 1 - // contact has already validationCompany = TRUE - when(contactReference.getValidationCompany()).thenReturn(null); - when(contact.getValidationProgram()).thenReturn(Boolean.TRUE); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - // ContactReference after saving contact will normally have this values - when(contactReference.getValidationProgram()).thenReturn(Boolean.TRUE); - when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); - - log.info("test 6 : Delete contact (new contact is null) -> " + - "decrement realTides and estimatedTides"); - transaction = manager.getContext().beginTransaction(); - try { - when(contactReference.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - service.updateSampleMonthTidesValue(transaction, contactReference, - null, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 6 : verification sampleMonth real tides = 0" + - "and estimated tides = 0"); - checkTidesValue(0, true); - checkTidesValue(0, false); - - log.info("test 7 : SampleMonth will change from 03/2010 to 04/2010" + - " -> decrement estimated tides from oldMonth"); - transaction = manager.getContext().beginTransaction(); - try { - // contactReference OBSERVATION_DONE, validations true/true - // contact OBSERVATION_DONE, validations true/true - when(contactReference.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - when(contact.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - when(contact.getObservationBeginDate()). - thenReturn(DateUtil.createDate(3, 4, 2010)); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - log.info("test 7 : verification old sampleMonth estimated tides = 0"); - checkTidesValue(0, false); - - log.info("test 7 : verification new sampleMonth estimated " + - "tides = 1 and real tides = 1"); - transaction = manager.getContext().beginTransaction(); - try { - SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); - - TopiaQuery query = dao.createQuery(); - query.addEquals(SampleMonth.PROPERTY_PERIOD_DATE, DateUtil.createDate(1, 4, 2010)); - - SampleMonth month = dao.findByQuery(query); - - assertEquals(1, month.getEstimatedTidesValue()); - assertEquals(1, month.getRealTidesValue()); - - } finally { - transaction.closeContext(); - } - } - - @Test - public void testDecrementSampleMonthContactRefused() - throws TopiaException, NullSampleMonthException { - log.info("testDecrementSampleMonthContactRefused"); - - /** PREPARE DATA **/ - prepareData(false, false); - - // contactReference as the same tideBeginDate and sampleRow as contact - Date tideBeginDate = new Date(contact.getObservationBeginDate().getTime()); - when(contactReference.getObservationBeginDate()).thenReturn(tideBeginDate); - when(contactReference.getSampleRow()).thenReturn(sampleRow); - - // Initialize correct old status in contactReference - when(contactReference.getValidationCompany()).thenReturn(Boolean.TRUE); - when(contactReference.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - when(contactReference.getValidationProgram()).thenReturn(null); - - - // Initialize data in sampleMonth - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); - - sampleMonth.addEstimatedTideTime(1); - sampleMonth.addRealTideTime(1); - - dao.update(sampleMonth); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - // both estimated and real as value = 1 - checkTidesValue(1, false); - checkTidesValue(1, true); - - /** EXEC METHOD **/ - log.info("test 1 : validationProgram null -> FALSE, estimated -1" + - " and real -1"); - transaction = manager.getContext().beginTransaction(); - try { - when(contact.getValidationCompany()).thenReturn(Boolean.TRUE); - when(contact.getContactState()). - thenReturn(ContactState.OBSERVATION_DONE); - when(contact.getValidationProgram()).thenReturn(Boolean.FALSE); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - checkTidesValue(0, false); - checkTidesValue(0, true); - - log.info("test 2 : validationProgram FALSE -> null, estimated +1" + - " and real +1"); - transaction = manager.getContext().beginTransaction(); - try { - when(contactReference.getValidationProgram()). - thenReturn(Boolean.FALSE); - when(contact.getValidationProgram()).thenReturn(null); - - service.updateSampleMonthTidesValue(transaction, contactReference, - contact, true); - - transaction.commitTransaction(); - } finally { - transaction.closeContext(); - } - - checkTidesValue(1, false); - checkTidesValue(1, true); - } - - protected void checkTidesValue(int expected, boolean real) - throws TopiaException { - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction); - - SampleMonth result = dao.findByTopiaId(sampleMonth.getTopiaId()); - int test = real ? result.getRealTidesValue() : - result.getEstimatedTidesValue(); - assertEquals(expected, test); - } finally { - transaction.closeContext(); - } - } - - @Test - public void testLoadContactCsv() throws TopiaException, - WaoBusinessException, - IOException, - ImportRefusedException, - ParseException { - log.info("testLoadContactCsv"); - - /** PREPARE DATA **/ - prepareData(true, true); - - when(reader.get(CONTACT.CONT_ETAT.name())). - thenReturn(ContactState.OBSERVATION_DONE.name()); - when(reader.get(CONTACT.OBSERV_ID.name())). - thenReturn(observer.getLogin()); - when(reader.get(SAMPLING.PLAN_CODE.name())). - thenReturn(sampleRow.getCode()); - when(reader.get(BOAT.NAVS_COD.name())). - thenReturn(String.valueOf(boat.getImmatriculation())); - when(reader.get(CONTACT.CONT_DEBUT_MAREE.name())). - thenReturn("22/03/2010 1:00"); - when(reader.get(CONTACT.CONT_FIN_MAREE.name())). - thenReturn("22/03/10 2:15"); - when(reader.get(CONTACT.CONT_NB_OBSERV.name())). - thenReturn("1"); - when(reader.get(CONTACT.CONT_MAM_CAPT.name())). - thenReturn(""); - when(reader.get(CONTACT.CONT_MAM_OBS.name())). - thenReturn("X"); - when(reader.get(CONTACT.CONT_ALLEGRO.name())). - thenReturn("25/03/2010"); - when(reader.get(CONTACT.CONT_SOCIETE_VALID.name())). - thenReturn("A"); - when(reader.get(CONTACT.CONT_PROGRAM_VALID.name())). - thenReturn(""); - when(reader.get(CONTACT.CONT_CREATION.name())). - thenReturn("18/03/10"); - when(reader.get(CONTACT.CONT_CODE.name())). - thenReturn(""); - String comment = "Commentaire sur le contact\nAutre ligne"; - when(reader.get(CONTACT.CONT_COMMENT.name())). - thenReturn(comment); - when(reader.get(CONTACT.CONT_DATA_RELIABILITY.name())). - thenReturn("DOUBTFUL"); - when(reader.get(CONTACT.CONT_SAMPLING_STRATEGY.name())). - thenReturn(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES.name()); - when(reader.get(CONTACT.CONT_COMPLETE_SAMPLING.name())). - thenReturn("Y"); - - when(creator.getCompany()).thenReturn(company); - when(creator.isAdmin()).thenReturn(false); - when(creator.getLogin()).thenReturn(observer.getLogin()); - - /** EXEC METHOD **/ - - log.info("test 1 : load contact by Creator jmichmuche -> no error"); - ContactInput result = new ContactInput(); - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - result.initialize(transaction, creator, 1); - service.loadContactCsv(reader, result, false); - Date createDate = DateUtil.createDate(18,3,2010); - assertEquals(createDate, result.getCreationDate()); - assertEquals(ContactState.OBSERVATION_DONE, result.getContactState()); - assertEquals(observer, result.getMainObserver()); - assertEquals(sampleRow, result.getSampleRow()); - assertEquals(boat, result.getBoat()); - - assertEquals(DateUtil.getDifferenceInMinutes(DateUtil.createDate(0,0,1,22,3,2010), result.getObservationBeginDate()), 0); - assertEquals(DateUtil.getDifferenceInMinutes(DateUtil.createDate(0,15,2,22,3,2010), result.getObservationEndDate()), 0); - - assertEquals(1, result.getNbObservants()); - assertFalse(result.getMammalsCapture()); - assertTrue(result.getMammalsObservation()); - assertEquals(comment, result.getComment()); - assertEquals(DateUtil.createDate(25,3,2010), - result.getDataInputDate()); - // No validation update : creator is not an admin - assertNull(result.getValidationCompany()); - assertNull(result.getValidationProgram()); - } finally { - transaction.closeContext(); - } - - log.info("test 2 : Error on boat"); - when(reader.get(BOAT.NAVS_COD.name())).thenReturn("2222"); - checkImportError(Contact.PROPERTY_BOAT); - // Reinit boat - when(reader.get(BOAT.NAVS_COD.name())). - thenReturn(String.valueOf(boat.getImmatriculation())); - - log.info("test 3 : Error on company"); - when(creator.getCompany()).thenReturn(null); - checkImportError(WaoUser.PROPERTY_COMPANY); - // Reinit creator company - when(creator.getCompany()).thenReturn(company); - - log.info("test 4 : Error on observer"); - when(reader.get(CONTACT.OBSERV_ID.name())).thenReturn("FAKE"); - checkImportError(Contact.PROPERTY_MAIN_OBSERVER); - // Reinit observer - when(reader.get(CONTACT.OBSERV_ID.name())). - thenReturn(observer.getLogin()); - - log.info("test 5 : Error on sampleRow"); - when(reader.get(SAMPLING.PLAN_CODE.name())).thenReturn("FAKE"); - checkImportError(Contact.PROPERTY_SAMPLE_ROW); - // Reinit sampleRow - when(reader.get(SAMPLING.PLAN_CODE.name())). - thenReturn(sampleRow.getCode()); - - log.info("test 6 : Error on state"); - when(reader.get(CONTACT.CONT_ETAT.name())).thenReturn("FAKE"); - checkImportError(Contact.PROPERTY_STATE); - // Reinit state - when(reader.get(CONTACT.CONT_ETAT.name())). - thenReturn(ContactState.OBSERVATION_DONE.name()); - } - - protected void checkImportError(String field) throws TopiaException { - ContactInput result = new ContactInput(); - TopiaContext transaction = manager.getContext().beginTransaction(); - try { - result.initialize(transaction, creator, 1); - service.loadContactCsv(reader, result, false); - } catch (Exception eee) { - log.error("Error : " + eee.getMessage()); - assertEquals(ImportRefusedException.class, eee.getClass()); - ImportRefusedException ex = (ImportRefusedException)eee; - assertEquals(field, ex.getField()); - } finally { - transaction.closeContext(); - } - } - - @Test - public void testCreateOrUpdateContact() - throws TopiaException, WaoBusinessException { - log.info("testCreateOrUpdateContact"); - - /** PREPARE DATA **/ - prepareData(true, true); - -// TopiaContext transaction = manager.getContext().beginTransaction(); -// ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); -// List<Contact> allContact = dao.findAll(); -// for (Contact contact : allContact) { -// dao.delete(contact); -// } - - ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); - - // Don't use a mock in this case - Contact newContact = service.newContact(connectedUser, sampleRow, boat); - newContact.setCreationDate(DateUtil.createDate(2, 3, 2010)); - - /** EXEC METHOD **/ - - log.info("test 1 : Create new contact with state CONTACT_START"); - TopiaContext transaction = null; - String newTopiaId = null; - try { - transaction = manager.getContext().beginTransaction(); - - service.createOrUpdateContact(transaction, null, newContact, false); - transaction.commitTransaction(); - - newTopiaId = newContact.getTopiaId(); - assertNotNull(newTopiaId); - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } - - log.info("test 1 : Check contact existence"); - try { - transaction = manager.getContext().beginTransaction(); - - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - - Contact existingContact = dao.findByTopiaId(newTopiaId); - assertNotNull(existingContact); - assertEquals(boat, existingContact.getBoat()); - assertEquals(sampleRow, existingContact.getSampleRow()); - assertEquals(observer, existingContact.getMainObserver()); - assertEquals(ContactState.CONTACT_START, - existingContact.getContactState()); - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } - - log.info("test 2 : Update the contact with state OBSERVATION_DONE, " + - "tideBeginDate, tideEndDate and NbObservants"); - Date tideBeginDate = DateUtil.createDate(18,3,2010); - Date tideEndDate = DateUtil.createDate(19,3,2010); - try { - transaction = manager.getContext().beginTransaction(); - - newContact.setContactState(ContactState.OBSERVATION_DONE); - newContact.setObservationBeginDate(tideBeginDate); - newContact.setObservationEndDate(tideEndDate); - newContact.setNbObservants(1); - - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - Contact oldContact = dao.findByTopiaId(newTopiaId); - - service.createOrUpdateContact(transaction, oldContact, newContact, false); - transaction.commitTransaction(); - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } - - log.info("test 2 : Check update contact"); - try { - transaction = manager.getContext().beginTransaction(); - - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - - Contact existingContact = dao.findByTopiaId(newTopiaId); - assertNotNull(existingContact); - assertEquals(1, existingContact.getNbObservants()); - assertEquals(tideBeginDate, existingContact.getObservationBeginDate()); - assertEquals(tideEndDate, existingContact.getObservationEndDate()); - assertEquals(ContactState.OBSERVATION_DONE, - existingContact.getContactState()); - - // Will have an update on sampleMonth 03/2010 for estimatedTides - SampleMonthDAO monthDAO = - WaoDAOHelper.getSampleMonthDAO(transaction); - SampleMonth existingMonth = - monthDAO.findByTopiaId(sampleMonth.getTopiaId()); - assertNotNull(existingMonth); - assertEquals(1, existingMonth.getEstimatedTidesValue()); - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } - } - - @Test - public void testImportContactCsv() - throws TopiaException, WaoBusinessException, IOException { - log.info("testImportContactCsv"); - - /** PREPARE DATA **/ - prepareData(true, true); - - when(creator.getCompany()).thenReturn(company); - when(creator.getLogin()).thenReturn(observer.getLogin()); - when(creator.getProfile()).thenReturn(new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true)); - - /** EXEC METHOD **/ - log.info("test 1 : Import new contact with observer creator"); - InputStream input = - getClass().getResourceAsStream("/import/contacts.csv"); - try { - ImportResults results = service.importContactCsv(creator, input); - assertEquals(0, results.getNbRowsRefused()); - assertEquals(1, results.getNbRowsImported()); - assertTrue(results.getErrors().isEmpty()); - } finally { - input.close(); - } - - log.info("test 1 : Check creation of the contact"); - TopiaContext transaction = null; - try { - transaction = manager.getContext().beginTransaction(); - - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - - List<Contact> contactsFound = dao.findAll(); - assertEquals(1, contactsFound.size()); - Contact contactFound = contactsFound.get(0); - assertNull(contactFound.getValidationCompany()); - assertNull(contactFound.getValidationProgram()); - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } - - log.info("test 2 : Import new contact with super admin creator"); - when(creator.getCompany()).thenReturn(company); - when(creator.getLogin()).thenReturn("admin"); - when(creator.getProfile()).thenReturn(new UserProfileImpl(ObsProgram.OBSMER, UserRole.ADMIN, true)); - - input = getClass().getResourceAsStream("/import/contacts.csv"); - try { - ImportResults results = service.importContactCsv(creator, input); - assertEquals(1, results.getNbRowsImported()); - assertEquals(0, results.getNbRowsRefused()); - assertTrue(results.getErrors().isEmpty()); - } finally { - input.close(); - } - } -} Copied: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactTest.java (from rev 1306, trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactImplTest.java) =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactTest.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -0,0 +1,111 @@ +/* + * #%L + * Wao :: Business + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.wao.service; + +import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.ContactFilter; +import fr.ifremer.wao.bean.ContactFilterImpl; +import fr.ifremer.wao.bean.ObsProgram; +import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.WaoUser; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + * ServiceContactImplTest + * + * Created: 3 mai 2010 + * + * @author fdesbois + * $Id$ + */ +public class ServiceContactTest extends AbstractServiceTest { + + private static final Logger log = + LoggerFactory.getLogger(ServiceContactTest.class); + + private ServiceContact service; + + @Before + public void initialize() { + service = manager.getServiceContact(); + } + + @Test + public void testGetContactsFilteredByObserver() throws TopiaException { + log.info("getContactsFilteredByObserver"); + + /** PREPARE DATA **/ + Contact contact = createDefaultContact(); + + /** EXEC METHOD **/ + ContactFilter filter = new ContactFilterImpl(); + filter.setObserver(findDefaultObserver()); + + log.info("test 1 : Ok good filter, contact is correctly returned"); + Map<String, Contact> results = service.getContacts(filter); + + Assert.assertEquals(1, results.size()); + Contact contactFind = results.get(contact.getTopiaId()); + Assert.assertEquals(contact, contactFind); + + log.info("test 2 : Bad filter, no contact is returned"); + WaoUser observer2 = createUser("marge", + UserRole.OBSERVER, findDefaultCompany()); + + filter.setObserver(observer2); + + results = service.getContacts(filter); + Assert.assertEquals(0, results.size()); + } + + @Test + public void testSaveContactWithMultipleObservers() throws TopiaException { + Contact contact = createDefaultContact(); + + Company company = createCompany("Boite"); + WaoUser toto = createUser("toto", UserRole.OBSERVER, company); + contact.addSecondaryObservers(toto); + contact.addSecondaryObservers(createUser("titi", UserRole.OBSERVER, company)); + + ConnectedUser connectedUser = getConnectedUser(toto, UserRole.COORDINATOR, ObsProgram.OBSMER); + service.saveContact(connectedUser, contact, false); + + Contact savedContact = service.getContact(contact.getTopiaId()); + Assert.assertEquals(2, savedContact.getSecondaryObservers().size()); + + contact.clearSecondaryObservers(); + service.saveContact(connectedUser, contact, false); + savedContact = service.getContact(contact.getTopiaId()); + Assert.assertEquals(0, savedContact.getSecondaryObservers().size()); + } + + +} Property changes on: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,170 +0,0 @@ -/* - * #%L - * Wao :: Business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao.service; - -import fr.ifremer.wao.TestManager; -import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.SamplingFilterImpl; -import fr.ifremer.wao.entity.FishingZone; -import org.apache.commons.io.IOUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * - * @author fdesbois <fdesbois at codelutin.com> - */ -public class ServiceReferentialImplTest { - - private static TestManager manager; - - private static final Logger log = LoggerFactory.getLogger(ServiceReferentialImplTest.class); - - private ServiceReferential service; - - public ServiceReferentialImplTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - manager.start(); - service = manager.getServiceReferential(); - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - - /** - * Test of getFacades method, of class ServiceReferentialImpl. - */ - @Test - public void testGetFacades() throws Exception { - log.info("getFacades"); - - InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); - service.importFishingZoneCsv(input); - - List<String> facades = service.getFacades(new SamplingFilterImpl()); - assertEquals(3, facades.size()); - assertTrue(facades.contains("Atlantique")); - assertTrue(facades.contains("Mer du Nord")); - assertTrue(facades.contains("Méditerranée")); - } - - @Test - public void testGetSectors() throws Exception { - log.info("getSectors"); - - InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); - service.importFishingZoneCsv(input); - - SamplingFilter filter = new SamplingFilterImpl(); - - List<String> sectors = service.getSectors(filter); - assertEquals(5, sectors.size()); - assertTrue(sectors.contains("Manche")); - assertTrue(sectors.contains("Mer du Nord")); - assertTrue(sectors.contains("Manche Ouest")); - assertTrue(sectors.contains("Golfe de Gascogne")); - assertTrue(sectors.contains("Méditerranée")); - - filter.setFacadeName("Atlantique"); - - sectors = service.getSectors(filter); - assertEquals(2, sectors.size()); - assertTrue(sectors.contains("Manche Ouest")); - assertTrue(sectors.contains("Golfe de Gascogne")); - } - - /** - * Test of getFishingZones method, of class ServiceReferentialImpl. - * @throws WaoException if error during import or getFishingZones - */ - @Test - public void testGetFishingZones() { - log.info("getFishingZones"); - - InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); - int nbNew = service.importFishingZoneCsv(input); - // nbNew = 6 - - List<FishingZone> results = service.getFishingZones(); - assertEquals(nbNew, results.size()); - } - - /** - * Test of importFishingZoneCsv method, of class ServiceReferentialImpl. - * @throws WaoException if import error - */ - @Test - public void testImportFishingZoneCsv() { - log.info("importFishingZoneCsv"); - - InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); - int result = service.importFishingZoneCsv(input); - assertEquals(6, result); - } - - @Test - public void testImportTerrestrialDivision() { - InputStream input = null; - try { - input = getClass().getResourceAsStream("/import/purifiedTerrestrialDivisions.csv"); - service.importTerrestrialDivisions(input); - int nbTerrestrialDivisions = service.getAllObservationUnits().size(); - input = getClass().getResourceAsStream("/import/purifiedTerrestrialDivisions.csv"); - service.importTerrestrialDivisions(input); - assertEquals("importing the same file two times should not create extra lines", - nbTerrestrialDivisions, service.getAllObservationUnits().size()); - } finally { - IOUtils.closeQuietly(input); - } - } - -} Copied: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialTest.java (from rev 1314, trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java) =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialTest.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -0,0 +1,138 @@ +/* + * #%L + * Wao :: Business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.wao.service; + +import fr.ifremer.wao.WaoServices; +import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.SamplingFilter; +import fr.ifremer.wao.bean.SamplingFilterImpl; +import fr.ifremer.wao.entity.FishingZone; +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + * @author fdesbois <fdesbois at codelutin.com> + */ +public class ServiceReferentialTest extends AbstractServiceTest { + + private static final Logger log = LoggerFactory.getLogger(ServiceReferentialTest.class); + + private ServiceReferential service; + + @Before + public void setUp() throws Exception { + service = manager.getServiceReferential(); + } + + /** + * Test of getFacades method, of class ServiceReferentialImpl. + */ + @Test + public void testGetFacades() throws Exception { + InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + service.importFishingZoneCsv(input); + + List<String> facades = service.getFacades(new SamplingFilterImpl()); + assertEquals(3, facades.size()); + assertTrue(facades.contains("Atlantique")); + assertTrue(facades.contains("Mer du Nord")); + assertTrue(facades.contains("Méditerranée")); + } + + @Test + public void testGetSectors() throws Exception { + InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + service.importFishingZoneCsv(input); + + SamplingFilter filter = new SamplingFilterImpl(); + + List<String> sectors = service.getSectors(filter); + assertEquals(5, sectors.size()); + assertTrue(sectors.contains("Manche")); + assertTrue(sectors.contains("Mer du Nord")); + assertTrue(sectors.contains("Manche Ouest")); + assertTrue(sectors.contains("Golfe de Gascogne")); + assertTrue(sectors.contains("Méditerranée")); + + filter.setFacadeName("Atlantique"); + + sectors = service.getSectors(filter); + assertEquals(2, sectors.size()); + assertTrue(sectors.contains("Manche Ouest")); + assertTrue(sectors.contains("Golfe de Gascogne")); + } + + /** + * Test of getFishingZones method, of class ServiceReferentialImpl. + * @throws WaoException if error during import or getFishingZones + */ + @Test + public void testGetFishingZones() { + InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + int nbNew = service.importFishingZoneCsv(input); + // nbNew = 6 + + List<FishingZone> results = service.getFishingZones(); + assertEquals(nbNew, results.size()); + } + + /** + * Test of importFishingZoneCsv method, of class ServiceReferentialImpl. + * @throws WaoException if import error + */ + @Test + public void testImportFishingZoneCsv() { + InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + int result = service.importFishingZoneCsv(input); + assertEquals(6, result); + } + + @Test + public void testImportTerrestrialDivision() { + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/purifiedTerrestrialDivisions.csv"); + service.importTerrestrialDivisions(input); + int nbTerrestrialDivisions = service.getAllObservationUnits().size(); + input = getClass().getResourceAsStream("/import/purifiedTerrestrialDivisions.csv"); + service.importTerrestrialDivisions(input); + assertEquals("importing the same file two times should not create extra lines", + nbTerrestrialDivisions, service.getAllObservationUnits().size()); + } finally { + IOUtils.closeQuietly(input); + } + } + +} Property changes on: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -1,677 +0,0 @@ -/* - * #%L - * Wao :: Business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -package fr.ifremer.wao.service; - -import fr.ifremer.wao.WaoBusinessException; -import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.bean.ConnectedUser; -import fr.ifremer.wao.bean.FacadeRow; -import fr.ifremer.wao.bean.ObsProgram; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.SamplingFilterImpl; -import fr.ifremer.wao.bean.SamplingStrategy; -import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyDAO; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactDAO; -import fr.ifremer.wao.entity.ContactImpl; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.DCF5CodeImpl; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatDAO; -import fr.ifremer.wao.entity.FishingGearDCFDAO; -import fr.ifremer.wao.entity.FishingGearDCFImpl; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.FishingZoneDAO; -import fr.ifremer.wao.entity.Profession; -import fr.ifremer.wao.entity.ProfessionDAO; -import fr.ifremer.wao.entity.ProfessionImpl; -import fr.ifremer.wao.entity.SampleMonth; -import fr.ifremer.wao.entity.SampleMonthImpl; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowDAO; -import fr.ifremer.wao.entity.SampleRowLogImpl; -import fr.ifremer.wao.entity.TargetSpeciesDCFImpl; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.io.ImportResults; -import org.junit.Assert; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.util.DateUtil; -import org.nuiton.util.PeriodDates; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; - -/** - * ServiceSamplingImplTest - * - * Created: 30 nov. 2009 - * - * @author fdesbois <fdesbois at codelutin.com> - */ -public class ServiceSamplingImplTest extends AbstractServiceTest { - - private static final Logger log = - LoggerFactory.getLogger(ServiceSamplingImplTest.class); - - @Test - public void testCreateUpdateSampleRow() throws Exception { - log.info("createUpdateSampleRow"); - - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - List<FishingZone> zones = prepareFishingZones(transaction); - - InputStream input = getClass().getResourceAsStream("/import/navires.csv"); - ServiceBoatImpl serviceBoat = (ServiceBoatImpl) manager.getServiceBoat(); - serviceBoat.importBoatCsv(input); - - // add DRB, DRH and ALG as existing codes - FishingGearDCFDAO fishingGearDCFDAO = WaoDAOHelper.getFishingGearDCFDAO(transaction); - fishingGearDCFDAO.create(new FishingGearDCFImpl("DRB")); - fishingGearDCFDAO.create(new FishingGearDCFImpl("DRH")); - WaoDAOHelper.getTargetSpeciesDCFDAO(transaction).create(new TargetSpeciesDCFImpl("ALG")); - - transaction.commitTransaction(); - - transaction.closeContext(); - - // CREATE - Profession profession1 = new ProfessionImpl(); - profession1.setMeshSize(">=18"); - profession1.setSize("90-1000"); - profession1.setLibelle("Chalutage de poissons tubes"); - - List<SampleMonth> months = new ArrayList<SampleMonth>(); - for (int i = 0; i < 12; i++) { - SampleMonth month = new SampleMonthImpl(); - Calendar calendar = new GregorianCalendar(2009, i, 1); - month.setPeriodDate(calendar.getTime()); - month.setExpectedTidesValue(3); - months.add(month); - } - for (int i = 0; i < 3; i++) { - SampleMonth month = new SampleMonthImpl(); - Calendar calendar = new GregorianCalendar(2010, i, 1); - month.setPeriodDate(calendar.getTime()); - month.setExpectedTidesValue(4); - months.add(month); - } - - SampleRow row = serviceSampling.newSampleRow(getConnectedAdmin()); - row.setCode("2010_03"); - row.setNbObservants(3); - row.setAverageTideTime(2.5); - row.setProgramName("DPMA-2009"); - row.setPeriodBegin(DateUtil.createDate(1, 1, 2009)); - row.setPeriodEnd(DateUtil.createDate(31, 3, 2010)); - row.setProfession(profession1); - row.setSampleMonth(months); - row.setFishingZone(zones); - row.setFishingZonesInfos("port tres loin du champ"); - - // for row, add DCF5 codes DRB_ALG, DRH - Collection<DCF5Code> dcf5codes = new ArrayList<DCF5Code>(); - DCF5Code dcf5 = new DCF5CodeImpl(); - dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRB")); - dcf5.setTargetSpeciesDCF(new TargetSpeciesDCFImpl("ALG")); - dcf5codes.add(dcf5); - dcf5 = new DCF5CodeImpl(); - dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRH")); - dcf5codes.add(dcf5); - row.setDCF5Code(dcf5codes); - - /** EXEC CREATE **/ - List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); - serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl(), getConnectedAdmin()); - assertNotNull(row.getTopiaId()); - - assertNotNull(row.getProfession().getTopiaId()); - - SampleRow result = serviceSampling.getSampleRow(row.getTopiaId()); - assertEquals(3, result.getFishingZone().size()); - assertEquals(3, result.getElligibleBoat().size()); - - // TEST FOR DELETE ELLIGIBLE PROPERTY_BOAT - boats.remove(2); - serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl(), getConnectedAdmin()); - - result = serviceSampling.getSampleRow(row.getTopiaId()); - assertEquals(2, result.getElligibleBoat().size()); - - // TEST FOR REMOVE FISHING ZONE - //FishingZone zone = result.getFishingZone().get(0); - result.getFishingZone().remove(0); - serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl(), getConnectedAdmin()); - - result = serviceSampling.getSampleRow(row.getTopiaId()); - assertEquals(2, result.getFishingZone().size()); - - log.info("test if sampleRow becomes null in contact after update"); - - Contact contact = new ContactImpl(); - WaoUser observer = createDefaultObserver(); - contact.setMainObserver(observer); - contact.setSampleRow(result); - - ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); - manager.getServiceContact().saveContact(connectedUser, contact, false); - -// serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); - - transaction = manager.getContext().beginTransaction(); - try { - ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); - - Contact contactFound = contactDAO.findBySampleRow(row); - - Assert.assertNotNull(contactFound); - - } finally { - transaction.closeContext(); - } - - } - - @Test - public void testUpdateElligibleBoats() throws TopiaException { - log.info("testUpdateElligibleBoats"); - - /** PREPARE DATA **/ - SampleRow row = createDefaultSampleRow(); - Boat boat = createDefaultBoat(); - - // Create an elligibleBoat active for company - ElligibleBoat elligible = createElligibleBoat(row, boat, true); - // Retrieve the sampleRow (updated with elligible) - row = findDefaultSampleRow(SampleRow.PROPERTY_ELLIGIBLE_BOAT); - - /** EXEC METHOD **/ - List<Boat> boats = new ArrayList<Boat>(); - boats.add(boat); - - TopiaContext transaction = serviceSampling.beginTransaction(); - // Will update the existing ElligibleBoat and set globalActive to true - List<List<Integer>> results = - serviceSampling.updateElligibleBoats(transaction, row, boats); - - /** CHECKING RESULTS **/ - Assert.assertEquals(2, results.size()); - // Index=1 for updatedImmatriculations, 1 is updated - Assert.assertEquals(1, results.get(1).size()); - // Index=0 for removedImmatriculations, 0 is removed - Assert.assertEquals(0, results.get(0).size()); - - Assert.assertEquals(1, row.sizeElligibleBoat()); - ElligibleBoat updatedElligible = - row.getElligibleBoatByTopiaId(elligible.getTopiaId()); - - Assert.assertTrue(updatedElligible.getGlobalActive()); - } - - /** - * Test of getSampleRowsOrderedByFishingZone method, of class ServiceSamplingImpl. - */ - @Test - public void testGetSampleRowsOrderedByFishingZone() throws Exception { - log.info("getSampleRowsOrderedByFishingZone"); - - /** PREPARE DATA **/ - - TopiaContext transaction = manager.getContext().beginTransaction(); - - List<FishingZone> zones = prepareFishingZones(transaction); - - //Program program1 = programDAO.create(Program.NAME, "DPMA-2009"); - Date dateBegin1 = DateUtil.createDate(1, 1, 2009); - Date dateEnd1 = DateUtil.createDate(1, 3, 2010); - PeriodDates period1 = new PeriodDates(dateBegin1, dateEnd1); - - //Program program2 = programDAO.create(Program.NAME, "PPDA-2008"); - Date dateBegin2 = DateUtil.createDate(1, 1, 2008); - Date dateEnd2 = DateUtil.createDate(1, 12, 2008); - PeriodDates period2 = new PeriodDates(dateBegin2, dateEnd2); - - SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - - SampleRow row1 = dao.create(); - row1.setCode("2010_0001"); - row1.addFishingZone(zones.get(2)); - row1.setProgramName("DPMA-2009"); - row1.setPeriod(period1); - - log.info(row1.getCode() + " :: " + row1.getFacade() + " :: " + row1.getSectors()); - - SampleRow row2 = dao.create(); - row2.setCode("2010_0002"); - row2.addFishingZone(zones.get(0)); - row2.setProgramName("DPMA-2009"); - row2.setPeriod(period1); - - log.info(row2.getCode() + " :: " + row2.getFacade() + " :: " + row2.getSectors()); - - SampleRow row3 = dao.create(); - row3.setCode("2010_0003"); - row3.addFishingZone(zones.get(1)); - row3.addFishingZone(zones.get(2)); - row3.addFishingZone(zones.get(0)); - row3.setProgramName("PPDA-2008"); - row3.setPeriod(period2); - - log.info(row3.getCode() + " :: " + row3.getFacade() + " :: " + row3.getSectors()); - - SampleRow row4 = dao.create(); - row4.setCode("2010_0004"); - row4.addFishingZone(zones.get(0)); // Mer du Nord :: Manche - row4.setProgramName("DPMA-2009"); - row4.setPeriod(period1); - - log.info(row4.getCode() + " :: " + row4.getFacade() + " :: " + row4.getSectors()); - - transaction.commitTransaction(); - - /** EXEC service method **/ - - // FIRST TEST : - // ORDER by FishingZone (facadeName, sectorName, districtCode) - // BIG PERIOD, included program1 and program2 - // NO COMPANY (= null) - Calendar begin = new GregorianCalendar(2000, 0, 1, 0, 0, 0); - Calendar end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); - SamplingFilter filter = new SamplingFilterImpl(); - filter.setPeriod(new PeriodDates(begin, end)); - filter.setObsProgram(ObsProgram.OBSMER); - // RESULT : [2010_0002, 2010_0004, 2010_0001, 2010_0003] - FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); - List<SampleRow> rows = facade.getValues(); - assertEquals(4, rows.size()); - SampleRow resultRow0 = rows.get(0); - assertEquals("2010_0002", resultRow0.getCode()); - SampleRow resultRow1 = rows.get(1); - assertEquals("2010_0004", resultRow1.getCode()); - -// List<FishingZone> zoneRow1 = resultRow1.getFishingZone(); -// assertEquals(3, zoneRow1.size()); -// FishingZone resultZone0 = zoneRow1.get(0); -// assertEquals("VIIb", resultZone0.getDistrictCode()); -// FishingZone resultZone1 = zoneRow1.get(1); -// assertEquals("VI", resultZone1.getDistrictCode()); -// FishingZone resultZone2 = zoneRow1.get(2); -// assertEquals("V", resultZone2.getDistrictCode()); - - SampleRow resultRow2 = rows.get(2); - assertEquals("2010_0003", resultRow2.getCode()); - SampleRow resultRow3 = rows.get(3); - assertEquals("2010_0001", resultRow3.getCode()); - - // SECOND TEST : - // ORDER by FishingZone (facadeName, sectorName, districtCode) - // BIG PERIOD, not included program2 - // NO COMPANY (= null) - begin = new GregorianCalendar(2009, 0, 1, 0, 0, 0); - end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); - filter.setPeriod(new PeriodDates(begin, end)); - // RESULT : [2010_0002, 2010_0004, 2010_0001] - facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); - rows = facade.getValues(); - assertEquals(3, rows.size()); - resultRow0 = rows.get(0); - assertEquals("2010_0002", resultRow0.getCode()); - resultRow1 = rows.get(1); - assertEquals("2010_0004", resultRow1.getCode()); - resultRow2 = rows.get(2); - assertEquals("2010_0001", resultRow2.getCode()); - - } - - private List<FishingZone> prepareFishingZones(TopiaContext transaction) throws TopiaException { - - FishingZoneDAO fishingZoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - - FishingZone fishingZone1 = fishingZoneDAO.create(); - fishingZone1.setFacadeName("Atlantique"); - fishingZone1.setSectorName("Secteur Mer Celtique et Ouest Irlande centré Pays bigouden"); - fishingZone1.setDistrictCode("VIIb"); - - FishingZone fishingZone2 = fishingZoneDAO.create(); - fishingZone2.setFacadeName("Manche"); - fishingZone2.setSectorName("Secteur Cherbourg Honfleur centré sur Port-en-Bessin"); - fishingZone2.setDistrictCode("VI"); - - FishingZone fishingZone3 = fishingZoneDAO.create(); - fishingZone3.setFacadeName("Manche"); - fishingZone3.setSectorName("Secteur du Havre à Dunkerque centré sur Boulogne"); - fishingZone3.setDistrictCode("V"); - - transaction.commitTransaction(); - - return fishingZoneDAO.findAll(); - } - - public void testGetSampleRowsForUser() throws Exception { - log.info("getSampleRowsForUser"); - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); - FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); - FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - Company company = companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - Calendar begin = new GregorianCalendar(2009,8,1); - Calendar end = new GregorianCalendar(2010,11,31); - SampleRowDAO sampleRowDAO = WaoDAOHelper.getSampleRowDAO(transaction); - SampleRow row = sampleRowDAO.create( - SampleRow.PROPERTY_CODE,"2010_178", - SampleRow.PROPERTY_COMPANY,company, - SampleRow.PROPERTY_PROGRAM_NAME, "DPMA-2009", - SampleRow.PROPERTY_PERIOD_BEGIN, begin.getTime(), - SampleRow.PROPERTY_PERIOD_END, end.getTime()); - - - transaction.commitTransaction(); - transaction.closeContext(); - - InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); - - /** EXEC METHOD **/ - SamplingFilter filter = new SamplingFilterImpl(); -// User admin = new UserImpl(); -// admin.setAdmin(true); -// filter.setCompany() - filter.setNbMonthFinishedFromToday(0); - List<SampleRow> results = serviceSampling.getSampleRowsByFilter(filter); - // total in file : 11, 1 refused, 1 finished - assertEquals(9, results.size()); - -// User user = new UserImpl(); -// user.setCompany(company); - filter.setCompany(company); - results = serviceSampling.getSampleRowsByFilter(filter); - assertEquals(1, results.size()); - } - - @Test - public void testGetNewProfession() throws Exception { - log.info("getNewProfession"); - - /** PREPARE DATA **/ - - TopiaContext transaction = manager.getContext().beginTransaction(); - - ProfessionDAO dao = WaoDAOHelper.getProfessionDAO(transaction); - - Profession profession = dao.create( - Profession.PROPERTY_LIBELLE, "Fileyage en barre", - Profession.PROPERTY_MESH_SIZE, "< 80", - Profession.PROPERTY_OTHER, "90mm", - Profession.PROPERTY_SPECIES, "barre, lieu noir, saumon des plages"); - - transaction.commitTransaction(); - transaction.closeContext(); - - /** EXEC METHOD **/ - Profession newProfession = serviceSampling.getNewProfession(profession); - Assert.assertNotSame(profession, newProfession); - Assert.assertEquals("Fileyage en barre", newProfession.getLibelle()); - Assert.assertEquals("< 80", newProfession.getMeshSize()); - Assert.assertEquals("90mm", newProfession.getOther()); - Assert.assertEquals("barre, lieu noir, saumon des plages", newProfession.getSpecies()); - - } - - @Test - public void testDeleteSampleRow() throws Exception { - log.info("deleteSampleRow"); - - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); - FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); - FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - companyDAO.create(Company.PROPERTY_NAME, "BIS"); - transaction.commitTransaction(); - - - InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); - - SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); - SampleRow row = rowDAO.findByCode("2010_0001"); - row.getProfession(); - row.getProfession(); - row.getCompany(); - row.sizeSampleMonth(); - row.sizeElligibleBoat(); - row.sizeSampleRowLog(); - transaction.closeContext(); - - input = getClass().getResourceAsStream("/import/navires.csv"); - ServiceBoat serviceBoat = manager.getServiceBoat(); - serviceBoat.importBoatCsv(input); - List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); - - serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl(), getConnectedAdmin()); - /** EXEC METHOD **/ - - serviceSampling.deleteSampleRow(row); - transaction = manager.getContext().beginTransaction(); - rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); - row = rowDAO.findByCode("2010_0001"); - assertNull(row); - - ElligibleBoatDAO elligibleDAO = WaoDAOHelper.getElligibleBoatDAO(transaction); - List<ElligibleBoat> elligibles = elligibleDAO.findAll(); - assertEquals(0, elligibles.size()); - - log.info("test if sampleRow can't be deleted if contacts are associated"); - - row = rowDAO.findByCode("2010_0002"); - transaction.closeContext(); - - Contact contact = new ContactImpl(); - WaoUser observer = createDefaultObserver(); - contact.setMainObserver(observer); - contact.setSampleRow(row); - - ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); - manager.getServiceContact().saveContact(connectedUser, contact, false); - - try { - serviceSampling.deleteSampleRow(row); - Assert.fail("deleting a sample-row with associated contact should" - + " not be permitted"); - } catch (WaoBusinessException eee) { - if (log.isTraceEnabled()) { - log.trace("exception raised while trying to delete sample row", - eee); - } - } - } - - @Test - public void testImportSamplingPlanCsv() - throws TopiaException, WaoException, WaoBusinessException { - log.info("importSamplingPlanCsv"); - - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); - FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); - FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - companyDAO.create(Company.PROPERTY_NAME, "BIS"); - - transaction.commitTransaction(); - transaction.closeContext(); - - /** EXEC METHOD **/ - InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - ImportResults result = serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); - - // total imported - assertEquals(12, result.getNbRowsImported()); - // total refused - assertEquals(1, result.getNbRowsRefused()); - - /** CHECK VALUES **/ - transaction = manager.getContext().beginTransaction(); - - SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); - - // Error #2221 : don't keep the same profession for two different rows - SampleRow row2 = rowDAO.findByCode("2010_0010"); - SampleRow row3 = rowDAO.findByCode("2010_0011"); - assertNotSame(row2.getProfession(), row3.getProfession()); - - ProfessionDAO professionDAO = - WaoDAOHelper.getProfessionDAO(transaction); - - List<Profession> professions = professionDAO.findAll(); - assertEquals(12, professions.size()); - - SampleRow row1 = rowDAO.findByCode("2010_0001"); - assertNotNull(row1); - assertEquals(1, row1.getNbObservants()); - assertEquals(1.5, row1.getAverageTideTime(), 0.1); - assertEquals("Un petit commentaire", row1.getComment()); - - assertEquals("MA-2009", row1.getProgramName()); - - Profession profession = row1.getProfession(); - assertNotNull(profession); - - List<SampleMonth> months = row1.getSampleMonth(); - assertEquals(11, months.size()); - - Collection<FishingZone> zones = row1.getFishingZone(); - assertEquals(2, zones.size()); - zones.contains(zoneI); - zones.contains(zoneIId); - - Collection<DCF5Code> dcf5codes = row1.getDCF5Code(); - assertEquals(1, dcf5codes.size()); - - assertEquals(row1.getSamplingStrategy(), SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); - - transaction.closeContext(); - } - - @Test - public void testGetPrograms() throws Exception { - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); - zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); - zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - companyDAO.create(Company.PROPERTY_NAME, "BIS"); - transaction.commitTransaction(); - transaction.closeContext(); - - InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); - - /** EXEC METHOD **/ - List<String> programs = serviceSampling.getPrograms(null); - assertEquals(4, programs.size()); - } - - - @Test - public void testGetNewSampleRowCode() throws Exception { - log.info("getNewSampleRowCode"); - - /** PREPARE DATA **/ - TopiaContext transaction = manager.getContext().beginTransaction(); - - FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); - FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); - FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); - FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); - companyDAO.create(Company.PROPERTY_NAME, "BIS"); - transaction.commitTransaction(); - - ServiceSampling serviceSampling = manager.getServiceSampling(); - InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); - - transaction.closeContext(); - - /** EXEC METHOD **/ - - Calendar begin = new GregorianCalendar(2009, 11, 1); - - String result = serviceSampling.getNewSampleRowCode(begin.getTime()); - Assert.assertEquals("2009_0007", result); - - // Test regex for replacment in importSamplingPlanCsv -// String code = "2010_1"; -// code = code.replaceFirst("_(\\d)$", "_0$1"); -// Assert.assertEquals("2010_01", code); -// -// code = "2010_04"; -// code = code.replaceFirst("_(\\d)$", "_0$1"); -// Assert.assertEquals("2010_04", code); - } - -} Copied: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingTest.java (from rev 1306, trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java) =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingTest.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -0,0 +1,662 @@ +/* + * #%L + * Wao :: Business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +package fr.ifremer.wao.service; + +import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.WaoDAOHelper; +import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.FacadeRow; +import fr.ifremer.wao.bean.ObsProgram; +import fr.ifremer.wao.bean.SamplingFilter; +import fr.ifremer.wao.bean.SamplingFilterImpl; +import fr.ifremer.wao.bean.SamplingStrategy; +import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyDAO; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactDAO; +import fr.ifremer.wao.entity.ContactImpl; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.DCF5CodeImpl; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatDAO; +import fr.ifremer.wao.entity.FishingGearDCFDAO; +import fr.ifremer.wao.entity.FishingGearDCFImpl; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.FishingZoneDAO; +import fr.ifremer.wao.entity.Profession; +import fr.ifremer.wao.entity.ProfessionDAO; +import fr.ifremer.wao.entity.ProfessionImpl; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleMonthImpl; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowDAO; +import fr.ifremer.wao.entity.SampleRowLogImpl; +import fr.ifremer.wao.entity.TargetSpeciesDCFImpl; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.io.ImportResults; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.util.DateUtil; +import org.nuiton.util.PeriodDates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; + +/** + * ServiceSamplingImplTest + * + * Created: 30 nov. 2009 + * + * @author fdesbois <fdesbois at codelutin.com> + */ +public class ServiceSamplingTest extends AbstractServiceTest { + + private static final Logger log = + LoggerFactory.getLogger(ServiceSamplingTest.class); + + @Test + public void testCreateUpdateSampleRow() throws Exception { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + List<FishingZone> zones = prepareFishingZones(transaction); + + InputStream input = getClass().getResourceAsStream("/import/navires.csv"); + ServiceBoatImpl serviceBoat = (ServiceBoatImpl) manager.getServiceBoat(); + serviceBoat.importBoatCsv(input); + + // add DRB, DRH and ALG as existing codes + FishingGearDCFDAO fishingGearDCFDAO = WaoDAOHelper.getFishingGearDCFDAO(transaction); + fishingGearDCFDAO.create(new FishingGearDCFImpl("DRB")); + fishingGearDCFDAO.create(new FishingGearDCFImpl("DRH")); + WaoDAOHelper.getTargetSpeciesDCFDAO(transaction).create(new TargetSpeciesDCFImpl("ALG")); + + transaction.commitTransaction(); + + transaction.closeContext(); + + // CREATE + Profession profession1 = new ProfessionImpl(); + profession1.setMeshSize(">=18"); + profession1.setSize("90-1000"); + profession1.setLibelle("Chalutage de poissons tubes"); + + List<SampleMonth> months = new ArrayList<SampleMonth>(); + for (int i = 0; i < 12; i++) { + SampleMonth month = new SampleMonthImpl(); + Calendar calendar = new GregorianCalendar(2009, i, 1); + month.setPeriodDate(calendar.getTime()); + month.setExpectedTidesValue(3); + months.add(month); + } + for (int i = 0; i < 3; i++) { + SampleMonth month = new SampleMonthImpl(); + Calendar calendar = new GregorianCalendar(2010, i, 1); + month.setPeriodDate(calendar.getTime()); + month.setExpectedTidesValue(4); + months.add(month); + } + + SampleRow row = serviceSampling.newSampleRow(getConnectedAdmin()); + row.setCode("2010_03"); + row.setNbObservants(3); + row.setAverageTideTime(2.5); + row.setProgramName("DPMA-2009"); + row.setPeriodBegin(DateUtil.createDate(1, 1, 2009)); + row.setPeriodEnd(DateUtil.createDate(31, 3, 2010)); + row.setProfession(profession1); + row.setSampleMonth(months); + row.setFishingZone(zones); + row.setFishingZonesInfos("port tres loin du champ"); + + // for row, add DCF5 codes DRB_ALG, DRH + Collection<DCF5Code> dcf5codes = new ArrayList<DCF5Code>(); + DCF5Code dcf5 = new DCF5CodeImpl(); + dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRB")); + dcf5.setTargetSpeciesDCF(new TargetSpeciesDCFImpl("ALG")); + dcf5codes.add(dcf5); + dcf5 = new DCF5CodeImpl(); + dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRH")); + dcf5codes.add(dcf5); + row.setDCF5Code(dcf5codes); + + /** EXEC CREATE **/ + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); + serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl(), getConnectedAdmin()); + assertNotNull(row.getTopiaId()); + + assertNotNull(row.getProfession().getTopiaId()); + + SampleRow result = serviceSampling.getSampleRow(row.getTopiaId()); + assertEquals(3, result.getFishingZone().size()); + assertEquals(3, result.getElligibleBoat().size()); + + // TEST FOR DELETE ELLIGIBLE PROPERTY_BOAT + boats.remove(2); + serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl(), getConnectedAdmin()); + + result = serviceSampling.getSampleRow(row.getTopiaId()); + assertEquals(2, result.getElligibleBoat().size()); + + // TEST FOR REMOVE FISHING ZONE + //FishingZone zone = result.getFishingZone().get(0); + result.getFishingZone().remove(0); + serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl(), getConnectedAdmin()); + + result = serviceSampling.getSampleRow(row.getTopiaId()); + assertEquals(2, result.getFishingZone().size()); + + // test if sampleRow becomes null in contact after update + + Contact contact = new ContactImpl(); + WaoUser observer = createDefaultObserver(); + contact.setMainObserver(observer); + contact.setSampleRow(result); + + ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); + manager.getServiceContact().saveContact(connectedUser, contact, false); + +// serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); + + transaction = manager.getContext().beginTransaction(); + try { + ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); + + Contact contactFound = contactDAO.findBySampleRow(row); + + Assert.assertNotNull(contactFound); + + } finally { + transaction.closeContext(); + } + + } + + @Test + public void testUpdateElligibleBoats() throws TopiaException { + /** PREPARE DATA **/ + SampleRow row = createDefaultSampleRow(); + Boat boat = createDefaultBoat(); + + // Create an elligibleBoat active for company + ElligibleBoat elligible = createElligibleBoat(row, boat, true); + // Retrieve the sampleRow (updated with elligible) + row = findDefaultSampleRow(SampleRow.PROPERTY_ELLIGIBLE_BOAT); + + /** EXEC METHOD **/ + List<Boat> boats = new ArrayList<Boat>(); + boats.add(boat); + + TopiaContext transaction = serviceSampling.beginTransaction(); + // Will update the existing ElligibleBoat and set globalActive to true + List<List<Integer>> results = + serviceSampling.updateElligibleBoats(transaction, row, boats); + + /** CHECKING RESULTS **/ + Assert.assertEquals(2, results.size()); + // Index=1 for updatedImmatriculations, 1 is updated + Assert.assertEquals(1, results.get(1).size()); + // Index=0 for removedImmatriculations, 0 is removed + Assert.assertEquals(0, results.get(0).size()); + + Assert.assertEquals(1, row.sizeElligibleBoat()); + ElligibleBoat updatedElligible = + row.getElligibleBoatByTopiaId(elligible.getTopiaId()); + + Assert.assertTrue(updatedElligible.getGlobalActive()); + } + + /** + * Test of getSampleRowsOrderedByFishingZone method, of class ServiceSamplingImpl. + */ + @Test + public void testGetSampleRowsOrderedByFishingZone() throws Exception { + /** PREPARE DATA **/ + + TopiaContext transaction = manager.getContext().beginTransaction(); + + List<FishingZone> zones = prepareFishingZones(transaction); + + //Program program1 = programDAO.create(Program.NAME, "DPMA-2009"); + Date dateBegin1 = DateUtil.createDate(1, 1, 2009); + Date dateEnd1 = DateUtil.createDate(1, 3, 2010); + PeriodDates period1 = new PeriodDates(dateBegin1, dateEnd1); + + //Program program2 = programDAO.create(Program.NAME, "PPDA-2008"); + Date dateBegin2 = DateUtil.createDate(1, 1, 2008); + Date dateEnd2 = DateUtil.createDate(1, 12, 2008); + PeriodDates period2 = new PeriodDates(dateBegin2, dateEnd2); + + SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); + + SampleRow row1 = dao.create(); + row1.setCode("2010_0001"); + row1.addFishingZone(zones.get(2)); + row1.setProgramName("DPMA-2009"); + row1.setPeriod(period1); + + log.trace(row1.getCode() + " :: " + row1.getFacade() + " :: " + row1.getSectors()); + + SampleRow row2 = dao.create(); + row2.setCode("2010_0002"); + row2.addFishingZone(zones.get(0)); + row2.setProgramName("DPMA-2009"); + row2.setPeriod(period1); + + log.trace(row2.getCode() + " :: " + row2.getFacade() + " :: " + row2.getSectors()); + + SampleRow row3 = dao.create(); + row3.setCode("2010_0003"); + row3.addFishingZone(zones.get(1)); + row3.addFishingZone(zones.get(2)); + row3.addFishingZone(zones.get(0)); + row3.setProgramName("PPDA-2008"); + row3.setPeriod(period2); + + log.trace(row3.getCode() + " :: " + row3.getFacade() + " :: " + row3.getSectors()); + + SampleRow row4 = dao.create(); + row4.setCode("2010_0004"); + row4.addFishingZone(zones.get(0)); // Mer du Nord :: Manche + row4.setProgramName("DPMA-2009"); + row4.setPeriod(period1); + + log.trace(row4.getCode() + " :: " + row4.getFacade() + " :: " + row4.getSectors()); + + transaction.commitTransaction(); + + /** EXEC service method **/ + + // FIRST TEST : + // ORDER by FishingZone (facadeName, sectorName, districtCode) + // BIG PERIOD, included program1 and program2 + // NO COMPANY (= null) + Calendar begin = new GregorianCalendar(2000, 0, 1, 0, 0, 0); + Calendar end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); + SamplingFilter filter = new SamplingFilterImpl(); + filter.setPeriod(new PeriodDates(begin, end)); + filter.setObsProgram(ObsProgram.OBSMER); + // RESULT : [2010_0002, 2010_0004, 2010_0001, 2010_0003] + FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); + List<SampleRow> rows = facade.getValues(); + assertEquals(4, rows.size()); + SampleRow resultRow0 = rows.get(0); + assertEquals("2010_0002", resultRow0.getCode()); + SampleRow resultRow1 = rows.get(1); + assertEquals("2010_0004", resultRow1.getCode()); + +// List<FishingZone> zoneRow1 = resultRow1.getFishingZone(); +// assertEquals(3, zoneRow1.size()); +// FishingZone resultZone0 = zoneRow1.get(0); +// assertEquals("VIIb", resultZone0.getDistrictCode()); +// FishingZone resultZone1 = zoneRow1.get(1); +// assertEquals("VI", resultZone1.getDistrictCode()); +// FishingZone resultZone2 = zoneRow1.get(2); +// assertEquals("V", resultZone2.getDistrictCode()); + + SampleRow resultRow2 = rows.get(2); + assertEquals("2010_0003", resultRow2.getCode()); + SampleRow resultRow3 = rows.get(3); + assertEquals("2010_0001", resultRow3.getCode()); + + // SECOND TEST : + // ORDER by FishingZone (facadeName, sectorName, districtCode) + // BIG PERIOD, not included program2 + // NO COMPANY (= null) + begin = new GregorianCalendar(2009, 0, 1, 0, 0, 0); + end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); + filter.setPeriod(new PeriodDates(begin, end)); + // RESULT : [2010_0002, 2010_0004, 2010_0001] + facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); + rows = facade.getValues(); + assertEquals(3, rows.size()); + resultRow0 = rows.get(0); + assertEquals("2010_0002", resultRow0.getCode()); + resultRow1 = rows.get(1); + assertEquals("2010_0004", resultRow1.getCode()); + resultRow2 = rows.get(2); + assertEquals("2010_0001", resultRow2.getCode()); + + } + + private List<FishingZone> prepareFishingZones(TopiaContext transaction) throws TopiaException { + + FishingZoneDAO fishingZoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + + FishingZone fishingZone1 = fishingZoneDAO.create(); + fishingZone1.setFacadeName("Atlantique"); + fishingZone1.setSectorName("Secteur Mer Celtique et Ouest Irlande centré Pays bigouden"); + fishingZone1.setDistrictCode("VIIb"); + + FishingZone fishingZone2 = fishingZoneDAO.create(); + fishingZone2.setFacadeName("Manche"); + fishingZone2.setSectorName("Secteur Cherbourg Honfleur centré sur Port-en-Bessin"); + fishingZone2.setDistrictCode("VI"); + + FishingZone fishingZone3 = fishingZoneDAO.create(); + fishingZone3.setFacadeName("Manche"); + fishingZone3.setSectorName("Secteur du Havre à Dunkerque centré sur Boulogne"); + fishingZone3.setDistrictCode("V"); + + transaction.commitTransaction(); + + return fishingZoneDAO.findAll(); + } + + public void testGetSampleRowsForUser() throws Exception { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); + FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); + FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + Company company = companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + Calendar begin = new GregorianCalendar(2009,8,1); + Calendar end = new GregorianCalendar(2010,11,31); + SampleRowDAO sampleRowDAO = WaoDAOHelper.getSampleRowDAO(transaction); + SampleRow row = sampleRowDAO.create( + SampleRow.PROPERTY_CODE,"2010_178", + SampleRow.PROPERTY_COMPANY,company, + SampleRow.PROPERTY_PROGRAM_NAME, "DPMA-2009", + SampleRow.PROPERTY_PERIOD_BEGIN, begin.getTime(), + SampleRow.PROPERTY_PERIOD_END, end.getTime()); + + + transaction.commitTransaction(); + transaction.closeContext(); + + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); + + /** EXEC METHOD **/ + SamplingFilter filter = new SamplingFilterImpl(); +// User admin = new UserImpl(); +// admin.setAdmin(true); +// filter.setCompany() + filter.setNbMonthFinishedFromToday(0); + List<SampleRow> results = serviceSampling.getSampleRowsByFilter(filter); + // total in file : 11, 1 refused, 1 finished + assertEquals(9, results.size()); + +// User user = new UserImpl(); +// user.setCompany(company); + filter.setCompany(company); + results = serviceSampling.getSampleRowsByFilter(filter); + assertEquals(1, results.size()); + } + + @Test + public void testGetNewProfession() throws Exception { + /** PREPARE DATA **/ + + TopiaContext transaction = manager.getContext().beginTransaction(); + + ProfessionDAO dao = WaoDAOHelper.getProfessionDAO(transaction); + + Profession profession = dao.create( + Profession.PROPERTY_LIBELLE, "Fileyage en barre", + Profession.PROPERTY_MESH_SIZE, "< 80", + Profession.PROPERTY_OTHER, "90mm", + Profession.PROPERTY_SPECIES, "barre, lieu noir, saumon des plages"); + + transaction.commitTransaction(); + transaction.closeContext(); + + /** EXEC METHOD **/ + Profession newProfession = serviceSampling.getNewProfession(profession); + Assert.assertNotSame(profession, newProfession); + Assert.assertEquals("Fileyage en barre", newProfession.getLibelle()); + Assert.assertEquals("< 80", newProfession.getMeshSize()); + Assert.assertEquals("90mm", newProfession.getOther()); + Assert.assertEquals("barre, lieu noir, saumon des plages", newProfession.getSpecies()); + + } + + @Test + public void testDeleteSampleRow() throws Exception { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); + FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); + FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + companyDAO.create(Company.PROPERTY_NAME, "BIS"); + transaction.commitTransaction(); + + + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); + + SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); + SampleRow row = rowDAO.findByCode("2010_0001"); + row.getProfession(); + row.getProfession(); + row.getCompany(); + row.sizeSampleMonth(); + row.sizeElligibleBoat(); + row.sizeSampleRowLog(); + transaction.closeContext(); + + input = getClass().getResourceAsStream("/import/navires.csv"); + ServiceBoat serviceBoat = manager.getServiceBoat(); + serviceBoat.importBoatCsv(input); + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); + + serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl(), getConnectedAdmin()); + /** EXEC METHOD **/ + + serviceSampling.deleteSampleRow(row); + transaction = manager.getContext().beginTransaction(); + rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); + row = rowDAO.findByCode("2010_0001"); + assertNull(row); + + ElligibleBoatDAO elligibleDAO = WaoDAOHelper.getElligibleBoatDAO(transaction); + List<ElligibleBoat> elligibles = elligibleDAO.findAll(); + assertEquals(0, elligibles.size()); + + // test if sampleRow can't be deleted if contacts are associated + + row = rowDAO.findByCode("2010_0002"); + transaction.closeContext(); + + Contact contact = new ContactImpl(); + WaoUser observer = createDefaultObserver(); + contact.setMainObserver(observer); + contact.setSampleRow(row); + + ConnectedUser connectedUser = getConnectedUser(observer, UserRole.OBSERVER, ObsProgram.OBSMER); + manager.getServiceContact().saveContact(connectedUser, contact, false); + + try { + serviceSampling.deleteSampleRow(row); + Assert.fail("deleting a sample-row with associated contact should" + + " not be permitted"); + } catch (WaoBusinessException eee) { + if (log.isTraceEnabled()) { + log.trace("exception raised while trying to delete sample row", + eee); + } + } + } + + @Test + public void testImportSamplingPlanCsv() + throws TopiaException, WaoException, WaoBusinessException { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); + FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); + FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + companyDAO.create(Company.PROPERTY_NAME, "BIS"); + + transaction.commitTransaction(); + transaction.closeContext(); + + /** EXEC METHOD **/ + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + ImportResults result = serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); + + // total imported + assertEquals(12, result.getNbRowsImported()); + // total refused + assertEquals(1, result.getNbRowsRefused()); + + /** CHECK VALUES **/ + transaction = manager.getContext().beginTransaction(); + + SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); + + // Error #2221 : don't keep the same profession for two different rows + SampleRow row2 = rowDAO.findByCode("2010_0010"); + SampleRow row3 = rowDAO.findByCode("2010_0011"); + assertNotSame(row2.getProfession(), row3.getProfession()); + + ProfessionDAO professionDAO = + WaoDAOHelper.getProfessionDAO(transaction); + + List<Profession> professions = professionDAO.findAll(); + assertEquals(12, professions.size()); + + SampleRow row1 = rowDAO.findByCode("2010_0001"); + assertNotNull(row1); + assertEquals(1, row1.getNbObservants()); + assertEquals(1.5, row1.getAverageTideTime(), 0.1); + assertEquals("Un petit commentaire", row1.getComment()); + + assertEquals("MA-2009", row1.getProgramName()); + + Profession profession = row1.getProfession(); + assertNotNull(profession); + + List<SampleMonth> months = row1.getSampleMonth(); + assertEquals(11, months.size()); + + Collection<FishingZone> zones = row1.getFishingZone(); + assertEquals(2, zones.size()); + zones.contains(zoneI); + zones.contains(zoneIId); + + Collection<DCF5Code> dcf5codes = row1.getDCF5Code(); + assertEquals(1, dcf5codes.size()); + + assertEquals(row1.getSamplingStrategy(), SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); + + transaction.closeContext(); + } + + @Test + public void testGetPrograms() throws Exception { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); + zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); + zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + companyDAO.create(Company.PROPERTY_NAME, "BIS"); + transaction.commitTransaction(); + transaction.closeContext(); + + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); + + /** EXEC METHOD **/ + List<String> programs = serviceSampling.getPrograms(null); + assertEquals(4, programs.size()); + } + + + @Test + public void testGetNewSampleRowCode() throws Exception { + /** PREPARE DATA **/ + TopiaContext transaction = manager.getContext().beginTransaction(); + + FishingZoneDAO zoneDAO = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZone zoneIId = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IId"); + FishingZone zoneIV = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "IV"); + FishingZone zoneI = zoneDAO.create(FishingZone.PROPERTY_DISTRICT_CODE, "I"); + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + companyDAO.create(Company.PROPERTY_NAME, "TARTANPION"); + companyDAO.create(Company.PROPERTY_NAME, "BIS"); + transaction.commitTransaction(); + + ServiceSampling serviceSampling = manager.getServiceSampling(); + InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceSampling.importSamplingPlanCsv(input, getConnectedUser(null, UserRole.ADMIN, ObsProgram.OBSMER)); + + transaction.closeContext(); + + /** EXEC METHOD **/ + + Calendar begin = new GregorianCalendar(2009, 11, 1); + + String result = serviceSampling.getNewSampleRowCode(begin.getTime()); + Assert.assertEquals("2009_0007", result); + + // Test regex for replacment in importSamplingPlanCsv +// String code = "2010_1"; +// code = code.replaceFirst("_(\\d)$", "_0$1"); +// Assert.assertEquals("2010_01", code); +// +// code = "2010_04"; +// code = code.replaceFirst("_(\\d)$", "_0$1"); +// Assert.assertEquals("2010_04", code); + } + +} Property changes on: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSynthesisImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -70,16 +70,11 @@ private static final Logger log = LoggerFactory.getLogger(ServiceSynthesisImplTest.class); - private ServiceSynthesis service; + protected ServiceSynthesis service; @Before - public void setCurrentDate() { - manager.setCurrentDate(DateUtil.createDate(5, 10, 2010)); - } - - @Before public void initialize() { - log.info("initialize ServiceSynthesisImplTest"); + manager.setCurrentDate(DateUtil.createDate(5, 10, 2010)); service = manager.getServiceSynthesis(); } @@ -88,7 +83,6 @@ */ @Test public void testGetBoardingBoats() throws Exception { - log.info("getBoardingBoats"); /** PREPARE DATA **/ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = manager.getServiceBoat(); @@ -187,7 +181,6 @@ */ @Test public void testGetComplianceBoardingIndicator() throws Exception { - log.info("getComplianceBoardingIndicator"); /** PREPARE DATA **/ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = manager.getServiceBoat(); @@ -304,7 +297,6 @@ */ @Test public void testGetContactStateStatistics() throws Exception { - log.info("getContactStateStatistics"); /** PREPARE DATA **/ // Company TARTANPION @@ -376,7 +368,6 @@ */ @Test public void testGetContactDataInputDateReactivity() throws Exception { - log.info("getContactDataInputDateReactivity"); /** PREPARE DATA **/ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = manager.getServiceBoat(); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2011-06-09 09:35:04 UTC (rev 1327) @@ -56,11 +56,10 @@ private static final Logger log = LoggerFactory.getLogger(ServiceUserImplTest.class); - private ServiceUser service; + protected ServiceUser service; @Before public void setUp() throws Exception { - super.setUp(); service = manager.getServiceUser(); } @@ -75,8 +74,6 @@ */ @Test public void testCreateUser() throws Exception { - log.info("############### START ############### testCreateUpdateUser"); - // create a user with no role WaoUser user = new WaoUserImpl(); user.setLogin("login"); @@ -130,7 +127,6 @@ @Test public void testUpdateUser() throws WaoBusinessException, TopiaException { - log.info("############### START ############### testUpdateUser"); // ---- PREPARE DATA ---- // @@ -176,7 +172,6 @@ */ @Test public void testGetObservers() throws Exception { - log.info("############### START ############### testGetObservers"); UserProfile adminProfile = new UserProfileImpl( ObsProgram.OBSMER, @@ -285,8 +280,6 @@ */ @Test public void testCreateDefaultAdmin() throws Exception { - log.info("############### START ############### testCreateDefaultAdmin"); - service.createDefaultAdmin(); ServiceUser serviceUser = manager.getServiceUser(); Modified: trunk/wao-business/src/test/resources/log4j.properties =================================================================== --- trunk/wao-business/src/test/resources/log4j.properties 2011-06-08 16:22:13 UTC (rev 1326) +++ trunk/wao-business/src/test/resources/log4j.properties 2011-06-09 09:35:04 UTC (rev 1327) @@ -32,5 +32,5 @@ log4j.appender.A1.layout.ConversionPattern=%d %5p [%t] (%F:%L) %M - %m%n log4j.logger.fr.ifremer.wao=DEBUG -log4j.logger.org.nuiton.util=INFO +log4j.logger.org.nuiton.util=WARN log4j.logger.org.nuiton.util.beans.BinderProvider=ERROR