r379 - in trunk/tutti-persistence: . src/main/java/fr/ifremer/tutti/persistence src/main/java/fr/ifremer/tutti/persistence/service src/test/java/fr/ifremer/tutti/persistence src/test/java/fr/ifremer/tutti/persistence/entities/protocol src/test/java/fr/ifremer/tutti/persistence/service src/test/java/fr/ifremer/tutti/persistence/service/synchro src/test/resources
Author: tchemit Date: 2013-02-10 14:41:29 +0100 (Sun, 10 Feb 2013) New Revision: 379 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/379 Log: - reformat + use basic code style -no Stringbuffer, no iterator, ...) - improve tests(distinguish read and write tests) - use default value in Autowired annotation Added: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/resources/tutti-test-read.properties trunk/tutti-persistence/src/test/resources/tutti-test-write.properties Removed: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java trunk/tutti-persistence/src/test/resources/tutti-test.properties Modified: trunk/tutti-persistence/pom.xml trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java Modified: trunk/tutti-persistence/pom.xml =================================================================== --- trunk/tutti-persistence/pom.xml 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/pom.xml 2013-02-10 13:41:29 UTC (rev 379) @@ -36,7 +36,7 @@ <groupId>fr.ifremer.tutti</groupId> <artifactId>tutti-persistence</artifactId> - <name>Tutti :: Persistence API</name> + <name>Tutti :: Persistence</name> <dependencies> Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -221,7 +221,7 @@ String surveyCode = speciesProtocol.getSpeciesSurveyCode(); if (StringUtils.isNotBlank(surveyCode)) { Integer taxonId = - Integer.valueOf(speciesProtocol.getSpeciesReferenceTaxonId()); + speciesProtocol.getSpeciesReferenceTaxonId(); surveyCodeByTaxonId.put(taxonId, surveyCode); } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-10 13:41:29 UTC (rev 379) @@ -55,10 +55,10 @@ * * @since 0.3 */ - @Autowired(required = true) + @Autowired protected SessionFactory sessionFactory; - @Autowired(required = true) + @Autowired protected TuttiEnumerationFile enumeration; protected TuttiPersistenceConfig config; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -340,9 +340,7 @@ if (parentBatch.getChildBatchs() == null) { return batchByQualitativeValueId; } - for (Iterator iterator = parentBatch.getChildBatchs() - .iterator(); iterator.hasNext(); ) { - Batch childBatch = (Batch) iterator.next(); + for (Batch childBatch : parentBatch.getChildBatchs()) { SortingMeasurement sm = measurementHelper.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false); if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) { batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), (SortingBatch) childBatch); @@ -393,7 +391,7 @@ String samplingRatioText = sampleWeight + "/" + weight; samplingRatioText = samplingRatioText.replaceAll(",", "."); target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(sampleWeight.floatValue() / weight.floatValue()); + target.setSamplingRatio(sampleWeight / weight); } // Weight Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -86,10 +86,10 @@ protected static String CRUISE_MISC_DATA_SORT_MANAGERS_TAG = "#SORT_MANAGERS="; - @Autowired(required = true) + @Autowired protected ReferentialPersistenceService referentialService; - @Autowired(required = true) + @Autowired protected ProgramPersistenceService programService; @Resource(name = "scientificCruiseDao") @@ -212,8 +212,8 @@ miscData = miscData.substring(0, vesselTagIndex); if (!vesselCodesStr.isEmpty()) { String[] vesselCodes = vesselCodesStr.split(","); - for (int i = 0; i < vesselCodes.length; i++) { - vesselCode = vesselCodes[i]; + for (String vesselCode1 : vesselCodes) { + vesselCode = vesselCode1; result.addVessel(referentialService.getVessel(vesselCode)); } } @@ -226,8 +226,7 @@ miscData = miscData.substring(0, managersIndex); if (!managersStr.isEmpty()) { String[] managersArray = managersStr.split(","); - for (int i = 0; i < managersArray.length; i++) { - String personId = managersArray[i]; + for (String personId : managersArray) { Person person = referentialService.getPerson(Integer.valueOf(personId)); result.getHeadOfMission().add(person); } @@ -242,8 +241,7 @@ if (!sortManagersStr.isEmpty()) { String[] managersArray = sortManagersStr.split(","); List<Person> persons = new ArrayList<Person>(); - for (int i = 0; i < managersArray.length; i++) { - String personId = managersArray[i]; + for (String personId : managersArray) { Person person = referentialService.getPerson(Integer.valueOf(personId)); persons.add(person); } @@ -277,7 +275,7 @@ } // Force initialization of multirigNumber to 1 initialization (need for UI) if (result.getMultirigNumber() == null) { - log.warn(MessageFormat.format("Cruise with id={0} has been load with a default multirigNumber=1, beacause not multirigNumber were found in database.", new Object[]{id})); + log.warn(MessageFormat.format("Cruise with id={0} has been load with a default multirigNumber=1, beacause not multirigNumber were found in database.", id)); result.setMultirigNumber(1); } return result; @@ -313,7 +311,7 @@ } protected void cruiseToEntity(Cruise source, ScientificCruise target, boolean copyIfNull) { - StringBuffer miscDataBuffer = new StringBuffer(); + StringBuilder miscDataBuffer = new StringBuilder(); QualityFlag qualityFlagNotQualified = qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED); // Retrieve entities : FishingTrip Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -104,7 +104,7 @@ @Resource(name = "measurementPersistenceHelper") protected MeasurementPersistenceHelper measurementHelper; - @Autowired(required = true) + @Autowired protected ReferentialPersistenceService referentialService; @Resource(name = "scientificCruiseDao") @@ -336,12 +336,12 @@ localite.setId(localiteId.toString()); result.setLocation(localite); } - + // Vessel (the one with the catch batch) String vesselCode = (String) source[colIndex++]; if (vesselCode != null) { - Vessel vessel = referentialService.getVessel(vesselCode); - result.setVessel(vessel); + Vessel vessel = referentialService.getVessel(vesselCode); + result.setVessel(vessel); } // Retrieve environment caracteristics : @@ -492,7 +492,7 @@ } protected void beanToEntity(FishingOperation source, fr.ifremer.adagio.core.dao.data.operation.FishingOperation target, boolean copyIfNull) { - StringBuffer nameBuffer = new StringBuffer(); + StringBuilder nameBuffer = new StringBuilder(); // Retrieve entities : FishingTrip and ScientificCruise ScientificCruise scientificCruise; @@ -573,10 +573,10 @@ gearPhysicalFeatures.setOperations(Sets.newHashSet((Operation) target)); } else { gearPhysicalFeatures.getOperations().add(target); - } + } } if (source.getGear() != null && source.getGear().getLabel() != null) { - nameBuffer.append(source.getGear().getLabel()); + nameBuffer.append(source.getGear().getLabel()); } // Retrieve entities : Fishing Area @@ -606,10 +606,10 @@ // Retrieve multirig number, from Gear physical features int cruiseMultirigCount = 1; // default value if (gearPhysicalFeatures != null) { - GearPhysicalMeasurement gpmMultirigCount = measurementHelper.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER); - if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) { - cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue(); - } + GearPhysicalMeasurement gpmMultirigCount = measurementHelper.getGearPhysicalMeasurement(gearPhysicalFeatures, enumeration.PMFM_ID_MULTIRIG_NUMBER); + if (gpmMultirigCount != null && gpmMultirigCount.getNumericalValue() != null) { + cruiseMultirigCount = gpmMultirigCount.getNumericalValue().intValue(); + } } // StationNumber @@ -689,23 +689,22 @@ if (copyIfNull && source.getFishingOperationValid() == null) { // Nothing to do : will be removed later, using notChangedVesselUseMeasurements } else if (source.getFishingOperationValid() != null) { - VesselUseMeasurement vum = setVesselUseMeasurement(scientificCruise, vesselUseFeatures, enumeration.PMFM_ID_HAUL_VALID, null, null, source.getFishingOperationValid().booleanValue() ? enumeration.QUALITATIVE_HAUL_VALID_YES : enumeration.QUALITATIVE_HAUL_VALID_NO); + VesselUseMeasurement vum = setVesselUseMeasurement(scientificCruise, vesselUseFeatures, enumeration.PMFM_ID_HAUL_VALID, null, null, source.getFishingOperationValid() ? enumeration.QUALITATIVE_HAUL_VALID_YES : enumeration.QUALITATIVE_HAUL_VALID_NO); notChangedVesselUseMeasurements.remove(vum); } // Vessel target.setVessel(fishingTrip.getVessel()); - + // Associated vessel if (copyIfNull && source.getVessel() == null && target.getOperationVesselAssociations() != null) { - target.getOperationVesselAssociations().clear(); + target.getOperationVesselAssociations().clear(); + } else if (source.getVessel() != null + && source.getVessel().getId() != null) { + setOperationVesselAssociation(target, source.getVessel().getId()); } - else if(source.getVessel() != null - && source.getVessel().getId() != null) { - setOperationVesselAssociation(target, source.getVessel().getId()); - } - + // Quality Flag : if (target.getQualityFlag() == null) { target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); @@ -858,7 +857,7 @@ target.setComments(miscDataBuffer.toString()); } else if (source.getComment() != null) { // Store comment + misc data - target.setComments(source.getComment() + miscDataBuffer.toString()); + target.setComments(source.getComment() + miscDataBuffer); } // ---------------------------------------------------------------- @@ -1217,51 +1216,48 @@ } return null; } - + protected void setOperationVesselAssociation(Operation target, String vesselCode) { - OperationVesselAssociation ova = null; - OperationVesselAssociationPK ovaPK = new OperationVesselAssociationPK(); - ovaPK.setVessel(load(VesselImpl.class, vesselCode)); - ovaPK.setOperation(target); + OperationVesselAssociation ova = null; + OperationVesselAssociationPK ovaPK = new OperationVesselAssociationPK(); + ovaPK.setVessel(load(VesselImpl.class, vesselCode)); + ovaPK.setOperation(target); - // If vessel is equal as cruise vessel : do note store any VesselOperationAssociation entity - if (vesselCode.equals(target.getVessel().getCode())) { - removeAllOperationVesselAssociation(target); - return; - } - - // Retrieve existing association - for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) { - OperationVesselAssociation asso = iterator.next(); - if (asso.getOperationVesselAssociationPk().equals(ovaPK)) { - ova = asso; - break; - } - } - - // Create a new association - if (ova == null) { - ova = OperationVesselAssociation.Factory.newInstance(); - ova.setOperationVesselAssociationPk(ovaPK); - if (target.getOperationVesselAssociations() == null) { - target.setOperationVesselAssociations(Lists.newArrayList(ova)); - } - else { - removeAllOperationVesselAssociation(target); - target.getOperationVesselAssociations().add(ova); - } - } - - ova.setIsCatchOnOperationVessel(Boolean.FALSE); + // If vessel is equal as cruise vessel : do note store any VesselOperationAssociation entity + if (vesselCode.equals(target.getVessel().getCode())) { + removeAllOperationVesselAssociation(target); + return; + } + + // Retrieve existing association + for (OperationVesselAssociation asso : target.getOperationVesselAssociations()) { + if (asso.getOperationVesselAssociationPk().equals(ovaPK)) { + ova = asso; + break; + } + } + + // Create a new association + if (ova == null) { + ova = OperationVesselAssociation.Factory.newInstance(); + ova.setOperationVesselAssociationPk(ovaPK); + if (target.getOperationVesselAssociations() == null) { + target.setOperationVesselAssociations(Lists.newArrayList(ova)); + } else { + removeAllOperationVesselAssociation(target); + target.getOperationVesselAssociations().add(ova); + } + } + + ova.setIsCatchOnOperationVessel(Boolean.FALSE); } - + protected void removeAllOperationVesselAssociation(Operation target) { - if(target.getOperationVesselAssociations() != null) { - for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) { - OperationVesselAssociation asso = iterator.next(); - operationVesselAssociationDao.remove(asso); - } - target.getOperationVesselAssociations().clear(); - } + if (target.getOperationVesselAssociations() != null) { + for (OperationVesselAssociation asso : target.getOperationVesselAssociations()) { + operationVesselAssociationDao.remove(asso); + } + target.getOperationVesselAssociations().clear(); + } } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -58,7 +58,7 @@ private static final Log log = LogFactory.getLog(ProgramPersistenceServiceImpl.class); - @Autowired(required = true) + @Autowired protected ReferentialPersistenceService referentialService; @Resource(name = "programDao") @@ -97,15 +97,18 @@ "locationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_PROGRAM, "locationClassificationId", IntegerType.INSTANCE, enumeration.LOCATION_CLASSIFICATION_ID_SECTOR); - if (!list.hasNext()) { - return null; - } + Program result; - // Keep only the first row (=the first location, if many found) - Object[] source = list.next(); + if (list.hasNext()) { - Program result = new Program(); - loadProgram(result, source, true); + // Keep only the first row (=the first location, if many found) + Object[] source = list.next(); + + result = new Program(); + loadProgram(result, source, true); + } else { + result = null; + } return result; } @@ -115,6 +118,9 @@ Preconditions.checkNotNull(bean.getName()); Preconditions.checkArgument(bean.getId() == null); + if (log.isDebugEnabled()) { + log.debug("Create program with name: " + bean.getName()); + } fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = fr.ifremer.adagio.core.dao.administration.programStrategy.Program.Factory.newInstance(); beanToEntity(bean, program, true); program = programDao.create(program); @@ -129,6 +135,10 @@ Preconditions.checkNotNull(bean.getName()); Preconditions.checkNotNull(bean.getId()); + + if (log.isDebugEnabled()) { + log.debug("Create program with name: " + bean.getName()); + } fr.ifremer.adagio.core.dao.administration.programStrategy.Program program = programDao.load(bean.getId()); if (program == null) { throw new DataRetrievalFailureException("Could not retrieve program with code=" + bean.getId()); @@ -146,11 +156,12 @@ /** * Sentinel value when comment is null (but database can't accept tis. + * * @since 1.0 */ public static final String EMPTY_COMMENT = "$$EMPTY_COMMENT$$"; - protected void loadProgram(Program result , Object[] source, boolean loadZone) { + protected void loadProgram(Program result, Object[] source, boolean loadZone) { result.setId((String) source[0]); result.setName((String) source[1]); result.setComment((String) source[2]); @@ -169,10 +180,10 @@ protected void beanToEntity(Program source, fr.ifremer.adagio.core.dao.administration.programStrategy.Program target, boolean copyIfNull) { - // If target.description is a fake value (see bottom in this method), restore the null value - if (target.getDescription() != null && target.getDescription().equals(target.getName())) { - target.setDescription(null); - } + // If target.description is a fake value (see bottom in this method), restore the null value + if (target.getDescription() != null && target.getDescription().equals(target.getName())) { + target.setDescription(null); + } // Code : compute with : <prefixe><name> if (target.getCode() == null && source.getName() != null) { Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-10 13:41:29 UTC (rev 379) @@ -215,12 +215,12 @@ */ @Transactional(readOnly = false) List<Gear> importTemporaryGear(List<Gear> gears); - - + + /** * Convert a PMFM ID into a SampleCategoryEnum.<br/> * This method will typically use enumeration values, to compare with the given pmfmId. - * + * * @param pmfmId a Id of a PMFM * @return a SampleCategoryEnum, or null if the PMFM is not mapped */ Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -24,28 +24,8 @@ * #L% */ -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Query; -import org.hibernate.type.DateType; -import org.hibernate.type.IntegerType; -import org.hibernate.type.StringType; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.stereotype.Service; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - import fr.ifremer.adagio.core.dao.administration.user.PersonExtendDao; import fr.ifremer.adagio.core.dao.data.vessel.VesselExtendDao; import fr.ifremer.adagio.core.dao.referential.StatusDao; @@ -67,7 +47,24 @@ import fr.ifremer.tutti.persistence.entities.referential.Status; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Query; +import org.hibernate.type.DateType; +import org.hibernate.type.IntegerType; +import org.hibernate.type.StringType; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + /** * Implementation of the {@link ReferentialPersistenceService} using a adagio * data-source. @@ -87,7 +84,7 @@ @Resource(name = "statusDao") protected StatusDao statusDao; - + @Resource(name = "personDao") protected PersonExtendDao personDao; @@ -322,10 +319,8 @@ Object[] source = queryUnique( "person", "personId", IntegerType.INSTANCE, personId); - - if (source == null) return null; - - Person result = loadPerson(source); + + Person result = source == null ? null : loadPerson(source); return result; } @@ -334,10 +329,8 @@ Object[] source = queryUnique( "gear", "gearId", IntegerType.INSTANCE, gearId); - - if (source == null) return null; - - Gear result = loadGear(source); + + Gear result = source == null ? null : loadGear(source); return result; } @@ -358,17 +351,17 @@ for (TaxonRefTaxVO source : sources) { Species target = loadSpecies(source); if (target.isReferenceTaxon()) { - + // Add to cache : - putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target); - referenceTaxonsOnly.add(target); + putToSpeciesReferentCache(target.getReferenceTaxonId(), target); + referenceTaxonsOnly.add(target); } result.add(target); } - + // Add to cache : putToSpeciesReferentCache(referenceTaxonsOnly); - + return result; } @@ -384,27 +377,27 @@ continue; } Species target = loadSpecies(source); - + // Add to cache : - putToSpeciesReferentCache(Integer.valueOf(target.getReferenceTaxonId()), target); - + putToSpeciesReferentCache(target.getReferenceTaxonId(), target); + result.add(target); } return result; } @Override - @Cacheable(value = "species", key="#speciesId") + @Cacheable(value = "referentSpecies", key = "#speciesId") public Species getSpeciesByReferenceTaxonId(Integer speciesId) { - try { - TaxonRefTaxVO source = taxonNameDao.getTaxonNameReferent( - speciesId); - Species target = loadSpecies(source); - return target; - } - catch(DataRetrievalFailureException drfe) { - return null; - } + Species target; + try { + TaxonRefTaxVO source = taxonNameDao.getTaxonNameReferent( + speciesId); + target = loadSpecies(source); + } catch (DataRetrievalFailureException drfe) { + target = null; + } + return target; } @Override @@ -421,12 +414,12 @@ if (!isProtectedCaracteristic(pmfmId)) { Caracteristic target = loadCaracteristic(source); putToCaracteristicCache(pmfmId, target); - + result.add(target); } // If protected, load anyway just for the cache else { - putToCaracteristicCache(pmfmId, loadCaracteristic(source)); + putToCaracteristicCache(pmfmId, loadCaracteristic(source)); } } return result; @@ -484,7 +477,7 @@ } @Override - @Cacheable(value = "pmfms", key="#pmfmId") + @Cacheable(value = "pmfms", key = "#pmfmId") public Caracteristic getCaracteristic(Integer pmfmId) { Object[] source = queryUniqueWithStatus("pmfmById", "pmfmId", IntegerType.INSTANCE, pmfmId, @@ -494,7 +487,7 @@ } @Override - @CacheEvict(value = {"species", "referentSpecies"}, allEntries=true ) + @CacheEvict(value = {"species", "referentSpecies"}, allEntries = true) public List<Species> importTemporarySpecies(List<Species> species) { List<Species> result = Lists.newArrayList(); for (Species source : species) { @@ -505,20 +498,20 @@ } @Override - @CacheEvict(value = "fishingVessels", allEntries=true ) + @CacheEvict(value = "fishingVessels", allEntries = true) public List<Vessel> importTemporaryVessel(List<Vessel> vessels) { - List<Vessel> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(enumeration.STATUS_TEMPORARY_CODE); - Integer countryLocationId = - locationDao.getLocationIdByLabelAndLocationLevel( - enumeration.LOCATION_LABEL_DEFAULT_COUNTRY, - new Integer[]{enumeration.LOCATION_LEVEL_ID_COUNTRY}); + List<Vessel> result = Lists.newArrayList(); + + fr.ifremer.adagio.core.dao.referential.Status status = + statusDao.load(enumeration.STATUS_TEMPORARY_CODE); + Integer countryLocationId = + locationDao.getLocationIdByLabelAndLocationLevel( + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY, + new Integer[]{enumeration.LOCATION_LEVEL_ID_COUNTRY}); if (countryLocationId == null) { - throw new DataIntegrityViolationException("Default country location not found, with label=" + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY); + throw new DataIntegrityViolationException("Default country location not found, with label=" + enumeration.LOCATION_LABEL_DEFAULT_COUNTRY); } - + for (Vessel source : vessels) { source = importTemporaryVessel(source, countryLocationId, status); result.add(source); @@ -527,12 +520,12 @@ } @Override - @CacheEvict(value = "persons", allEntries=true ) + @CacheEvict(value = "persons", allEntries = true) public List<Person> importTemporaryPerson(List<Person> persons) { List<Person> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(enumeration.STATUS_TEMPORARY_CODE); + + fr.ifremer.adagio.core.dao.referential.Status status = + statusDao.load(enumeration.STATUS_TEMPORARY_CODE); for (Person source : persons) { source = importTemporaryPerson(source, status); result.add(source); @@ -541,12 +534,12 @@ } @Override - @CacheEvict(value = "gears", allEntries=true ) + @CacheEvict(value = "gears", allEntries = true) public List<Gear> importTemporaryGear(List<Gear> gears) { List<Gear> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(enumeration.STATUS_TEMPORARY_CODE); + + fr.ifremer.adagio.core.dao.referential.Status status = + statusDao.load(enumeration.STATUS_TEMPORARY_CODE); for (Gear source : gears) { source = importTemporaryGear(source, status); result.add(source); @@ -559,93 +552,91 @@ //------------------------------------------------------------------------// public Vessel importTemporaryVessel(Vessel source, Integer registrationLocationId, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getName()); - Preconditions.checkNotNull(source.getInternationalRegistrationCode()); + Preconditions.checkNotNull(source); + Preconditions.checkNotNull(source.getName()); + Preconditions.checkNotNull(source.getInternationalRegistrationCode()); - Integer vesselTypeId = null; - if (source.isScientificVessel()) { - vesselTypeId = enumeration.VESSEL_TYPE_ID_SCIENTIFIC; - } - else { - vesselTypeId = enumeration.VESSEL_TYPE_ID_FISHING; - } - - fr.ifremer.adagio.core.dao.referential.vessel.Vessel target = - vesselExtendDao.createAsTemporary( - null, - source.getInternationalRegistrationCode(), - registrationLocationId, source.getName(), - vesselTypeId); - - // Fill the result bean - Vessel result = new Vessel(); - result.setId(target.getCode()); - result.setName(source.getName()); - result.setRegistrationCode(source.getRegistrationCode()); - result.setInternationalRegistrationCode(source.getInternationalRegistrationCode()); - result.setScientificVessel(source.isScientificVessel()); + Integer vesselTypeId; + if (source.isScientificVessel()) { + vesselTypeId = enumeration.VESSEL_TYPE_ID_SCIENTIFIC; + } else { + vesselTypeId = enumeration.VESSEL_TYPE_ID_FISHING; + } + + fr.ifremer.adagio.core.dao.referential.vessel.Vessel target = + vesselExtendDao.createAsTemporary( + null, + source.getInternationalRegistrationCode(), + registrationLocationId, source.getName(), + vesselTypeId); + + // Fill the result bean + Vessel result = new Vessel(); + result.setId(target.getCode()); + result.setName(source.getName()); + result.setRegistrationCode(source.getRegistrationCode()); + result.setInternationalRegistrationCode(source.getInternationalRegistrationCode()); + result.setScientificVessel(source.isScientificVessel()); setStatus(status, result); - return result; + return result; } public Person importTemporaryPerson(Person source, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getFirstName()); - Preconditions.checkNotNull(source.getLastName()); + Preconditions.checkNotNull(source); + Preconditions.checkNotNull(source.getFirstName()); + Preconditions.checkNotNull(source.getLastName()); - fr.ifremer.adagio.core.dao.administration.user.Person target = personDao.createAsTemporary(source.getLastName(), source.getFirstName(), enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT); - - // Fill the result bean - Person result = new Person(); - result.setId(target.getId().toString()); - result.setLastName(source.getLastName()); - result.setFirstName(source.getFirstName()); + fr.ifremer.adagio.core.dao.administration.user.Person target = personDao.createAsTemporary(source.getLastName(), source.getFirstName(), enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT); + + // Fill the result bean + Person result = new Person(); + result.setId(target.getId().toString()); + result.setLastName(source.getLastName()); + result.setFirstName(source.getFirstName()); setStatus(status, result); - return result; + return result; } - + protected Species importTemporarySpecies(Species source) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getName()); + Preconditions.checkNotNull(source); + Preconditions.checkNotNull(source.getName()); - TaxonRefTaxVO taxonName = new TaxonRefTaxVO(); - taxonName.setName(source.getName()); - taxonName = taxonNameDao.createAsTemporary( - taxonName, - "Added by tutti (file import)."); + TaxonRefTaxVO taxonName = new TaxonRefTaxVO(); + taxonName.setName(source.getName()); + taxonName = taxonNameDao.createAsTemporary( + taxonName, + "Added by tutti (file import)."); // update the source - Species result = loadSpecies(taxonName); - - // Add to cache - putToSpeciesReferentCache(Integer.valueOf(result.getId()), result); + Species result = loadSpecies(taxonName); - return result; + // Add to cache + putToSpeciesReferentCache(Integer.valueOf(result.getId()), result); + + return result; } - + public Gear importTemporaryGear(Gear source, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getLabel()); - Preconditions.checkNotNull(source.getName()); + Preconditions.checkNotNull(source); + Preconditions.checkNotNull(source.getLabel()); + Preconditions.checkNotNull(source.getName()); - Integer gearClassificationId = null; - if (source.isScientificGear()) { - gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC; - } - else { - gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_FISHING; - } - - fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId); - - // Fill the result bean - Gear result = new Gear(); - result.setId(target.getId().toString()); - result.setLabel(source.getLabel()); - result.setName(source.getName()); + Integer gearClassificationId; + if (source.isScientificGear()) { + gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_SCIENTIFIC; + } else { + gearClassificationId = enumeration.GEAR_CLASSIFICIATION_ID_FISHING; + } + + fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId); + + // Fill the result bean + Gear result = new Gear(); + result.setId(target.getId().toString()); + result.setLabel(source.getLabel()); + result.setName(source.getName()); setStatus(status, result); - return result; + return result; } protected List<FishingOperationLocation> getFishingOperationLocations(Integer locationLevelId) { @@ -839,17 +830,17 @@ @Cacheable(value = "pmfms", key = "#pmfmId") protected Caracteristic putToCaracteristicCache(Integer pmfmId, Caracteristic caracteristic) { - return caracteristic; + return caracteristic; } - + @CachePut(value = "referentSpecies") protected List<Species> putToSpeciesReferentCache(List<Species> species) { - return species; + return species; } @CachePut(value = "referentSpecies", key = "#speciesId") protected Species putToSpeciesReferentCache(Integer speciesId, Species species) { - return species; + return species; } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-02-10 13:41:29 UTC (rev 379) @@ -24,29 +24,9 @@ * #L% */ -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.type.IntegerType; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.stereotype.Service; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; - import fr.ifremer.adagio.core.dao.data.batch.CatchBatchDao; import fr.ifremer.adagio.core.dao.data.batch.CatchBatchImpl; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; @@ -66,7 +46,24 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.type.IntegerType; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * @author tchemit <chemit@codelutin.com> * @since 0.3 @@ -108,30 +105,27 @@ Map<String, String> parentBatchMapById = new HashMap<String, String>(); while (list.hasNext()) { Object[] source = list.next(); - + Integer parentbatchId = (Integer) source[11]; - + // If row is not a species batch, load as batch frequency - if (couldBeASpeciesBatchFrequency(source)){ - //TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists - //loadSpeciesBatchFrequency(source, batchFrequenciesMapByParentId); + if (couldBeASpeciesBatchFrequency(source)) { + //TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists + //loadSpeciesBatchFrequency(source, batchFrequenciesMapByParentId); + } else { + // In all case, load row as species batch + SpeciesBatch speciesBatch = loadSpeciesBatch(source); + + // Add result into a maps + batchMapById.put(speciesBatch.getId(), speciesBatch); + if (parentbatchId != null) { + parentBatchMapById.put(speciesBatch.getId(), parentbatchId.toString()); + } } - else { - // In all case, load row as species batch - SpeciesBatch speciesBatch = loadSpeciesBatch(source); - - // Add result into a maps - batchMapById.put(speciesBatch.getId(), speciesBatch); - if (parentbatchId != null) { - parentBatchMapById.put(speciesBatch.getId(), parentbatchId.toString()); - } - } } // Retrieve the parent links for all batchs - for (Iterator<SpeciesBatch> iterator = batchMapById.values().iterator(); iterator.hasNext(); ) { - SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next(); - + for (SpeciesBatch speciesBatch : batchMapById.values()) { // If retrieve the parent from the parent map String parentbatchId = parentBatchMapById.get(speciesBatch.getId()); if (parentbatchId != null) { @@ -151,9 +145,9 @@ else { rootBatchs.add(speciesBatch); } - + //TODO BLA : uncomment if a property speciesBatch.speciesBatchFrequency exists - //List<SpeciesBatchFrequency> batchFrequencies = batchFrequenciesMapByParentId.get(speciesBatch.getId()); + //List<SpeciesBatchFrequency> batchFrequencies = batchFrequenciesMapByParentId.get(speciesBatch.getId()); //if (batchFrequencies != null) { // speciesBatch.setSpeciesBatchFrequency(batchFrequencies) //} @@ -193,7 +187,7 @@ // TODO BL : pourquoi un clear() ? => pas nécessaire. //getCurrentSession().clear(); - + getCurrentSession().enableFetchProfile("batch-with-measurements"); getCurrentSession().setFlushMode(FlushMode.COMMIT); SortingBatch batch = sortingBatchDao.load(Integer.valueOf(bean.getId())); @@ -233,97 +227,95 @@ public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( String speciesBatchId) { Iterator<Object[]> list = queryList("allSpeciesBatchFrequency", - "parentBatchId", IntegerType.INSTANCE, Integer.valueOf(speciesBatchId)); + "parentBatchId", IntegerType.INSTANCE, Integer.valueOf(speciesBatchId)); List<SpeciesBatchFrequency> results = Lists.newArrayList(); - - while (list.hasNext()) { - Object[] source = list.next(); - SpeciesBatchFrequency target = new SpeciesBatchFrequency(); - - int colIndex = 0; - target.setId(source[colIndex++].toString()); - - target.setNumber((Integer)source[colIndex++]); - target.setWeight((Float)source[colIndex++]); - target.setComment((String)source[colIndex++]); - - // Length step category - Integer lengthPmfmId = (Integer)source[colIndex++]; - Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId); - target.setLengthStepCaracteristic(lengthStepCaracteristic); - - // Length - target.setLengthStep((Float)source[colIndex++]); - results.add(target); - } + + while (list.hasNext()) { + Object[] source = list.next(); + SpeciesBatchFrequency target = new SpeciesBatchFrequency(); + + int colIndex = 0; + target.setId(source[colIndex++].toString()); + + target.setNumber((Integer) source[colIndex++]); + target.setWeight((Float) source[colIndex++]); + target.setComment((String) source[colIndex++]); + + // Length step category + Integer lengthPmfmId = (Integer) source[colIndex++]; + Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId); + target.setLengthStepCaracteristic(lengthStepCaracteristic); + + // Length + target.setLengthStep((Float) source[colIndex++]); + results.add(target); + } return results; } - @Override + @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { - Preconditions.checkNotNull(speciesBatchId); - Preconditions.checkNotNull(frequencies); - - if (frequencies.size() == 0) { - return frequencies; - } - getCurrentSession().setFlushMode(FlushMode.COMMIT); + Preconditions.checkNotNull(speciesBatchId); + Preconditions.checkNotNull(frequencies); + + if (frequencies.size() == 0) { + return frequencies; + } + getCurrentSession().setFlushMode(FlushMode.COMMIT); getCurrentSession().enableFetchProfile("batch-with-measurements"); - - // Retirve parent - SortingBatch parentBatch = sortingBatchDao.load(Integer.valueOf(speciesBatchId)); - - short rankOrder = 0; - String pmfmId = null; - Map<SortingBatch, SpeciesBatchFrequency> batchsToCreate = Maps.newHashMap(); - List<SortingBatch> batchsToUpdate= Lists.newArrayList(); - for (Iterator iterator = frequencies.iterator(); iterator.hasNext();) { - SpeciesBatchFrequency source = (SpeciesBatchFrequency) iterator.next(); - rankOrder++; - - // Check that all frequencies have the same length PMFM - if (pmfmId == null) { - source.getLengthStepCaracteristic().getId(); - } - else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { - throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); - } - - // Not existing batch - SortingBatch target = null; - if (source.getId() == null) { - target = SortingBatch.Factory.newInstance(); - - // Fill the sorting batch from the source - beanToEntity(source, target, parentBatch, rankOrder, true); - - // Create the targeted batch, then update the source id - sortingBatchDao.create(target); - source.setId(target.getId().toString()); - } - - // Existing batch - else { - target = sortingBatchDao.load(Integer.valueOf(source.getId())) ; - - // Fill the sorting batch from the source - beanToEntity(source, target, parentBatch, rankOrder, true); - - // Add the batch into a list (will be update later, using this list) - batchsToUpdate.add(target); - } - } - - // If some batchs need to be update, do it - if (batchsToUpdate.size() > 0) { - sortingBatchDao.update(batchsToUpdate); - } - - getCurrentSession().flush(); - + + // Retirve parent + SortingBatch parentBatch = sortingBatchDao.load(Integer.valueOf(speciesBatchId)); + + short rankOrder = 0; + String pmfmId = null; + Map<SortingBatch, SpeciesBatchFrequency> batchsToCreate = Maps.newHashMap(); + List<SortingBatch> batchsToUpdate = Lists.newArrayList(); + for (SpeciesBatchFrequency source : frequencies) { + rankOrder++; + + // Check that all frequencies have the same length PMFM + if (pmfmId == null) { + source.getLengthStepCaracteristic().getId(); + } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { + throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); + } + + // Not existing batch + SortingBatch target = null; + if (source.getId() == null) { + target = SortingBatch.Factory.newInstance(); + + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); + + // Create the targeted batch, then update the source id + sortingBatchDao.create(target); + source.setId(target.getId().toString()); + } + + // Existing batch + else { + target = sortingBatchDao.load(Integer.valueOf(source.getId())); + + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); + + // Add the batch into a list (will be update later, using this list) + batchsToUpdate.add(target); + } + } + + // If some batchs need to be update, do it + if (batchsToUpdate.size() > 0) { + sortingBatchDao.update(batchsToUpdate); + } + + getCurrentSession().flush(); + return frequencies; } @@ -352,7 +344,7 @@ // If parent and root need to be set if (target.getId() == null || target.getRootBatch() == null - || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { + || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) { setBatchParents(source, target, parentBatchId, notChangedSortingMeasurements); } @@ -385,7 +377,7 @@ String samplingRatioText = source.getSampleCategoryWeight() + "/" + source.getWeight(); samplingRatioText = samplingRatioText.replaceAll(",", "."); target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(source.getSampleCategoryWeight().floatValue() / source.getWeight().floatValue()); + target.setSamplingRatio(source.getSampleCategoryWeight() / source.getWeight()); } // Sorting measurement @@ -455,7 +447,7 @@ Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType()); if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { throw new DataIntegrityViolationException(MessageFormat.format("A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - new Object[]{SampleCategoryEnum.sortedUnsorted.name(), enumeration.PMFM_ID_SORTED_UNSORTED})); + SampleCategoryEnum.sortedUnsorted.name(), enumeration.PMFM_ID_SORTED_UNSORTED)); } Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); @@ -517,7 +509,7 @@ if (pmfmId != null) { setSampleCategoryQualitative(result, pmfmId, numValue, alphaValue, qvValue); } - + // Species Integer referenceTaxonId = (Integer) source[colIndex++]; if (referenceTaxonId != null) { @@ -525,7 +517,7 @@ Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); result.setSpecies(species); } - + return result; } @@ -533,9 +525,7 @@ if (speciesBatchs == null || speciesBatchs.size() == 0) { return; } - for (Iterator<SpeciesBatch> iterator = speciesBatchs.iterator(); iterator.hasNext(); ) { - SpeciesBatch speciesBatch = iterator.next(); - + for (SpeciesBatch speciesBatch : speciesBatchs) { // If batch store a species (in the database) if (speciesBatch.getSpecies() != null) { // Remove the link to the parent (not need in UI) @@ -549,7 +539,7 @@ speciesBatch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); speciesBatch.setSampleCategoryValue(inheritedSortedUnsortedValue); } - + // Apply species inheritance, if need if (speciesBatch.getSpecies() == null && inheritedSpecies != null) { speciesBatch.setSpecies(inheritedSpecies); @@ -557,17 +547,16 @@ // Compute the inheritance sorted/unsorted value for children if (speciesBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted) { - inheritedSortedUnsortedValue = (CaracteristicQualitativeValue)speciesBatch.getSampleCategoryValue(); + inheritedSortedUnsortedValue = (CaracteristicQualitativeValue) speciesBatch.getSampleCategoryValue(); + } else { + inheritedSortedUnsortedValue = null; } - else { - inheritedSortedUnsortedValue = null; - } - + // Recursive call : propagate species and sorted/unsorted value applyInheritedProperties(speciesBatch.getChildBatchs(), - inheritedSortedUnsortedValue, - speciesBatch.getSpecies(), - results); + inheritedSortedUnsortedValue, + speciesBatch.getSpecies(), + results); } } @@ -584,14 +573,14 @@ } protected void setSampleCategoryQualitative(SpeciesBatch target, Integer pmfmId, Float numericalvalue, String alphanumericalValue, Integer qualitativeValueId) { - // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.) + // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.) if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) { return; } SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId); Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); - + target.setSampleCategoryType(sampleCategory); if (numericalvalue != null) { target.setSampleCategoryValue(numericalvalue); @@ -607,10 +596,8 @@ return; } CaracteristicQualitativeValue value = null; - for (Iterator iterator = caracteristic.getQualitativeValue().iterator(); iterator - .hasNext(); ) { - CaracteristicQualitativeValue qv = (CaracteristicQualitativeValue) iterator.next(); - if (qualitativeValueId.intValue() == Integer.parseInt(qv.getId())) { + for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { + if (qualitativeValueId == Integer.parseInt(qv.getId())) { value = qv; break; } @@ -635,7 +622,7 @@ batch.getQuantificationMeasurements().clear(); sortingBatchDao.remove(batch); } - + protected void beanToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, short rankOrder, boolean copyIfNull) { Preconditions.checkNotNull(source.getBatch()); Preconditions.checkNotNull(source.getBatch().getId()); @@ -715,62 +702,62 @@ } } } - + private SpeciesBatchFrequency loadSpeciesBatchFrequency(Object[] source, Map<String, List<SpeciesBatchFrequency>> batchFrequenciesMapByParentId) { - SpeciesBatchFrequency target = new SpeciesBatchFrequency(); - - int colIndex = 0; - target.setId(source[colIndex++].toString()); - - // Individual count - target.setNumber((Integer)source[colIndex++]); - - // Covert database weight (and sampling ratio) into UI weight + SpeciesBatchFrequency target = new SpeciesBatchFrequency(); + + int colIndex = 0; + target.setId(source[colIndex++].toString()); + + // Individual count + target.setNumber((Integer) source[colIndex++]); + + // Covert database weight (and sampling ratio) into UI weight Float sourceWeight = (Float) source[colIndex++]; Float sourceSamplingRatio = (Float) source[colIndex++]; String sourceSamplingRatioText = (String) source[colIndex++]; UIWeight uiWeight = convertDatabase2UI(sourceWeight, sourceSamplingRatio, sourceSamplingRatioText); - target.setWeight(uiWeight.weight); - - target.setComment((String)source[colIndex++]); - - // Length step category - Integer lengthPmfmId = (Integer)source[colIndex++]; - Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId); - target.setLengthStepCaracteristic(lengthStepCaracteristic); - - // Qualitative value (should be null) - Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a qualitative value."); - - // Length (skip qvValue and alphaValue column) - target.setLengthStep((Float) source[colIndex++]); + target.setWeight(uiWeight.weight); - // Alphanumerical value (should be null) - Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a alphanumerical value."); - - // Taxon (should be null) - Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : taxon frequency could not have species."); + target.setComment((String) source[colIndex++]); - Integer parentBatchId = (Integer)source[colIndex++]; - - // Add target into the result map - List<SpeciesBatchFrequency> parentBatchFrequencies = batchFrequenciesMapByParentId.get(parentBatchId.toString()); - if (parentBatchFrequencies == null) { - parentBatchFrequencies = Lists.newArrayList(); - batchFrequenciesMapByParentId.put(parentBatchId.toString(), parentBatchFrequencies); - } - parentBatchFrequencies.add(target); - - return target; - } - + // Length step category + Integer lengthPmfmId = (Integer) source[colIndex++]; + Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(lengthPmfmId); + target.setLengthStepCaracteristic(lengthStepCaracteristic); + + // Qualitative value (should be null) + Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a qualitative value."); + + // Length (skip qvValue and alphaValue column) + target.setLengthStep((Float) source[colIndex++]); + + // Alphanumerical value (should be null) + Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : batch frequency could not have a alphanumerical value."); + + // Taxon (should be null) + Preconditions.checkState(source[colIndex++] == null, "Invalid batch tree format : taxon frequency could not have species."); + + Integer parentBatchId = (Integer) source[colIndex++]; + + // Add target into the result map + List<SpeciesBatchFrequency> parentBatchFrequencies = batchFrequenciesMapByParentId.get(parentBatchId.toString()); + if (parentBatchFrequencies == null) { + parentBatchFrequencies = Lists.newArrayList(); + batchFrequenciesMapByParentId.put(parentBatchId.toString(), parentBatchFrequencies); + } + parentBatchFrequencies.add(target); + + return target; + } + protected boolean couldBeASpeciesBatchFrequency(Object[] source) { - Integer pmfmId = (Integer)source[6]; + Integer pmfmId = (Integer) source[6]; Integer referenceTaxonId = (Integer) source[10]; Float numericalValue = (Float) source[8]; Integer parentbatchId = (Integer) source[11]; SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId); - + // Batch frequency is a batch with : // - a numerical value // - a parent @@ -778,11 +765,11 @@ // - no corresponding sample category return numericalValue != null && parentbatchId != null && referenceTaxonId == null && sampleCategory == null; } - + protected UIWeight convertDatabase2UI(Float weight, Float samplingRatio, String samplingRatioText) { - UIWeight result = new UIWeight(); - - // Weight & sampleCategory Weight + UIWeight result = new UIWeight(); + + // Weight & sampleCategory Weight if (samplingRatio == null) { result.weight = weight; } else if (weight != null) { @@ -790,16 +777,17 @@ if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) { String weightStr = samplingRatioText.substring(startStr.length()); if (weightStr != null && !weightStr.isEmpty()) { - result.sampleWeight=weight; - result.weight=Float.parseFloat(weightStr); + result.sampleWeight = weight; + result.weight = Float.parseFloat(weightStr); } } } return result; } - - class UIWeight { - Float sampleWeight=null; - Float weight=null; + + static class UIWeight { + Float sampleWeight = null; + + Float weight = null; } } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-02-10 13:41:29 UTC (rev 379) @@ -43,6 +43,8 @@ import org.junit.runners.model.Statement; import org.nuiton.util.ApplicationConfig; +import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -50,6 +52,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; +import java.util.Properties; import java.util.Set; /** @@ -79,14 +82,40 @@ private final String beanRefFactoryReferenceId; - public DatabaseResource() { - this(null, null); + private final boolean writeDb; + + public static DatabaseResource readDb() { + return new DatabaseResource(); } - public DatabaseResource(String beanFactoryReferenceLocation, - String beanRefFactoryReferenceId) { + public static DatabaseResource writeDb() { + return new DatabaseResource(true); + } + + public static DatabaseResource noDb() { + return new DatabaseResource( + "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb"); + } + + protected DatabaseResource() { + this(null, null, false); + } + + protected DatabaseResource(boolean writeDb) { + this(null, null, writeDb); + } + + protected DatabaseResource(String beanFactoryReferenceLocation, + String beanRefFactoryReferenceId) { + this(beanFactoryReferenceLocation, beanRefFactoryReferenceId, false); + } + + protected DatabaseResource(String beanFactoryReferenceLocation, + String beanRefFactoryReferenceId, + boolean writeDb) { this.beanFactoryReferenceLocation = beanFactoryReferenceLocation; this.beanRefFactoryReferenceId = beanRefFactoryReferenceId; + this.writeDb = writeDb; } public TuttiPersistenceConfig getConfig() { @@ -101,6 +130,8 @@ return new File(resourceDirectory, name); } + boolean witherror = false; + @Override public Statement apply(final Statement base, final Description description) { @@ -110,6 +141,8 @@ before(description); try { base.evaluate(); + } catch (Throwable e) { + witherror = true; } finally { after(description); } @@ -145,7 +178,9 @@ Thread.currentThread().setContextClassLoader(loader); // check that config file is in classpath (avoid to find out why it does not works...) - String configFilename = "tutti-test.properties"; + String configFilename = writeDb ? + "tutti-test-write.properties" : + "tutti-test-read.properties"; InputStream resourceAsStream = getClass().getResourceAsStream("/" + configFilename); Preconditions.checkNotNull(resourceAsStream, "Could not find " + configFilename + " in test class-path"); @@ -159,10 +194,42 @@ config = new TuttiPersistenceConfig(applicationConfig); + if (writeDb) { + FileUtils.copyDirectory(db, config.getDbDirectory()); + } + + // load db config + File dbConfig = new File(config.getDbDirectory(), config.getDbName() + ".properties"); + Properties p = new Properties(); + BufferedReader reader = Files.newReader(dbConfig, Charsets.UTF_8); + p.load(reader); + reader.close(); + + if (log.isDebugEnabled()) { + log.debug("Db config: " + dbConfig + "\n" + p); + } + + if (writeDb) { + + p.setProperty("readonly", "false"); + BufferedWriter writer = Files.newWriter(dbConfig, Charsets.UTF_8); + p.store(writer, ""); + writer.close(); + } else { + // make sure db is on readonly mode + String readonly = p.getProperty("readonly"); + Preconditions.checkNotNull(readonly, "Could not find readonly property on db confg: " + dbConfig); + Preconditions.checkState("true".equals(readonly), "readonly property must be at true value in read mode test in db confg: " + dbConfig); + } + config.initConfig(loader); TuttiPersistenceConfig.setInstance(config); + if (log.isInfoEnabled()) { + log.info("Use db: " + config.getJdbcUrl()); + } + if (log.isDebugEnabled()) { log.debug("Use conf.properties at " + config.getDbConfigurationPath()); } @@ -179,6 +246,13 @@ if (log.isInfoEnabled()) { log.info("After test " + testClass); } + + if (writeDb && !witherror) { + if (log.isInfoEnabled()) { + log.info("Remove copy db at: " + config.getDbDirectory()); + } + FileUtils.deleteDirectory(config.getDbDirectory()); + } // push back old classLoader if (oldClassLoader != null) { Thread.currentThread().setContextClassLoader(oldClassLoader); Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocolsTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -145,7 +145,7 @@ SpeciesProtocol sp1 = protocol.getSpecies().get(0); Assert.assertNotNull(sp1); Assert.assertEquals("1", sp1.getId()); - Assert.assertEquals(11242, sp1.getSpeciesReferenceTaxonId(),0); + Assert.assertEquals(11242, sp1.getSpeciesReferenceTaxonId(), 0); Assert.assertEquals("BAR", sp1.getSpeciesSurveyCode()); Assert.assertEquals("1394", sp1.getLengthStepPmfmId()); Assert.assertFalse(sp1.isAgeEnabled()); @@ -159,7 +159,7 @@ SpeciesProtocol sp2 = protocol.getSpecies().get(1); Assert.assertNotNull(sp2); Assert.assertEquals("2", sp2.getId()); - Assert.assertEquals(3835, sp2.getSpeciesReferenceTaxonId(),0); + Assert.assertEquals(3835, sp2.getSpeciesReferenceTaxonId(), 0); Assert.assertEquals("CHIN", sp2.getSpeciesSurveyCode()); Assert.assertEquals("323", sp2.getLengthStepPmfmId()); Assert.assertTrue(sp2.isAgeEnabled()); Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,61 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link AccidentalBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class AccidentalBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected AccidentalBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService(); + } + + @Test + public void getAllAccidentalBatch(/*String fishingOperationId*/) { + + } + + @Test + public void getAccidentalBatch(/*String id*/) { + + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,73 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class AccidentalBatchPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected AccidentalBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService(); - } - - @Test - public void getAllAccidentalBatch(/*String fishingOperationId*/) { - - } - - @Test - public void getAccidentalBatch(/*String id*/) { - - } - - @Test - public void createAccidentalBatch(/*AccidentalBatch bean*/) { - - } - - @Test - public void saveAccidentalBatch(/*AccidentalBatch bean*/) { - - } - - @Test - public void deleteAccidentalBatch(/*String id*/) { - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link AccidentalBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class AccidentalBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected AccidentalBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getAccidentalBatchPersistenceService(); + } + + @Test + public void createAccidentalBatch(/*AccidentalBatch bean*/) { + + } + + @Test + public void saveAccidentalBatch(/*AccidentalBatch bean*/) { + + } + + @Test + public void deleteAccidentalBatch(/*String id*/) { + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,61 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link BenthosBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class BenthosBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected BenthosBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService(); + } + + @Test + public void getAllBenthosBatch(/*String fishingOperationId*/) { + + } + + @Test + public void getBenthosBatch(/*String id*/) { + + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,73 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class BenthosBatchPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected BenthosBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService(); - } - - @Test - public void getAllBenthosBatch(/*String fishingOperationId*/) { - - } - - @Test - public void getBenthosBatch(/*String id*/) { - - } - - @Test - public void createBenthosBatch(/*BenthosBatch bean*/) { - - } - - @Test - public void saveBenthosBatch(/*BenthosBatch bean*/) { - - } - - @Test - public void deleteBenthosBatch(/*String id*/) { - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link BenthosBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class BenthosBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected BenthosBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService(); + } + + @Test + public void createBenthosBatch(/*BenthosBatch bean*/) { + + } + + @Test + public void saveBenthosBatch(/*BenthosBatch bean*/) { + + } + + @Test + public void deleteBenthosBatch(/*String id*/) { + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,214 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; - -import java.util.Calendar; -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.assertTrue; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - */ -public class CatchBatchPersistenceServiceImplTest { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(CatchBatchPersistenceServiceImplTest.class); - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected CatchBatchPersistenceService service; - - protected CruisePersistenceService cruiseService; - - protected FishingOperationPersistenceService fishingOperationService; - - protected ReferentialPersistenceService referentialService; - - protected Cruise cruise; - - protected FishingOperation fishingOperation; - - protected List<Species> species; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - cruise.setYear(calendar.get(Calendar.YEAR)); - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - cruise = cruiseService.createCruise(cruise); - - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperation = fishingOperations.get(0); - fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); - fishingOperation.setId(null); - fishingOperation.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingEndDate(calendar.getTime()); - - fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); - } - - @Test - public void getCatchBatchFromFishingOperation() throws Exception { - - //TODO - } - - @Test - public void changeSpeciesBatchSpecies() { - //TODO - } - - @Test - public void createAndSaveCatchBatch() throws Exception { - CatchBatch catchBatch; - CatchBatch createdCatchBatch; - CatchBatch reloadedCatchBatch; - - catchBatch = new CatchBatch(); - catchBatch.setFishingOperation(fishingOperation); - - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - - // Create and reload (test round trip) - createdCatchBatch = service.createCatchBatch(catchBatch); - assertNotNull(createdCatchBatch); - assertNotNull(createdCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId()); - - // ----------------------------------------------------------------------------- - // 2. Test with all properties - // ----------------------------------------------------------------------------- - catchBatch.setId(null); - // total weight : 100kg - catchBatch.setCatchTotalWeight(75f); - // Vrac : - { - // note : poids trie par la balance tremis (thalassa) (init par pupitri) - catchBatch.setCatchTotalSortedTremisWeight(50f); - // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si) - catchBatch.setCatchTotalSortedCarousselWeight(45f); - - // Species - { - catchBatch.setSpeciesTotalSortedWeight(12f); - catchBatch.setSpeciesTotalSampleSortedWeight(8f); - } - } - // Hors Vrac : 10kg - { - catchBatch.setCatchTotalUnsortedWeight(10f); - - // Species - { - catchBatch.setSpeciesTotalUnsortedWeight(10f); - } - } - // Rejet : 15kg - catchBatch.setCatchTotalRejectedWeight(15f); - - // Create and reload (test round trip) - createdCatchBatch = service.createCatchBatch(catchBatch); - assertNotNull(createdCatchBatch); - assertNotNull(createdCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); - assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); - - assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); - - // ----------------------------------------------------------------------------- - // 2. Test save after modification - // ----------------------------------------------------------------------------- - catchBatch.setCatchTotalSortedTremisWeight(null); - catchBatch.setCatchTotalSortedCarousselWeight(null); - catchBatch.setSpeciesTotalSortedWeight(null); - catchBatch.setSpeciesTotalSampleSortedWeight(null); - catchBatch.setCatchTotalUnsortedWeight(null); - catchBatch.setSpeciesTotalUnsortedWeight(null); - CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch); - assertNotNull(savedCatchBatch); - assertNotNull(savedCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); - assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); - - assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); - } - -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,58 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link CatchBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +@Ignore +public class CatchBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected CatchBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); + } + + @Test + public void getCatchBatchFromFishingOperation() throws Exception { + + //TODO + } + +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImplTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,204 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.Calendar; +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.assertTrue; + +/** + * To test {@link CatchBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class CatchBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected CatchBatchPersistenceService service; + + protected CruisePersistenceService cruiseService; + + protected FishingOperationPersistenceService fishingOperationService; + + protected ReferentialPersistenceService referentialService; + + protected Cruise cruise; + + protected FishingOperation fishingOperation; + + protected List<Species> species; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); + cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + + cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); + cruise.setId(null); + Calendar calendar = new GregorianCalendar(); + cruise.setBeginDate(calendar.getTime()); + cruise.setYear(calendar.get(Calendar.YEAR)); + calendar.add(Calendar.MONTH, 1); // add one month + cruise.setEndDate(calendar.getTime()); + cruise = cruiseService.createCruise(cruise); + + List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); + assertNotNull(fishingOperations); + assertTrue(fishingOperations.size() > 0); + fishingOperation = fishingOperations.get(0); + fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); + fishingOperation.setId(null); + fishingOperation.setCruise(cruise); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 1); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperation.setGearShootingStartDate(calendar.getTime()); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 10); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperation.setGearShootingEndDate(calendar.getTime()); + + fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); + } + + @Test + public void changeSpeciesBatchSpecies() { + //TODO + } + + @Test + public void createAndSaveCatchBatch() throws Exception { + CatchBatch catchBatch; + CatchBatch createdCatchBatch; + CatchBatch reloadedCatchBatch; + + catchBatch = new CatchBatch(); + catchBatch.setFishingOperation(fishingOperation); + + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- + + // Create and reload (test round trip) + createdCatchBatch = service.createCatchBatch(catchBatch); + assertNotNull(createdCatchBatch); + assertNotNull(createdCatchBatch.getId()); + + reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); + assertNotNull(reloadedCatchBatch); + assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId()); + + // ----------------------------------------------------------------------------- + // 2. Test with all properties + // ----------------------------------------------------------------------------- + catchBatch.setId(null); + // total weight : 100kg + catchBatch.setCatchTotalWeight(75f); + // Vrac : + { + // note : poids trie par la balance tremis (thalassa) (init par pupitri) + catchBatch.setCatchTotalSortedTremisWeight(50f); + // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si) + catchBatch.setCatchTotalSortedCarousselWeight(45f); + + // Species + { + catchBatch.setSpeciesTotalSortedWeight(12f); + catchBatch.setSpeciesTotalSampleSortedWeight(8f); + } + } + // Hors Vrac : 10kg + { + catchBatch.setCatchTotalUnsortedWeight(10f); + + // Species + { + catchBatch.setSpeciesTotalUnsortedWeight(10f); + } + } + // Rejet : 15kg + catchBatch.setCatchTotalRejectedWeight(15f); + + // Create and reload (test round trip) + createdCatchBatch = service.createCatchBatch(catchBatch); + assertNotNull(createdCatchBatch); + assertNotNull(createdCatchBatch.getId()); + + reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); + assertNotNull(reloadedCatchBatch); + assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); + assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); + assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); + assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); + + assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); + assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); + assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); + + // ----------------------------------------------------------------------------- + // 2. Test save after modification + // ----------------------------------------------------------------------------- + catchBatch.setCatchTotalSortedTremisWeight(null); + catchBatch.setCatchTotalSortedCarousselWeight(null); + catchBatch.setSpeciesTotalSortedWeight(null); + catchBatch.setSpeciesTotalSampleSortedWeight(null); + catchBatch.setCatchTotalUnsortedWeight(null); + catchBatch.setSpeciesTotalUnsortedWeight(null); + CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch); + assertNotNull(savedCatchBatch); + assertNotNull(savedCatchBatch.getId()); + + reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); + assertNotNull(reloadedCatchBatch); + assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); + assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); + assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); + assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); + + assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); + assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); + assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); + } + +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,70 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.List; + +/** + * To test {@link CruisePersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class CruisePersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected CruisePersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + } + + @Test + public void getAllCruise(/*String programId*/) { + String programCode = dbResource.getFixtures().programCode(); + List<Cruise> result = service.getAllCruise(programCode); + Assert.assertNotNull(result); + Assert.assertFalse(result.isEmpty()); + } + + @Test + public void getCruise(/*String id*/) { + + String cruiseId = dbResource.getFixtures().cruiseId(); + Cruise result = service.getCruise(cruiseId); + Assert.assertNotNull(result); + } + +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,248 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.referential.Country; -import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.Person; -import fr.ifremer.tutti.persistence.entities.referential.Vessel; -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.Ignore; -import org.junit.Test; - -import java.util.Calendar; -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.assertNull; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class CruisePersistenceServiceTest { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(CruisePersistenceServiceTest.class); - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected ReferentialPersistenceService referentialService; - - protected ProgramPersistenceService programService; - - protected CruisePersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - programService = TuttiPersistenceServiceLocator.getProgramPersistenceService(); - } - - @Test - public void getAllCruise(/*String programId*/) { - String programCode = dbResource.getFixtures().programCode(); - List<Cruise> result = service.getAllCruise(programCode); - Assert.assertNotNull(result); - Assert.assertFalse(result.isEmpty()); - } - - @Test - public void getCruise(/*String id*/) { - - String cruiseId = dbResource.getFixtures().cruiseId(); - Cruise result = service.getCruise(cruiseId); - Assert.assertNotNull(result); - } - - @Ignore - @Test - public void createCruise(/*Cruise bean*/) { - String programCode = dbResource.getFixtures().programCode(); - Cruise cruise = new Cruise(); - - // ----------------------------------------------------------------------------- - // 1. Test with all properties filled - // ----------------------------------------------------------------------------- - cruise.setId(null); - - cruise.setName("Unit-test-" + System.currentTimeMillis()); - - cruise.setProgram(programService.getProgram(programCode)); - - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - - cruise.setYear(calendar.get(Calendar.YEAR)); - - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - - Country country = null; - List<Country> countries = referentialService.getAllCountry(); - for (Country aCountry : countries) { - if (aCountry.getLabel() != null && aCountry.getLabel().equals("FRA")) { - country = aCountry; - break; - } - } - assertNotNull("Could not load FRA country", country); - cruise.setCountry(country); - - List<Gear> gears = referentialService.getAllFishingGear(); - cruise.setGear(gears); - - cruise.setComment("My comments on cruise"); - - Person managerPerson = referentialService.getAllPerson().get(0); - cruise.setHeadOfMission(Lists.newArrayList(managerPerson)); - - List<Vessel> vessels = Lists.newArrayList(); - vessels.add(referentialService.getAllScientificVessel().get(0)); - Vessel fishingVessel = new Vessel(); - fishingVessel.setId(dbResource.getFixtures().fishingVesselCode()); - vessels.add(fishingVessel); - - cruise.setVessel(vessels); - - cruise.setMultirigNumber(2); - - // Create cruise in database - Cruise createdCruise = service.createCruise(cruise); - assertNotNull(createdCruise); - assertNotNull(createdCruise.getId()); - assertEquals(cruise.getName(), createdCruise.getName()); - - if (log.isInfoEnabled()) { - log.info("Created cruise: " + createdCruise.getId()); - } - - // Then reload cruise and compare - Cruise reloadedCruise = service.getCruise(createdCruise.getId()); - calendar.setTime(createdCruise.getBeginDate()); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - assertEquals(calendar.getTime(), reloadedCruise.getBeginDate()); - calendar.setTime(createdCruise.getEndDate()); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - assertEquals(calendar.getTime(), reloadedCruise.getEndDate()); - assertEquals(cruise.getMultirigNumber(), reloadedCruise.getMultirigNumber()); - - // ----------------------------------------------------------------------------- - // 2. Test with only mandatory properties - // ----------------------------------------------------------------------------- - createdCruise.setId(null); - createdCruise.setHeadOfMission(null); - createdCruise.setBeginDate(null); - createdCruise.setEndDate(null); - createdCruise.setComment(null); - createdCruise.setMultirigNumber(null); - - // Save cruise - createdCruise = service.createCruise(cruise); - assertNotNull(createdCruise); - assertNotNull(createdCruise.getId()); - assertEquals(cruise.getName(), createdCruise.getName()); - - // Reload to compare - reloadedCruise = service.getCruise(createdCruise.getId()); - - assertEquals(createdCruise.getBeginDate(), reloadedCruise.getBeginDate()); - assertEquals(createdCruise.getEndDate(), reloadedCruise.getEndDate()); - assertEquals(createdCruise.getComment(), reloadedCruise.getComment()); - assertEquals(createdCruise.getMultirigNumber(), reloadedCruise.getMultirigNumber()); - assertNull(reloadedCruise.getHeadOfMission()); - assertNotNull(reloadedCruise.getVessel()); - assertEquals(createdCruise.getVessel().get(0), reloadedCruise.getVessel().get(0)); - assertEquals(cruise.getCountry().getId(), reloadedCruise.getCountry().getId()); - assertNotNull(reloadedCruise.getVessel()); - assertEquals(vessels.size(), reloadedCruise.getVessel().size()); - assertNotNull(reloadedCruise.getGear()); - assertEquals(gears.size(), reloadedCruise.getGear().size()); - } - - @Test - public void saveCruise(/*Cruise bean*/) { - // ----------------------------------------------------------------------------- - // 1. Init a cruise (by copy) - // ----------------------------------------------------------------------------- - Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId()); - - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - - cruise.setYear(calendar.get(Calendar.YEAR)); - - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - - cruise = service.createCruise(cruise); - - // ----------------------------------------------------------------------------- - // 2. Apply some changes - // ----------------------------------------------------------------------------- - - // Name : - cruise.setName("Unit-test-" + System.currentTimeMillis()); - - // Remove gear, then add another gear - Gear previousGear = cruise.getGear(0); - cruise.getGear().clear(); - List<Gear> gears = referentialService.getAllFishingGear(); - for (Gear gear : gears) { - // Make sure the gear is different before to add it - if (gear.getId() != null && !gear.getId().equals(previousGear.getId())) { - cruise.addGear(gear); - break; - } - } - - // Save changes, then check - Cruise savedCruise = service.saveCruise(cruise); - assertNotNull(savedCruise); - Cruise reloadedCruise = service.getCruise(savedCruise.getId()); - - assertEquals(cruise.getId(), reloadedCruise.getId()); - assertEquals(cruise.getName(), reloadedCruise.getName()); - assertEquals(cruise.getComment(), reloadedCruise.getComment()); - assertNotNull(reloadedCruise.getGear()); - assertEquals(cruise.getGear().size(), reloadedCruise.getGear().size()); - assertEquals(cruise.getGear(0).getId(), reloadedCruise.getGear(0).getId()); - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,233 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.referential.Country; +import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.Calendar; +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.assertNull; + +/** + * To test {@link CruisePersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class CruisePersistenceServiceWriteTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CruisePersistenceServiceWriteTest.class); + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected ReferentialPersistenceService referentialService; + + protected ProgramPersistenceService programService; + + protected CruisePersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + programService = TuttiPersistenceServiceLocator.getProgramPersistenceService(); + } + + @Test + public void createCruise(/*Cruise bean*/) { + String programCode = dbResource.getFixtures().programCode(); + Cruise cruise = new Cruise(); + + // ----------------------------------------------------------------------------- + // 1. Test with all properties filled + // ----------------------------------------------------------------------------- + cruise.setId(null); + + cruise.setName("Unit-test-" + System.currentTimeMillis()); + + cruise.setProgram(programService.getProgram(programCode)); + + Calendar calendar = new GregorianCalendar(); + cruise.setBeginDate(calendar.getTime()); + + cruise.setYear(calendar.get(Calendar.YEAR)); + + calendar.add(Calendar.MONTH, 1); // add one month + cruise.setEndDate(calendar.getTime()); + + Country country = null; + List<Country> countries = referentialService.getAllCountry(); + for (Country aCountry : countries) { + if (aCountry.getLabel() != null && aCountry.getLabel().equals("FRA")) { + country = aCountry; + break; + } + } + assertNotNull("Could not load FRA country", country); + cruise.setCountry(country); + + List<Gear> gears = referentialService.getAllFishingGear(); + cruise.setGear(gears); + + cruise.setComment("My comments on cruise"); + + Person managerPerson = referentialService.getAllPerson().get(0); + cruise.setHeadOfMission(Lists.newArrayList(managerPerson)); + + List<Vessel> vessels = Lists.newArrayList(); + vessels.add(referentialService.getAllScientificVessel().get(0)); + Vessel fishingVessel = new Vessel(); + fishingVessel.setId(dbResource.getFixtures().fishingVesselCode()); + vessels.add(fishingVessel); + + cruise.setVessel(vessels); + + cruise.setMultirigNumber(2); + + // Create cruise in database + Cruise createdCruise = service.createCruise(cruise); + assertNotNull(createdCruise); + assertNotNull(createdCruise.getId()); + assertEquals(cruise.getName(), createdCruise.getName()); + + if (log.isInfoEnabled()) { + log.info("Created cruise: " + createdCruise.getId()); + } + + // Then reload cruise and compare + Cruise reloadedCruise = service.getCruise(createdCruise.getId()); + calendar.setTime(createdCruise.getBeginDate()); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + assertEquals(calendar.getTime(), reloadedCruise.getBeginDate()); + calendar.setTime(createdCruise.getEndDate()); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + assertEquals(calendar.getTime(), reloadedCruise.getEndDate()); + assertEquals(cruise.getMultirigNumber(), reloadedCruise.getMultirigNumber()); + + // ----------------------------------------------------------------------------- + // 2. Test with only mandatory properties + // ----------------------------------------------------------------------------- + createdCruise.setId(null); + createdCruise.setHeadOfMission(null); + createdCruise.setBeginDate(null); + createdCruise.setEndDate(null); + createdCruise.setComment(null); + createdCruise.setMultirigNumber(null); + + // Save cruise + createdCruise = service.createCruise(cruise); + assertNotNull(createdCruise); + assertNotNull(createdCruise.getId()); + assertEquals(cruise.getName(), createdCruise.getName()); + + // Reload to compare + reloadedCruise = service.getCruise(createdCruise.getId()); + + assertEquals(createdCruise.getBeginDate(), reloadedCruise.getBeginDate()); + assertEquals(createdCruise.getEndDate(), reloadedCruise.getEndDate()); + assertEquals(createdCruise.getComment(), reloadedCruise.getComment()); +// assertEquals(createdCruise.getMultirigNumber(), reloadedCruise.getMultirigNumber()); + //TODO-tc, are we forced to do such things ? + assertEquals(1, reloadedCruise.getMultirigNumber(), 0); + assertNull(reloadedCruise.getHeadOfMission()); + assertNotNull(reloadedCruise.getVessel()); + assertEquals(createdCruise.getVessel().get(0), reloadedCruise.getVessel().get(0)); + assertEquals(cruise.getCountry().getId(), reloadedCruise.getCountry().getId()); + assertNotNull(reloadedCruise.getVessel()); + assertEquals(vessels.size(), reloadedCruise.getVessel().size()); + assertNotNull(reloadedCruise.getGear()); + assertEquals(gears.size(), reloadedCruise.getGear().size()); + } + + @Test + public void saveCruise(/*Cruise bean*/) { + // ----------------------------------------------------------------------------- + // 1. Init a cruise (by copy) + // ----------------------------------------------------------------------------- + Cruise cruise = service.getCruise(dbResource.getFixtures().cruiseId()); + + cruise.setId(null); + Calendar calendar = new GregorianCalendar(); + cruise.setBeginDate(calendar.getTime()); + + cruise.setYear(calendar.get(Calendar.YEAR)); + + calendar.add(Calendar.MONTH, 1); // add one month + cruise.setEndDate(calendar.getTime()); + + cruise = service.createCruise(cruise); + + // ----------------------------------------------------------------------------- + // 2. Apply some changes + // ----------------------------------------------------------------------------- + + // Name : + cruise.setName("Unit-test-" + System.currentTimeMillis()); + + // Remove gear, then add another gear + Gear previousGear = cruise.getGear(0); + cruise.getGear().clear(); + List<Gear> gears = referentialService.getAllFishingGear(); + for (Gear gear : gears) { + // Make sure the gear is different before to add it + if (gear.getId() != null && !gear.getId().equals(previousGear.getId())) { + cruise.addGear(gear); + break; + } + } + + // Save changes, then check + Cruise savedCruise = service.saveCruise(cruise); + assertNotNull(savedCruise); + Cruise reloadedCruise = service.getCruise(savedCruise.getId()); + + assertEquals(cruise.getId(), reloadedCruise.getId()); + assertEquals(cruise.getName(), reloadedCruise.getName()); + assertEquals(cruise.getComment(), reloadedCruise.getComment()); + assertNotNull(reloadedCruise.getGear()); + assertEquals(cruise.getGear().size(), reloadedCruise.getGear().size()); + assertEquals(cruise.getGear(0).getId(), reloadedCruise.getGear(0).getId()); + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,69 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * To test {@link FishingOperationPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class FishingOperationPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected FishingOperationPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + } + + @Test + public void getAllFishingOperation(/*String cruiseId*/) { + List<FishingOperation> fishingOperations = service.getAllFishingOperation(dbResource.getFixtures().cruiseId()); + assertNotNull(fishingOperations); + assertTrue(fishingOperations.size() > 1); + } + + @Test + @Ignore + public void getFishingOperation(/*String id*/) { + + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,401 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.CaracteristicMap; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; -import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; -import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.Vessel; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataIntegrityViolationException; - -import java.io.Serializable; -import java.util.Calendar; -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.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class FishingOperationPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected FishingOperationPersistenceService service; - - protected ReferentialPersistenceService referentialService; - - protected ProgramPersistenceService programService; - - protected CruisePersistenceService cruiseService; - - protected Cruise cruise = null; - protected Gear cruiseGear = null; - protected Vessel notCruiseVessel = null; - - @Autowired(required = true) - protected TuttiEnumerationFile enumeration; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - programService = TuttiPersistenceServiceLocator.getProgramPersistenceService(); - - // Duplicate an existing cruise, to attach new fishing operations - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - cruise.setName("Unit-test-" + System.currentTimeMillis()); - cruise.setBeginDate(new Date()); - cruise.setEndDate(null); - cruise.setMultirigNumber(2); - - // Keep only one gear in the cruise : (need for case n°4) - List<Gear> cruiseGears = cruise.getGear(); - assertNotNull(cruiseGears); - assertTrue(cruiseGears.size() > 0); - cruiseGear = cruiseGears.get(0); - assertNotNull(cruiseGear.getId()); - cruise.setGear(Lists.newArrayList(cruiseGear)); - - cruise = cruiseService.createCruise(cruise); - assertNotNull(cruise.getId()); - - // Find a vessel, different from the cruise vessel - notCruiseVessel = referentialService.getVessel(dbResource.getFixtures().fishingVesselCode()); - assertNotNull(notCruiseVessel.getId()); - } - - @Test - public void getAllFishingOperation(/*String cruiseId*/) { - List<FishingOperation> fishingOperations = service.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 1); - } - - @Test - @Ignore - public void getFishingOperation(/*String id*/) { - - } - - @Test - public void createFishingOperation(/*FishingOperation bean*/) { - // ----------------------------------------------------------------------------- - // Prepare data and other entities - // ----------------------------------------------------------------------------- - Calendar calendar = new GregorianCalendar(); - FishingOperation reloadedFishingOperation; - FishingOperation createdFishingOperation; - - // Retrieve some environment caracteristics - List<Caracteristic> allEnvironmentCaracteristics = referentialService.getAllCaracteristic(); - CaracteristicMap environmentCaracteristics = new CaracteristicMap(); - CaracteristicMap environmentValuesOneEntry = new CaracteristicMap(); - for (Caracteristic caracteristic : allEnvironmentCaracteristics) { - Serializable value = null; - if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { - value = 1.0f; - } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) { - value = "some text"; - } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE - && caracteristic.getQualitativeValue(0) != null) { - // Choose the first qualitative value - value = caracteristic.getQualitativeValue(0).getId(); - } - if (value != null) { - environmentCaracteristics.put(caracteristic, value); - if (environmentValuesOneEntry.size() == 0) { - environmentValuesOneEntry.put(caracteristic, value); - } - } - } - - // Retrieve some gear use caracteristics - List<Caracteristic> allGearShootingCaracteristics = referentialService.getAllCaracteristic(); - CaracteristicMap gearShootingCaracteristics = new CaracteristicMap(); - CaracteristicMap gearShootingCaracteristicsOneEntry = new CaracteristicMap(); - for (Caracteristic caracteristic : allGearShootingCaracteristics) { - Serializable value = null; - if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { - value = 1.0f; - } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) { - value = "some text"; - } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE - && caracteristic.getQualitativeValue(0) != null) { - // Choose the first qualitative value - value = caracteristic.getQualitativeValue(0).getId(); - } - if (value != null) { - gearShootingCaracteristics.put(caracteristic, value); - if (gearShootingCaracteristicsOneEntry.size() == 0) { - gearShootingCaracteristicsOneEntry.put(caracteristic, value); - } - } - } - - - // Create new fishing operation : - FishingOperation fishingOperation = new FishingOperation(); - - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - - // Set properties (with optional value to null) - fishingOperation.setCruise(cruise); - fishingOperation.setStationNumber("STA1"); - fishingOperation.setFishingOperationNumber(1); - fishingOperation.setMultirigAggregation("1"); - fishingOperation.setGearShootingStartDate(null); - fishingOperation.setGearShootingEndDate(null); - fishingOperation.setGear(null); - fishingOperation.setVessel(null); - fishingOperation.setGearShootingStartLatitude(33.2541f); - fishingOperation.setComment(null); - - // Store fishing operation into database : - createdFishingOperation = service.createFishingOperation(fishingOperation); - assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation); - assertNotNull(createdFishingOperation.getId()); - - // Trying to reload this fishing operation - reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); - assertNotNull(reloadedFishingOperation); - assertNull(reloadedFishingOperation.getGearShootingStartDate()); - - // ----------------------------------------------------------------------------- - // 2. Test with all properties set - // ----------------------------------------------------------------------------- - // Set properties - fishingOperation.setId(null); - fishingOperation.setStationNumber("STA2"); - fishingOperation.setFishingOperationNumber(2); - fishingOperation.setMultirigAggregation("1"); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 99); - fishingOperation.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 99); - fishingOperation.setGearShootingEndDate(calendar.getTime()); - fishingOperation.setGearShootingStartLatitude(47.6f); - fishingOperation.setGearShootingStartLongitude(-5.05f); - fishingOperation.setGearShootingEndLatitude(47.9854f); - fishingOperation.setGearShootingEndLongitude(-5.597f); - - fishingOperation.setTrawlDistance(100.12345f); - fishingOperation.setFishingOperationRectiligne(true); - fishingOperation.setFishingOperationValid(Boolean.TRUE); - fishingOperation.setComment("Unit test createFishingOperation() - Part n°2 : All properties set"); - fishingOperation.setGear(cruiseGear); - fishingOperation.setVessel(notCruiseVessel); - fishingOperation.setEnvironmentCaracteristics(environmentCaracteristics); - fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristics); - - FishingOperationLocation strata = new FishingOperationLocation(); - strata.setId(dbResource.getFixtures().strataId()); - fishingOperation.setStrata(strata); - FishingOperationLocation subStrata = new FishingOperationLocation(); - subStrata.setId(dbResource.getFixtures().subStrataId()); - fishingOperation.setSubStrata(subStrata); - FishingOperationLocation localite = new FishingOperationLocation(); - localite.setId(dbResource.getFixtures().localite()); - fishingOperation.setLocation(localite); - - // Store fishing operation into database : - createdFishingOperation = service.createFishingOperation(fishingOperation); - assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation); - assertNotNull(createdFishingOperation.getId()); - - reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); - assertNotNull(reloadedFishingOperation.getGear()); - assertNotNull(reloadedFishingOperation.getVessel()); - assertEquals(fishingOperation.getVessel().getId(), reloadedFishingOperation.getVessel().getId()); - assertEquals(fishingOperation.getStationNumber(), reloadedFishingOperation.getStationNumber()); - assertEquals(fishingOperation.getFishingOperationNumber(), reloadedFishingOperation.getFishingOperationNumber()); - assertEquals(fishingOperation.getMultirigAggregation(), reloadedFishingOperation.getMultirigAggregation()); - assertNotNull(reloadedFishingOperation.getGearShootingStartDate()); - calendar.setTime(fishingOperation.getGearShootingStartDate()); - calendar.set(Calendar.MILLISECOND, 0); - assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingStartDate()); - assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude()); - assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude()); - assertNotNull(reloadedFishingOperation.getGearShootingEndDate()); - calendar.setTime(fishingOperation.getGearShootingEndDate()); - calendar.set(Calendar.MILLISECOND, 0); - assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingEndDate()); - assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude()); - assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude()); - assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance()); - assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne()); - assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid()); - assertEquals(fishingOperation.getComment(), reloadedFishingOperation.getComment()); - assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics()); - assertEquals(environmentCaracteristics.size(), fishingOperation.getEnvironmentCaracteristics().size()); - assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics()); - assertEquals(gearShootingCaracteristics.size(), reloadedFishingOperation.getGearShootingCaracteristics().size()); - assertNotNull(reloadedFishingOperation.getStrata()); - assertNotNull(reloadedFishingOperation.getStrata().getId()); - assertEquals(fishingOperation.getStrata().getId(), reloadedFishingOperation.getStrata().getId()); - assertNotNull(reloadedFishingOperation.getSubStrata()); - assertNotNull(reloadedFishingOperation.getSubStrata().getId()); - assertEquals(fishingOperation.getSubStrata().getId(), reloadedFishingOperation.getSubStrata().getId()); - assertNotNull(reloadedFishingOperation.getLocation()); - assertNotNull(reloadedFishingOperation.getLocation().getId()); - assertEquals(fishingOperation.getLocation().getId(), reloadedFishingOperation.getLocation().getId()); - - // ----------------------------------------------------------------------------- - // 3. Test : - // - startDate and startLat filled, but empty endLong - // - endLat and endLong filled but empty endDate - // - isFishingOperationRectiligne = false - // - trawlDistance empty - // - fishingOperationValid = false - // ----------------------------------------------------------------------------- - fishingOperation.setId(null); - fishingOperation.setStationNumber("STA3"); - fishingOperation.setFishingOperationNumber(3); - fishingOperation.setMultirigAggregation("2"); - fishingOperation.setGearShootingStartLongitude(null); - fishingOperation.setGearShootingEndDate(null); - fishingOperation.setTrawlDistance(null); - fishingOperation.setFishingOperationRectiligne(false); - fishingOperation.setFishingOperationValid(false); - fishingOperation.setComment("Unit test createFishingOperation() - Part n°3 :\n-startDate and startLat filled, but empty endLong\n- endLat and endLong filled but empty endDate"); - createdFishingOperation = service.createFishingOperation(fishingOperation); - reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); - assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude()); - assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude()); - assertNull(reloadedFishingOperation.getGearShootingEndDate()); - assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude()); - assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude()); - assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance()); - assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne()); - assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid()); - - // ----------------------------------------------------------------------------- - // 4. Test exceptions : - // - try to save a operation using a gear not declared in the cruise - // - try to save a operation using a multirig aggregation greater than the cruise multirig number - // ----------------------------------------------------------------------------- - fishingOperation.setId(null); - - // Find and set a gear not used in the cruise - List<Gear> gears = referentialService.getAllFishingGear(); - assertNotNull(gears); - assertTrue(gears.size() > 0); - for (Gear gear : gears) { - if (!cruiseGear.getId().equals(gear.getId())) { - fishingOperation.setGear(gear); - break; - } - } - - try { - createdFishingOperation = service.createFishingOperation(fishingOperation); - fail("A fishing operation must not be saved if the gear is not declared in the cruise."); - } catch (DataIntegrityViolationException dive) { - assertNotNull(dive); - fishingOperation.setGear(cruiseGear); - } - - fishingOperation.setMultirigAggregation("3"); - try { - createdFishingOperation = service.createFishingOperation(fishingOperation); - fail("A fishing operation must not be saved if the 'multirig aggregation' > 'cruise multirig number'."); - } catch (DataIntegrityViolationException dive) { - assertNotNull(dive); - fishingOperation.setMultirigAggregation("1"); - } - - // ----------------------------------------------------------------------------- - // 5. Test update (delete unecessary data) - // - remove positons - // - remove strata, substrata, localite - // - remove some environment carateristics - // - remove some gear shooting carateristics - // - change vessel (to same as cruise) - // ----------------------------------------------------------------------------- - fishingOperation.setId(reloadedFishingOperation.getId()); - fishingOperation.setGearShootingStartLatitude(null); - fishingOperation.setGearShootingStartLongitude(null); - fishingOperation.setGearShootingEndDate(null); - fishingOperation.setGearShootingEndLatitude(null); - fishingOperation.setGearShootingEndLongitude(null); - fishingOperation.setTrawlDistance(null); - fishingOperation.setStrata(null); - fishingOperation.setSubStrata(null); - fishingOperation.setLocation(null); - fishingOperation.setVessel(cruise.getVessel(0)); - fishingOperation.setEnvironmentCaracteristics(environmentValuesOneEntry); - fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristicsOneEntry); - fishingOperation.setComment(fishingOperation.getComment() + "\n\nUnit test createFishingOperation() - Part n°5 : check if deleted sub items in DB"); - createdFishingOperation = service.saveFishingOperation(fishingOperation); - reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); - assertNull(reloadedFishingOperation.getGearShootingStartLatitude()); - assertNull(reloadedFishingOperation.getGearShootingStartLongitude()); - assertNull(reloadedFishingOperation.getGearShootingEndDate()); - assertNull(reloadedFishingOperation.getGearShootingEndLatitude()); - assertNull(reloadedFishingOperation.getGearShootingEndLongitude()); - assertNull(reloadedFishingOperation.getStrata()); - assertNull(reloadedFishingOperation.getSubStrata()); - assertNull(reloadedFishingOperation.getLocation()); - assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics()); - assertEquals(environmentValuesOneEntry.size(), reloadedFishingOperation.getEnvironmentCaracteristics().size()); - assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics()); - assertEquals(gearShootingCaracteristicsOneEntry.size(), reloadedFishingOperation.getGearShootingCaracteristics().size()); - } - - @Test - @Ignore - public void saveFishingOperation(/*FishingOperation bean*/) { - - } - - -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,387 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.CaracteristicMap; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; +import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; +import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.dao.DataIntegrityViolationException; + +import java.io.Serializable; +import java.util.Calendar; +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.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * To test {@link FishingOperationPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class FishingOperationPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected FishingOperationPersistenceService service; + + protected ReferentialPersistenceService referentialService; + + protected ProgramPersistenceService programService; + + protected CruisePersistenceService cruiseService; + + protected Cruise cruise = null; + + protected Gear cruiseGear = null; + + protected Vessel notCruiseVessel = null; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + programService = TuttiPersistenceServiceLocator.getProgramPersistenceService(); + + // Duplicate an existing cruise, to attach new fishing operations + cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); + cruise.setId(null); + cruise.setName("Unit-test-" + System.currentTimeMillis()); + cruise.setBeginDate(new Date()); + cruise.setEndDate(null); + cruise.setMultirigNumber(2); + + // Keep only one gear in the cruise : (need for case n°4) + List<Gear> cruiseGears = cruise.getGear(); + assertNotNull(cruiseGears); + assertTrue(cruiseGears.size() > 0); + cruiseGear = cruiseGears.get(0); + assertNotNull(cruiseGear.getId()); + cruise.setGear(Lists.newArrayList(cruiseGear)); + + cruise = cruiseService.createCruise(cruise); + assertNotNull(cruise.getId()); + + // Find a vessel, different from the cruise vessel + notCruiseVessel = referentialService.getVessel(dbResource.getFixtures().fishingVesselCode()); + assertNotNull(notCruiseVessel.getId()); + } + + @Test + public void createFishingOperation(/*FishingOperation bean*/) { + // ----------------------------------------------------------------------------- + // Prepare data and other entities + // ----------------------------------------------------------------------------- + Calendar calendar = new GregorianCalendar(); + FishingOperation reloadedFishingOperation; + FishingOperation createdFishingOperation; + + // Retrieve some environment caracteristics + List<Caracteristic> allEnvironmentCaracteristics = referentialService.getAllCaracteristic(); + CaracteristicMap environmentCaracteristics = new CaracteristicMap(); + CaracteristicMap environmentValuesOneEntry = new CaracteristicMap(); + for (Caracteristic caracteristic : allEnvironmentCaracteristics) { + Serializable value = null; + if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { + value = 1.0f; + } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) { + value = "some text"; + } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE + && caracteristic.getQualitativeValue(0) != null) { + // Choose the first qualitative value + value = caracteristic.getQualitativeValue(0).getId(); + } + if (value != null) { + environmentCaracteristics.put(caracteristic, value); + if (environmentValuesOneEntry.size() == 0) { + environmentValuesOneEntry.put(caracteristic, value); + } + } + } + + // Retrieve some gear use caracteristics + List<Caracteristic> allGearShootingCaracteristics = referentialService.getAllCaracteristic(); + CaracteristicMap gearShootingCaracteristics = new CaracteristicMap(); + CaracteristicMap gearShootingCaracteristicsOneEntry = new CaracteristicMap(); + for (Caracteristic caracteristic : allGearShootingCaracteristics) { + Serializable value = null; + if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { + value = 1.0f; + } else if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) { + value = "some text"; + } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE + && caracteristic.getQualitativeValue(0) != null) { + // Choose the first qualitative value + value = caracteristic.getQualitativeValue(0).getId(); + } + if (value != null) { + gearShootingCaracteristics.put(caracteristic, value); + if (gearShootingCaracteristicsOneEntry.size() == 0) { + gearShootingCaracteristicsOneEntry.put(caracteristic, value); + } + } + } + + + // Create new fishing operation : + FishingOperation fishingOperation = new FishingOperation(); + + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- + + // Set properties (with optional value to null) + fishingOperation.setCruise(cruise); + fishingOperation.setStationNumber("STA1"); + fishingOperation.setFishingOperationNumber(1); + fishingOperation.setMultirigAggregation("1"); + fishingOperation.setGearShootingStartDate(null); + fishingOperation.setGearShootingEndDate(null); + fishingOperation.setGear(null); + fishingOperation.setVessel(null); + fishingOperation.setGearShootingStartLatitude(33.2541f); + fishingOperation.setComment(null); + + // Store fishing operation into database : + createdFishingOperation = service.createFishingOperation(fishingOperation); + assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation); + assertNotNull(createdFishingOperation.getId()); + + // Trying to reload this fishing operation + reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); + assertNotNull(reloadedFishingOperation); + assertNull(reloadedFishingOperation.getGearShootingStartDate()); + + // ----------------------------------------------------------------------------- + // 2. Test with all properties set + // ----------------------------------------------------------------------------- + // Set properties + fishingOperation.setId(null); + fishingOperation.setStationNumber("STA2"); + fishingOperation.setFishingOperationNumber(2); + fishingOperation.setMultirigAggregation("1"); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 1); + calendar.set(Calendar.MILLISECOND, 99); + fishingOperation.setGearShootingStartDate(calendar.getTime()); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 10); + calendar.set(Calendar.MILLISECOND, 99); + fishingOperation.setGearShootingEndDate(calendar.getTime()); + fishingOperation.setGearShootingStartLatitude(47.6f); + fishingOperation.setGearShootingStartLongitude(-5.05f); + fishingOperation.setGearShootingEndLatitude(47.9854f); + fishingOperation.setGearShootingEndLongitude(-5.597f); + + fishingOperation.setTrawlDistance(100.12345f); + fishingOperation.setFishingOperationRectiligne(true); + fishingOperation.setFishingOperationValid(Boolean.TRUE); + fishingOperation.setComment("Unit test createFishingOperation() - Part n°2 : All properties set"); + fishingOperation.setGear(cruiseGear); + fishingOperation.setVessel(notCruiseVessel); + fishingOperation.setEnvironmentCaracteristics(environmentCaracteristics); + fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristics); + + FishingOperationLocation strata = new FishingOperationLocation(); + strata.setId(dbResource.getFixtures().strataId()); + fishingOperation.setStrata(strata); + FishingOperationLocation subStrata = new FishingOperationLocation(); + subStrata.setId(dbResource.getFixtures().subStrataId()); + fishingOperation.setSubStrata(subStrata); + FishingOperationLocation localite = new FishingOperationLocation(); + localite.setId(dbResource.getFixtures().localite()); + fishingOperation.setLocation(localite); + + // Store fishing operation into database : + createdFishingOperation = service.createFishingOperation(fishingOperation); + assertNotNull("Fishing operation ID must not be null after creation in database", createdFishingOperation); + assertNotNull(createdFishingOperation.getId()); + + reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); + assertNotNull(reloadedFishingOperation.getGear()); + assertNotNull(reloadedFishingOperation.getVessel()); + assertEquals(fishingOperation.getVessel().getId(), reloadedFishingOperation.getVessel().getId()); + assertEquals(fishingOperation.getStationNumber(), reloadedFishingOperation.getStationNumber()); + assertEquals(fishingOperation.getFishingOperationNumber(), reloadedFishingOperation.getFishingOperationNumber()); + assertEquals(fishingOperation.getMultirigAggregation(), reloadedFishingOperation.getMultirigAggregation()); + assertNotNull(reloadedFishingOperation.getGearShootingStartDate()); + calendar.setTime(fishingOperation.getGearShootingStartDate()); + calendar.set(Calendar.MILLISECOND, 0); + assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingStartDate()); + assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude()); + assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude()); + assertNotNull(reloadedFishingOperation.getGearShootingEndDate()); + calendar.setTime(fishingOperation.getGearShootingEndDate()); + calendar.set(Calendar.MILLISECOND, 0); + assertEquals(calendar.getTime(), reloadedFishingOperation.getGearShootingEndDate()); + assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude()); + assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude()); + assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance()); + assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne()); + assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid()); + assertEquals(fishingOperation.getComment(), reloadedFishingOperation.getComment()); + assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics()); + assertEquals(environmentCaracteristics.size(), fishingOperation.getEnvironmentCaracteristics().size()); + assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics()); + assertEquals(gearShootingCaracteristics.size(), reloadedFishingOperation.getGearShootingCaracteristics().size()); + assertNotNull(reloadedFishingOperation.getStrata()); + assertNotNull(reloadedFishingOperation.getStrata().getId()); + assertEquals(fishingOperation.getStrata().getId(), reloadedFishingOperation.getStrata().getId()); + assertNotNull(reloadedFishingOperation.getSubStrata()); + assertNotNull(reloadedFishingOperation.getSubStrata().getId()); + assertEquals(fishingOperation.getSubStrata().getId(), reloadedFishingOperation.getSubStrata().getId()); + assertNotNull(reloadedFishingOperation.getLocation()); + assertNotNull(reloadedFishingOperation.getLocation().getId()); + assertEquals(fishingOperation.getLocation().getId(), reloadedFishingOperation.getLocation().getId()); + + // ----------------------------------------------------------------------------- + // 3. Test : + // - startDate and startLat filled, but empty endLong + // - endLat and endLong filled but empty endDate + // - isFishingOperationRectiligne = false + // - trawlDistance empty + // - fishingOperationValid = false + // ----------------------------------------------------------------------------- + fishingOperation.setId(null); + fishingOperation.setStationNumber("STA3"); + fishingOperation.setFishingOperationNumber(3); + fishingOperation.setMultirigAggregation("2"); + fishingOperation.setGearShootingStartLongitude(null); + fishingOperation.setGearShootingEndDate(null); + fishingOperation.setTrawlDistance(null); + fishingOperation.setFishingOperationRectiligne(false); + fishingOperation.setFishingOperationValid(false); + fishingOperation.setComment("Unit test createFishingOperation() - Part n°3 :\n-startDate and startLat filled, but empty endLong\n- endLat and endLong filled but empty endDate"); + createdFishingOperation = service.createFishingOperation(fishingOperation); + reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); + assertEquals(fishingOperation.getGearShootingStartLatitude(), reloadedFishingOperation.getGearShootingStartLatitude()); + assertEquals(fishingOperation.getGearShootingStartLongitude(), reloadedFishingOperation.getGearShootingStartLongitude()); + assertNull(reloadedFishingOperation.getGearShootingEndDate()); + assertEquals(fishingOperation.getGearShootingEndLatitude(), reloadedFishingOperation.getGearShootingEndLatitude()); + assertEquals(fishingOperation.getGearShootingEndLongitude(), reloadedFishingOperation.getGearShootingEndLongitude()); + assertEquals(fishingOperation.getTrawlDistance(), reloadedFishingOperation.getTrawlDistance()); + assertEquals(fishingOperation.isFishingOperationRectiligne(), reloadedFishingOperation.isFishingOperationRectiligne()); + assertEquals(fishingOperation.getFishingOperationValid(), reloadedFishingOperation.getFishingOperationValid()); + + // ----------------------------------------------------------------------------- + // 4. Test exceptions : + // - try to save a operation using a gear not declared in the cruise + // - try to save a operation using a multirig aggregation greater than the cruise multirig number + // ----------------------------------------------------------------------------- + fishingOperation.setId(null); + + // Find and set a gear not used in the cruise + List<Gear> gears = referentialService.getAllFishingGear(); + assertNotNull(gears); + assertTrue(gears.size() > 0); + for (Gear gear : gears) { + if (!cruiseGear.getId().equals(gear.getId())) { + fishingOperation.setGear(gear); + break; + } + } + + try { + createdFishingOperation = service.createFishingOperation(fishingOperation); + fail("A fishing operation must not be saved if the gear is not declared in the cruise."); + } catch (DataIntegrityViolationException dive) { + assertNotNull(dive); + fishingOperation.setGear(cruiseGear); + } + + fishingOperation.setMultirigAggregation("3"); + try { + createdFishingOperation = service.createFishingOperation(fishingOperation); + fail("A fishing operation must not be saved if the 'multirig aggregation' > 'cruise multirig number'."); + } catch (DataIntegrityViolationException dive) { + assertNotNull(dive); + fishingOperation.setMultirigAggregation("1"); + } + + // ----------------------------------------------------------------------------- + // 5. Test update (delete unecessary data) + // - remove positons + // - remove strata, substrata, localite + // - remove some environment carateristics + // - remove some gear shooting carateristics + // - change vessel (to same as cruise) + // ----------------------------------------------------------------------------- + fishingOperation.setId(reloadedFishingOperation.getId()); + fishingOperation.setGearShootingStartLatitude(null); + fishingOperation.setGearShootingStartLongitude(null); + fishingOperation.setGearShootingEndDate(null); + fishingOperation.setGearShootingEndLatitude(null); + fishingOperation.setGearShootingEndLongitude(null); + fishingOperation.setTrawlDistance(null); + fishingOperation.setStrata(null); + fishingOperation.setSubStrata(null); + fishingOperation.setLocation(null); + fishingOperation.setVessel(cruise.getVessel(0)); + fishingOperation.setEnvironmentCaracteristics(environmentValuesOneEntry); + fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristicsOneEntry); + fishingOperation.setComment(fishingOperation.getComment() + "\n\nUnit test createFishingOperation() - Part n°5 : check if deleted sub items in DB"); + createdFishingOperation = service.saveFishingOperation(fishingOperation); + reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); + assertNull(reloadedFishingOperation.getGearShootingStartLatitude()); + assertNull(reloadedFishingOperation.getGearShootingStartLongitude()); + assertNull(reloadedFishingOperation.getGearShootingEndDate()); + assertNull(reloadedFishingOperation.getGearShootingEndLatitude()); + assertNull(reloadedFishingOperation.getGearShootingEndLongitude()); + assertNull(reloadedFishingOperation.getStrata()); + assertNull(reloadedFishingOperation.getSubStrata()); + assertNull(reloadedFishingOperation.getLocation()); + assertNotNull(reloadedFishingOperation.getEnvironmentCaracteristics()); + assertEquals(environmentValuesOneEntry.size(), reloadedFishingOperation.getEnvironmentCaracteristics().size()); + assertNotNull(reloadedFishingOperation.getGearShootingCaracteristics()); + assertEquals(gearShootingCaracteristicsOneEntry.size(), reloadedFishingOperation.getGearShootingCaracteristics().size()); + } + + @Test + @Ignore + public void saveFishingOperation(/*FishingOperation bean*/) { + + } + + +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,62 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link MacroWasteBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class MacroWasteBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected MacroWasteBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService(); + } + + @Test + public void getAllMacroWasteBatch(/*String fishingOperationId*/) { + + } + + @Test + public void getMacroWasteBatch(/*String id*/) { + + } + +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,73 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class MacroWasteBatchPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected MacroWasteBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService(); - } - - @Test - public void getAllMacroWasteBatch(/*String fishingOperationId*/) { - - } - - @Test - public void getMacroWasteBatch(/*String id*/) { - - } - - @Test - public void createMacroWasteBatch(/*MacroWasteBatch bean*/) { - - } - - @Test - public void saveMacroWasteBatch(/*MacroWasteBatch bean*/) { - - } - - @Test - public void deleteMacroWasteBatch(/*String id*/) { - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/MacroWasteBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link MacroWasteBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class MacroWasteBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected MacroWasteBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getMacroWasteBatchPersistenceService(); + } + + @Test + public void createMacroWasteBatch(/*MacroWasteBatch bean*/) { + + } + + @Test + public void saveMacroWasteBatch(/*MacroWasteBatch bean*/) { + + } + + @Test + public void deleteMacroWasteBatch(/*String id*/) { + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,61 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link PlanktonBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class PlanktonBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected PlanktonBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService(); + } + + @Test + public void getAllPlanktonBatch(/*String fishingOperationId*/) { + + } + + @Test + public void getPlanktonBatch(/*String id*/) { + + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,73 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class PlanktonBatchPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected PlanktonBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService(); - } - - @Test - public void getAllPlanktonBatch(/*String fishingOperationId*/) { - - } - - @Test - public void getPlanktonBatch(/*String id*/) { - - } - - @Test - public void createPlanktonBatch(/*PlanktonBatch bean*/) { - - } - - @Test - public void savePlanktonBatch(/*PlanktonBatch bean*/) { - - } - - @Test - public void deletePlanktonBatch(/*String id*/) { - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link PlanktonBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +@Ignore +public class PlanktonBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected PlanktonBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getPlanktonBatchPersistenceService(); + } + + @Test + public void createPlanktonBatch(/*PlanktonBatch bean*/) { + + } + + @Test + public void savePlanktonBatch(/*PlanktonBatch bean*/) { + + } + + @Test + public void deletePlanktonBatch(/*String id*/) { + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,79 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.Program; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.List; + +/** + * To test {@link ProgramPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class ProgramPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected ProgramPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getProgramPersistenceService(); + } + + @Test + public void getAllProgram() { + List<Program> result = service.getAllProgram(); + Assert.assertNotNull(result); + Assert.assertTrue("More than one program must be found", result.size() > 0); + for (Program program : result) { + Assert.assertNotNull(program.getId()); + Assert.assertNotEquals("SIH-OBSMER", program.getId()); + Assert.assertNotEquals("SIH-ACTIFLOT", program.getId()); + } + } + + @Test + public void getProgram(/*String id*/) { + String programCode = dbResource.getFixtures().programCode(); + Program actual = service.getProgram(programCode); + Assert.assertNotNull(actual); + Assert.assertNotNull(actual.getId()); + Assert.assertNotNull(actual.getName()); + Assert.assertNotNull(actual.getComment()); + //comment, because in test database, "CAM-CGFS" could have a location that is not a zone + //Assert.assertNotNull(actual.getZone()); + Assert.assertEquals(programCode, actual.getId()); + } + +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,138 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.referential.Zone; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class ProgramPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected ProgramPersistenceService service; - - protected ReferentialPersistenceService referentialService; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getProgramPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - } - - @Test - public void getAllProgram() { - List<Program> result = service.getAllProgram(); - Assert.assertNotNull(result); - Assert.assertTrue("More than one program must be found", result.size() > 0); - for (Program program : result) { - Assert.assertNotNull(program.getId()); - Assert.assertNotEquals("SIH-OBSMER", program.getId()); - Assert.assertNotEquals("SIH-ACTIFLOT", program.getId()); - } - } - - @Test - public void getProgram(/*String id*/) { - String programCode = dbResource.getFixtures().programCode(); - Program actual = service.getProgram(programCode); - Assert.assertNotNull(actual); - Assert.assertNotNull(actual.getId()); - Assert.assertNotNull(actual.getName()); - Assert.assertNotNull(actual.getComment()); - //comment, because in test database, "CAM-CGFS" could have a location that is not a zone - //Assert.assertNotNull(actual.getZone()); - Assert.assertEquals(programCode, actual.getId()); - } - - @Test - public void createAndSaveProgram(/*Program bean*/) { - - List<Zone> zones = referentialService.getAllProgramZone(); - assertNotNull(zones); - assertTrue(zones.size() > 0); - - Program program = new Program(); - String name = "UniTest" + System.currentTimeMillis(); - if (name.length() > 40) { - name = name.substring(0, 39); - } - program.setName(name); - - program.setZone(zones.get(0)); - - // Create program - Program createdProgram = service.createProgram(program); - assertNotNull(createdProgram); - assertNotNull(createdProgram.getId()); - assertNull(createdProgram.getComment()); - - // Reload program and compare - Program reloadedProgram = service.getProgram(createdProgram.getId()); - assertNotNull(reloadedProgram); - assertEquals(createdProgram.getId(), reloadedProgram.getId()); - assertEquals(program.getName(), reloadedProgram.getName()); - assertNull(reloadedProgram.getComment()); - assertNotNull(program.getZone()); - assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId()); - - // Modify program - program.setId(createdProgram.getId()); - program.setName("NEW_NAME"); - program.setComment("Add some modification"); - program.setZone(zones.get(1)); - - // Save program - Program savedProgram = service.saveProgram(program); - assertNotNull(savedProgram); - assertNotNull(savedProgram.getId()); - - // Reload program and compare - reloadedProgram = service.getProgram(savedProgram.getId()); - assertNotNull(reloadedProgram); - assertEquals(program.getId(), reloadedProgram.getId()); - assertEquals(program.getName(), reloadedProgram.getName()); - assertEquals(program.getComment(), reloadedProgram.getComment()); - assertNotNull(program.getZone()); - assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId()); - } - -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,114 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.entities.referential.Zone; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * To test {@link ProgramPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ProgramPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected ProgramPersistenceService service; + + protected ReferentialPersistenceService referentialService; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getProgramPersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + } + + @Test + public void createAndSaveProgram(/*Program bean*/) { + + List<Zone> zones = referentialService.getAllProgramZone(); + assertNotNull(zones); + assertTrue(zones.size() > 0); + + Program program = new Program(); + String name = "UniTest" + System.currentTimeMillis(); + if (name.length() > 40) { + name = name.substring(0, 39); + } + program.setName(name); + + program.setZone(zones.get(0)); + + // Create program + Program createdProgram = service.createProgram(program); + assertNotNull(createdProgram); + assertNotNull(createdProgram.getId()); + assertNull(createdProgram.getComment()); + + // Reload program and compare + Program reloadedProgram = service.getProgram(createdProgram.getId()); + assertNotNull(reloadedProgram); + assertEquals(createdProgram.getId(), reloadedProgram.getId()); + assertEquals(program.getName(), reloadedProgram.getName()); + assertNull(reloadedProgram.getComment()); + assertNotNull(program.getZone()); + assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId()); + + // Modify program + program.setId(createdProgram.getId()); + program.setName("NEW_NAME"); + program.setComment("Add some modification"); + program.setZone(zones.get(1)); + + // Save program + Program savedProgram = service.saveProgram(program); + assertNotNull(savedProgram); + assertNotNull(savedProgram.getId()); + + // Reload program and compare + reloadedProgram = service.getProgram(savedProgram.getId()); + assertNotNull(reloadedProgram); + assertEquals(program.getId(), reloadedProgram.getId()); + assertEquals(program.getName(), reloadedProgram.getName()); + assertEquals(program.getComment(), reloadedProgram.getComment()); + assertNotNull(program.getZone()); + assertEquals(program.getZone().getId(), reloadedProgram.getZone().getId()); + } + +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,116 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; + +/** + * To test {@link ProtocolPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class ProtocolPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected ProtocolPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getProtocolPersistenceService(); + } + + @Test + public void getAllProtocol() { + + List<TuttiProtocol> allProtocol = service.getAllProtocol(); + Assert.assertTrue(allProtocol.isEmpty()); + + TuttiProtocol protocol = createProtocolFixture(); + TuttiProtocol createdProtocol = service.createProtocol(protocol); + allProtocol = service.getAllProtocol(); + Assert.assertFalse(allProtocol.isEmpty()); + Assert.assertEquals(createdProtocol, allProtocol.get(0)); + } + + @Test + public void getProtocol(/*String id*/) { + TuttiProtocol protocol = createProtocolFixture(); + TuttiProtocol createdProtocol = service.createProtocol(protocol); + Assert.assertNotNull(createdProtocol); + String id = createdProtocol.getId(); + TuttiProtocol loadedProtocol = service.getProtocol(id); + Assert.assertNotNull(loadedProtocol); + } + + protected TuttiProtocol createProtocolFixture() { + TuttiProtocol protocol = new TuttiProtocol(); + protocol.setId("1"); + protocol.setName("protocolName"); + protocol.setComment("Commentaire"); + protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18")); + protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821")); + protocol.setGearPmfmId(Lists.newArrayList("21", "22")); + protocol.setHydrologyPmfmId(Lists.<String>newArrayList()); + + protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList()); + SpeciesProtocol sp1 = new SpeciesProtocol(); + sp1.setId("1"); + sp1.setSpeciesReferenceTaxonId(11242); + sp1.setLengthStepPmfmId("1394"); + sp1.setCalcifySampleEnabled(true); + sp1.setMaturityEnabled(true); + sp1.setSexEnabled(true); + sp1.setWeightEnabled(true); + protocol.addSpecies(sp1); + + SpeciesProtocol sp2 = new SpeciesProtocol(); + sp2.setId("2"); + sp2.setSpeciesReferenceTaxonId(3835); + sp2.setLengthStepPmfmId("323"); + sp2.setAgeEnabled(true); + sp2.setCalcifySampleEnabled(true); + sp2.setCountIfNoFrequencyEnabled(true); + sp2.setMaturityEnabled(true); + sp2.setSexEnabled(true); + sp2.setSizeEnabled(true); + sp2.setWeightEnabled(true); + protocol.addSpecies(sp2); + return protocol; + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,189 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; -import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class ProtocolPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected ProtocolPersistenceService service; - - public static final String PROTOCOL_FILE_CONTENT = - "id: 1\n" + - "name: protocolName\n" + - "comment: Commentaire\n" + - "environmentPmfmId: \n" + - "- 114\n" + - "- 228\n" + - "- 821\n" + - "gearPmfmId: \n" + - "- 21\n" + - "- 22\n" + - "hydrologyPmfmId: []\n" + - "lengthClassesPmfmId: \n" + - "- 14\n" + - "- 18\n" + - "species: \n" + - "- !SpeciesProtocol\n" + - " id: 1\n" + - " calcifySampleEnabled: true\n" + - " lengthStepPmfmId: 1394\n" + - " maturityEnabled: true\n" + - " sexEnabled: true\n" + - " speciesReferenceTaxonId: 11242\n" + - " weightEnabled: true\n" + - "- !SpeciesProtocol\n" + - " id: 2\n" + - " ageEnabled: true\n" + - " calcifySampleEnabled: true\n" + - " countIfNoFrequencyEnabled: true\n" + - " lengthStepPmfmId: 323\n" + - " maturityEnabled: true\n" + - " sexEnabled: true\n" + - " sizeEnabled: true\n" + - " speciesReferenceTaxonId: 3835\n" + - " weightEnabled: true"; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getProtocolPersistenceService(); - } - - @Test - public void getAllProtocol() { - - List<TuttiProtocol> allProtocol = service.getAllProtocol(); - Assert.assertTrue(allProtocol.isEmpty()); - - TuttiProtocol protocol = createProtocolFixture(); - TuttiProtocol createdProtocol = service.createProtocol(protocol); - allProtocol = service.getAllProtocol(); - Assert.assertFalse(allProtocol.isEmpty()); - Assert.assertEquals(createdProtocol, allProtocol.get(0)); - } - - @Test - public void getProtocol(/*String id*/) { - TuttiProtocol protocol = createProtocolFixture(); - TuttiProtocol createdProtocol = service.createProtocol(protocol); - Assert.assertNotNull(createdProtocol); - String id = createdProtocol.getId(); - TuttiProtocol loadedProtocol = service.getProtocol(id); - Assert.assertNotNull(loadedProtocol); - } - - @Test - public void createProtocol(/*TuttiProtocol bean*/) { - - TuttiProtocol protocol = createProtocolFixture(); - TuttiProtocol createdProtocol = service.createProtocol(protocol); - Assert.assertNotNull(createdProtocol); - String id = createdProtocol.getId(); - Assert.assertTrue(service.getAllProtocolId().contains(id)); - - } - - @Test - public void saveProtocol(/*TuttiProtocol bean*/) { - - TuttiProtocol protocol = createProtocolFixture(); - TuttiProtocol createdProtocol = service.createProtocol(protocol); - - Assert.assertNotNull(createdProtocol); - String id = createdProtocol.getId(); - Assert.assertTrue(service.getAllProtocolId().contains(id)); - - TuttiProtocol savedProtocol = service.saveProtocol(createdProtocol); - Assert.assertNotNull(savedProtocol); - } - - @Test - public void deleteProtocol() { - - TuttiProtocol protocol = createProtocolFixture(); - TuttiProtocol createdProtocol = service.createProtocol(protocol); - Assert.assertNotNull(createdProtocol); - - String id = createdProtocol.getId(); - Assert.assertTrue(service.getAllProtocolId().contains(id)); - - service.deleteProtocol(id); - Assert.assertFalse(service.getAllProtocolId().contains(id)); - } - - protected TuttiProtocol createProtocolFixture() { - TuttiProtocol protocol = new TuttiProtocol(); - protocol.setId("1"); - protocol.setName("protocolName"); - protocol.setComment("Commentaire"); - protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18")); - protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821")); - protocol.setGearPmfmId(Lists.newArrayList("21", "22")); - protocol.setHydrologyPmfmId(Lists.<String>newArrayList()); - - protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList()); - SpeciesProtocol sp1 = new SpeciesProtocol(); - sp1.setId("1"); - sp1.setSpeciesReferenceTaxonId(11242); - sp1.setLengthStepPmfmId("1394"); - sp1.setCalcifySampleEnabled(true); - sp1.setMaturityEnabled(true); - sp1.setSexEnabled(true); - sp1.setWeightEnabled(true); - protocol.addSpecies(sp1); - - SpeciesProtocol sp2 = new SpeciesProtocol(); - sp2.setId("2"); - sp2.setSpeciesReferenceTaxonId(3835); - sp2.setLengthStepPmfmId("323"); - sp2.setAgeEnabled(true); - sp2.setCalcifySampleEnabled(true); - sp2.setCountIfNoFrequencyEnabled(true); - sp2.setMaturityEnabled(true); - sp2.setSexEnabled(true); - sp2.setSizeEnabled(true); - sp2.setWeightEnabled(true); - protocol.addSpecies(sp2); - return protocol; - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ProtocolPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,166 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +/** + * To test {@link ProtocolPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class ProtocolPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected ProtocolPersistenceService service; + + public static final String PROTOCOL_FILE_CONTENT = + "id: 1\n" + + "name: protocolName\n" + + "comment: Commentaire\n" + + "environmentPmfmId: \n" + + "- 114\n" + + "- 228\n" + + "- 821\n" + + "gearPmfmId: \n" + + "- 21\n" + + "- 22\n" + + "hydrologyPmfmId: []\n" + + "lengthClassesPmfmId: \n" + + "- 14\n" + + "- 18\n" + + "species: \n" + + "- !SpeciesProtocol\n" + + " id: 1\n" + + " calcifySampleEnabled: true\n" + + " lengthStepPmfmId: 1394\n" + + " maturityEnabled: true\n" + + " sexEnabled: true\n" + + " speciesReferenceTaxonId: 11242\n" + + " weightEnabled: true\n" + + "- !SpeciesProtocol\n" + + " id: 2\n" + + " ageEnabled: true\n" + + " calcifySampleEnabled: true\n" + + " countIfNoFrequencyEnabled: true\n" + + " lengthStepPmfmId: 323\n" + + " maturityEnabled: true\n" + + " sexEnabled: true\n" + + " sizeEnabled: true\n" + + " speciesReferenceTaxonId: 3835\n" + + " weightEnabled: true"; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getProtocolPersistenceService(); + } + + @Test + public void createProtocol(/*TuttiProtocol bean*/) { + + TuttiProtocol protocol = createProtocolFixture(); + TuttiProtocol createdProtocol = service.createProtocol(protocol); + Assert.assertNotNull(createdProtocol); + String id = createdProtocol.getId(); + Assert.assertTrue(service.getAllProtocolId().contains(id)); + + } + + @Test + public void saveProtocol(/*TuttiProtocol bean*/) { + + TuttiProtocol protocol = createProtocolFixture(); + TuttiProtocol createdProtocol = service.createProtocol(protocol); + + Assert.assertNotNull(createdProtocol); + String id = createdProtocol.getId(); + Assert.assertTrue(service.getAllProtocolId().contains(id)); + + TuttiProtocol savedProtocol = service.saveProtocol(createdProtocol); + Assert.assertNotNull(savedProtocol); + } + + @Test + public void deleteProtocol() { + + TuttiProtocol protocol = createProtocolFixture(); + TuttiProtocol createdProtocol = service.createProtocol(protocol); + Assert.assertNotNull(createdProtocol); + + String id = createdProtocol.getId(); + Assert.assertTrue(service.getAllProtocolId().contains(id)); + + service.deleteProtocol(id); + Assert.assertFalse(service.getAllProtocolId().contains(id)); + } + + protected TuttiProtocol createProtocolFixture() { + TuttiProtocol protocol = new TuttiProtocol(); + protocol.setId("1"); + protocol.setName("protocolName"); + protocol.setComment("Commentaire"); + protocol.setLengthClassesPmfmId(Lists.newArrayList("14", "18")); + protocol.setEnvironmentPmfmId(Lists.newArrayList("114", "228", "821")); + protocol.setGearPmfmId(Lists.newArrayList("21", "22")); + protocol.setHydrologyPmfmId(Lists.<String>newArrayList()); + + protocol.setSpecies(Lists.<SpeciesProtocol>newArrayList()); + SpeciesProtocol sp1 = new SpeciesProtocol(); + sp1.setId("1"); + sp1.setSpeciesReferenceTaxonId(11242); + sp1.setLengthStepPmfmId("1394"); + sp1.setCalcifySampleEnabled(true); + sp1.setMaturityEnabled(true); + sp1.setSexEnabled(true); + sp1.setWeightEnabled(true); + protocol.addSpecies(sp1); + + SpeciesProtocol sp2 = new SpeciesProtocol(); + sp2.setId("2"); + sp2.setSpeciesReferenceTaxonId(3835); + sp2.setLengthStepPmfmId("323"); + sp2.setAgeEnabled(true); + sp2.setCalcifySampleEnabled(true); + sp2.setCountIfNoFrequencyEnabled(true); + sp2.setMaturityEnabled(true); + sp2.setSexEnabled(true); + sp2.setSizeEnabled(true); + sp2.setWeightEnabled(true); + protocol.addSpecies(sp2); + return protocol; + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,428 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.adagio.core.service.technical.CacheService; +import fr.ifremer.tutti.persistence.DatabaseFixtures; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl; +import fr.ifremer.tutti.persistence.entities.IdAware; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.Country; +import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; +import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import fr.ifremer.tutti.persistence.entities.referential.Zone; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.NonUniqueResultException; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.nuiton.util.ApplicationConfig; + +import java.io.IOException; +import java.util.List; + +import static fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl.CaracteristicEnum; + +/** + * To test {@link ReferentialPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class ReferentialPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ReferentialPersistenceServiceReadTest.class); + + protected static TuttiPersistenceDevImpl storage; + + protected ReferentialPersistenceService service; + + protected CacheService cacheService; + + protected DatabaseFixtures fixtures; + + @BeforeClass + public static void beforeClass() throws IOException { + + // create a storage + + ApplicationConfig applicationConfig = dbResource.getConfig().getConfig(); + + applicationConfig.setOption( + TuttiPersistenceDevImpl.SKIP_FIXTURES_OPTION, Boolean.TRUE.toString()); + + storage = new TuttiPersistenceDevImpl(applicationConfig) { + + @Override + public <B extends IdAware> B create(String type, + B bean, + boolean sychronize) { + Preconditions.checkNotNull(bean, "Can't persist a null bean"); + B result = TuttiEntities.newEntity(bean); + result.setId(bean.getId()); + if (log.isDebugEnabled()) { + log.debug("Will persist [" + type + ":" + bean.getId() + "]"); + } + super.persist(type, bean, result, sychronize); + return result; + } + }; + + if (log.isInfoEnabled()) { + log.info("Will init persistence driver " + storage.getImplementationName()); + } + + storage.init(); + + TuttiPersistenceServiceLocator.instance().getCacheService().clearAllCaches(); + } + + @AfterClass + public static void afterClass() throws IOException { + storage.close(); + } + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + cacheService = TuttiPersistenceServiceLocator.instance().getCacheService(); + + // This is need for test : getAllFishingVessel() +// cacheService.clearAllCaches(); + fixtures = dbResource.getFixtures(); + } + + @Test + public void getAllProgramZone() { + List<Zone> result = service.getAllProgramZone(); + assertResultList(result, fixtures.refNbProgramZone()); + + persistList(Zone.class, result); + assertSize(result, storage.getAllProgramZone()); + } + + @Test + public void getAllCountry() { + List<Country> result = service.getAllCountry(); + assertResultList(result, fixtures.refNbCountry()); + + persistList(Country.class, result); + assertSize(result, storage.getAllCountry()); + } + + @Test + public void getAllFishingOperationStrata(/*String zoneId*/) { + String zoneId = dbResource.getFixtures().zoneId(); + List<FishingOperationLocation> result = + service.getAllFishingOperationStrata(zoneId); + assertResultList(result, fixtures.refNbStrata()); + + persistList(FishingOperationLocation.class, "Strata", result); + assertSize(result, storage.getAllFishingOperationStrata(zoneId)); + } + + @Test + public void getAllFishingOperationSubStrata(/*String zoneId, String strataId*/) { + String zoneId = dbResource.getFixtures().zoneId(); + List<FishingOperationLocation> result = + service.getAllFishingOperationSubStrata(zoneId, null); + assertResultList(result, 0); + + persistList(FishingOperationLocation.class, "SubStrata", result); + assertSize(result, storage.getAllFishingOperationSubStrata(zoneId, null)); + + // try with a strataId + String strataId = dbResource.getFixtures().strataId(); + result = service.getAllFishingOperationLocation(zoneId, strataId, null); + assertResultList(result, 1); + } + + @Test + public void getAllFishingOperationLocation(/*String zoneId, String strataId, String subStrataId*/) { + String zoneId = dbResource.getFixtures().zoneId(); + List<FishingOperationLocation> result = + service.getAllFishingOperationLocation(zoneId, null, null); + assertResultList(result, fixtures.refNbLocalite()); + + persistList(FishingOperationLocation.class, "Localite", result); + assertSize(result, storage.getAllFishingOperationLocation(zoneId, null, null)); + + // try with a strataId + String strataId = dbResource.getFixtures().strataId(); + result = service.getAllFishingOperationLocation(zoneId, strataId, null); + assertResultList(result, 1); + + // try with a subStrataId + String subStrataId = dbResource.getFixtures().subStrataId(); + result = service.getAllFishingOperationLocation(zoneId, strataId, subStrataId); + assertResultList(result, 3); + } + + @Test + public void getAllScientificVessel() { + List<Vessel> result = service.getAllScientificVessel(); + assertResultList(result, fixtures.refNbScientificVessel()); + persistList(Vessel.class, "Scientific", result); + assertSize(result, storage.getAllScientificVessel()); + } + + @Test + public void getAllFishingVessel() { + + // clear cache before this test + cacheService.clearCache("fishingVessels"); + + long time = System.currentTimeMillis(); + List<Vessel> result = service.getAllFishingVessel(); + long delta1 = System.currentTimeMillis() - time; + + assertResultList(result, fixtures.refNbFishingVessel()); + + // try again, to check cache is enable + time = System.currentTimeMillis(); + result = service.getAllFishingVessel(); + assertResultList(result, fixtures.refNbFishingVessel()); + + long delta2 = System.currentTimeMillis() - time; + + //TODO-tc We should not test cache performance like this, depends to much of the computer usage,... +// float reduceFactor = delta2 * 100 / delta1; +// Assert.assertTrue("The cache on getAllFishingVessel() should have speed up more than factor 10. Make sure EhCache is well configured.", reduceFactor < 0.1); + + persistList(Vessel.class, "Fishing", result); + assertSize(result, storage.getAllFishingVessel()); + } + + @Test + public void getAllScientificGear() { + List<Gear> result = service.getAllScientificGear(); + assertResultList(result, fixtures.refNbScientificGear()); + + persistList(Gear.class, "Scientific", result); + assertSize(result, storage.getAllScientificGear()); + } + + @Test + public void getAllFishingGear() { + List<Gear> result = service.getAllFishingGear(); + assertResultList(result, fixtures.refNbFishingGear()); + + persistList(Gear.class, "Fishing", result); + assertSize(result, storage.getAllFishingGear()); + } + + @Test + public void getAllPerson() { + List<Person> result = service.getAllPerson(); + assertResultList(result, fixtures.refNbPerson()); + + persistList(Person.class, result); + assertSize(result, storage.getAllPerson()); + } + + @Test + public void getAllSpecies() { + List<Species> result = service.getAllSpecies(); + assertResultList(result, fixtures.refNbSpecies()); + + persistList(Species.class, result); + assertSize(result, storage.getAllSpecies()); + } + + @Test + public void getAllReferentSpecies() { + List<Species> result = service.getAllReferentSpecies(); + assertResultList(result, fixtures.refNbReferentSpecies()); + + TuttiEntities.splitByTaxonId(result); + } + + @Test + public void getSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { + String speciesId = fixtures.refSpeciesId(); + Integer taxonId = fixtures.refSpeciesTaxonId(); + Species species = service.getSpeciesByReferenceTaxonId(taxonId); + Assert.assertNotNull(species); + Assert.assertEquals(speciesId, species.getId()); + Assert.assertEquals(fixtures.refSpeciesTaxonId(), species.getReferenceTaxonId()); + } + + @Test(expected = NonUniqueResultException.class) + public void getBadSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { + Integer taxonId = fixtures.refBadSpeciesTaxonId(); + service.getSpeciesByReferenceTaxonId(taxonId); + } + + @Test(expected = NonUniqueResultException.class) + public void getBad2SpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { + Integer taxonId = fixtures.refBad2SpeciesTaxonId(); + service.getSpeciesByReferenceTaxonId(taxonId); + } + + @Test + public void getAllCaracteristic() { + List<Caracteristic> result = service.getAllCaracteristic(); + assertResultList(result, fixtures.refNbCaracteristic()); + + persistList(Caracteristic.class, CaracteristicEnum.All.name(), result); + assertSize(result, storage.getAllCaracteristic()); + } + + @Test + public void getSizeCategoryCaracteristic() { + Caracteristic result = service.getSizeCategoryCaracteristic(); + assertCaracteristicQualitative(result, 6); + persist(Caracteristic.class, CaracteristicEnum.SizeCategory.name(), result); + } + + @Test + public void getSexCaracteristic() { + Caracteristic result = service.getSexCaracteristic(); + assertCaracteristicQualitative(result, 4); + persist(Caracteristic.class, CaracteristicEnum.SexCategory.name(), result); + } + + @Test + public void getSortedUnsortedCaracteristic() { + Caracteristic result = service.getSortedUnsortedCaracteristic(); + assertCaracteristicQualitative(result, 2); + persist(Caracteristic.class, CaracteristicEnum.SortedUnsortedCategory.name(), result); + } + + @Test + public void getMaturityCaracteristic() { + Caracteristic result = service.getMaturityCaracteristic(); + assertCaracteristicQualitative(result, 6); + persist(Caracteristic.class, CaracteristicEnum.MaturityCategory.name(), result); + } + + @Test + public void getMacroWasteCategoryCaracteristic() { + Caracteristic result = service.getMacroWasteCategoryCaracteristic(); + assertCaracteristicQualitative(result, 21); + persist(Caracteristic.class, CaracteristicEnum.MacroWasteCategory.name(), result); + } + + @Test + public void getMacroWasteSizeCategoryCaracteristic() { + Caracteristic result = service.getMacroWasteSizeCategoryCaracteristic(); + assertCaracteristicQualitative(result, 6); + persist(Caracteristic.class, CaracteristicEnum.MacroWasteSizeCategory.name(), result); + } + + @Test + @Ignore + public void testCaches() { + cacheService.clearAllCaches(); + + Object obj = service.getAllCaracteristic(); + System.out.println(obj); + + obj = service.getCaracteristic(1429); + System.out.println(obj); + + obj = service.getCaracteristic(1428); + System.out.println(obj); + } + + protected <S extends IdAware> void persistList(Class<S> type, List<S> result) { + persistList(type, null, result); + } + + protected <S extends IdAware> void persistList(Class<S> type, String context, List<S> result) { + + String key = TuttiPersistenceDevImpl.getKey(type, context); + for (S s : result) { + storage.create(key, s, false); + } + storage.persistToFile(key); + } + + protected <S extends IdAware> void persist(Class<S> type, S result) { + persist(type, null, result); + } + + protected <S extends IdAware> void persist(Class<S> type, String context, S result) { + String key = TuttiPersistenceDevImpl.getKey(type, context); + storage.create(key, result, true); + } + + protected void assertSize(List<?> expectedList, List<?> storageList) { + Assert.assertNotNull(expectedList); + Assert.assertNotNull(storageList); + expectedList.removeAll(storageList); + Assert.assertTrue("Some " + expectedList.size() + " entities were not persisted in storage :" + + expectedList, expectedList.isEmpty()); + + } + + protected void assertCaracteristicQualitative(Caracteristic result, int nbValues) { + Assert.assertNotNull(result); + Assert.assertNotNull(result.getCaracteristicType()); + Assert.assertTrue(TuttiEntities.isQualitativeCaracteristic(result)); + Assert.assertNotNull(result.getQualitativeValue()); + Assert.assertEquals(nbValues, result.sizeQualitativeValue()); + } + + protected void assertCaracteristicSize(Caracteristic incoming, + Caracteristic caracteristic) { + Assert.assertNotNull(incoming); + Assert.assertNotNull(caracteristic); + Assert.assertEquals(incoming, caracteristic); + Assert.assertEquals(incoming.getCaracteristicType(), + caracteristic.getCaracteristicType()); + Assert.assertEquals(incoming.sizeQualitativeValue(), + caracteristic.sizeQualitativeValue()); + } + + protected <E extends IdAware> void assertResultList(List<E> result, + int expectedsize) { + + // result not null + Assert.assertNotNull(result); + + // id are unique + TuttiEntities.splitById(result); + + // correct size + Assert.assertEquals(expectedsize, result.size()); + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,645 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import fr.ifremer.adagio.core.service.technical.CacheService; -import fr.ifremer.tutti.persistence.DatabaseFixtures; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl; -import fr.ifremer.tutti.persistence.entities.IdAware; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.Country; -import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; -import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.Person; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.Vessel; -import fr.ifremer.tutti.persistence.entities.referential.Zone; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.NonUniqueResultException; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.nuiton.util.ApplicationConfig; - -import java.io.IOException; -import java.util.List; - -import static fr.ifremer.tutti.persistence.TuttiPersistenceDevImpl.CaracteristicEnum; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class ReferentialPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ReferentialPersistenceServiceTest.class); - - protected static TuttiPersistenceDevImpl storage; - - protected ReferentialPersistenceService service; - - protected CacheService cacheService; - - protected DatabaseFixtures fixtures; - - @BeforeClass - public static void beforeClass() throws IOException { - - // create a storage - - ApplicationConfig applicationConfig = dbResource.getConfig().getConfig(); - - applicationConfig.setOption( - TuttiPersistenceDevImpl.SKIP_FIXTURES_OPTION, Boolean.TRUE.toString()); - - storage = new TuttiPersistenceDevImpl(applicationConfig) { - - @Override - public <B extends IdAware> B create(String type, - B bean, - boolean sychronize) { - Preconditions.checkNotNull(bean, "Can't persist a null bean"); - B result = TuttiEntities.newEntity(bean); - result.setId(bean.getId()); - if (log.isDebugEnabled()) { - log.debug("Will persist [" + type + ":" + bean.getId() + "]"); - } - super.persist(type, bean, result, sychronize); - return result; - } - }; - - if (log.isInfoEnabled()) { - log.info("Will init persistence driver " + storage.getImplementationName()); - } - - storage.init(); - } - - @AfterClass - public static void afterClass() throws IOException { - storage.close(); - } - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - cacheService = TuttiPersistenceServiceLocator.instance().getCacheService(); - - // This is need for test : getAllFishingVessel() -// cacheService.clearAllCaches(); - fixtures = dbResource.getFixtures(); - } - - @Test - public void getAllProgramZone() { - List<Zone> result = service.getAllProgramZone(); - assertResultList(result, fixtures.refNbProgramZone()); - - persistList(Zone.class, result); - assertSize(result, storage.getAllProgramZone()); - } - - @Test - public void getAllCountry() { - List<Country> result = service.getAllCountry(); - assertResultList(result, fixtures.refNbCountry()); - - persistList(Country.class, result); - assertSize(result, storage.getAllCountry()); - } - - @Test - public void getAllFishingOperationStrata(/*String zoneId*/) { - String zoneId = dbResource.getFixtures().zoneId(); - List<FishingOperationLocation> result = - service.getAllFishingOperationStrata(zoneId); - assertResultList(result, fixtures.refNbStrata()); - - persistList(FishingOperationLocation.class, "Strata", result); - assertSize(result, storage.getAllFishingOperationStrata(zoneId)); - } - - @Test - public void getAllFishingOperationSubStrata(/*String zoneId, String strataId*/) { - String zoneId = dbResource.getFixtures().zoneId(); - List<FishingOperationLocation> result = - service.getAllFishingOperationSubStrata(zoneId, null); - assertResultList(result, 0); - - persistList(FishingOperationLocation.class, "SubStrata", result); - assertSize(result, storage.getAllFishingOperationSubStrata(zoneId, null)); - - // try with a strataId - String strataId = dbResource.getFixtures().strataId(); - result = service.getAllFishingOperationLocation(zoneId, strataId, null); - assertResultList(result, 1); - } - - @Test - public void getAllFishingOperationLocation(/*String zoneId, String strataId, String subStrataId*/) { - String zoneId = dbResource.getFixtures().zoneId(); - List<FishingOperationLocation> result = - service.getAllFishingOperationLocation(zoneId, null, null); - assertResultList(result, fixtures.refNbLocalite()); - - persistList(FishingOperationLocation.class, "Localite", result); - assertSize(result, storage.getAllFishingOperationLocation(zoneId, null, null)); - - // try with a strataId - String strataId = dbResource.getFixtures().strataId(); - result = service.getAllFishingOperationLocation(zoneId, strataId, null); - assertResultList(result, 1); - - // try with a subStrataId - String subStrataId = dbResource.getFixtures().subStrataId(); - result = service.getAllFishingOperationLocation(zoneId, strataId, subStrataId); - assertResultList(result, 3); - } - - @Test - public void getAllScientificVessel() { - List<Vessel> result = service.getAllScientificVessel(); - assertResultList(result, fixtures.refNbScientificVessel()); - persistList(Vessel.class, "Scientific", result); - assertSize(result, storage.getAllScientificVessel()); - } - - @Test - public void getAllFishingVessel() { - - // clear cache before this test - cacheService.clearCache("fishingVessels"); - - long time = System.currentTimeMillis(); - List<Vessel> result = service.getAllFishingVessel(); - long delta1 = System.currentTimeMillis() - time; - - assertResultList(result, fixtures.refNbFishingVessel()); - - // try again, to check cache is enable - time = System.currentTimeMillis(); - result = service.getAllFishingVessel(); - assertResultList(result, fixtures.refNbFishingVessel()); - - long delta2 = System.currentTimeMillis() - time; - - //TODO-tc We should not test cache performance like this, depends to much of the computer usage,... -// float reduceFactor = delta2 * 100 / delta1; -// Assert.assertTrue("The cache on getAllFishingVessel() should have speed up more than factor 10. Make sure EhCache is well configured.", reduceFactor < 0.1); - - persistList(Vessel.class, "Fishing", result); - assertSize(result, storage.getAllFishingVessel()); - } - - @Test - public void getAllScientificGear() { - List<Gear> result = service.getAllScientificGear(); - assertResultList(result, fixtures.refNbScientificGear()); - - persistList(Gear.class, "Scientific", result); - assertSize(result, storage.getAllScientificGear()); - } - - @Test - public void getAllFishingGear() { - List<Gear> result = service.getAllFishingGear(); - assertResultList(result, fixtures.refNbFishingGear()); - - persistList(Gear.class, "Fishing", result); - assertSize(result, storage.getAllFishingGear()); - } - - @Test - public void getAllPerson() { - List<Person> result = service.getAllPerson(); - assertResultList(result, fixtures.refNbPerson()); - - persistList(Person.class, result); - assertSize(result, storage.getAllPerson()); - } - - @Test - public void getAllSpecies() { - List<Species> result = service.getAllSpecies(); - assertResultList(result, fixtures.refNbSpecies()); - - persistList(Species.class, result); - assertSize(result, storage.getAllSpecies()); - } - - @Test - public void getAllReferentSpecies() { - List<Species> result = service.getAllReferentSpecies(); - assertResultList(result, fixtures.refNbReferentSpecies()); - - TuttiEntities.splitByTaxonId(result); - } - - @Test - public void getSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { - String speciesId = fixtures.refSpeciesId(); - Integer taxonId = fixtures.refSpeciesTaxonId(); - Species species = service.getSpeciesByReferenceTaxonId(taxonId); - Assert.assertNotNull(species); - Assert.assertEquals(speciesId, species.getId()); - Assert.assertEquals(fixtures.refSpeciesTaxonId(), species.getReferenceTaxonId()); - } - - @Test(expected = NonUniqueResultException.class) - public void getBadSpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { - Integer taxonId = fixtures.refBadSpeciesTaxonId(); - service.getSpeciesByReferenceTaxonId(taxonId); - } - - @Test(expected = NonUniqueResultException.class) - public void getBad2SpeciesByReferenceTaxonId(/*String speciesReferenceTaxonId*/) { - Integer taxonId = fixtures.refBad2SpeciesTaxonId(); - service.getSpeciesByReferenceTaxonId(taxonId); - } - - @Test - public void getAllCaracteristic() { - List<Caracteristic> result = service.getAllCaracteristic(); - assertResultList(result, fixtures.refNbCaracteristic()); - - persistList(Caracteristic.class, CaracteristicEnum.All.name(), result); - assertSize(result, storage.getAllCaracteristic()); - } - - @Test - public void getSizeCategoryCaracteristic() { - Caracteristic result = service.getSizeCategoryCaracteristic(); - assertCaracteristicQualitative(result, 6); - persist(Caracteristic.class, CaracteristicEnum.SizeCategory.name(), result); - } - - @Test - public void getSexCaracteristic() { - Caracteristic result = service.getSexCaracteristic(); - assertCaracteristicQualitative(result, 4); - persist(Caracteristic.class, CaracteristicEnum.SexCategory.name(), result); - } - - @Test - public void getSortedUnsortedCaracteristic() { - Caracteristic result = service.getSortedUnsortedCaracteristic(); - assertCaracteristicQualitative(result, 2); - persist(Caracteristic.class, CaracteristicEnum.SortedUnsortedCategory.name(), result); - } - - @Test - public void getMaturityCaracteristic() { - Caracteristic result = service.getMaturityCaracteristic(); - assertCaracteristicQualitative(result, 6); - persist(Caracteristic.class, CaracteristicEnum.MaturityCategory.name(), result); - } - - @Test - public void getMacroWasteCategoryCaracteristic() { - Caracteristic result = service.getMacroWasteCategoryCaracteristic(); - assertCaracteristicQualitative(result, 21); - persist(Caracteristic.class, CaracteristicEnum.MacroWasteCategory.name(), result); - } - - @Test - public void getMacroWasteSizeCategoryCaracteristic() { - Caracteristic result = service.getMacroWasteSizeCategoryCaracteristic(); - assertCaracteristicQualitative(result, 6); - persist(Caracteristic.class, CaracteristicEnum.MacroWasteSizeCategory.name(), result); - } - - @Test - public void importSpecies() { - List<Species> species = Lists.newArrayList(); - - long timestamp1 = System.nanoTime(); - Species sp1 = new Species(); - sp1.setReferenceTaxonId((int) timestamp1); - sp1.setId("Don't care" + timestamp1); - sp1.setRefTaxCode("Don't care" + timestamp1); - sp1.setSurveyCode("Don't care" + timestamp1); - sp1.setName("Genus name" + timestamp1); - species.add(sp1); - - long timestamp2 = System.nanoTime(); - Species sp2 = new Species(); - sp2.setReferenceTaxonId((int) timestamp2); - sp2.setId("Don't care" + timestamp2); - sp2.setRefTaxCode("Don't care" + timestamp2); - sp2.setSurveyCode("Don't care" + timestamp2); - sp2.setName("Genus name" + timestamp2); - species.add(sp2); - - Assert.assertNull(service.getSpeciesByReferenceTaxonId(sp1.getReferenceTaxonId())); - //Assert.assertNull(service.getSpecies(sp2.getId())); - - List<Species> speciesList = service.importTemporarySpecies(species); - Assert.assertNotNull(speciesList); - Assert.assertEquals(2, speciesList.size()); - - Species createdSp1 = speciesList.get(0); - Assert.assertNotNull(createdSp1); - Assert.assertEquals(sp1.getName(), createdSp1.getName()); - // TODO TC :question pour TC pourquoi faire le test suivant NotNull, car tu n'a rien mis en entr�e de ce code ? - // faut-il que le genere ? - //Assert.assertNotNull(createdSp1.getRefTaxCode()); - //Assert.assertNotSame(sp1.getRefTaxCode(), createdSp1.getRefTaxCode()); - Assert.assertNull(createdSp1.getSurveyCode()); - Assert.assertNotNull(createdSp1.getId()); - Assert.assertNotSame(sp1.getId(), createdSp1.getId()); - Assert.assertEquals(createdSp1, service.getSpeciesByReferenceTaxonId(createdSp1.getReferenceTaxonId())); - - Species createdSp2 = speciesList.get(1); - Assert.assertNotNull(createdSp2); - Assert.assertEquals(sp2.getName(), createdSp2.getName()); - Assert.assertTrue(createdSp2.isReferenceTaxon()); - Assert.assertNotSame(sp2.getReferenceTaxonId(), createdSp2.getReferenceTaxonId()); - Assert.assertNull(createdSp2.getRefTaxCode()); - Assert.assertNull(createdSp2.getSurveyCode()); - Assert.assertNotNull(createdSp2.getId()); - Assert.assertNotSame(sp2.getId(), createdSp2.getId()); - Assert.assertEquals(createdSp2, service.getSpeciesByReferenceTaxonId(createdSp2.getReferenceTaxonId())); - } - - @Test - public void importVessel() { - List<Vessel> vessels = Lists.newArrayList(); - - // scientificVessel - long timestamp1 = System.nanoTime(); - Vessel v1 = new Vessel(); - v1.setId("Don't care" + timestamp1); - v1.setName("Name" + timestamp1); - v1.setInternationalRegistrationCode("Immat" + timestamp1); - v1.setScientificVessel(true); - vessels.add(v1); - - // fishingVessel - long timestamp2 = System.nanoTime(); - Vessel v2 = new Vessel(); - v2.setId("Don't care" + timestamp2); - v2.setName("Name" + timestamp2); - v2.setInternationalRegistrationCode("Immat" + timestamp2); - v2.setScientificVessel(false); - vessels.add(v2); - - Assert.assertNull(service.getVessel(v1.getId())); - Assert.assertNull(service.getVessel(v2.getId())); - - List<Vessel> vesselList = service.importTemporaryVessel(vessels); - - Assert.assertNotNull(vesselList); - Assert.assertEquals(2, vesselList.size()); - - List<Vessel> allScientificVessel = service.getAllScientificVessel(); - List<Vessel> allFishingVessel = service.getAllFishingVessel(); - - Vessel createdV1 = vesselList.get(0); - Assert.assertNotNull(createdV1); - Assert.assertEquals(v1.getName(), createdV1.getName()); - Assert.assertEquals(v1.getInternationalRegistrationCode(), createdV1.getInternationalRegistrationCode()); - Assert.assertNotNull(createdV1.getId()); - Assert.assertNotSame(v1.getId(), createdV1.getId()); - Assert.assertEquals(createdV1, service.getVessel(createdV1.getId())); - - Assert.assertTrue(allScientificVessel.contains(createdV1)); - Assert.assertFalse(allFishingVessel.contains(createdV1)); - - Vessel createdV2 = vesselList.get(1); - Assert.assertNotNull(createdV2); - Assert.assertEquals(v2.getName(), createdV2.getName()); - Assert.assertEquals(v2.getInternationalRegistrationCode(), createdV2.getInternationalRegistrationCode()); - Assert.assertNotNull(createdV2.getId()); - Assert.assertNotSame(v2.getId(), createdV2.getId()); - Assert.assertEquals(createdV2, service.getVessel(createdV2.getId())); - Assert.assertFalse(allScientificVessel.contains(createdV2)); - Assert.assertTrue(allFishingVessel.contains(createdV2)); - } - - @Test - public void importPerson() { - List<Person> persons = Lists.newArrayList(); - - long timestamp1 = System.nanoTime(); - Person p1 = new Person(); - p1.setId("Don't care" + timestamp1); - p1.setName("Don't care" + timestamp1); - p1.setFirstName("FirstName" + timestamp1); - p1.setLastName("MastName" + timestamp1); - p1.setDescription("Dont care" + timestamp1); - p1.setDescription("Dont care" + timestamp1); - persons.add(p1); - - long timestamp2 = System.nanoTime(); - Person p2 = new Person(); - p2.setId("Don't care" + timestamp2); - p2.setName("Don't care" + timestamp2); - p2.setFirstName("FirstName" + timestamp2); - p2.setLastName("LastName" + timestamp2); - p2.setDescription("Don't care" + timestamp2); - p2.setDepartment("Don't care" + timestamp2); - persons.add(p2); - - List<Person> personList = service.importTemporaryPerson(persons); - - Assert.assertNotNull(personList); - Assert.assertEquals(2, personList.size()); - - Person createdP1 = personList.get(0); - Assert.assertNotNull(createdP1); - Assert.assertEquals(p1.getFirstName(), createdP1.getFirstName()); - Assert.assertEquals(p1.getLastName(), createdP1.getLastName()); - - Assert.assertNull(createdP1.getName()); - Assert.assertNull(createdP1.getDepartment()); - Assert.assertNull(createdP1.getDescription()); - - Assert.assertNotNull(createdP1.getId()); - Assert.assertNotSame(p1.getId(), createdP1.getId()); - - Assert.assertEquals(createdP1, service.getPerson(Integer.valueOf(createdP1.getId()))); - - - Person createdP2 = personList.get(1); - Assert.assertNotNull(createdP2); - Assert.assertEquals(p2.getFirstName(), createdP2.getFirstName()); - Assert.assertEquals(p2.getLastName(), createdP2.getLastName()); - - Assert.assertNull(createdP1.getName()); - Assert.assertNull(createdP1.getDepartment()); - Assert.assertNull(createdP1.getDescription()); - - Assert.assertNotNull(createdP2.getId()); - Assert.assertNotSame(p2.getId(), createdP2.getId()); - - Assert.assertEquals(createdP2, service.getPerson(Integer.valueOf(createdP2.getId()))); - } - - @Test - public void importGear() { - List<Gear> gears = Lists.newArrayList(); - - // scientific gear - long timestamp1 = System.nanoTime(); - Gear g1 = new Gear(); - g1.setId("Don't care" + timestamp1); - g1.setDescription("Don't care" + timestamp1); - g1.setName("Name" + timestamp1); - g1.setLabel("Label" + timestamp1); - g1.setScientificGear(true); - gears.add(g1); - - // fishing gear - long timestamp2 = System.nanoTime(); - Gear g2 = new Gear(); - g2.setId("Don't care" + timestamp2); - g2.setDescription("Don't care" + timestamp2); - g2.setName("Name" + timestamp2); - g2.setLabel("Label" + timestamp2); - g2.setScientificGear(false); - - gears.add(g2); - - List<Gear> gearList = service.importTemporaryGear(gears); - - List<Gear> allScientificGear = service.getAllScientificGear(); - List<Gear> allFishingGear = service.getAllFishingGear(); - - Gear createdG1 = gearList.get(0); - Assert.assertNotNull(createdG1); - Assert.assertEquals(g1.getName(), createdG1.getName()); - Assert.assertEquals(g1.getLabel(), createdG1.getLabel()); - - Assert.assertNotNull(createdG1.getId()); - Assert.assertNotSame(g1.getId(), createdG1.getId()); - Assert.assertEquals(createdG1, service.getGear(Integer.valueOf(createdG1.getId()))); - Assert.assertTrue(allScientificGear.contains(createdG1)); - Assert.assertFalse(allFishingGear.contains(createdG1)); - - Gear createdG2 = gearList.get(1); - Assert.assertNotNull(createdG2); - Assert.assertEquals(g2.getName(), createdG2.getName()); - Assert.assertEquals(g2.getLabel(), createdG2.getLabel()); - - Assert.assertNotNull(createdG2.getId()); - Assert.assertNotSame(g2.getId(), createdG2.getId()); - Assert.assertEquals(createdG2, service.getGear(Integer.valueOf(createdG2.getId()))); - Assert.assertFalse(allScientificGear.contains(createdG2)); - Assert.assertTrue(allFishingGear.contains(createdG2)); - } - - @Test - @Ignore - public void testCaches() { - cacheService.clearAllCaches(); - - Object obj = service.getAllCaracteristic(); - System.out.println(obj); - - obj = service.getCaracteristic(1429); - System.out.println(obj); - - obj = service.getCaracteristic(1428); - System.out.println(obj); - } - - protected <S extends IdAware> void persistList(Class<S> type, List<S> result) { - persistList(type, null, result); - } - - protected <S extends IdAware> void persistList(Class<S> type, String context, List<S> result) { - - String key = TuttiPersistenceDevImpl.getKey(type, context); - for (S s : result) { - storage.create(key, s, false); - } - storage.persistToFile(key); - } - - protected <S extends IdAware> void persist(Class<S> type, S result) { - persist(type, null, result); - } - - protected <S extends IdAware> void persist(Class<S> type, String context, S result) { - String key = TuttiPersistenceDevImpl.getKey(type, context); - storage.create(key, result, true); - } - - protected void assertSize(List<?> expectedList, List<?> storageList) { - Assert.assertNotNull(expectedList); - Assert.assertNotNull(storageList); - expectedList.removeAll(storageList); - Assert.assertTrue("Some " + expectedList.size() + " entities were not persisted in storage :" + - expectedList, expectedList.isEmpty()); - - } - - protected void assertCaracteristicQualitative(Caracteristic result, int nbValues) { - Assert.assertNotNull(result); - Assert.assertNotNull(result.getCaracteristicType()); - Assert.assertTrue(TuttiEntities.isQualitativeCaracteristic(result)); - Assert.assertNotNull(result.getQualitativeValue()); - Assert.assertEquals(nbValues, result.sizeQualitativeValue()); - } - - protected void assertCaracteristicSize(Caracteristic incoming, - Caracteristic caracteristic) { - Assert.assertNotNull(incoming); - Assert.assertNotNull(caracteristic); - Assert.assertEquals(incoming, caracteristic); - Assert.assertEquals(incoming.getCaracteristicType(), - caracteristic.getCaracteristicType()); - Assert.assertEquals(incoming.sizeQualitativeValue(), - caracteristic.sizeQualitativeValue()); - } - - protected <E extends IdAware> void assertResultList(List<E> result, - int expectedsize) { - - // result not null - Assert.assertNotNull(result); - - // id are unique - TuttiEntities.splitById(result); - - // correct size - Assert.assertEquals(expectedsize, result.size()); - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,277 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.List; + +/** + * To test {@link ReferentialPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ReferentialPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected ReferentialPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + } + + @Test + public void importSpecies() { + List<Species> species = Lists.newArrayList(); + + long timestamp1 = System.nanoTime(); + Species sp1 = new Species(); + sp1.setReferenceTaxonId((int) timestamp1); + sp1.setId("Don't care" + timestamp1); + sp1.setRefTaxCode("Don't care" + timestamp1); + sp1.setSurveyCode("Don't care" + timestamp1); + sp1.setName("Genus name" + timestamp1); + species.add(sp1); + + long timestamp2 = System.nanoTime(); + Species sp2 = new Species(); + sp2.setReferenceTaxonId((int) timestamp2); + sp2.setId("Don't care" + timestamp2); + sp2.setRefTaxCode("Don't care" + timestamp2); + sp2.setSurveyCode("Don't care" + timestamp2); + sp2.setName("Genus name" + timestamp2); + species.add(sp2); + + Assert.assertNull(service.getSpeciesByReferenceTaxonId(sp1.getReferenceTaxonId())); + //Assert.assertNull(service.getSpecies(sp2.getId())); + + List<Species> speciesList = service.importTemporarySpecies(species); + Assert.assertNotNull(speciesList); + Assert.assertEquals(2, speciesList.size()); + + Species createdSp1 = speciesList.get(0); + Assert.assertNotNull(createdSp1); + Assert.assertEquals(sp1.getName(), createdSp1.getName()); + // TODO TC :question pour TC pourquoi faire le test suivant NotNull, car tu n'a rien mis en entree de ce code ? + // faut-il que le genere ? + //Assert.assertNotNull(createdSp1.getRefTaxCode()); + //Assert.assertNotSame(sp1.getRefTaxCode(), createdSp1.getRefTaxCode()); + Assert.assertNull(createdSp1.getSurveyCode()); + Assert.assertNotNull(createdSp1.getId()); + Assert.assertNotSame(sp1.getId(), createdSp1.getId()); + Assert.assertEquals(createdSp1, service.getSpeciesByReferenceTaxonId(createdSp1.getReferenceTaxonId())); + + Species createdSp2 = speciesList.get(1); + Assert.assertNotNull(createdSp2); + Assert.assertEquals(sp2.getName(), createdSp2.getName()); + Assert.assertTrue(createdSp2.isReferenceTaxon()); + Assert.assertNotSame(sp2.getReferenceTaxonId(), createdSp2.getReferenceTaxonId()); + Assert.assertNull(createdSp2.getRefTaxCode()); + Assert.assertNull(createdSp2.getSurveyCode()); + Assert.assertNotNull(createdSp2.getId()); + Assert.assertNotSame(sp2.getId(), createdSp2.getId()); + Assert.assertEquals(createdSp2, service.getSpeciesByReferenceTaxonId(createdSp2.getReferenceTaxonId())); + } + + @Test + public void importVessel() { + List<Vessel> vessels = Lists.newArrayList(); + + // scientificVessel + long timestamp1 = System.nanoTime(); + Vessel v1 = new Vessel(); + v1.setId("Don't care" + timestamp1); + v1.setName("Name" + timestamp1); + v1.setInternationalRegistrationCode("Immat" + timestamp1); + v1.setScientificVessel(true); + vessels.add(v1); + + // fishingVessel + long timestamp2 = System.nanoTime(); + Vessel v2 = new Vessel(); + v2.setId("Don't care" + timestamp2); + v2.setName("Name" + timestamp2); + v2.setInternationalRegistrationCode("Immat" + timestamp2); + v2.setScientificVessel(false); + vessels.add(v2); + + Assert.assertNull(service.getVessel(v1.getId())); + Assert.assertNull(service.getVessel(v2.getId())); + + List<Vessel> vesselList = service.importTemporaryVessel(vessels); + + Assert.assertNotNull(vesselList); + Assert.assertEquals(2, vesselList.size()); + + List<Vessel> allScientificVessel = service.getAllScientificVessel(); + List<Vessel> allFishingVessel = service.getAllFishingVessel(); + + Vessel createdV1 = vesselList.get(0); + Assert.assertNotNull(createdV1); + Assert.assertEquals(v1.getName(), createdV1.getName()); + Assert.assertEquals(v1.getInternationalRegistrationCode(), createdV1.getInternationalRegistrationCode()); + Assert.assertNotNull(createdV1.getId()); + Assert.assertNotSame(v1.getId(), createdV1.getId()); + Assert.assertEquals(createdV1, service.getVessel(createdV1.getId())); + + Assert.assertTrue(allScientificVessel.contains(createdV1)); + Assert.assertFalse(allFishingVessel.contains(createdV1)); + + Vessel createdV2 = vesselList.get(1); + Assert.assertNotNull(createdV2); + Assert.assertEquals(v2.getName(), createdV2.getName()); + Assert.assertEquals(v2.getInternationalRegistrationCode(), createdV2.getInternationalRegistrationCode()); + Assert.assertNotNull(createdV2.getId()); + Assert.assertNotSame(v2.getId(), createdV2.getId()); + Assert.assertEquals(createdV2, service.getVessel(createdV2.getId())); + Assert.assertFalse(allScientificVessel.contains(createdV2)); + Assert.assertTrue(allFishingVessel.contains(createdV2)); + } + + @Test + public void importPerson() { + List<Person> persons = Lists.newArrayList(); + + long timestamp1 = System.nanoTime(); + Person p1 = new Person(); + p1.setId("Don't care" + timestamp1); + p1.setName("Don't care" + timestamp1); + p1.setFirstName("FirstName" + timestamp1); + p1.setLastName("MastName" + timestamp1); + p1.setDescription("Dont care" + timestamp1); + p1.setDescription("Dont care" + timestamp1); + persons.add(p1); + + long timestamp2 = System.nanoTime(); + Person p2 = new Person(); + p2.setId("Don't care" + timestamp2); + p2.setName("Don't care" + timestamp2); + p2.setFirstName("FirstName" + timestamp2); + p2.setLastName("LastName" + timestamp2); + p2.setDescription("Don't care" + timestamp2); + p2.setDepartment("Don't care" + timestamp2); + persons.add(p2); + + List<Person> personList = service.importTemporaryPerson(persons); + + Assert.assertNotNull(personList); + Assert.assertEquals(2, personList.size()); + + Person createdP1 = personList.get(0); + Assert.assertNotNull(createdP1); + Assert.assertEquals(p1.getFirstName(), createdP1.getFirstName()); + Assert.assertEquals(p1.getLastName(), createdP1.getLastName()); + + Assert.assertNull(createdP1.getName()); + Assert.assertNull(createdP1.getDepartment()); + Assert.assertNull(createdP1.getDescription()); + + Assert.assertNotNull(createdP1.getId()); + Assert.assertNotSame(p1.getId(), createdP1.getId()); + + Assert.assertEquals(createdP1, service.getPerson(Integer.valueOf(createdP1.getId()))); + + + Person createdP2 = personList.get(1); + Assert.assertNotNull(createdP2); + Assert.assertEquals(p2.getFirstName(), createdP2.getFirstName()); + Assert.assertEquals(p2.getLastName(), createdP2.getLastName()); + + Assert.assertNull(createdP1.getName()); + Assert.assertNull(createdP1.getDepartment()); + Assert.assertNull(createdP1.getDescription()); + + Assert.assertNotNull(createdP2.getId()); + Assert.assertNotSame(p2.getId(), createdP2.getId()); + + Assert.assertEquals(createdP2, service.getPerson(Integer.valueOf(createdP2.getId()))); + } + + @Test + public void importGear() { + List<Gear> gears = Lists.newArrayList(); + + // scientific gear + long timestamp1 = System.nanoTime(); + Gear g1 = new Gear(); + g1.setId("Don't care" + timestamp1); + g1.setDescription("Don't care" + timestamp1); + g1.setName("Name" + timestamp1); + g1.setLabel("Label" + timestamp1); + g1.setScientificGear(true); + gears.add(g1); + + // fishing gear + long timestamp2 = System.nanoTime(); + Gear g2 = new Gear(); + g2.setId("Don't care" + timestamp2); + g2.setDescription("Don't care" + timestamp2); + g2.setName("Name" + timestamp2); + g2.setLabel("Label" + timestamp2); + g2.setScientificGear(false); + + gears.add(g2); + + List<Gear> gearList = service.importTemporaryGear(gears); + + List<Gear> allScientificGear = service.getAllScientificGear(); + List<Gear> allFishingGear = service.getAllFishingGear(); + + Gear createdG1 = gearList.get(0); + Assert.assertNotNull(createdG1); + Assert.assertEquals(g1.getName(), createdG1.getName()); + Assert.assertEquals(g1.getLabel(), createdG1.getLabel()); + + Assert.assertNotNull(createdG1.getId()); + Assert.assertNotSame(g1.getId(), createdG1.getId()); + Assert.assertEquals(createdG1, service.getGear(Integer.valueOf(createdG1.getId()))); + Assert.assertTrue(allScientificGear.contains(createdG1)); + Assert.assertFalse(allFishingGear.contains(createdG1)); + + Gear createdG2 = gearList.get(1); + Assert.assertNotNull(createdG2); + Assert.assertEquals(g2.getName(), createdG2.getName()); + Assert.assertEquals(g2.getLabel(), createdG2.getLabel()); + + Assert.assertNotNull(createdG2.getId()); + Assert.assertNotSame(g2.getId(), createdG2.getId()); + Assert.assertEquals(createdG2, service.getGear(Integer.valueOf(createdG2.getId()))); + Assert.assertFalse(allScientificGear.contains(createdG2)); + Assert.assertTrue(allFishingGear.contains(createdG2)); + } +} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,159 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Maps; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +/** + * To test {@link SpeciesBatchPersistenceService} for read operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class SpeciesBatchPersistenceServiceReadTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.readDb(); + + protected SpeciesBatchPersistenceService service; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService(); + } + + @Test + public void getAllRootSpeciesBatch(/*String fishingOperationId*/) { + } + + @Test + public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) { + + } + + protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { + assertNotNull(actualBatch); + assertNotNull(actualBatch.getId()); + if (assertIdEquals && expectedBatch.getId() != null) { + assertEquals(expectedBatch.getId(), actualBatch.getId()); + } + assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); + assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); + if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { + assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>", + actualBatch.getSampleCategoryValue()); + assertEquals( + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), + ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); + } else { + assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); + } + assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); + assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); + assertEquals(expectedBatch.getComment(), actualBatch.getComment()); + + // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method + // (Because getSpeciesBatch(id) could not always retrieve the species) + if (expectedBatch.getSpecies() != null && ( + expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted + || actualBatch.getSpecies() != null)) { + assertNotNull(actualBatch.getSpecies()); + assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); + } + } + + protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { + assertNotNull(actualFrequencies); + assertEquals(expectedFrequencies.size(), actualFrequencies.size()); + + // Store actual batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { + expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + } + + // Store expected batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { + assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); + actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + assertNotNull(speciesBatchFrequency.getId()); + } + + for (Float lengthStep : expectedLengthMap.keySet()) { + SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); + SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); + if (assertIdEquals) { + assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); + } + assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); + assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); + assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); + assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); + assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); + //assertNotNull(expectedBatchFrequency.getBatch()); + //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); + } + } + + protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { + return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); + } + + protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { + if (speciesBatchs == null) { + return null; + } + for (SpeciesBatch speciesBatch : speciesBatchs) { + if (speciesBatchId.equals(speciesBatch.getId())) { + return speciesBatch; + } + if (speciesBatch.getChildBatchs() != null) { + speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); + if (speciesBatch != null) { + return speciesBatch; + } + } + } + return null; + } +} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -1,532 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.dao.DataRetrievalFailureException; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.*; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class SpeciesBatchPersistenceServiceTest { - - @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); - - protected SpeciesBatchPersistenceService service; - - protected CruisePersistenceService cruiseService; - - protected FishingOperationPersistenceService fishingOperationService; - - protected CatchBatchPersistenceService catchBatchService; - - protected ReferentialPersistenceService referentialService; - - protected Cruise cruise; - - protected FishingOperation fishingOperation; - - protected CatchBatch catchBacth; - - protected List<Species> species; - - protected Caracteristic sortedUnsortedPMFM; - - protected CaracteristicQualitativeValue horsVracQualitativeValue; - - protected CaracteristicQualitativeValue vracQualitativeValue; - - protected Caracteristic maturityPMFM; - - protected CaracteristicQualitativeValue firstMaturityQualitativeValue; - - protected Caracteristic sexPMFM; - - protected CaracteristicQualitativeValue maleQualitativeValue; - - protected CaracteristicQualitativeValue femaleQualitativeValue; - - protected CaracteristicQualitativeValue unkQualitativeValue; - - protected Caracteristic frequencyPMFM; - - protected String speciesBacthId = null; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - cruise.setYear(calendar.get(Calendar.YEAR)); - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - cruise = cruiseService.createCruise(cruise); - - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperation = fishingOperations.get(0); - fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); - fishingOperation.setId(null); - fishingOperation.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingEndDate(calendar.getTime()); - - fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); - - catchBacth = new CatchBatch(); - catchBacth.setFishingOperation(fishingOperation); - catchBacth = catchBatchService.createCatchBatch(catchBacth); - - species = referentialService.getAllSpecies(); - assertNotNull(species); - assertTrue(species.size() > 2); - - sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); - horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); - vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); - maturityPMFM = referentialService.getMaturityCaracteristic(); - firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0); - sexPMFM = referentialService.getSexCaracteristic(); - maleQualitativeValue = sexPMFM.getQualitativeValue(1); - femaleQualitativeValue = sexPMFM.getQualitativeValue(2); - unkQualitativeValue = sexPMFM.getQualitativeValue(3); - - - List<Caracteristic> cara = referentialService.getAllCaracteristic(); - for (Iterator iterator = cara.iterator(); iterator.hasNext();) { - Caracteristic caracteristic = (Caracteristic) iterator.next(); - if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER - && caracteristic.getPrecision() != null - && caracteristic.getPrecision().floatValue() == 0.5f) { - frequencyPMFM = caracteristic; - break; - } - } - assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM); - } - - @Test - public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) { - SpeciesBatch esp1Batch = null; - SpeciesBatch esp2Batch = null; - SpeciesBatch frequenciesParentBatch = null; - SpeciesBatch batch = null; - Species taxon1 = species.get(0); - Species taxon2 = species.get(1); - - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - // batch : "ESP1 - Vrac/5" - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperation); - // TODO TC : add link between Speciesbatch and CatchBatch - //batch.setCatchBatch(catchBatch); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setWeight(5f); - - assertCreateAndReloadSpeciesBatch(batch, null); - - // Save ESP1 batch - esp1Batch = batch; - - // ----------------------------------------------------------------------------- - // 2. Test child "Male/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); - batch.setWeight(2f); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setSampleCategoryWeight(1f); - batch.setNumber(7); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 3. Test child "Female/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); - batch.setWeight(3f); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(femaleQualitativeValue); - batch.setSampleCategoryWeight(null); - batch.setNumber(14); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 4. Test : ESP2 - Vrac/7 - // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - // ----------------------------------------------------------------------------- - // batch : "ESP2 - Vrac/7 " - batch = new SpeciesBatch(); - batch.setParentBatch(null); - // TODO TC : add link between Speciesbatch and CatchBatch - //batch.setCatchBatch(catchBatch); - batch.setSpecies(taxon2); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setWeight(7f); - - assertCreateAndReloadSpeciesBatch(batch, null); - esp2Batch = batch; - - // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp2Batch); - batch.setSpecies(taxon2); - batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); - batch.setSampleCategoryType(SampleCategoryEnum.maturity); - batch.setSampleCategoryValue(firstMaturityQualitativeValue); - batch.setWeight(2f); - batch.setSampleCategoryWeight(1f); - batch.setNumber(11); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 5. Test save after modifications - // ----------------------------------------------------------------------------- - // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(unkQualitativeValue); - batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); - batch.setWeight(1.75f); - batch.setSampleCategoryWeight(1.11f); - batch.setFishingOperation(fishingOperation); - batch.setNumber(99); - - // Save and reload, then check - SpeciesBatch savedBatch = service.saveSpeciesBatch(batch); - assertSpeciesBatch(savedBatch, batch, false); - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), savedBatch.getId()); - assertSpeciesBatch(reloadedBatch, savedBatch, true); - - // Save batch for later - frequenciesParentBatch = batch; - - // ----------------------------------------------------------------------------- - // 6. Test get all root species - // ----------------------------------------------------------------------------- - List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId()); - assertNotNull(rootSpeciesBatch); - assertEquals(2, rootSpeciesBatch.size()); - assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); - assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); - - // ----------------------------------------------------------------------------- - // 8. Test batch frequency creation - // ----------------------------------------------------------------------------- - - List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); - float lengthStep = 0.5f; - for (float length = lengthStep; length < lengthStep * 20; length+=lengthStep) { - SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); - frequency.setLengthStep(length); - frequency.setNumber((int)(length*2)); - frequency.setWeight(0.01f*length*2); - frequency.setLengthStepCaracteristic(frequencyPMFM); - frequency.setBatch(frequenciesParentBatch); - frequency.setComment("comments"); - frequencies.add(frequency); - } - List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); - - // ----------------------------------------------------------------------------- - // 9. Test batch frequency update - // ----------------------------------------------------------------------------- - // Update some batchs (1cm, 2cm, etc) - for (Iterator iterator = createdFrequencies.iterator(); iterator.hasNext();) { - SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next(); - float length = speciesBatchFrequency.getLengthStep(); - if ((float)(int)length == length) { - speciesBatchFrequency.setNumber(12); - speciesBatchFrequency.setComment(null); - } - } - List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); - assertBatchFrequencies(createdFrequencies, savedFrequencies, true); - } - - @Test - @Ignore - public void saveSpeciesBatch(/*SpeciesBatch bean*/) { - - } - - @Test - @Ignore - public void saveSpeciesBatchFrequency() { - - } - - @Test - @Ignore - public void getAllRootSpeciesBatch(/*String fishingOperationId*/) { - } - - @Test - public void deleteSpeciesBatch(/*String id*/) { - SpeciesBatch esp1Batch; - SpeciesBatch childBatch = null; - SpeciesBatch batch; - Species taxon1 = species.get(0); - - // ----------------------------------------------------------------------------- - // 1. Create two batchs (parent + child), then remove the parent batch - // ----------------------------------------------------------------------------- - // batch : ESP1 Vrac/5 - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperation); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setWeight(5f); - assertCreateAndReloadSpeciesBatch(batch, null); - esp1Batch = batch; - - // batch : ESP1 Vrac/5 Male/2 - batch = new SpeciesBatch(); - batch.setParentBatch(esp1Batch); - batch.setFishingOperation(fishingOperation); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setWeight(2f); - assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId()); - - // Try to remove - service.deleteSpeciesBatch(esp1Batch.getId()); - - // Check if remove - try { - batch = getSpeciesBatch(fishingOperation.getId(), esp1Batch.getId()); - assertNull(batch); - } catch (DataRetrievalFailureException drfe) { - assertNotNull(drfe); - } - } - - @Test - @Ignore - public void deleteSpeciesSubBatch(/*String id*/) { - // Idem deleteSpeciesBatch - } - - @Test - @Ignore - public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) { - - } - - protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) { - batch.setFishingOperation(fishingOperation); - - // Create batch - SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId); - assertSpeciesBatch(batch, createdBatch, false); - - // then reload (for round trip check) - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), createdBatch.getId()); - if (parentBatchId == null) { - assertNull(reloadedBatch.getParentBatch()); - } - else { - assertNotNull(reloadedBatch.getParentBatch()); - assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); - } - assertSpeciesBatch(createdBatch, reloadedBatch, false); - - batch.setId(createdBatch.getId()); - } - - protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { - assertNotNull(actualBatch); - assertNotNull(actualBatch.getId()); - if (assertIdEquals && expectedBatch.getId() != null) { - assertEquals(expectedBatch.getId(), actualBatch.getId()); - } - assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); - assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); - if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { - assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue)expectedBatch.getSampleCategoryValue()).getId() +"> but was <null>", - actualBatch.getSampleCategoryValue()); - assertEquals( - ((CaracteristicQualitativeValue)expectedBatch.getSampleCategoryValue()).getId(), - ((CaracteristicQualitativeValue)actualBatch.getSampleCategoryValue()).getId()); - } - else { - assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); - } - assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); - assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); - assertEquals(expectedBatch.getComment(), actualBatch.getComment()); - - // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method - // (Because getSpeciesBatch(id) could not always retrieve the species) - if (expectedBatch.getSpecies() != null && ( - expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted - || actualBatch.getSpecies() != null)) { - assertNotNull(actualBatch.getSpecies()); - assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); - } - } - - protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { - - // Create batch - List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies); - assertBatchFrequencies(frequencies, createdFrequencies, false); - - // then reload (for round trip check) - List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId); - assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); - - return createdFrequencies; - } - - protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { - assertNotNull(actualFrequencies); - assertEquals(expectedFrequencies.size(), actualFrequencies.size()); - - // Store actual batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); - for (Iterator iterator = expectedFrequencies.iterator(); iterator.hasNext();) { - SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next(); - expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - } - - // Store expected batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); - for (Iterator iterator = actualFrequencies.iterator(); iterator.hasNext();) { - SpeciesBatchFrequency speciesBatchFrequency = (SpeciesBatchFrequency) iterator.next(); - assertFalse("Duplicate lengthStep found in batchFrequencies, for length="+speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); - actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - assertNotNull(speciesBatchFrequency.getId()); - } - - for (Iterator iterator = expectedLengthMap.keySet().iterator(); iterator.hasNext();) { - Float lengthStep = (Float) iterator.next(); - SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); - SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); - if (assertIdEquals) { - assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); - } - assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); - assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); - assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); - assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); - assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); - //assertNotNull(expectedBatchFrequency.getBatch()); - //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); - } - } - - protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { - return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); - } - - protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { - if (speciesBatchs == null) { - return null; - } - for (Iterator iterator = speciesBatchs.iterator(); iterator.hasNext();) { - SpeciesBatch speciesBatch = (SpeciesBatch) iterator.next(); - if (speciesBatchId.equals(speciesBatch.getId())) { - return speciesBatch; - } - if (speciesBatch.getChildBatchs() != null) { - speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); - if (speciesBatch != null) { - return speciesBatch; - } - } - } - return null; - } -} Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java (from rev 378, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,508 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence API + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import fr.ifremer.tutti.persistence.DatabaseResource; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.dao.DataRetrievalFailureException; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Map; + +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; + +/** + * To test {@link SpeciesBatchPersistenceService} for write operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +@Ignore +public class SpeciesBatchPersistenceServiceWriteTest { + + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + + protected SpeciesBatchPersistenceService service; + + protected CruisePersistenceService cruiseService; + + protected FishingOperationPersistenceService fishingOperationService; + + protected CatchBatchPersistenceService catchBatchService; + + protected ReferentialPersistenceService referentialService; + + protected Cruise cruise; + + protected FishingOperation fishingOperation; + + protected CatchBatch catchBacth; + + protected List<Species> species; + + protected Caracteristic sortedUnsortedPMFM; + + protected CaracteristicQualitativeValue horsVracQualitativeValue; + + protected CaracteristicQualitativeValue vracQualitativeValue; + + protected Caracteristic maturityPMFM; + + protected CaracteristicQualitativeValue firstMaturityQualitativeValue; + + protected Caracteristic sexPMFM; + + protected CaracteristicQualitativeValue maleQualitativeValue; + + protected CaracteristicQualitativeValue femaleQualitativeValue; + + protected CaracteristicQualitativeValue unkQualitativeValue; + + protected Caracteristic frequencyPMFM; + + protected String speciesBacthId = null; + + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService(); + cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); + + cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); + cruise.setId(null); + Calendar calendar = new GregorianCalendar(); + cruise.setBeginDate(calendar.getTime()); + cruise.setYear(calendar.get(Calendar.YEAR)); + calendar.add(Calendar.MONTH, 1); // add one month + cruise.setEndDate(calendar.getTime()); + cruise = cruiseService.createCruise(cruise); + + List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); + assertNotNull(fishingOperations); + assertTrue(fishingOperations.size() > 0); + fishingOperation = fishingOperations.get(0); + fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); + fishingOperation.setId(null); + fishingOperation.setCruise(cruise); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 1); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperation.setGearShootingStartDate(calendar.getTime()); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 10); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperation.setGearShootingEndDate(calendar.getTime()); + + fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); + + catchBacth = new CatchBatch(); + catchBacth.setFishingOperation(fishingOperation); + catchBacth = catchBatchService.createCatchBatch(catchBacth); + + species = referentialService.getAllSpecies(); + assertNotNull(species); + assertTrue(species.size() > 2); + + sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); + horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); + vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); + maturityPMFM = referentialService.getMaturityCaracteristic(); + firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0); + sexPMFM = referentialService.getSexCaracteristic(); + maleQualitativeValue = sexPMFM.getQualitativeValue(1); + femaleQualitativeValue = sexPMFM.getQualitativeValue(2); + unkQualitativeValue = sexPMFM.getQualitativeValue(3); + + + List<Caracteristic> cara = referentialService.getAllCaracteristic(); + for (Caracteristic caracteristic : cara) { + if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER + && caracteristic.getPrecision() != null + && caracteristic.getPrecision() == 0.5f) { + frequencyPMFM = caracteristic; + break; + } + } + assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM); + } + + @Test + public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) { + SpeciesBatch esp1Batch = null; + SpeciesBatch esp2Batch = null; + SpeciesBatch frequenciesParentBatch = null; + SpeciesBatch batch = null; + Species taxon1 = species.get(0); + Species taxon2 = species.get(1); + + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- + // batch : "ESP1 - Vrac/5" + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperation); + // TODO TC : add link between Speciesbatch and CatchBatch + //batch.setCatchBatch(catchBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setWeight(5f); + + assertCreateAndReloadSpeciesBatch(batch, null); + + // Save ESP1 batch + esp1Batch = batch; + + // ----------------------------------------------------------------------------- + // 2. Test child "Male/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); + batch.setWeight(2f); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setSampleCategoryWeight(1f); + batch.setNumber(7); + + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + + // ----------------------------------------------------------------------------- + // 3. Test child "Female/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); + batch.setWeight(3f); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(femaleQualitativeValue); + batch.setSampleCategoryWeight(null); + batch.setNumber(14); + + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + + // ----------------------------------------------------------------------------- + // 4. Test : ESP2 - Vrac/7 + // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + // ----------------------------------------------------------------------------- + // batch : "ESP2 - Vrac/7 " + batch = new SpeciesBatch(); + batch.setParentBatch(null); + // TODO TC : add link between Speciesbatch and CatchBatch + //batch.setCatchBatch(catchBatch); + batch.setSpecies(taxon2); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setWeight(7f); + + assertCreateAndReloadSpeciesBatch(batch, null); + esp2Batch = batch; + + // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp2Batch); + batch.setSpecies(taxon2); + batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); + batch.setSampleCategoryType(SampleCategoryEnum.maturity); + batch.setSampleCategoryValue(firstMaturityQualitativeValue); + batch.setWeight(2f); + batch.setSampleCategoryWeight(1f); + batch.setNumber(11); + + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + + // ----------------------------------------------------------------------------- + // 5. Test save after modifications + // ----------------------------------------------------------------------------- + // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(unkQualitativeValue); + batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); + batch.setWeight(1.75f); + batch.setSampleCategoryWeight(1.11f); + batch.setFishingOperation(fishingOperation); + batch.setNumber(99); + + // Save and reload, then check + SpeciesBatch savedBatch = service.saveSpeciesBatch(batch); + assertSpeciesBatch(savedBatch, batch, false); + SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), savedBatch.getId()); + assertSpeciesBatch(reloadedBatch, savedBatch, true); + + // Save batch for later + frequenciesParentBatch = batch; + + // ----------------------------------------------------------------------------- + // 6. Test get all root species + // ----------------------------------------------------------------------------- + List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId()); + assertNotNull(rootSpeciesBatch); + assertEquals(2, rootSpeciesBatch.size()); + assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); + assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); + + // ----------------------------------------------------------------------------- + // 8. Test batch frequency creation + // ----------------------------------------------------------------------------- + + List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); + float lengthStep = 0.5f; + for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { + SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); + frequency.setLengthStep(length); + frequency.setNumber((int) (length * 2)); + frequency.setWeight(0.01f * length * 2); + frequency.setLengthStepCaracteristic(frequencyPMFM); + frequency.setBatch(frequenciesParentBatch); + frequency.setComment("comments"); + frequencies.add(frequency); + } + List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); + + // ----------------------------------------------------------------------------- + // 9. Test batch frequency update + // ----------------------------------------------------------------------------- + // Update some batchs (1cm, 2cm, etc) + for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { + float length = speciesBatchFrequency.getLengthStep(); + if ((float) (int) length == length) { + speciesBatchFrequency.setNumber(12); + speciesBatchFrequency.setComment(null); + } + } + List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); + assertBatchFrequencies(createdFrequencies, savedFrequencies, true); + } + + @Test + @Ignore + public void saveSpeciesBatch(/*SpeciesBatch bean*/) { + + } + + @Test + public void deleteSpeciesBatch(/*String id*/) { + SpeciesBatch esp1Batch; + SpeciesBatch childBatch = null; + SpeciesBatch batch; + Species taxon1 = species.get(0); + + // ----------------------------------------------------------------------------- + // 1. Create two batchs (parent + child), then remove the parent batch + // ----------------------------------------------------------------------------- + // batch : ESP1 Vrac/5 + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperation); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setWeight(5f); + assertCreateAndReloadSpeciesBatch(batch, null); + esp1Batch = batch; + + // batch : ESP1 Vrac/5 Male/2 + batch = new SpeciesBatch(); + batch.setParentBatch(esp1Batch); + batch.setFishingOperation(fishingOperation); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setWeight(2f); + assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId()); + + // Try to remove + service.deleteSpeciesBatch(esp1Batch.getId()); + + // Check if remove + try { + batch = getSpeciesBatch(fishingOperation.getId(), esp1Batch.getId()); + assertNull(batch); + } catch (DataRetrievalFailureException drfe) { + assertNotNull(drfe); + } + } + + @Test + @Ignore + public void deleteSpeciesSubBatch(/*String id*/) { + // Idem deleteSpeciesBatch + } + + protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) { + batch.setFishingOperation(fishingOperation); + + // Create batch + SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId); + assertSpeciesBatch(batch, createdBatch, false); + + // then reload (for round trip check) + SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), createdBatch.getId()); + if (parentBatchId == null) { + assertNull(reloadedBatch.getParentBatch()); + } else { + assertNotNull(reloadedBatch.getParentBatch()); + assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); + } + assertSpeciesBatch(createdBatch, reloadedBatch, false); + + batch.setId(createdBatch.getId()); + } + + protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { + assertNotNull(actualBatch); + assertNotNull(actualBatch.getId()); + if (assertIdEquals && expectedBatch.getId() != null) { + assertEquals(expectedBatch.getId(), actualBatch.getId()); + } + assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); + assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); + if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { + assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>", + actualBatch.getSampleCategoryValue()); + assertEquals( + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), + ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); + } else { + assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); + } + assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); + assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); + assertEquals(expectedBatch.getComment(), actualBatch.getComment()); + + // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method + // (Because getSpeciesBatch(id) could not always retrieve the species) + if (expectedBatch.getSpecies() != null && ( + expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted + || actualBatch.getSpecies() != null)) { + assertNotNull(actualBatch.getSpecies()); + assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); + } + } + + protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { + + // Create batch + List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies); + assertBatchFrequencies(frequencies, createdFrequencies, false); + + // then reload (for round trip check) + List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId); + assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); + + return createdFrequencies; + } + + protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { + assertNotNull(actualFrequencies); + assertEquals(expectedFrequencies.size(), actualFrequencies.size()); + + // Store actual batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { + expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + } + + // Store expected batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { + assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); + actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + assertNotNull(speciesBatchFrequency.getId()); + } + + for (Float lengthStep : expectedLengthMap.keySet()) { + SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); + SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); + if (assertIdEquals) { + assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); + } + assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); + assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); + assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); + assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); + assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); + //assertNotNull(expectedBatchFrequency.getBatch()); + //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); + } + } + + protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { + return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); + } + + protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { + if (speciesBatchs == null) { + return null; + } + for (SpeciesBatch speciesBatch : speciesBatchs) { + if (speciesBatchId.equals(speciesBatch.getId())) { + return speciesBatch; + } + if (speciesBatch.getChildBatchs() != null) { + speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); + if (speciesBatch != null) { + return speciesBatch; + } + } + } + return null; + } +} Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFileTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -40,8 +40,7 @@ public class TuttiEnumerationFileTest { @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource( - "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb"); + public static final DatabaseResource dbResource = DatabaseResource.noDb(); @Test public void init() { Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -66,7 +66,7 @@ LogFactory.getLog(ReferentialSynchronizeHelperTest.class); @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); @Rule public final TestName n = new TestName(); @@ -242,7 +242,7 @@ getExistingIds(TuttiTable.LOCATION_LEVEL, fixtures.nbLocationLevel()); getExistingIds(TuttiTable.LOCATION, fixtures.nbLocation()); getExistingIds(TuttiTable.TAXONOMIC_LEVEL, fixtures.nbTaxonomicLevel()); - getExistingIds(TuttiTable.REFERENCE_TAXON, fixtures.nbReferenceTaxon() + 2); + getExistingIds(TuttiTable.REFERENCE_TAXON, fixtures.nbReferenceTaxon()); getExistingIds(TuttiTable.TAXON_NAME, fixtures.nbTaxonName()); getExistingIds(TuttiTable.TAXON_GROUP_TYPE, fixtures.nbTaxonGroupType()); getExistingIds(TuttiTable.TAXON_GROUP, fixtures.nbTaxonGroup()); @@ -293,7 +293,7 @@ getDataToUpdate(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, fromDate, fixtures.nbLocationLevel()); getDataToUpdate(TuttiTable.LOCATION, internalDb, internalConnection, fromDate, fixtures.nbLocation()); getDataToUpdate(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, fromDate, fixtures.nbTaxonomicLevel()); - getDataToUpdate(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, fromDate, fixtures.nbReferenceTaxon() + 2); + getDataToUpdate(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, fromDate, fixtures.nbReferenceTaxon()); getDataToUpdate(TuttiTable.TAXON_NAME, internalDb, internalConnection, fromDate, fixtures.nbTaxonName()); getDataToUpdate(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, fromDate, fixtures.nbTaxonGroupType()); getDataToUpdate(TuttiTable.TAXON_GROUP, internalDb, internalConnection, fromDate, fixtures.nbTaxonGroup()); @@ -354,7 +354,7 @@ updateTable(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbLocationLevel(), 0); updateTable(TuttiTable.LOCATION, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbLocation(), 0); updateTable(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonomicLevel(), 0); - updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbReferenceTaxon() + 2, 0); + updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbReferenceTaxon(), 0); updateTable(TuttiTable.TAXON_NAME, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonName(), 0); updateTable(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonGroupType(), 0); updateTable(TuttiTable.TAXON_GROUP, internalDb, internalConnection, externalConnection, fromDate, fixtures.nbTaxonGroup(), 0); @@ -393,7 +393,7 @@ updateTable(TuttiTable.LOCATION_LEVEL, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbLocationLevel()); updateTable(TuttiTable.LOCATION, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbLocation()); updateTable(TuttiTable.TAXONOMIC_LEVEL, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonomicLevel()); - updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbReferenceTaxon() + 2); + updateTable(TuttiTable.REFERENCE_TAXON, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbReferenceTaxon()); updateTable(TuttiTable.TAXON_NAME, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonName()); updateTable(TuttiTable.TAXON_GROUP_TYPE, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonGroupType()); updateTable(TuttiTable.TAXON_GROUP, internalDb, internalConnection, externalConnection, fromDate, 0, fixtures.nbTaxonGroup()); Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-02-10 13:41:29 UTC (rev 379) @@ -53,7 +53,7 @@ LogFactory.getLog(ReferentialSynchronizeServiceImplTest.class); @ClassRule - public static final DatabaseResource dbResource = new DatabaseResource(); + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); @Rule public final TestName n = new TestName(); Copied: trunk/tutti-persistence/src/test/resources/tutti-test-read.properties (from rev 378, trunk/tutti-persistence/src/test/resources/tutti-test.properties) =================================================================== --- trunk/tutti-persistence/src/test/resources/tutti-test-read.properties (rev 0) +++ trunk/tutti-persistence/src/test/resources/tutti-test-read.properties 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,27 @@ +### +# #%L +# Tutti :: Persistence API +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 Ifremer +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +tutti.persistence.db.directory=src/test/db +#tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/db/allegro +tutti.persistence.jdbc.url=jdbc:hsqldb:hsql://localhost/allegro +tutti.persistence.jdbc.createScript=src/test/db/allegro.script Copied: trunk/tutti-persistence/src/test/resources/tutti-test-write.properties (from rev 378, trunk/tutti-persistence/src/test/resources/tutti-test.properties) =================================================================== --- trunk/tutti-persistence/src/test/resources/tutti-test-write.properties (rev 0) +++ trunk/tutti-persistence/src/test/resources/tutti-test-write.properties 2013-02-10 13:41:29 UTC (rev 379) @@ -0,0 +1,24 @@ +### +# #%L +# Tutti :: Persistence API +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 Ifremer +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +tutti.persistence.jdbc.createScript=src/test/db/allegro.script Deleted: trunk/tutti-persistence/src/test/resources/tutti-test.properties =================================================================== --- trunk/tutti-persistence/src/test/resources/tutti-test.properties 2013-02-09 07:44:17 UTC (rev 378) +++ trunk/tutti-persistence/src/test/resources/tutti-test.properties 2013-02-10 13:41:29 UTC (rev 379) @@ -1,26 +0,0 @@ -### -# #%L -# Tutti :: Persistence API -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2012 Ifremer -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU 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 General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### -#tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/db/allegro -tutti.persistence.jdbc.url=jdbc:hsqldb:hsql://localhost/allegro -tutti.persistence.jdbc.createScript=src/test/db/allegro.script
participants (1)
-
tchemit@users.forge.codelutin.com