Author: bleny Date: 2011-07-01 15:06:42 +0000 (Fri, 01 Jul 2011) New Revision: 1366 Log: add validation when importing for ObsDeb + test Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFieldWorkTest.java Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFieldWorkTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFieldWorkTest.java 2011-07-01 15:06:25 UTC (rev 1365) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/business/ObsDebFieldWorkTest.java 2011-07-01 15:06:42 UTC (rev 1366) @@ -24,6 +24,7 @@ package fr.ifremer.wao.business; import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.BoatFilter; import fr.ifremer.wao.bean.ConnectedUser; import fr.ifremer.wao.bean.ContactFilter; @@ -44,6 +45,8 @@ import fr.ifremer.wao.io.ImportResults; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; +import org.h2.util.New; +import org.hamcrest.BaseMatcher; import org.junit.Assert; import org.junit.Test; import org.nuiton.util.DateUtil; @@ -56,6 +59,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; /** * @@ -76,6 +80,9 @@ protected static final String SAMPLING_PLAN_WITH_OBSERVERS_CSV = "PLAN_CODE;REGION_IFREMER_COD;OBSERVATEUR_COD;OBSERVATION_DATE;UNITE_OBSERVATION_COD;OBSERVATEURS;LIGNE_SANS_CONTACTS\n" + "2011_890;GA;OBS1;13/02/2010;UO007;josh;N"; + protected static final String SAMPLING_PLAN_WITH_CONFLICTING_SAMPLE_ROW_CSV = + "PLAN_CODE;REGION_IFREMER_COD;OBSERVATEUR_COD;OBSERVATION_DATE;UNITE_OBSERVATION_COD;OBSERVATEURS;LIGNE_SANS_CONTACTS\n" + + ";MA;OBS2;13/02/2010;UO087;josh;N"; protected ObsDebFixtures fixtures = new ObsDebFixtures(manager); @@ -115,10 +122,6 @@ ImportResults importResults = serviceSampling.importSamplingPlanCsv(input, fixtures.joshAsAdministrator()); Assert.assertEquals(4, importResults.getNbRowsImported()); Assert.assertEquals(0, importResults.getNbRowsRefused()); - - // trying to re-import must fail due to conflicting sample-rows - input = IOUtils.toInputStream(SAMPLING_PLAN_CSV); - importResults = serviceSampling.importSamplingPlanCsv(input, fixtures.joshAsAdministrator()); } /** @@ -277,6 +280,20 @@ public void coordinatorCannotBreakSamplingPlan() throws IOException, WaoBusinessException { coordinatorCanAddObserversViaImport(); + try { + InputStream input = IOUtils.toInputStream(SAMPLING_PLAN_WITH_CONFLICTING_SAMPLE_ROW_CSV); + serviceSampling.importSamplingPlanCsv(input, fixtures.joshAsCoordinator()); + Assert.fail("trying to re-import must fail due to conflicting sample-rows"); + } catch (WaoException e) { + if (log.isTraceEnabled()) { + log.trace("exception raised by importing conflicting sample row", e); + } + // check that the exception raised is related to validation and + // not to a bug + Assert.assertTrue(e.getCause().getCause().getCause().getMessage(). + startsWith("Erreur de validation de la ligne")); + } + // josh cannot be affected to this row, because on the same day // he is to be elsewhere SampleRow row2011_891 = serviceSampling.getSampleRowByCode(fixtures.joshAsCoordinator(), "2011_891");