Skip to content
Snippets Groups Projects
Commit b4420311 authored by pkupczyk's avatar pkupczyk
Browse files

SP-302 / BIS-214 : Improvements to PathInfoDb - junits

SVN: 26940
parent cef16d01
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
package ch.systemsx.cisd.openbis.generic.shared.basic.dto; package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.Collection;
import java.util.List; import java.util.TreeMap;
/** /**
* Simple implementation of {@link IDatasetLocationNode}. * Simple implementation of {@link IDatasetLocationNode}.
...@@ -32,7 +32,8 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable ...@@ -32,7 +32,8 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable
private IDatasetLocation location; private IDatasetLocation location;
private List<IDatasetLocationNode> contained = new ArrayList<IDatasetLocationNode>(); private TreeMap<String, IDatasetLocationNode> contained =
new TreeMap<String, IDatasetLocationNode>();
public DatasetLocationNode(IDatasetLocation location) public DatasetLocationNode(IDatasetLocation location)
{ {
...@@ -56,9 +57,9 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable ...@@ -56,9 +57,9 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable
} }
@Override @Override
public List<IDatasetLocationNode> getComponents() public Collection<IDatasetLocationNode> getComponents()
{ {
return contained; return contained.values();
} }
public void addContained(IDatasetLocationNode node) public void addContained(IDatasetLocationNode node)
...@@ -67,7 +68,7 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable ...@@ -67,7 +68,7 @@ public class DatasetLocationNode implements IDatasetLocationNode, Serializable
{ {
throw new IllegalArgumentException("Node cannot be null"); throw new IllegalArgumentException("Node cannot be null");
} }
contained.add(node); contained.put(node.getLocation().getDataSetCode(), node);
} }
} }
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
package ch.systemsx.cisd.openbis.generic.shared.basic.dto; package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.util.ArrayList; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.TreeMap;
/** /**
* Implementation of {@link IDatasetLocationNode} that uses {@link ExternalData} object as a source * Implementation of {@link IDatasetLocationNode} that uses {@link ExternalData} object as a source
...@@ -60,7 +61,7 @@ public class ExternalDataLocationNode implements IDatasetLocationNode ...@@ -60,7 +61,7 @@ public class ExternalDataLocationNode implements IDatasetLocationNode
} }
@Override @Override
public List<IDatasetLocationNode> getComponents() public Collection<IDatasetLocationNode> getComponents()
{ {
if (isContainer() == false) if (isContainer() == false)
{ {
...@@ -72,15 +73,16 @@ public class ExternalDataLocationNode implements IDatasetLocationNode ...@@ -72,15 +73,16 @@ public class ExternalDataLocationNode implements IDatasetLocationNode
if (containedExternalDatas != null) if (containedExternalDatas != null)
{ {
List<IDatasetLocationNode> containedLocationNodes = TreeMap<String, IDatasetLocationNode> containedLocationNodes =
new ArrayList<IDatasetLocationNode>(containedExternalDatas.size()); new TreeMap<String, IDatasetLocationNode>();
for (ExternalData containedExternalData : containedExternalDatas) for (ExternalData containedExternalData : containedExternalDatas)
{ {
containedLocationNodes.add(new ExternalDataLocationNode(containedExternalData)); containedLocationNodes.put(containedExternalData.getCode(),
new ExternalDataLocationNode(containedExternalData));
} }
return containedLocationNodes; return containedLocationNodes.values();
} else } else
{ {
return Collections.emptyList(); return Collections.emptyList();
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
package ch.systemsx.cisd.openbis.generic.shared.basic.dto; package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.util.List; import java.util.Collection;
/** /**
* Stores information about a location of a data sets and its components. * Stores information about a location of a data set and its components.
* *
* @author pkupczyk * @author pkupczyk
*/ */
...@@ -37,9 +37,9 @@ public interface IDatasetLocationNode ...@@ -37,9 +37,9 @@ public interface IDatasetLocationNode
boolean isContainer(); boolean isContainer();
/** /**
* Returns a list of component locations. For a data set that is not a container always returns * Returns a collection of component locations. For a data set that is not a container always
* an empty list. Never returns null. * returns an empty collection. Never returns null.
*/ */
List<IDatasetLocationNode> getComponents(); Collection<IDatasetLocationNode> getComponents();
} }
...@@ -29,10 +29,13 @@ import java.util.Collections; ...@@ -29,10 +29,13 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import junit.framework.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -47,6 +50,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet; ...@@ -47,6 +50,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IDatasetLocationNode;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetShareId; import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetShareId;
...@@ -221,7 +225,7 @@ public class DatasetListerTest extends AbstractDAOTest ...@@ -221,7 +225,7 @@ public class DatasetListerTest extends AbstractDAOTest
assertEquals("20081105092259900-0", dataSets.get(0).getCode()); assertEquals("20081105092259900-0", dataSets.get(0).getCode());
assertEquals("STANDARD", dataSets.get(0).getDataStore().getCode()); assertEquals("STANDARD", dataSets.get(0).getDataStore().getCode());
assertEquals(0, dataSets.get(0).getProperties().size()); assertEquals(0, dataSets.get(0).getProperties().size());
assertEquals(17, dataSets.size()); assertEquals(23, dataSets.size());
} }
@Test @Test
...@@ -383,7 +387,7 @@ public class DatasetListerTest extends AbstractDAOTest ...@@ -383,7 +387,7 @@ public class DatasetListerTest extends AbstractDAOTest
assertEquals("42", ((DataSet) dataSet).getShareId()); assertEquals("42", ((DataSet) dataSet).getShareId());
assertEquals(4711L, ((DataSet) dataSet).getSize().longValue()); assertEquals(4711L, ((DataSet) dataSet).getSize().longValue());
assertEquals(DataSetArchivingStatus.AVAILABLE, ((DataSet) dataSet).getStatus()); assertEquals(DataSetArchivingStatus.AVAILABLE, ((DataSet) dataSet).getStatus());
assertEquals(23, list.size()); assertEquals(29, list.size());
} }
@Test @Test
...@@ -406,7 +410,77 @@ public class DatasetListerTest extends AbstractDAOTest ...@@ -406,7 +410,77 @@ public class DatasetListerTest extends AbstractDAOTest
DataSetShareId dataSet2 = list.get(1); DataSetShareId dataSet2 = list.get(1);
assertEquals("20081105092159111-1", dataSet2.getDataSetCode()); assertEquals("20081105092159111-1", dataSet2.getDataSetCode());
assertEquals("42", dataSet2.getShareId()); assertEquals("42", dataSet2.getShareId());
assertEquals(25, list.size()); assertEquals(31, list.size());
}
@Test
public void testListLocationsByDatasetCodeForRootContainer()
{
IDatasetLocationNode root = lister.listLocationsByDatasetCode("ROOT_CONTAINER");
Iterator<IDatasetLocationNode> rootComponents = root.getComponents().iterator();
assertContainerLocation(root, "ROOT_CONTAINER", 2);
IDatasetLocationNode container1 = rootComponents.next();
Iterator<IDatasetLocationNode> container1Components = container1.getComponents().iterator();
assertContainerLocation(container1, "CONTAINER_1", 2);
assertComponentLocation(container1Components.next(), "COMPONENT_1A",
"contained/COMPONENT_1A");
assertComponentLocation(container1Components.next(), "COMPONENT_1B",
"contained/COMPONENT_1B");
IDatasetLocationNode container2 = rootComponents.next();
Iterator<IDatasetLocationNode> container2Components = container2.getComponents().iterator();
assertContainerLocation(container2, "CONTAINER_2", 1);
assertComponentLocation(container2Components.next(), "COMPONENT_2A",
"contained/COMPONENT_2A");
}
@Test
public void testListLocationsByDatasetCodeForContainer()
{
IDatasetLocationNode container = lister.listLocationsByDatasetCode("CONTAINER_1");
Iterator<IDatasetLocationNode> containerComponents = container.getComponents().iterator();
assertContainerLocation(container, "CONTAINER_1", 2);
assertComponentLocation(containerComponents.next(), "COMPONENT_1A",
"contained/COMPONENT_1A");
assertComponentLocation(containerComponents.next(), "COMPONENT_1B",
"contained/COMPONENT_1B");
}
@Test
public void testListLocationsByDatasetCodeForComponent()
{
IDatasetLocationNode component = lister.listLocationsByDatasetCode("COMPONENT_1A");
assertComponentLocation(component, "COMPONENT_1A", "contained/COMPONENT_1A");
}
@Test
public void testListLocationsByDatasetCodeForNotExisting()
{
IDatasetLocationNode component =
lister.listLocationsByDatasetCode("COMPONENT_NOT_EXISTING");
Assert.assertNull(component);
}
private void assertContainerLocation(IDatasetLocationNode containerNode, String containerCode,
int numberOfComponents)
{
Assert.assertTrue(containerNode.isContainer());
Assert.assertEquals(containerCode, containerNode.getLocation().getDataSetCode());
Assert.assertNull(containerNode.getLocation().getDataSetLocation());
Assert.assertEquals(numberOfComponents, containerNode.getComponents().size());
}
private void assertComponentLocation(IDatasetLocationNode componentNode, String componentCode,
String componentLocation)
{
Assert.assertFalse(componentNode.isContainer());
Assert.assertEquals(componentCode, componentNode.getLocation().getDataSetCode());
Assert.assertEquals(componentLocation, componentNode.getLocation().getDataSetLocation());
Assert.assertEquals(0, componentNode.getComponents().size());
} }
private void assertSameDataSetsForSameCode(Map<String, ExternalData> dataSetsByCode, private void assertSameDataSetsForSameCode(Map<String, ExternalData> dataSetsByCode,
......
...@@ -23,3 +23,9 @@ ...@@ -23,3 +23,9 @@
26 VALIDATIONS_CNTNR-26 6 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 \N \N \N \N 26 VALIDATIONS_CNTNR-26 6 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 \N \N \N \N
27 VALIDATIONS_IMPOS-27 7 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 1 26 \N \N 27 VALIDATIONS_IMPOS-27 7 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 1 26 \N \N
28 VALIDATIONS_PARENT-28 8 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 \N \N \N \N 28 VALIDATIONS_PARENT-28 8 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 23 1 t \N 2 \N \N \N \N
29 ROOT_CONTAINER 4 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N \N \N \N \N
30 CONTAINER_1 4 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N \N 29 \N \N
31 CONTAINER_2 4 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N \N 29 \N \N
32 COMPONENT_1A 2 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N 1 30 \N \N
33 COMPONENT_2A 2 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N 1 31 \N \N
34 COMPONENT_1B 2 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N 1 30 \N \N
...@@ -16,3 +16,6 @@ ...@@ -16,3 +16,6 @@
21 xml/result-21 8 1 4 U \N AVAILABLE \N \N f -50 t 21 xml/result-21 8 1 4 U \N AVAILABLE \N \N f -50 t
27 xml/result-27 8 1 4 U \N AVAILABLE \N \N f -50 t 27 xml/result-27 8 1 4 U \N AVAILABLE \N \N f -50 t
28 xml/result-28 8 1 4 U \N AVAILABLE \N \N f -50 t 28 xml/result-28 8 1 4 U \N AVAILABLE \N \N f -50 t
32 contained/COMPONENT_1A 8 1 4 U \N AVAILABLE \N \N f -50 t
33 contained/COMPONENT_2A 8 1 4 U \N AVAILABLE \N \N f -50 t
34 contained/COMPONENT_1B 8 1 4 U \N AVAILABLE \N \N f -50 t
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment