From 7d2e214ed90900c5e00b1fb96ab17213b2b665c9 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 15 Apr 2010 08:41:33 +0000 Subject: [PATCH] LMS-1485 more unit tests SVN: 15474 --- .../dss/LcaMicDataSetPropertiesExtractor.java | 4 +- .../cisd/dss/LcaMicDataSetUploader.java | 2 +- .../LcaMicDataSetPropertiesExtractorTest.java | 79 ++++++++++ .../cisd/dss/LcaMicDataSetUploaderTest.java | 143 ++++++++++++++++++ 4 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractorTest.java create mode 100644 eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetUploaderTest.java diff --git a/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractor.java b/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractor.java index 9cbf08b8f42..c1161d8474d 100644 --- a/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractor.java +++ b/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractor.java @@ -34,6 +34,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty; class LcaMicDataSetPropertiesExtractor extends TimeSeriesDataSetPropertiesExtractor { + static final String GROWTH_RATE = "GROWTH_RATE"; + LcaMicDataSetPropertiesExtractor(Properties properties) { super(properties); @@ -49,7 +51,7 @@ class LcaMicDataSetPropertiesExtractor extends TimeSeriesDataSetPropertiesExtrac throw new UserFailureException("Empty file: " + file); } String[] items = StringUtils.split(lines.get(0), " \t"); - NewProperty growthRate = new NewProperty("GROWTH_RATE", items[items.length - 1]); + NewProperty growthRate = new NewProperty(GROWTH_RATE, items[items.length - 1]); List<NewProperty> properties = HeaderUtils.extractHeaderProperties(incomingDataSetPath, ignoreEmptyLines, true, true); properties.add(growthRate); diff --git a/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetUploader.java b/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetUploader.java index 8398f03ad7a..fa7d89a06de 100644 --- a/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetUploader.java +++ b/eu_basysbio/source/java/eu/basysbio/cisd/dss/LcaMicDataSetUploader.java @@ -66,7 +66,7 @@ class LcaMicDataSetUploader extends AbstractDataSetUploader super(dataSource, service, parameters); } - public LcaMicDataSetUploader(ITimeSeriesDAO dao, IEncapsulatedOpenBISService service, + LcaMicDataSetUploader(ITimeSeriesDAO dao, IEncapsulatedOpenBISService service, TimeSeriesDataSetUploaderParameters parameters) { super(dao, service, parameters); diff --git a/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractorTest.java b/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractorTest.java new file mode 100644 index 00000000000..4fca45bcd3e --- /dev/null +++ b/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetPropertiesExtractorTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package eu.basysbio.cisd.dss; + +import static eu.basysbio.cisd.dss.HeaderUtils.TIME_SERIES_HEADER_PROPERTIES; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.testng.annotations.Test; + +import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; +import ch.systemsx.cisd.common.filesystem.FileUtilities; +import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class LcaMicDataSetPropertiesExtractorTest extends AbstractFileSystemTestCase +{ + static final String EXAMPLE = + "# Ma::MS::B1::NT::EX::T1::NC::GrowthRate::Value[h^(-1)]::LIN::BBA9001#A_S20090325-2::NC\t0.68\n" + + "Time (s)\t" + + "Ma::MS::B1::NT::EX::T1::NC::LcaMicCfd::Value[um]::LIN::BBA9001#A_S20090325-2::NC\t" + + "Ma::MS::B1::NT::EX::T1::NC::LcaMicAbsFl::Mean[Au]::LIN::BBA9001#A_S20090325-2::NC\t" + + "Ma::MS::B1::NT::EX::T1::NC::LcaMicAbsFl::Std[Au]::LIN::BBA9001#A_S20090325-2::NC\n"; + + @Test + public void test() throws IOException + { + File ds = new File(workingDirectory, "ds"); + ds.mkdirs(); + File file = new File(ds, "t.txt"); + FileUtilities.writeToFile(file, EXAMPLE); + IDataSetPropertiesExtractor extractor = + new LcaMicDataSetPropertiesExtractor(new Properties()); + List<NewProperty> props = extractor.extractDataSetProperties(ds); + assertEquals(TIME_SERIES_HEADER_PROPERTIES.length + 1, props.size()); + Map<String, String> map = new HashMap<String, String>(); + for (NewProperty property : props) + { + map.put(property.getPropertyCode(), property.getValue()); + } + assertEquals("BBA9001#A_S20090325-2", map.get(TimeSeriesPropertyType.BI_ID.toString())); + assertEquals("B1", map.get(TimeSeriesPropertyType.BIOLOGICAL_REPLICATE_CODE.toString())); + assertEquals("NC", map.get(TimeSeriesPropertyType.CEL_LOC.toString())); + assertEquals("NC", map.get(TimeSeriesPropertyType.CG_LIST.toString())); + assertEquals("MS", map.get(TimeSeriesPropertyType.CULTIVATION_METHOD_EXPERIMENT_CODE.toString())); + assertEquals("Ma", map.get(TimeSeriesPropertyType.EXPERIMENT_CODE.toString())); + assertEquals("LIN", map.get(TimeSeriesPropertyType.SCALE_LIST.toString())); + assertEquals("T1", map.get(TimeSeriesPropertyType.TECHNICAL_REPLICATE_CODE_LIST.toString())); + assertEquals("0", map.get(TimeSeriesPropertyType.TIME_POINT_LIST.toString())); + assertEquals("LcaMicAbsFl, LcaMicCfd", map.get(TimeSeriesPropertyType.TIME_SERIES_DATA_SET_TYPE.toString())); + assertEquals(null, map.get(TimeSeriesPropertyType.UPLOADER_EMAIL.toString())); + assertEquals("Mean[Au], Std[Au], Value[um]", map.get(TimeSeriesPropertyType.VALUE_TYPE_LIST.toString())); + assertEquals("0.68", map.get(LcaMicDataSetPropertiesExtractor.GROWTH_RATE)); + } + +} diff --git a/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetUploaderTest.java b/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetUploaderTest.java new file mode 100644 index 00000000000..65495e07958 --- /dev/null +++ b/eu_basysbio/sourceTest/java/eu/basysbio/cisd/dss/LcaMicDataSetUploaderTest.java @@ -0,0 +1,143 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package eu.basysbio.cisd.dss; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import java.util.Properties; + +import org.jmock.Mockery; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; +import ch.systemsx.cisd.common.filesystem.FileUtilities; +import ch.systemsx.cisd.etlserver.cifex.CifexExtractorHelper; +import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; +import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class LcaMicDataSetUploaderTest extends AbstractFileSystemTestCase +{ + private static FilenameFilter TXT_FILTER = new FilenameFilter() + { + public boolean accept(File dir, String name) + { + return name.endsWith(".txt"); + } + }; + + private static FilenameFilter PROPERTIES_FILTER = new FilenameFilter() + { + public boolean accept(File dir, String name) + { + return name.equals(CifexExtractorHelper.REQUEST_PROPERTIES_FILE); + } + }; + + private Mockery context; + private ITimeSeriesDAO dao; + private IEncapsulatedOpenBISService service; + private LcaMicDataSetUploader uploader; + private IDropBoxFeeder feeder; + private File dropBox; + + @BeforeMethod + public void beforeMethod() + { + context = new Mockery(); + dao = context.mock(ITimeSeriesDAO.class); + service = context.mock(IEncapsulatedOpenBISService.class); + feeder = context.mock(IDropBoxFeeder.class); + dropBox = new File(workingDirectory, "drop-box"); + dropBox.mkdirs(); + Properties properties = new Properties(); + properties.setProperty( + TimeSeriesDataSetUploaderParameters.TIME_SERIES_DATA_SET_DROP_BOX_PATH, dropBox + .toString()); + uploader = + new LcaMicDataSetUploader(dao, service, new TimeSeriesDataSetUploaderParameters( + properties, true)); + } + + @AfterMethod + public void tearDown() + { + // To following line of code should also be called at the end of each test method. + // Otherwise one does not known which test failed. + context.assertIsSatisfied(); + } + + @Test + public void test() + { + File tsvFile = new File(workingDirectory, "data.tsv"); + FileUtilities.writeToFile(tsvFile, LcaMicDataSetPropertiesExtractorTest.EXAMPLE + + "12\t2.5\t5.5\tN/A\n42\t42.5\t45.5\t3.25\n"); + + DataSetInformation dataSetInformation = new DataSetInformation(); + dataSetInformation.setExperimentIdentifier(new ExperimentIdentifier("p1", "e1")); + dataSetInformation.setDataSetCode("abc-1"); + dataSetInformation.setUploadingUserEmail("ab@c.de"); + uploader.handleTSVFile(tsvFile, dataSetInformation, feeder); + + List<String> data = getData(1); + assertEquals("BBA ID\t" + + "Ma::MS::B1::12::EX::T1::NC::LcaMicCfd::Value[um]::LIN::NB::NC\t" + + "Ma::MS::B1::42::EX::T1::NC::LcaMicCfd::Value[um]::LIN::NB::NC", data.get(0)); + assertEquals("BBA9001#A_S20090325-2\t2.5\t42.5", data.get(1)); + checkProperties(1); + data = getData(2); + assertEquals("BBA ID\t" + + "Ma::MS::B1::12::EX::T1::NC::LcaMicAbsFl::Mean[Au]::LIN::NB::NC\t" + + "Ma::MS::B1::42::EX::T1::NC::LcaMicAbsFl::Mean[Au]::LIN::NB::NC", data.get(0)); + assertEquals("BBA9001#A_S20090325-2\t5.5\t45.5", data.get(1)); + checkProperties(2); + data = getData(3); + assertEquals("BBA ID\t" + + "Ma::MS::B1::12::EX::T1::NC::LcaMicAbsFl::Std[Au]::LIN::NB::NC\t" + + "Ma::MS::B1::42::EX::T1::NC::LcaMicAbsFl::Std[Au]::LIN::NB::NC", data.get(0)); + assertEquals("BBA9001#A_S20090325-2\tN/A\t3.25", data.get(1)); + checkProperties(3); + context.assertIsSatisfied(); + } + + private List<String> getData(int number) + { + File ds = new File(dropBox, DataSetHandler.LCA_MIC_TIME_SERIES + number); + List<String> data = FileUtilities.loadToStringList(ds.listFiles(TXT_FILTER)[0]); + assertEquals(2, data.size()); + return data; + } + + private void checkProperties(int number) + { + File ds = new File(dropBox, DataSetHandler.LCA_MIC_TIME_SERIES + number); + List<String> data = FileUtilities.loadToStringList(ds.listFiles(PROPERTIES_FILTER)[0]); + assertEquals(2, data.size()); + assertEquals("comment=null,p1/e1,abc-1,LCA_MIC_TIME_SERIES,PROPRIETARY", data.get(0)); + assertEquals("user-email=ab@c.de", data.get(1)); + } + +} -- GitLab