r1031 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/test tutti-service/src/test/java/fr/ifremer/tutti/service/catches tutti-service/src/test/java/fr/ifremer/tutti/service/export
Author: kmorin Date: 2013-05-29 16:50:32 +0200 (Wed, 29 May 2013) New Revision: 1031 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1031 Log: add test on weight computing Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/test/DatabaseResource.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/test/DatabaseResource.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/test/DatabaseResource.java 2013-05-28 15:41:42 UTC (rev 1030) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/test/DatabaseResource.java 2013-05-29 14:50:32 UTC (rev 1031) @@ -188,16 +188,7 @@ if (defaultDbName) { dbName = "db"; } - File db = new File("src/test/" + dbName); - if (!db.exists()) { - if (log.isWarnEnabled()) { - log.warn("Could not find db at " + db + ", test [" + - testClass + "] is skipped."); - } - Assume.assumeTrue(false); - } - if (log.isInfoEnabled()) { log.info("Prepare test " + testClass); } @@ -229,6 +220,16 @@ config = new TuttiPersistenceConfig(applicationConfig); + File db = config.getDbDirectory(); + if (!db.exists()) { + + if (log.isWarnEnabled()) { + log.warn("Could not find db at " + db + ", test [" + + testClass + "] is skipped."); + } + Assume.assumeTrue(false); + } + if (writeDb) { copyDb(config.getDbDirectory(), !writeDb, null); } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java 2013-05-28 15:41:42 UTC (rev 1030) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java 2013-05-29 14:50:32 UTC (rev 1031) @@ -24,9 +24,203 @@ * #L% */ +import fr.ifremer.tutti.TuttiBusinessException; +import fr.ifremer.tutti.persistence.entities.data.*; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.List; + /** * @author kmorin <kmorin@codelutin.com> - * @since x.x + * @since 2.3 */ public class TuttiWeightComputingServiceTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(TuttiWeightComputingServiceTest.class); + + @ClassRule + public static final ServiceDbResource dbResource = + ServiceDbResource.readDb("dbCGFS"); + + public static final String PROGRAM_ID = "CAM-CGFS"; + + public static final String CRUISE_ID = "100002"; + + /* the one with the batches to compute */ + public static final String OPERATION_1_ID = "100108"; + + /* the one with the total species weight less than the sum of the batches */ + public static final String OPERATION_2_ID = "100109"; + + /* the one with the total benthos weight less than the sum of the batches */ + public static final String OPERATION_3_ID = "100110"; + + /* the one with the total marine litter weight less than the sum of the batches */ + public static final String OPERATION_4_ID = "100111"; + + /* the one with the total catch weight different from the sum of the sorted and unsorted total weight */ + public static final String OPERATION_5_ID = "100112"; + + /* the one with the total catch weight different from the rejected weight */ + public static final String OPERATION_6_ID = "100113"; + + /* the one working */ + public static final String OPERATION_7_ID = "100114"; + + protected TuttiWeightComputingService tuttiWeightComputingService; + + protected PersistenceService persistenceService; + + @Before + public void setUp() throws Exception { + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + tuttiWeightComputingService = serviceContext.getService(TuttiWeightComputingService.class); + persistenceService = serviceContext.getService(PersistenceService.class); + } + + @Test + public void computeCatchWeights() { + CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_2_ID); + try { + BatchContainer<SpeciesBatch> batches = persistenceService.getRootSpeciesBatch(OPERATION_2_ID); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, batches, null, null); + Assert.fail(); + + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on operation #2 : " + e.getMessage()); + } + } + + catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_3_ID); + try { + BatchContainer<BenthosBatch> batches = persistenceService.getRootBenthosBatch(OPERATION_3_ID); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, null, batches, null); + Assert.fail(); + + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on operation #3 : " + e.getMessage()); + } + } + + catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_4_ID); + try { + BatchContainer<MarineLitterBatch> batches = persistenceService.getRootMarineLitterBatch(OPERATION_4_ID); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, null, null, batches); + Assert.fail(); + + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on operation #4 : " + e.getMessage()); + } + } + + catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_5_ID); + try { + BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_5_ID); + BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_5_ID); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); + Assert.fail(); + + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on operation #5 : " + e.getMessage()); + } + } + + catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_6_ID); + try { + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, null, null, null); + Assert.fail(); + + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on operation #6 : " + e.getMessage()); + } + } + + catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_7_ID); + try { + BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_7_ID); + BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_7_ID); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); + if (log.isInfoEnabled()) { + log.info("Weight computing worked on operation #7"); + } + + } catch (TuttiBusinessException e) { + Assert.fail(); + } + } + + @Test + public void computeSpeciesBatch() { + BatchContainer<SpeciesBatch> speciesBatchContainer = persistenceService.getRootSpeciesBatch(OPERATION_1_ID); + List<SpeciesBatch> speciesBatches = speciesBatchContainer.getChildren(); + for (int i = 0 ; i < speciesBatches.size() - 1 ; i++) { + try { + SpeciesBatch batch = speciesBatches.get(i); + tuttiWeightComputingService.computeSpeciesBatch(batch); + Assert.fail(); + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on species batch #" + i + " : " + e.getMessage()); + } + } + } + SpeciesBatch speciesBatch = speciesBatches.get(speciesBatches.size() - 1); + try { + tuttiWeightComputingService.computeSpeciesBatch(speciesBatch); + if (log.isInfoEnabled()) { + log.info("last species batch weight computing worked"); + } + + } catch (TuttiBusinessException e) { + Assert.fail(); + } + + BatchContainer<BenthosBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(OPERATION_1_ID); + List<BenthosBatch> benthosBatches = benthosBatchContainer.getChildren(); + for (int i = 0 ; i < benthosBatches.size() - 1 ; i++) { + try { + BenthosBatch batch = benthosBatches.get(i); + tuttiWeightComputingService.computeBenthosBatch(batch); + Assert.fail(); + } catch (TuttiBusinessException e) { + //ok, it is supposed to throw an exception + if (log.isInfoEnabled()) { + log.info("expected error on species batch #" + i + " : " + e.getMessage()); + } + } + } + BenthosBatch benthosBatch = benthosBatches.get(benthosBatches.size() - 1); + try { + tuttiWeightComputingService.computeBenthosBatch(benthosBatch); + if (log.isInfoEnabled()) { + log.info("last benthos batch weight computing worked"); + } + + } catch (TuttiBusinessException e) { + Assert.fail(); + } + } + } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java 2013-05-28 15:41:42 UTC (rev 1030) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java 2013-05-29 14:50:32 UTC (rev 1031) @@ -75,7 +75,7 @@ public static final String SURVEY_CONTENT = "Annee;Serie;Serie_Partielle;Navire;Pays;Zone_Etude;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire\n" + - "2013;Campagne CGFS;;GWEN DREZ;FRA;CGFS - Manche Est / Sud Mer du Nord;Campagne CGFS_2013;01/05/2013 00:00:00;La Barbotière (Gujan-Mestras);31/05/2013 00:00:00;Etang de Palo;AURECHE Vincent;;;"; + "2013;Campagne CGFS;;GWEN DREZ;FRA;CGFS - Manche Est / Sud Mer du Nord;Campagne CGFS_2013;01/05/2013 00:00:00;La Barbotière (Gujan-Mestras);31/05/2013 00:00:00;Etang de Palo;Vincent AURECHE;;;"; public static final String OPERATION_CONTENT = "Annee;Serie;Serie_Partielle;Id_Operation;NumOrdre_Station;Engin;Navire;DateDeb_Op;LatDeb;LongDeb;DateFin_Op;LatFin;LongFin;Duree;Strate;Sous-Strate;Localite;Validite_OP;Rectiligne;Distance;Ouv_Verticale;Ouv_Horizontale_Ailes;Ouv_Horizontale_Panneaux;Commentaire\n" +
participants (1)
-
kmorin@users.forge.codelutin.com