Skip to content
Snippets Groups Projects
Commit 3796938e authored by felmer's avatar felmer
Browse files

LMS-761 Tests added to ExternalDataDAOTest.

SVN: 9959
parent f5300dff
No related branches found
No related tags found
No related merge requests found
...@@ -16,15 +16,40 @@ ...@@ -16,15 +16,40 @@
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db; package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
import java.util.List;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.common.types.BooleanOrUnknown;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDataSetTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IFileFormatTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ILocatorTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.FileFormatTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.HierarchyType;
import ch.systemsx.cisd.openbis.generic.shared.dto.LocatorTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProcedurePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SourceType;
import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.types.DataSetTypeCode;
/** /**
* Test cases for corresponding {@link ExternalDataDAO} class. * Test cases for corresponding {@link ExternalDataDAO} class.
* *
* @author Christian Ribeaud * @author Christian Ribeaud
*/ */
@Test(groups = @Test(groups =
...@@ -32,21 +57,155 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO; ...@@ -32,21 +57,155 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO;
public final class ExternalDataDAOTest extends AbstractDAOTest public final class ExternalDataDAOTest extends AbstractDAOTest
{ {
@Test
public final void testCreateDataSetCode()
{
IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO();
String code = externalDataDAO.createDataSetCode();
String[] tokens = code.split("-");
assertEquals(2, tokens.length);
int id = Integer.parseInt(tokens[1]) + 1;
code = externalDataDAO.createDataSetCode();
assertTrue("Expected id " + id + " at the end of code " + code, code.endsWith("-" + id));
}
@Test @Test
public final void testListExternalData() public final void testListExternalData()
{ {
// TODO 2008-10-28, Christian Ribeaud: Complete this test once we have added the possibility testCreateDataSet();
// to create external data in the database.
final IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO(); final IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO();
boolean fail = true; List<ExternalDataPE> list = externalDataDAO.listExternalData(pickASample(), SourceType.MEASUREMENT);
try
{ assertEquals(1, list.size());
externalDataDAO.listExternalData(null, null); ExternalDataPE dataSet = list.get(0);
} catch (final AssertionError e) assertEquals("abcd", dataSet.getLocation());
assertEquals(BooleanOrUnknown.U, dataSet.getComplete());
}
@Test
public void testCreateDataSet()
{
IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO();
ExternalDataPE externalData = new ExternalDataPE();
String dataSetCode = daoFactory.getExternalDataDAO().createDataSetCode();
externalData.setCode(dataSetCode);
externalData.setDataSetType(getDataSetType(DataSetTypeCode.UNKNOWN));
externalData.setProcedure(pickAProcedure());
externalData.setSampleAcquiredFrom(pickASample());
externalData.setFileFormatType(pickAFileFormatType());
externalData.setLocatorType(pickALocatorType());
externalData.setLocation("abcd");
externalData.setComplete(BooleanOrUnknown.U);
externalData.setStorageFormatVocabularyTerm(pickAStorageFormatVocabularyTerm());
externalData.setPlaceholder(true);
daoFactory.getExternalDataDAO().createDataSet(externalData);
ExternalDataPE dataSet = (ExternalDataPE) externalDataDAO.tryToFindDataSetByCode(dataSetCode);
assertEquals(externalData.getCode(), dataSet.getCode());
assertEquals(externalData.getDataSetType(), dataSet.getDataSetType());
assertEquals(externalData.getProcedure(), dataSet.getProcedure());
assertEquals(externalData.getFileFormatType(), dataSet.getFileFormatType());
assertEquals(externalData.getLocatorType(), dataSet.getLocatorType());
assertEquals(externalData.getLocation(), dataSet.getLocation());
assertEquals(externalData.getComplete(), dataSet.getComplete());
assertEquals(externalData.getStorageFormat(), dataSet.getStorageFormat());
assertEquals(externalData.isPlaceholder(), dataSet.isPlaceholder());
}
@Test
public void testUpdateDataSet()
{
IExternalDataDAO externalDataDAO = daoFactory.getExternalDataDAO();
DataPE data = new DataPE();
String dataSetCode = externalDataDAO.createDataSetCode();
data.setCode(dataSetCode);
data.setDataSetType(getDataSetType(DataSetTypeCode.UNKNOWN));
data.setProcedure(pickAProcedure());
data.setSampleDerivedFrom(pickASample());
data.setPlaceholder(true);
externalDataDAO.createDataSet(data);
ExternalDataPE externalData = new ExternalDataPE();
externalData.setId(externalDataDAO.tryToFindDataSetByCode(dataSetCode).getId());
externalData.setCode(dataSetCode);
externalData.setDataSetType(getDataSetType(DataSetTypeCode.HCS_IMAGE));
externalData.setProcedure(pickAProcedure());
externalData.setSampleAcquiredFrom(pickASample());
externalData.setFileFormatType(pickAFileFormatType());
externalData.setLocatorType(pickALocatorType());
externalData.setLocation("abcd");
externalData.setComplete(BooleanOrUnknown.U);
externalData.setStorageFormatVocabularyTerm(pickAStorageFormatVocabularyTerm());
externalData.setPlaceholder(true);
externalDataDAO.updateDataSet(externalData);
ExternalDataPE dataSet = (ExternalDataPE) externalDataDAO.tryToFindDataSetByCode(dataSetCode);
assertEquals(externalData.getCode(), dataSet.getCode());
assertEquals(externalData.getDataSetType(), dataSet.getDataSetType());
assertEquals(externalData.getProcedure(), dataSet.getProcedure());
assertEquals(externalData.getFileFormatType(), dataSet.getFileFormatType());
assertEquals(externalData.getLocatorType(), dataSet.getLocatorType());
assertEquals(externalData.getLocation(), dataSet.getLocation());
assertEquals(externalData.getComplete(), dataSet.getComplete());
assertEquals(externalData.getStorageFormat(), dataSet.getStorageFormat());
assertEquals(externalData.isPlaceholder(), dataSet.isPlaceholder());
}
protected VocabularyTermPE pickAStorageFormatVocabularyTerm()
{
String code = StorageFormat.VOCABULARY_CODE;
VocabularyPE vocabulary = daoFactory.getVocabularyDAO().tryFindVocabularyByCode(code);
assertNotNull(vocabulary);
return vocabulary.getTerms().iterator().next();
}
protected FileFormatTypePE pickAFileFormatType()
{
IFileFormatTypeDAO fileFormatTypeDAO = daoFactory.getFileFormatTypeDAO();
FileFormatTypePE fileFormatType = fileFormatTypeDAO.tryToFindFileFormatTypeByCode("TIFF");
assertNotNull(fileFormatType);
return fileFormatType;
}
protected LocatorTypePE pickALocatorType()
{
ILocatorTypeDAO locatorTypeDAO = daoFactory.getLocatorTypeDAO();
LocatorTypePE locatorType = locatorTypeDAO.tryToFindLocatorTypeByCode("RELATIVE_LOCATION");
assertNotNull(locatorType);
return locatorType;
}
protected SamplePE pickASample()
{
ISampleDAO sampleDAO = daoFactory.getSampleDAO();
DatabaseInstancePE dbInstance = daoFactory.getHomeDatabaseInstance();
SamplePE sample = sampleDAO.tryFindByCodeAndDatabaseInstance("MP", dbInstance, HierarchyType.CHILD);
assertNotNull(sample);
return sample;
}
protected DataSetTypePE getDataSetType(DataSetTypeCode type)
{
IDataSetTypeDAO dataSetTypeDAO = daoFactory.getDataSetTypeDAO();
String code = type.getCode();
DataSetTypePE dataSetType = dataSetTypeDAO.tryToFindDataSetTypeByCode(code);
assertNotNull(dataSetType);
return dataSetType;
}
protected ProcedurePE pickAProcedure()
{
List<ExperimentPE> experiments = daoFactory.getExperimentDAO().listExperiments();
for (ExperimentPE experimentPE : experiments)
{ {
fail = false; List<ProcedurePE> procedures = experimentPE.getProcedures();
if (procedures.isEmpty() == false)
{
return procedures.get(0);
}
} }
assertFalse(fail); fail("No experiment with a procedure found.");
return null; // to make the compiler happy
} }
} }
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