Author: bleny Date: 2014-03-17 10:58:05 +0100 (Mon, 17 Mar 2014) New Revision: 1724 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1724 Log: refs #4483 reintroduce SampleRowLogImplTest Added: trunk/wao-persistence/src/test/java/fr/ trunk/wao-persistence/src/test/java/fr/ifremer/ trunk/wao-persistence/src/test/java/fr/ifremer/wao/ trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/ trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/SampleRowLogImplTest.java Copied: trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/SampleRowLogImplTest.java (from rev 1723, tags/wao-3.4.1/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowLogTest.java) =================================================================== --- trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/SampleRowLogImplTest.java (rev 0) +++ trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/SampleRowLogImplTest.java 2014-03-17 09:58:05 UTC (rev 1724) @@ -0,0 +1,129 @@ +/* + * #%L + * Wao :: Business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2011 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.wao.entity; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.util.DateUtil; + +import java.util.ArrayList; +import java.util.Collections; + +public class SampleRowLogImplTest { + + private static final Log log = LogFactory.getLog(SampleRowLogImplTest.class); + + protected SampleRow nullSampleRow; + + protected SampleRow sampleRow; + + protected SampleRow newEmptySampleRow() { + SampleRow sampleRow = new SampleRowImpl(); + sampleRow.setObsProgram(ObsProgram.OBSMER); + sampleRow.setCode("1"); + + sampleRow.setPeriodBegin(DateUtil.createDate(1, 3, 2011)); + sampleRow.setPeriodEnd(DateUtil.createDate(1, 6, 2011)); + sampleRow.setProfession(new ProfessionImpl()); + sampleRow.setSampleMonth(Collections.<SampleMonth>emptyList()); + sampleRow.setElligibleBoat(Collections.<ElligibleBoat>emptyList()); + sampleRow.setFishingZone(new ArrayList<FishingZone>()); + return sampleRow; + } + + @Before + public void setUp() { + nullSampleRow = new SampleRowImpl(); + nullSampleRow.setObsProgram(ObsProgram.OBSMER); + nullSampleRow.setCode("1"); + + sampleRow = newEmptySampleRow(); + } + + /** + * comparison to an empty sample row should not generate error. + * test show that no NPE is thrown + */ + @Test + public void testNewSampleRowLog() { + SampleRowLog sampleRowLog = new SampleRowLogImpl(); + sampleRowLog.setLogText(null, sampleRow); + + if (log.isDebugEnabled()) { + log.debug(sampleRowLog.getLogText()); + } + } + + /** + * Comparing a row to it-self should be OK and generate an empty log + */ + @Test + public void testCompareSampleRowToItself() { + SampleRowLog sampleRowLog = new SampleRowLogImpl(); + sampleRowLog.setLogText(sampleRow, sampleRow); + + Assert.assertTrue("comparing a sample-row to itself should not generate text", + StringUtils.isEmpty(sampleRowLog.getLogText())); + + if (log.isDebugEnabled()) { + log.debug(sampleRowLog.getLogText()); + } + } + + @Test + public void testModifySampleRow() { + + // Create a new sample-row with the sampleRow + // as initial state + SampleRow newSampleRow = newEmptySampleRow(); + + // do some modifications + newSampleRow.setAverageTideTime(1.0); + newSampleRow.setProgramName("programName"); + FishingZone fishingZone = new FishingZoneImpl(); + fishingZone.setDistrictCode("IV"); + newSampleRow.addFishingZone(fishingZone); + newSampleRow.setPeriodEnd(DateUtil.createDate(1, 7, 2011)); + + // now create a log that should summarize the modifications done + SampleRowLog sampleRowLog = new SampleRowLogImpl(); + sampleRowLog.setLogText(sampleRow, newSampleRow); + + if (log.isDebugEnabled()) { + log.debug(sampleRowLog.getLogText()); + } + + // now check that generated log contains all needed info about + // the modifications done above + String text = sampleRowLog.getLogText(); + Assert.assertTrue("log mention new fishing zone", text.contains("IV")); + Assert.assertTrue("log mention new program name", text.contains("programName")); + Assert.assertTrue("log mention date change with old and new values", text.contains("06/2011") + && text.contains("07/2011")); + } +} Property changes on: trunk/wao-persistence/src/test/java/fr/ifremer/wao/entity/SampleRowLogImplTest.java ___________________________________________________________________ Added: svn:mergeinfo + /branches/wao-1.5.x/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowLogTest.java:679-733