diff --git a/bds/source/java/ch/systemsx/cisd/bds/DataStructureFactory.java b/bds/source/java/ch/systemsx/cisd/bds/DataStructureFactory.java index e4b5baa0e31e39cab03774a3ea8e5adb42596e57..d7e4b8c220ba79f08f0c15aa96baf20ebf2027b8 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/DataStructureFactory.java +++ b/bds/source/java/ch/systemsx/cisd/bds/DataStructureFactory.java @@ -20,45 +20,45 @@ import ch.systemsx.cisd.bds.storage.IStorage; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; /** - * Factory of data structures. - * Currently only structures compatible with Version 1.0 can be created. - * + * Factory of data structures. Currently only structures compatible with Version 1.0 can be created. + * * @author Franz-Josef Elmer */ public class DataStructureFactory { private static final Factory<IDataStructure> factory = new Factory<IDataStructure>(); - + static { factory.register(new Version(1, 0), DataStructureV1_0.class); } - + /** * Returns the class of the object returned after invoking {@link #createDataStructure(IStorage, Version)}. * * @param version Version of the data structure. * @throws DataStructureException if no data structure can be created for the specified version. */ - public static Class<? extends IDataStructure> getDataStructureClassFor(Version version) + public static Class<? extends IDataStructure> getDataStructureClassFor(final Version version) { return factory.getClassFor(version); } - + /** * Creates a data structure for the specified version. * * @param storage Storage behind the data structure. * @param version Version of the data structure to be created. - * @throws EnvironmentFailureException found data structure class has not an appropriated constructor. + * @throws EnvironmentFailureException found data structure class has not an appropriated constructor. * @throws DataStructureException if no data structure can be created for the specified version. */ - public static IDataStructure createDataStructure(IStorage storage, Version version) + public static IDataStructure createDataStructure(final IStorage storage, final Version version) { return factory.create(IStorage.class, storage, version); } private DataStructureFactory() { + // Can not be instantiated } } diff --git a/bds/source/java/ch/systemsx/cisd/bds/DataStructureLoader.java b/bds/source/java/ch/systemsx/cisd/bds/DataStructureLoader.java index 9f6ddd0e4bdfa4fdd6f6a80abf13bcfb0d226ca8..8783190a7ac990d80aa8885e2925932232dbca82 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/DataStructureLoader.java +++ b/bds/source/java/ch/systemsx/cisd/bds/DataStructureLoader.java @@ -23,8 +23,8 @@ import ch.systemsx.cisd.bds.storage.filesystem.FileStorage; import ch.systemsx.cisd.bds.storage.hdf5.HDF5Storage; /** - * Loader for {@link IDataStructure}s from the file system. - * + * Loader for {@link IDataStructure}s from the file system. + * * @author Franz-Josef Elmer */ public class DataStructureLoader @@ -34,7 +34,7 @@ public class DataStructureLoader /** * Creates an instance for the specified base directory where all data structures to be loaded have to exist. */ - public DataStructureLoader(File baseDir) + public DataStructureLoader(final File baseDir) { assert baseDir != null : "Unspecified base directory."; assert baseDir.isDirectory() : "Is not a directory : " + baseDir.getAbsolutePath(); @@ -44,19 +44,19 @@ public class DataStructureLoader /** * Loads the data structure with specified name. */ - public IDataStructure load(String name) + public final IDataStructure load(final String name) { - IStorage storage = createStorage(name); + final IStorage storage = createStorage(name); storage.mount(); - Version version = Version.loadFrom(storage.getRoot()); - IDataStructure dataStructure = DataStructureFactory.createDataStructure(storage, version); + final Version version = Version.loadFrom(storage.getRoot()); + final IDataStructure dataStructure = DataStructureFactory.createDataStructure(storage, version); dataStructure.open(); return dataStructure; } - - private IStorage createStorage(String name) + + private final IStorage createStorage(final String name) { - File file = new File(baseDir, name); + final File file = new File(baseDir, name); if (file.exists() == false) { throw new DataStructureException("No container name '" + name + "' exists in " + baseDir.getAbsolutePath()); @@ -65,13 +65,13 @@ public class DataStructureLoader { return new FileStorage(file); } - File hdf5File = new File(baseDir, name + ".hdf5"); + final File hdf5File = new File(baseDir, name + ".hdf5"); if (hdf5File.exists()) { return new HDF5Storage(hdf5File); } throw new DataStructureException("Couldn't found appropriate container named '" + name + "' in " + baseDir.getAbsolutePath()); - + } } diff --git a/bds/source/java/ch/systemsx/cisd/bds/DataStructureV1_0.java b/bds/source/java/ch/systemsx/cisd/bds/DataStructureV1_0.java index 71899de46daf2ed1557d625cba0f61ac313ccf0b..79f7f406f632decac59ae2017cb97280fcc5a953 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/DataStructureV1_0.java +++ b/bds/source/java/ch/systemsx/cisd/bds/DataStructureV1_0.java @@ -39,17 +39,17 @@ import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; */ public class DataStructureV1_0 extends AbstractDataStructure { - static final String CHECKSUM_DIRECTORY = "md5sum"; + public static final String CHECKSUM_DIRECTORY = "md5sum"; - static final String DIR_METADATA = "metadata"; + public static final String DIR_METADATA = "metadata"; - static final String DIR_PARAMETERS = "parameters"; + public static final String DIR_PARAMETERS = "parameters"; - static final String DIR_DATA = "data"; + public static final String DIR_DATA = "data"; - static final String DIR_ORIGINAL = "original"; + public static final String DIR_ORIGINAL = "original"; - static final String MAPPING_FILE = "standard_original_mapping"; + public static final String MAPPING_FILE = "standard_original_mapping"; private static final Version VERSION = new Version(1, 0); @@ -106,11 +106,12 @@ public class DataStructureV1_0 extends AbstractDataStructure /** * Sets the data format of this structure. */ - public void setFormat(Format format) + public final void setFormat(final Format format) { assert format != null : "Unspecified format."; assertOpenOrCreated(); this.format = format; + formatParameters.setFormatParameterFactory(format.getFormatParameterFactory()); } /** @@ -118,7 +119,7 @@ public class DataStructureV1_0 extends AbstractDataStructure * * @throws IllegalArgumentException if they is already a parameter with same name as <code>parameter</code>. */ - public void addFormatParameter(FormatParameter formatParameter) + public void addFormatParameter(final FormatParameter formatParameter) { assert formatParameter != null : "Unspecified format parameter."; formatParameters.addParameter(formatParameter); @@ -257,15 +258,6 @@ public class DataStructureV1_0 extends AbstractDataStructure standardOriginalMapping.put(path, reference); } - /** - * Sets a different <code>IFormatParameterFactory</code> implementation than the default one to encapsulated - * <code>FormatParameters</code>. - */ - public void setFormatParametersFactory(final IFormatParameterFactory formatParameterFactory) - { - formatParameters.setFormatParameterFactory(formatParameterFactory); - } - @Override protected void assertValid() { diff --git a/bds/source/java/ch/systemsx/cisd/bds/Format.java b/bds/source/java/ch/systemsx/cisd/bds/Format.java index ed66c35b628860f156e32e9d2b0c60facfdf7cd3..8e477ca9984a8ff5ae4e7c57ab4ad69583d7de36 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/Format.java +++ b/bds/source/java/ch/systemsx/cisd/bds/Format.java @@ -21,7 +21,7 @@ import ch.systemsx.cisd.bds.storage.IFile; import ch.systemsx.cisd.bds.storage.INode; /** - * Inmutable value object of a versioned format. + * Immutable value object of a versioned format. * * @author Franz-Josef Elmer */ @@ -64,7 +64,12 @@ public class Format implements IStorable } variant = ((IFile) file).getStringContent().trim(); } - return new Format(formatCode, formatVersion, variant); + Format format = FormatStore.getFormat(formatCode, formatVersion, variant); + if (format == null) + { + format = new Format(formatCode, formatVersion, variant); + } + return format; } private final String code; @@ -76,7 +81,7 @@ public class Format implements IStorable /** * Creates a new instance based on the specified format code, format variant (optional), and version. */ - public Format(String code, Version version, String variantOrNull) + public Format(final String code, final Version version, final String variantOrNull) { assert code != null : "Unspecified format code."; assert version != null : "Unpsecified version."; @@ -111,6 +116,14 @@ public class Format implements IStorable return variant; } + /** + * Returns the <code>IFormatParameterFactory</code> implementation for this <code>Format</code>. + */ + public IFormatParameterFactory getFormatParameterFactory() + { + return IFormatParameterFactory.DEFAULT_FORMAT_PARAMETER_FACTORY; + } + // // IStorable // @@ -126,6 +139,10 @@ public class Format implements IStorable } } + // + // Object + // + @Override public boolean equals(Object obj) { diff --git a/bds/source/java/ch/systemsx/cisd/bds/FormatParameters.java b/bds/source/java/ch/systemsx/cisd/bds/FormatParameters.java index 4d4eefc7bf57a2965fe88d9ecbdb1af90b5ecfdd..15fde98566cc501a288d723e022ee22828794ccf 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/FormatParameters.java +++ b/bds/source/java/ch/systemsx/cisd/bds/FormatParameters.java @@ -63,16 +63,12 @@ final class FormatParameters implements IFormatParameters, IStorable { final Object value = parameter.getValue(); assert value != null : "Parameter value can not be null."; - if (value instanceof String) - { - directory.addKeyValuePair(parameter.getName(), (String) value); - } else if (value instanceof IStorable) + if (value instanceof IStorable) { ((IStorable) value).saveTo(directory); } else { - throw new IllegalArgumentException(String.format( - "Parameter value '%s' must be a String or an IStorable implementation.", value)); + directory.addKeyValuePair(parameter.getName(), value.toString()); } } } diff --git a/bds/source/java/ch/systemsx/cisd/bds/FormatStore.java b/bds/source/java/ch/systemsx/cisd/bds/FormatStore.java new file mode 100644 index 0000000000000000000000000000000000000000..10c6a9922963758898430e295dbc061ad6015414 --- /dev/null +++ b/bds/source/java/ch/systemsx/cisd/bds/FormatStore.java @@ -0,0 +1,72 @@ +/* + * Copyright 2007 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 ch.systemsx.cisd.bds; + +import java.util.HashMap; +import java.util.Map; + +import ch.systemsx.cisd.bds.hcs.ImageHCSFormat1_0; + +/** + * A store of all active formats. + * + * @author Christian Ribeaud + */ +public final class FormatStore +{ + + private final static Map<String, Format> formats = createFormats(); + + private FormatStore() + { + // Can not be instantiated. + } + + private final static Map<String, Format> createFormats() + { + final Map<String, Format> map = new HashMap<String, Format>(); + map.put(getKey(UnknownFormat1_0.UNKNOWN_1_0), UnknownFormat1_0.UNKNOWN_1_0); + map.put(getKey(ImageHCSFormat1_0.IMAGE_HCS_1_0), ImageHCSFormat1_0.IMAGE_HCS_1_0); + return map; + } + + /** Constructs an unique key for given <var>format</var>. */ + private final static String getKey(final Format format) + { + return getKey(format.getCode(), format.getVersion(), format.getVariant()); + } + + /** Constructs an unique key for given <var>formatCode</var>, <var>version</var> and <var>variant</var>. */ + private final static String getKey(final String formatCode, final Version version, final String variant) + { + String key = formatCode + version.toString(); + if (variant != null) + { + key += variant; + } + return key; + } + + /** + * Returns corresponding <code>Format</code> for given format code, version and format variant. + */ + public final static Format getFormat(final String formatCode, final Version version, final String formatVariant) + throws DataStructureException + { + return formats.get(getKey(formatCode, version, formatVariant)); + } +} diff --git a/bds/source/java/ch/systemsx/cisd/bds/Version.java b/bds/source/java/ch/systemsx/cisd/bds/Version.java index 11721a4366375401ed19ad398a4c3016baa16d32..50d63671a170294034c1be832945bcb4e1a2de72 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/Version.java +++ b/bds/source/java/ch/systemsx/cisd/bds/Version.java @@ -23,7 +23,7 @@ import ch.systemsx.cisd.bds.storage.IDirectory; * * @author Franz-Josef Elmer */ -public final class Version +public final class Version implements IStorable { static final String VERSION = "version"; @@ -97,7 +97,11 @@ public final class Version return new Version(major, minor - 1); } - void saveTo(IDirectory directory) + // + // IStorable + // + + public final void saveTo(IDirectory directory) { IDirectory versionFolder = directory.makeDirectory(VERSION); versionFolder.addKeyValuePair(MAJOR, Integer.toString(major)); diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/Geometry.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/Geometry.java index d4e13d270ba8f6352ce4d642d2c94adaa2bd11b1..4ef1d7cc001afc0443dbc167849c0639077a1480 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/Geometry.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/Geometry.java @@ -72,13 +72,15 @@ public class Geometry implements IStorable /** * Loads the geometry from the specified directory. + * + * @param directory the geometry directory. Its name must start with given <var>geometryDirectoryName</var>. */ final static Geometry loadFrom(final IDirectory directory, final String geometryDirectoryName) { assert directory != null : "Given directory can not be null."; - assert geometryDirectoryName != null && geometryDirectoryName.trim().length() > 0 : "Given subdirectory name can not be empty."; - final IDirectory geometryFolder = Utilities.getSubDirectory(directory, geometryDirectoryName); - return new Geometry(Utilities.getNumber(geometryFolder, ROWS), Utilities.getNumber(geometryFolder, COLUMNS)); + assert directory.getName().startsWith(geometryDirectoryName) : "Given directory name must start with given '" + + geometryDirectoryName + "'."; + return new Geometry(Utilities.getNumber(directory, ROWS), Utilities.getNumber(directory, COLUMNS)); } // diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/ImageHCSFormat1_0.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/ImageHCSFormat1_0.java index 6ad2a41c4ece4f13c23f22abcd979a9205707011..818b7a221c9bb085a71c41523ccaaad7eda2a818 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/ImageHCSFormat1_0.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/ImageHCSFormat1_0.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.bds.hcs; import ch.systemsx.cisd.bds.Format; +import ch.systemsx.cisd.bds.IFormatParameterFactory; import ch.systemsx.cisd.bds.Version; /** @@ -41,10 +42,21 @@ public final class ImageHCSFormat1_0 extends Format /** * The one and only one instance. */ - public static final Format UNKNOWN_1_0 = new ImageHCSFormat1_0(); + public static final Format IMAGE_HCS_1_0 = new ImageHCSFormat1_0(); private ImageHCSFormat1_0() { super(FORMAT_CODE, new Version(1, 0), null); } + + // + // Format + // + + @Override + public final IFormatParameterFactory getFormatParameterFactory() + { + return new FormatParameterFactory(); + } + } diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureLoaderTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureLoaderTest.java index 24318085fbb78b823d6b71d4a9c7023dbe0baa69..13899c31b63594812993e55daa3e23af3fc465dd 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureLoaderTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureLoaderTest.java @@ -16,37 +16,28 @@ package ch.systemsx.cisd.bds; -import static ch.systemsx.cisd.bds.DataStructureV1_0Test.TEST_DIR; import static org.testng.AssertJUnit.assertEquals; import java.io.File; -import java.io.IOException; import java.util.Date; -import org.apache.commons.io.FileUtils; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.bds.storage.filesystem.FileStorage; +import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; /** * Test cases for corresponding {@link DataStructureLoader} class. * * @author Franz-Josef Elmer */ -public class DataStructureLoaderTest +public final class DataStructureLoaderTest extends AbstractFileSystemTestCase { - @BeforeMethod - public void setUp() throws IOException - { - TEST_DIR.mkdirs(); - FileUtils.cleanDirectory(TEST_DIR); - } @Test - public void testOpen() + public final void testOpen() { - File dir = new File(TEST_DIR, "ds"); + File dir = new File(workingDirectory, "ds"); assert dir.mkdir(); DataStructureV1_0 dataStructure = new DataStructureV1_0(new FileStorage(dir)); dataStructure.create(); @@ -61,7 +52,7 @@ public class DataStructureLoaderTest dataStructure.setProcessingType(ProcessingType.RAW_DATA); dataStructure.close(); - IDataStructure ds = new DataStructureLoader(TEST_DIR).load("ds"); + IDataStructure ds = new DataStructureLoader(workingDirectory).load("ds"); assertEquals(DataStructureV1_0.class, ds.getClass()); assertEquals(experimentIdentifier, ((DataStructureV1_0) ds).getExperimentIdentifier()); } diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureV1_0Test.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureV1_0Test.java index 2e6a3ed0553a660a6beccca5bec1c757fc4ad339..de45734868d8b8dea319aee6e84711e3886a636d 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureV1_0Test.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/DataStructureV1_0Test.java @@ -23,29 +23,26 @@ import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.fail; -import java.io.File; import java.io.IOException; import java.util.Date; import java.util.Iterator; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.bds.storage.IDirectory; import ch.systemsx.cisd.bds.storage.StorageException; import ch.systemsx.cisd.bds.storage.filesystem.FileStorage; +import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; /** * Test cases for corresponding {@link DataStructureV1_0} class. * * @author Franz-Josef Elmer */ -public class DataStructureV1_0Test +public final class DataStructureV1_0Test extends AbstractFileSystemTestCase { - static final File TEST_DIR = new File("targets" + File.separator + "unit-test-wd" + File.separator + "ds"); - private static void assertPartOfString(String part, String string) { assertTrue("Expected <" + part + "> is part of <" + string + ">", string.indexOf(part) >= 0); @@ -55,12 +52,16 @@ public class DataStructureV1_0Test private DataStructureV1_0 dataStructure; + // + // AbstractFileSystemTestCase + // + + @Override @BeforeMethod - public void setup() throws IOException + public final void setup() throws IOException { - TEST_DIR.mkdirs(); - FileUtils.cleanDirectory(TEST_DIR); - storage = new FileStorage(TEST_DIR); + super.setup(); + storage = new FileStorage(workingDirectory); dataStructure = new DataStructureV1_0(storage); } @@ -409,11 +410,11 @@ public class DataStructureV1_0Test assertEquals(ReferenceType.TRANSFORMED, reference.getReferenceType()); assertEquals("a b/x\tt", reference.getOriginalPath()); checkFormattedData(reloadedDataStructure.getFormattedData()); - + IDirectory metaDataDir = Utilities.getSubDirectory(root, DIR_METADATA); IDirectory checksumDir = Utilities.getSubDirectory(metaDataDir, CHECKSUM_DIRECTORY); - assertEquals("a1d0c6e83f027327d8461063f4ac58a6 answer\n", - Utilities.getString(checksumDir, DataStructureV1_0.DIR_ORIGINAL)); + assertEquals("a1d0c6e83f027327d8461063f4ac58a6 answer\n", Utilities.getString(checksumDir, + DataStructureV1_0.DIR_ORIGINAL)); } private void checkFormattedData(IFormattedData formattedData) @@ -546,6 +547,5 @@ public class DataStructureV1_0Test metaData.addKeyValuePair(DataStructureV1_0.MAPPING_FILE, ""); ProcessingType.COMPUTED_DATA.saveTo(metaData); storage.unmount(); - } } diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java new file mode 100644 index 0000000000000000000000000000000000000000..77de45b922026deaec137aff2f09e75e92a83385 --- /dev/null +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java @@ -0,0 +1,111 @@ +/* + * Copyright 2007 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 ch.systemsx.cisd.bds.hcs; + +import static org.testng.AssertJUnit.assertNotNull; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.bds.DataStructureLoader; +import ch.systemsx.cisd.bds.DataStructureV1_0; +import ch.systemsx.cisd.bds.ExperimentIdentifier; +import ch.systemsx.cisd.bds.ExperimentRegistrator; +import ch.systemsx.cisd.bds.ExperimentRegistratorDate; +import ch.systemsx.cisd.bds.FormatParameter; +import ch.systemsx.cisd.bds.IDataStructure; +import ch.systemsx.cisd.bds.MeasurementEntity; +import ch.systemsx.cisd.bds.ProcessingType; +import ch.systemsx.cisd.bds.Version; +import ch.systemsx.cisd.bds.storage.IDirectory; +import ch.systemsx.cisd.bds.storage.filesystem.FileStorage; +import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; + +/** + * Test cases for corresponding {@link DataStructureV1_0} class. + * + * @author Christian Ribeaud + */ +public final class HCSDataStructureV1_0Test extends AbstractFileSystemTestCase +{ + private FileStorage storage; + + private DataStructureV1_0 dataStructure; + + private final static ChannelList createChannelList() + { + final List<Channel> list = new ArrayList<Channel>(); + list.add(new Channel(1, 123)); + list.add(new Channel(2, 456)); + return new ChannelList(list); + } + + private void createExampleDataStructure() + { + storage.mount(); + IDirectory root = storage.getRoot(); + new Version(1, 0).saveTo(root); + final IDirectory data = root.makeDirectory(DataStructureV1_0.DIR_DATA); + final IDirectory originalDataDir = data.makeDirectory(DataStructureV1_0.DIR_ORIGINAL); + originalDataDir.addKeyValuePair("hello", "world"); + final IDirectory metaData = root.makeDirectory(DataStructureV1_0.DIR_METADATA); + new ExperimentIdentifier("g", "p", "e").saveTo(metaData); + new ExperimentRegistratorDate(new Date(0)).saveTo(metaData); + new ExperimentRegistrator("john", "doe", "j@doe").saveTo(metaData); + new MeasurementEntity("a", "b").saveTo(metaData); + metaData.addKeyValuePair(DataStructureV1_0.MAPPING_FILE, ""); + ProcessingType.COMPUTED_DATA.saveTo(metaData); + storage.unmount(); + } + + // + // AbstractFileSystemTestCase + // + + @Override + @BeforeMethod + public final void setup() throws IOException + { + super.setup(); + storage = new FileStorage(workingDirectory); + dataStructure = new DataStructureV1_0(storage); + } + + @Test + public final void testHCSImageDataStructure() + { + // Creating... + dataStructure.create(); + createExampleDataStructure(); + dataStructure.setFormat(ImageHCSFormat1_0.IMAGE_HCS_1_0); + dataStructure.addFormatParameter(new FormatParameter(ImageHCSFormat1_0.DEVICE_ID, "M1")); + dataStructure.addFormatParameter(new FormatParameter(ImageHCSFormat1_0.CONTAINS_ORIGINAL_DATA, Boolean.TRUE)); + dataStructure.addFormatParameter(new FormatParameter("doesNotMatter", createChannelList())); + dataStructure.addFormatParameter(new FormatParameter(PlateGeometry.PLATE_GEOMETRY, new PlateGeometry(2, 3))); + dataStructure.addFormatParameter(new FormatParameter(WellGeometry.WELL_GEOMETRY, new WellGeometry(7, 5))); + dataStructure.close(); + // And loading... + final IDataStructure ds = + new DataStructureLoader(workingDirectory.getParentFile()).load(getClass().getSimpleName()); + assertNotNull(ds); + } +} \ No newline at end of file diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java index 8559a453648adaad44f6322fbae556f594cd88f8..9485681f345426f26012290d00996e7014e537be 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java @@ -25,6 +25,7 @@ import java.io.File; import org.testng.annotations.Test; +import ch.systemsx.cisd.bds.Utilities; import ch.systemsx.cisd.bds.storage.IDirectory; import ch.systemsx.cisd.bds.storage.filesystem.NodeFactory; import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; @@ -83,7 +84,8 @@ public final class PlateGeometryTest extends AbstractFileSystemTestCase { testSaveTo(); final IDirectory dir = NodeFactory.createDirectoryNode(workingDirectory); - final Geometry loaded = PlateGeometry.loadFrom(dir); + final IDirectory geoDir = Utilities.getOrCreateSubDirectory(dir, PlateGeometry.PLATE_GEOMETRY); + final Geometry loaded = PlateGeometry.loadFrom(geoDir); assertNotNull(loaded); assertTrue(loaded.getRows() == 2); assertTrue(loaded.getColumns() == 3); diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java index f8e55586654b10f007c6ea1d6f98cbd4bfb1479d..179ef192b9bee023878e88fe94b2a000694ae78a 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java @@ -26,6 +26,7 @@ import java.io.File; import org.testng.annotations.Test; +import ch.systemsx.cisd.bds.Utilities; import ch.systemsx.cisd.bds.storage.IDirectory; import ch.systemsx.cisd.bds.storage.filesystem.NodeFactory; import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; @@ -83,7 +84,8 @@ public final class WellGeometryTest extends AbstractFileSystemTestCase { testSaveTo(); final IDirectory dir = NodeFactory.createDirectoryNode(workingDirectory); - final Geometry loaded = WellGeometry.loadFrom(dir); + final IDirectory geoDir = Utilities.getOrCreateSubDirectory(dir, WellGeometry.WELL_GEOMETRY); + final Geometry loaded = WellGeometry.loadFrom(geoDir); assertNotNull(loaded); assertTrue(loaded.getRows() == 2); assertTrue(loaded.getColumns() == 3);