Skip to content
Snippets Groups Projects
Commit 37138d76 authored by cramakri's avatar cramakri
Browse files

LMS-1811 Updated CinaBundleDataSetHandler and its test.

SVN: 18285
parent 5b6345e8
No related branches found
No related tags found
No related merge requests found
/*
* 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 ch.systemsx.cisd.cina.dss.bundle;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import ch.systemsx.cisd.etlserver.IDataSetHandler;
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.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/**
* Helper to help registering bundle data sets.
* <p>
* This helper registers the entire bundle as one data set.
*
* @author Chandrasekhar Ramakrishnan
*/
class BundleDataSetHelper
{
static class BundleRegistrationGlobalState
{
private final IDataSetHandler delegator;
private final IEncapsulatedOpenBISService openbisService;
private final SampleType replicaSampleType;
private final DataSetTypeWithVocabularyTerms imageDataSetType;
BundleRegistrationGlobalState(IDataSetHandler delegator,
IEncapsulatedOpenBISService openbisService, SampleType replicaSampleType,
DataSetTypeWithVocabularyTerms imageDataSetType)
{
this.delegator = delegator;
this.openbisService = openbisService;
this.replicaSampleType = replicaSampleType;
this.imageDataSetType = imageDataSetType;
}
IDataSetHandler getDelegator()
{
return delegator;
}
IEncapsulatedOpenBISService getOpenbisService()
{
return openbisService;
}
SampleType getReplicaSampleType()
{
return replicaSampleType;
}
DataSetTypeWithVocabularyTerms getImageDataSetType()
{
return imageDataSetType;
}
}
protected final BundleRegistrationGlobalState globalState;
protected final File dataSet;
protected final ArrayList<DataSetInformation> dataSetInformation;
BundleDataSetHelper(BundleRegistrationGlobalState globalState, File dataSet)
{
this.globalState = globalState;
this.dataSet = dataSet;
this.dataSetInformation = new ArrayList<DataSetInformation>();
}
public void process()
{
// Register the bundle as one data set
List<DataSetInformation> bigDataSet = getDelegator().handleDataSet(dataSet);
dataSetInformation.addAll(bigDataSet);
}
protected IDataSetHandler getDelegator()
{
return globalState.getDelegator();
}
protected IEncapsulatedOpenBISService getOpenbisService()
{
return globalState.getOpenbisService();
}
/**
* Get all the data set information that has been created as a result of {@link #process}. Only
* makes sense to invoke after process has been called
*/
public ArrayList<DataSetInformation> getDataSetInformation()
{
return dataSetInformation;
}
}
/*
* 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 ch.systemsx.cisd.cina.dss.bundle;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import ch.systemsx.cisd.cina.shared.metadata.BundleMetadataExtractor;
import ch.systemsx.cisd.cina.shared.metadata.ImageMetadataExtractor;
import ch.systemsx.cisd.cina.shared.metadata.ReplicaMetadataExtractor;
import ch.systemsx.cisd.etlserver.IDataSetHandler;
import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyTypeWithVocabulary;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier;
/**
* Helper class for processing bundle data sets.
* <p>
* This helper registers the entire bundle as one data set, generates samples for each replica, and
* registers each file as a data set associated with the sample.
*
* @author Chandrasekhar Ramakrishnan
*/
class BundleDataSetHelperRpc extends BundleDataSetHelper
{
private static final String MISC_DATA_SET_PROPERTY_CODE = "MISC";
// Invocation-specific State
private final SessionContextDTO sessionContext;
private final IDataSetHandlerRpc delegatorRpc;
BundleDataSetHelperRpc(BundleRegistrationGlobalState globalState, File dataSet)
{
super(globalState, dataSet);
IDataSetHandler delegator = globalState.getDelegator();
if (delegator instanceof IDataSetHandlerRpc)
{
delegatorRpc = (IDataSetHandlerRpc) delegator;
this.sessionContext = delegatorRpc.getSessionContext();
} else
{
throw new IllegalArgumentException(
"BundleDataSetHelperRpc used with non-RPC data set handler.");
}
}
/**
*
*/
@Override
public void process()
{
String dataSetName = dataSet.getName();
// Register the bundle as one data set
super.process();
if (dataSetInformation.isEmpty())
{
return;
}
ExternalData bigData =
getOpenbisService().tryGetDataSet(sessionContext.getSessionToken(),
getBigDataSetInformation().getDataSetCode());
File containerFile = delegatorRpc.getFileForExternalData(bigData);
File bundle = new File(containerFile, dataSetName);
BundleMetadataExtractor bundleMetadata = new BundleMetadataExtractor(bundle);
bundleMetadata.prepare();
for (ReplicaMetadataExtractor replicaMetadata : bundleMetadata.getReplicaMetadataExtractors())
{
handleDerivedDataSets(replicaMetadata);
}
}
private void handleDerivedDataSets(ReplicaMetadataExtractor replicaMetadata)
{
SampleIdentifier sampleId = registerReplicaSample();
// Register all the data sets derived from this sample
for (ImageMetadataExtractor imageMetadata : replicaMetadata.getImageMetadataExtractors())
{
handleDerivedDataSet(sampleId, imageMetadata);
}
}
/**
* Register a sample with this ID of type GRID_REPLICA, either derived from the GRID_TEMPLATE
* registered by the client or associated with the experiment.
*/
private SampleIdentifier registerReplicaSample()
{
DataSetInformation bigDataSetInfo = getBigDataSetInformation();
SampleType replicaSampleType = globalState.getReplicaSampleType();
long sampleCodeSuffix = getOpenbisService().drawANewUniqueID();
String sampleCode =
String.format("%s%d", replicaSampleType.getGeneratedCodePrefix(), sampleCodeSuffix);
ExperimentIdentifier experimentIdOrNull = bigDataSetInfo.getExperimentIdentifier();
SampleIdentifier parentIdOrNull = bigDataSetInfo.getSampleIdentifier();
// Either the experimentId or the parentId must be non-null
assert experimentIdOrNull != null || parentIdOrNull != null;
SampleIdentifier sampleId = null;
NewSample sample = null;
if (parentIdOrNull != null)
{
Sample parentSample = getOpenbisService().tryGetSampleWithExperiment(parentIdOrNull);
sampleId = new SampleIdentifier(parentIdOrNull.getSpaceLevel(), sampleCode);
sample =
NewSample.createWithParent(sampleId.toString(), replicaSampleType, null,
parentIdOrNull.toString());
sample.setExperimentIdentifier(parentSample.getExperiment().getIdentifier());
} else if (experimentIdOrNull != null)
{
SpaceIdentifier spaceId =
new SpaceIdentifier(experimentIdOrNull.getDatabaseInstanceCode(),
experimentIdOrNull.getSpaceCode());
sampleId = new SampleIdentifier(spaceId, sampleCode);
sample = NewSample.createWithParent(sampleId.toString(), replicaSampleType, null, null);
sample.setExperimentIdentifier(experimentIdOrNull.toString());
}
String userIdOrNull = (sessionContext == null) ? null : sessionContext.getUserName();
getOpenbisService().registerSample(sample, userIdOrNull);
return sampleId;
}
private void handleDerivedDataSet(SampleIdentifier sampleId,
ImageMetadataExtractor imageMetadata)
{
// Create a DataSetInformation
DataSetInformation imageDataSetInfo = createDataSetInformation(sampleId);
// Import the metadata
ArrayList<NewProperty> properties = createDataSetProperties(imageMetadata);
imageDataSetInfo.setDataSetProperties(properties);
File imageDataSet = imageMetadata.getFolder();
delegatorRpc.linkAndHandleDataSet(imageDataSet, imageDataSetInfo);
}
private ArrayList<NewProperty> createDataSetProperties(ImageMetadataExtractor imageMetadata)
{
List<PropertyTypeWithVocabulary> propertyTypes =
globalState.getImageDataSetType().getPropertyTypes();
ArrayList<NewProperty> properties = new ArrayList<NewProperty>();
for (PropertyTypeWithVocabulary propertyType : propertyTypes)
{
String value = imageMetadata.getMetadataMap().get(propertyType.getCode().toLowerCase());
if (null != value)
{
NewProperty prop;
prop = new NewProperty(propertyType.getCode(), value);
properties.add(prop);
}
}
// Add a property with everything
properties.add(new NewProperty(MISC_DATA_SET_PROPERTY_CODE, imageMetadata.getMetadataMap()
.toString()));
return properties;
}
private DataSetInformation createDataSetInformation(SampleIdentifier sampleId)
{
DataSetInformation imageDataSetInfo = new DataSetInformation();
imageDataSetInfo.setSampleCode(sampleId.getSampleCode());
imageDataSetInfo.setSpaceCode(sampleId.getSpaceLevel().getSpaceCode());
imageDataSetInfo.setInstanceCode(sampleId.getSpaceLevel().getDatabaseInstanceCode());
imageDataSetInfo.setDataSetType(globalState.getImageDataSetType().getDataSetType());
imageDataSetInfo.setParentDataSetCodes(Collections.singletonList(getBigDataSetInformation()
.getDataSetCode()));
return imageDataSetInfo;
}
/**
* Get the "big data set" -- the one that is the parent of all the derived data sets I register
*/
private DataSetInformation getBigDataSetInformation()
{
// The big data set is the first one registered.
return dataSetInformation.get(0);
}
}
...@@ -20,14 +20,12 @@ import java.io.File; ...@@ -20,14 +20,12 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import ch.systemsx.cisd.cina.dss.bundle.BundleDataSetHelper.BundleRegistrationGlobalState; import ch.systemsx.cisd.cina.dss.bundle.registrators.BundleRegistrationState;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants; import ch.systemsx.cisd.cina.dss.bundle.registrators.GridPreparationRegistrator;
import ch.systemsx.cisd.etlserver.IDataSetHandler; import ch.systemsx.cisd.etlserver.IDataSetHandler;
import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc; import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/** /**
* CINA registers data in the form of a bundle. A bundle contains several different kinds data sets. * CINA registers data in the form of a bundle. A bundle contains several different kinds data sets.
...@@ -84,23 +82,30 @@ public class CinaBundleDataSetHandler implements IDataSetHandler ...@@ -84,23 +82,30 @@ public class CinaBundleDataSetHandler implements IDataSetHandler
{ {
private final IDataSetHandler delegator; private final IDataSetHandler delegator;
private final BundleRegistrationGlobalState bundleRegistrationState; private final BundleRegistrationState bundleRegistrationState;
public CinaBundleDataSetHandler(Properties parentProperties, IDataSetHandler delegator, public CinaBundleDataSetHandler(Properties parentProperties, IDataSetHandler delegator,
IEncapsulatedOpenBISService openbisService) IEncapsulatedOpenBISService openbisService)
{ {
this.delegator = delegator; this.delegator = delegator;
this.bundleRegistrationState = createBundleRegistrationState(delegator, openbisService); if (delegator instanceof IDataSetHandlerRpc)
{
this.bundleRegistrationState =
createBundleRegistrationState((IDataSetHandlerRpc) delegator, openbisService);
} else
{
this.bundleRegistrationState = null;
}
} }
public List<DataSetInformation> handleDataSet(File dataSet) public List<DataSetInformation> handleDataSet(File dataSet)
{ {
BundleDataSetHelper helper;
if (delegator instanceof IDataSetHandlerRpc) if (delegator instanceof IDataSetHandlerRpc)
{ {
helper = new BundleDataSetHelperRpc(bundleRegistrationState, dataSet); GridPreparationRegistrator registrator =
helper.process(); new GridPreparationRegistrator(bundleRegistrationState, dataSet);
return helper.getDataSetInformation(); registrator.register();
return registrator.getDataSetInformation();
} else } else
{ {
// We are not being invoked from the command line, so we don't have enough contextual // We are not being invoked from the command line, so we don't have enough contextual
...@@ -110,14 +115,9 @@ public class CinaBundleDataSetHandler implements IDataSetHandler ...@@ -110,14 +115,9 @@ public class CinaBundleDataSetHandler implements IDataSetHandler
} }
} }
private static BundleRegistrationGlobalState createBundleRegistrationState( private static BundleRegistrationState createBundleRegistrationState(
IDataSetHandler delegator, IEncapsulatedOpenBISService openbisService) IDataSetHandlerRpc delegator, IEncapsulatedOpenBISService openbisService)
{ {
SampleType replicaSampleType = return new BundleRegistrationState(delegator, openbisService);
openbisService.getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
DataSetTypeWithVocabularyTerms imageDataSetType =
openbisService.getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
return new BundleRegistrationGlobalState(delegator, openbisService, replicaSampleType,
imageDataSetType);
} }
} }
...@@ -17,104 +17,66 @@ ...@@ -17,104 +17,66 @@
package ch.systemsx.cisd.cina.dss.bundle; package ch.systemsx.cisd.cina.dss.bundle;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Properties; import java.util.Properties;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; import ch.systemsx.cisd.cina.dss.bundle.registrators.CinaBundleRegistrationTest;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
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.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
/** /**
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
public class CinaBundleDataSetHandlerTest extends AbstractFileSystemTestCase public class CinaBundleDataSetHandlerTest extends CinaBundleRegistrationTest
{ {
private Mockery context;
private IEncapsulatedOpenBISService openbisService;
private CinaBundleDataSetHandler handler; private CinaBundleDataSetHandler handler;
private IDataSetHandlerRpc delegator; /**
* First set up expectations for the case that the entities do not exist, then set up the
private ExternalData externalData; * expectations for existing entities to simulate registering new entities.
*/
@Override @Test
@BeforeMethod public void testHandlingWithCreationOfNewEntities()
public void setUp() throws IOException
{ {
super.setUp();
context = new Mockery();
openbisService = context.mock(IEncapsulatedOpenBISService.class);
setupOpenBisExpectations(); setupOpenBisExpectations();
setupSessionContextExpectations();
setupCallerDataSetInfoExpectations();
delegator = context.mock(IDataSetHandlerRpc.class); File dataSetFile =
new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/");
setupNewEntititesExpectations();
setupExistingGridPrepExpectations();
setupExistingReplicaExpectations();
setupHandleRawDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/RawData/ReplicTest");
setupHandleReplicaMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/ReplicTest");
setupHandleBundleMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/BundleMetadata.xml");
initializeDataSetHandler(); initializeDataSetHandler();
} handler.handleDataSet(dataSetFile);
@AfterMethod
public void tearDown()
{
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
// TODO: Changing the code used by this test; once finished, I'll fix the test to match the new /**
// code. * Set up the expectations for existing entities to simulate registering updating entities.
@Test(groups = "broken") */
public void testHandling() @Test
public void testRegistratorForExistingEntities()
{ {
setupOpenBisExpectations();
setupSessionContextExpectations();
setupCallerDataSetInfoExpectations();
File dataSetFile = File dataSetFile =
new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/"); new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/");
setupDataSetHandlerExpectations(dataSetFile);
context.checking(new Expectations()
{
private long uniqueId = 1;
private void delegatorHandleDataSetExpectation(final String path)
{
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode("Derived");
dataSetInformation.setSampleCode("" + uniqueId++);
dataSetInformation.setSpaceCode("Space");
dataSetInformation.setInstanceCode("Test");
allowing(delegator).linkAndHandleDataSet(with(new File(path)),
with(any(DataSetInformation.class)));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
{
allowing(openbisService).drawANewUniqueID();
will(returnValue(uniqueId++));
allowing(openbisService).registerSample(with(any(NewSample.class)),
with("test"));
will(returnValue(new Long(1)));
delegatorHandleDataSetExpectation("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/Replica for MRC files/MRC for Thomas/test20090422_BacklashRef.mrc");
delegatorHandleDataSetExpectation("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/Replica for MRC files/MRC for Thomas/test20090424_TrackAtZeroRef.mrc");
delegatorHandleDataSetExpectation("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/Replica for STEM files/STEM/stem_134588_1.imag");
}
});
setupExistingGridPrepExpectations();
setupExistingReplicaExpectations();
setupHandleReplicaMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/ReplicTest");
setupHandleBundleMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/BundleMetadata.xml");
initializeDataSetHandler();
handler.handleDataSet(dataSetFile); handler.handleDataSet(dataSetFile);
context.assertIsSatisfied(); context.assertIsSatisfied();
...@@ -131,68 +93,4 @@ public class CinaBundleDataSetHandlerTest extends AbstractFileSystemTestCase ...@@ -131,68 +93,4 @@ public class CinaBundleDataSetHandlerTest extends AbstractFileSystemTestCase
handler = new CinaBundleDataSetHandler(props, delegator, openbisService); handler = new CinaBundleDataSetHandler(props, delegator, openbisService);
} }
private void setupOpenBisExpectations()
{
final SampleType sampleType = new SampleType();
sampleType.setCode(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
sampleType.setAutoGeneratedCode(true);
sampleType.setGeneratedCodePrefix("Replica-");
DataSetType dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
final DataSetTypeWithVocabularyTerms dataSetTypeWithTerms =
new DataSetTypeWithVocabularyTerms();
dataSetTypeWithTerms.setDataSetType(dataSetType);
externalData = new ExternalData();
externalData.setCode("1");
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
will(returnValue(sampleType));
one(openbisService).getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
will(returnValue(dataSetTypeWithTerms));
one(openbisService).tryGetDataSet("session-token", externalData.getCode());
will(returnValue(externalData));
}
});
}
private void setupDataSetHandlerExpectations(final File dataSet)
{
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode(externalData.getCode());
dataSetInformation.setSampleCode("GRID-1");
dataSetInformation.setSpaceCode("Space");
dataSetInformation.setInstanceCode("Test");
final Sample sample = new Sample();
Experiment exp = new Experiment();
exp.setIdentifier("/Space/Exp-1");
sample.setExperiment(exp);
sample.setIdentifier(dataSetInformation.getSampleIdentifier().toString());
final SessionContextDTO sessionContext = new SessionContextDTO();
sessionContext.setSessionToken("session-token");
sessionContext.setUserEmail("test@test.bar");
sessionContext.setUserName("test");
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).handleDataSet(dataSet);
will(returnValue(Collections.singletonList(dataSetInformation)));
allowing(delegator).getSessionContext();
will(returnValue(sessionContext));
one(delegator).getFileForExternalData(externalData);
will(returnValue(dataSet.getParentFile()));
allowing(openbisService).tryGetSampleWithExperiment(
dataSetInformation.getSampleIdentifier());
will(returnValue(sample));
}
});
}
} }
/*
* 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 ch.systemsx.cisd.cina.dss.bundle.registrators;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
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.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory;
/**
* @author Chandrasekhar Ramakrishnan
*/
public abstract class CinaBundleRegistrationTest extends AbstractFileSystemTestCase
{
protected static final String TEST_USER_NAME = "test";
private static final String SESSION_TOKEN = "session-token";
private static final String RAW_IMAGES_DATA_SET_CODE = "RAW_IMAGES_DATA_SET_CODE";
private static final String METADATA_DATA_SET_CODE = "METADATA_DATA_SET_CODE";
private static final String DB_CODE = "DB";
private static final String SPACE_CODE = "SPACE";
protected static final String EXPERIMENT_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE
+ "/PROJECT/EXP-1";
private static final String GRID_SAMPLE_CODE = "GRID-CODE";
protected static final String GRID_SAMPLE_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/"
+ GRID_SAMPLE_CODE;
private static final String REPLICA_SAMPLE_CODE = "REPLICA-CODE";
protected static final String REPLICA_SAMPLE_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/"
+ REPLICA_SAMPLE_CODE;
private static final String BUNDLE_METADATA_DATA_SET_CODE = null;
public static abstract class MatcherNoDesc<T> extends BaseMatcher<T>
{
public void describeTo(Description description)
{
}
}
protected Mockery context;
protected IEncapsulatedOpenBISService openbisService;
protected IDataSetHandlerRpc delegator;
private ExternalData externalData;
private DataSetTypeWithVocabularyTerms rawImagesDataSetTypeWithTerms;
private DataSetTypeWithVocabularyTerms metadataDataSetTypeWithTerms;
private DataSetTypeWithVocabularyTerms imageDataSetTypeWithTerms;
/**
*
*
*/
public CinaBundleRegistrationTest()
{
super();
}
/**
* @param cleanAfterMethod
*/
public CinaBundleRegistrationTest(boolean cleanAfterMethod)
{
super(cleanAfterMethod);
}
@Override
@BeforeMethod
public void setUp() throws IOException
{
super.setUp();
context = new Mockery();
openbisService = context.mock(IEncapsulatedOpenBISService.class);
delegator = context.mock(IDataSetHandlerRpc.class);
}
@AfterMethod
public void tearDown()
{
context.assertIsSatisfied();
}
protected void setupOpenBisExpectations()
{
final SampleType gridPrepSampleType = new SampleType();
gridPrepSampleType.setCode(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE);
gridPrepSampleType.setAutoGeneratedCode(true);
gridPrepSampleType.setGeneratedCodePrefix("GridPrep-");
final SampleType replicaSampleType = new SampleType();
replicaSampleType.setCode(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
replicaSampleType.setAutoGeneratedCode(true);
replicaSampleType.setGeneratedCodePrefix("Replica-");
DataSetType dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
rawImagesDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
rawImagesDataSetTypeWithTerms.setDataSetType(dataSetType);
dataSetType = new DataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
metadataDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
metadataDataSetTypeWithTerms.setDataSetType(dataSetType);
dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
imageDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
imageDataSetTypeWithTerms.setDataSetType(dataSetType);
externalData = new ExternalData();
externalData.setCode("1");
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).getSampleType(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE);
will(returnValue(gridPrepSampleType));
one(openbisService).getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
will(returnValue(replicaSampleType));
one(openbisService).getDataSetType(CinaConstants.RAW_IMAGES_DATA_SET_TYPE_CODE);
will(returnValue(rawImagesDataSetTypeWithTerms));
one(openbisService).getDataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
will(returnValue(metadataDataSetTypeWithTerms));
one(openbisService).getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
will(returnValue(imageDataSetTypeWithTerms));
// one(openbisService).tryGetDataSet("session-token", externalData.getCode());
// will(returnValue(externalData));
}
});
}
protected void setupExistingGridPrepExpectations()
{
final Sample sample = new Sample();
Experiment exp = new Experiment();
exp.setIdentifier(EXPERIMENT_IDENTIFIER);
sample.setExperiment(exp);
sample.setIdentifier(GRID_SAMPLE_IDENTIFIER);
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(GRID_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(sample));
}
});
}
protected void setupExistingReplicaExpectations()
{
final Sample sample = new Sample();
Experiment exp = new Experiment();
exp.setIdentifier(EXPERIMENT_IDENTIFIER);
sample.setExperiment(exp);
sample.setIdentifier(REPLICA_SAMPLE_IDENTIFIER);
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(sample));
}
});
}
protected void setupHandleRawDataSetExpectations(final String path)
{
// Create the Raw Images Data Set
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode(RAW_IMAGES_DATA_SET_CODE);
dataSetInformation.setSampleCode(REPLICA_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).handleDataSet(with(new File(path)),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
rawImagesDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
}
protected void setupHandleReplicaMetadataDataSetExpectations(final String path)
{
// Create the Raw Images Data Set
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode(METADATA_DATA_SET_CODE);
dataSetInformation.setSampleCode(REPLICA_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
externalData = new ExternalData();
externalData.setCode(METADATA_DATA_SET_CODE);
final File dataSetFile = new File(path);
final File imageDataSetFile = new File(dataSetFile, "stem_134629_1.imag");
// set up the expectations
context.checking(new Expectations()
{
{
// Register the metadata data set
one(delegator).handleDataSet(with(dataSetFile),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
metadataDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
// Retrieve the registered data set from openBIS
one(openbisService).tryGetDataSet(SESSION_TOKEN, METADATA_DATA_SET_CODE);
will(returnValue(externalData));
// Retrieve the registered data set from the store
one(delegator).getFileForExternalData(externalData);
will(returnValue(dataSetFile.getParentFile()));
// Register the images data set
one(delegator).linkAndHandleDataSet(with(imageDataSetFile),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
imageDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
}
protected void setupHandleBundleMetadataDataSetExpectations(final String path)
{
// Create the Raw Images Data Set
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode(BUNDLE_METADATA_DATA_SET_CODE);
dataSetInformation.setSampleCode(GRID_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
final File dataSetFile = new File(path);
// set up the expectations
context.checking(new Expectations()
{
{
// Register the metadata data set
one(delegator).handleDataSet(with(dataSetFile),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
metadataDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(GRID_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
}
protected void setupCallerDataSetInfoExpectations()
{
final DataSetInformation callerDataSetInfo = new DataSetInformation();
callerDataSetInfo.setSpaceCode(SPACE_CODE);
callerDataSetInfo.setInstanceCode(DB_CODE);
callerDataSetInfo.setExperimentIdentifier(new ExperimentIdentifierFactory(
EXPERIMENT_IDENTIFIER).createIdentifier());
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).getCallerDataSetInformation();
will(returnValue(callerDataSetInfo));
}
});
}
protected void setupSessionContextExpectations()
{
final SessionContextDTO sessionContext = new SessionContextDTO();
sessionContext.setSessionToken(SESSION_TOKEN);
sessionContext.setUserEmail("test@test.bar");
sessionContext.setUserName(TEST_USER_NAME);
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).getSessionContext();
will(returnValue(sessionContext));
}
});
}
protected void setupNewEntititesExpectations()
{
context.checking(new Expectations()
{
{
// The Grid Prep does not yet exist
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(GRID_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(null));
// Create the Grid Prep
one(openbisService).registerSample(with(new BaseMatcher<NewSample>()
{
public boolean matches(Object item)
{
if (item instanceof NewSample)
{
NewSample newSample = (NewSample) item;
assertEquals(GRID_SAMPLE_IDENTIFIER, newSample.getIdentifier());
assertEquals(EXPERIMENT_IDENTIFIER.toString(),
newSample.getExperimentIdentifier());
assertEquals(null, newSample.getParentIdentifier());
return true;
}
return false;
}
public void describeTo(Description description)
{
}
}), with(TEST_USER_NAME));
will(returnValue(new Long(1)));
// The Replica does not yet exist
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(null));
// Create the Replica
one(openbisService).registerSample(with(new MatcherNoDesc<NewSample>()
{
public boolean matches(Object item)
{
if (item instanceof NewSample)
{
NewSample newSample = (NewSample) item;
assertEquals(REPLICA_SAMPLE_IDENTIFIER,
newSample.getIdentifier());
assertEquals(EXPERIMENT_IDENTIFIER.toString(),
newSample.getExperimentIdentifier());
assertEquals(GRID_SAMPLE_IDENTIFIER,
newSample.getParentIdentifier());
return true;
}
return false;
}
}), with(TEST_USER_NAME));
will(returnValue(new Long(2)));
}
});
}
}
\ No newline at end of file
...@@ -17,108 +17,18 @@ ...@@ -17,108 +17,18 @@
package ch.systemsx.cisd.cina.dss.bundle.registrators; package ch.systemsx.cisd.cina.dss.bundle.registrators;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Collections;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory;
/** /**
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase public class GridPreparationRegistratorTest extends CinaBundleRegistrationTest
{ {
private static final String TEST_USER_NAME = "test"; protected GridPreparationRegistrator registrator;
private static final String SESSION_TOKEN = "session-token";
private static final String RAW_IMAGES_DATA_SET_CODE = "RAW_IMAGES_DATA_SET_CODE";
private static final String METADATA_DATA_SET_CODE = "METADATA_DATA_SET_CODE";
// Constants used in the test
private static final String DB_CODE = "DB";
private static final String SPACE_CODE = "SPACE";
private static final String EXPERIMENT_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE
+ "/PROJECT/EXP-1";
private static final String GRID_SAMPLE_CODE = "GRID-CODE";
private static final String GRID_SAMPLE_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/"
+ GRID_SAMPLE_CODE;
private static final String REPLICA_SAMPLE_CODE = "REPLICA-CODE";
private static final String REPLICA_SAMPLE_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/"
+ REPLICA_SAMPLE_CODE;
private static final String BUNDLE_METADATA_DATA_SET_CODE = null;
private static abstract class MatcherNoDesc<T> extends BaseMatcher<T>
{
public void describeTo(Description description)
{
}
}
private Mockery context;
private IEncapsulatedOpenBISService openbisService;
private IDataSetHandlerRpc delegator;
private ExternalData externalData;
private GridPreparationRegistrator registrator;
private DataSetTypeWithVocabularyTerms rawImagesDataSetTypeWithTerms;
private DataSetTypeWithVocabularyTerms metadataDataSetTypeWithTerms;
private DataSetTypeWithVocabularyTerms imageDataSetTypeWithTerms;
@Override
@BeforeMethod
public void setUp() throws IOException
{
super.setUp();
context = new Mockery();
openbisService = context.mock(IEncapsulatedOpenBISService.class);
delegator = context.mock(IDataSetHandlerRpc.class);
}
@AfterMethod
public void tearDown()
{
context.assertIsSatisfied();
}
@Test(expectedExceptions = @Test(expectedExceptions =
{ AssertionError.class }) { AssertionError.class })
...@@ -160,66 +70,7 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase ...@@ -160,66 +70,7 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
File dataSetFile = File dataSetFile =
new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/"); new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/");
context.checking(new Expectations() setupNewEntititesExpectations();
{
{
// The Grid Prep does not yet exist
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(GRID_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(null));
// Create the Grid Prep
one(openbisService).registerSample(with(new BaseMatcher<NewSample>()
{
public boolean matches(Object item)
{
if (item instanceof NewSample)
{
NewSample newSample = (NewSample) item;
assertEquals(GRID_SAMPLE_IDENTIFIER, newSample.getIdentifier());
assertEquals(EXPERIMENT_IDENTIFIER.toString(),
newSample.getExperimentIdentifier());
assertEquals(null, newSample.getParentIdentifier());
return true;
}
return false;
}
public void describeTo(Description description)
{
}
}), with(TEST_USER_NAME));
will(returnValue(new Long(1)));
// The Replica does not yet exist
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(null));
// Create the Replica
one(openbisService).registerSample(with(new MatcherNoDesc<NewSample>()
{
public boolean matches(Object item)
{
if (item instanceof NewSample)
{
NewSample newSample = (NewSample) item;
assertEquals(REPLICA_SAMPLE_IDENTIFIER,
newSample.getIdentifier());
assertEquals(EXPERIMENT_IDENTIFIER.toString(),
newSample.getExperimentIdentifier());
assertEquals(GRID_SAMPLE_IDENTIFIER,
newSample.getParentIdentifier());
return true;
}
return false;
}
}), with(TEST_USER_NAME));
will(returnValue(new Long(2)));
}
});
setupExistingGridPrepExpectations(); setupExistingGridPrepExpectations();
setupExistingReplicaExpectations(); setupExistingReplicaExpectations();
...@@ -233,241 +84,28 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase ...@@ -233,241 +84,28 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
private void setupOpenBisExpectations() /**
{ * Set up the expectations for existing entities to simulate registering updating entities.
final SampleType gridPrepSampleType = new SampleType(); */
gridPrepSampleType.setCode(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE); @Test
gridPrepSampleType.setAutoGeneratedCode(true); public void testRegistratorForExistingEntities()
gridPrepSampleType.setGeneratedCodePrefix("GridPrep-");
final SampleType replicaSampleType = new SampleType();
replicaSampleType.setCode(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
replicaSampleType.setAutoGeneratedCode(true);
replicaSampleType.setGeneratedCodePrefix("Replica-");
DataSetType dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
rawImagesDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
rawImagesDataSetTypeWithTerms.setDataSetType(dataSetType);
dataSetType = new DataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
metadataDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
metadataDataSetTypeWithTerms.setDataSetType(dataSetType);
dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
imageDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
imageDataSetTypeWithTerms.setDataSetType(dataSetType);
externalData = new ExternalData();
externalData.setCode("1");
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).getSampleType(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE);
will(returnValue(gridPrepSampleType));
one(openbisService).getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
will(returnValue(replicaSampleType));
one(openbisService).getDataSetType(CinaConstants.RAW_IMAGES_DATA_SET_TYPE_CODE);
will(returnValue(rawImagesDataSetTypeWithTerms));
one(openbisService).getDataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
will(returnValue(metadataDataSetTypeWithTerms));
one(openbisService).getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
will(returnValue(imageDataSetTypeWithTerms));
// one(openbisService).tryGetDataSet("session-token", externalData.getCode());
// will(returnValue(externalData));
}
});
}
private void setupExistingGridPrepExpectations()
{
final Sample sample = new Sample();
Experiment exp = new Experiment();
exp.setIdentifier(EXPERIMENT_IDENTIFIER);
sample.setExperiment(exp);
sample.setIdentifier(GRID_SAMPLE_IDENTIFIER);
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(GRID_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(sample));
}
});
}
private void setupExistingReplicaExpectations()
{
final Sample sample = new Sample();
Experiment exp = new Experiment();
exp.setIdentifier(EXPERIMENT_IDENTIFIER);
sample.setExperiment(exp);
sample.setIdentifier(REPLICA_SAMPLE_IDENTIFIER);
// set up the expectations
context.checking(new Expectations()
{
{
one(openbisService).tryGetSampleWithExperiment(
with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER)
.createIdentifier()));
will(returnValue(sample));
}
});
}
private void setupHandleRawDataSetExpectations(final String path)
{
// Create the Raw Images Data Set
final DataSetInformation dataSetInformation = new DataSetInformation();
dataSetInformation.setDataSetCode(RAW_IMAGES_DATA_SET_CODE);
dataSetInformation.setSampleCode(REPLICA_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).handleDataSet(with(new File(path)),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
rawImagesDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
}
private void setupHandleReplicaMetadataDataSetExpectations(final String path)
{ {
// Create the Raw Images Data Set setupOpenBisExpectations();
final DataSetInformation dataSetInformation = new DataSetInformation(); setupSessionContextExpectations();
dataSetInformation.setDataSetCode(METADATA_DATA_SET_CODE); setupCallerDataSetInfoExpectations();
dataSetInformation.setSampleCode(REPLICA_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
externalData = new ExternalData();
externalData.setCode(METADATA_DATA_SET_CODE);
final File dataSetFile = new File(path);
final File imageDataSetFile = new File(dataSetFile, "stem_134629_1.imag");
// set up the expectations
context.checking(new Expectations()
{
{
// Register the metadata data set
one(delegator).handleDataSet(with(dataSetFile),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
metadataDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
// Retrieve the registered data set from openBIS
one(openbisService).tryGetDataSet(SESSION_TOKEN, METADATA_DATA_SET_CODE);
will(returnValue(externalData));
// Retrieve the registered data set from the store
one(delegator).getFileForExternalData(externalData);
will(returnValue(dataSetFile.getParentFile()));
// Register the images data set File dataSetFile =
one(delegator).linkAndHandleDataSet(with(imageDataSetFile), new File("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/");
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
imageDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(REPLICA_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
}
private void setupHandleBundleMetadataDataSetExpectations(final String path) setupExistingGridPrepExpectations();
{ setupExistingReplicaExpectations();
// Create the Raw Images Data Set setupHandleReplicaMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/ReplicTest");
final DataSetInformation dataSetInformation = new DataSetInformation(); setupHandleBundleMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/BundleMetadata.xml");
dataSetInformation.setDataSetCode(BUNDLE_METADATA_DATA_SET_CODE);
dataSetInformation.setSampleCode(GRID_SAMPLE_CODE);
dataSetInformation.setSpaceCode(SPACE_CODE);
dataSetInformation.setInstanceCode(DB_CODE);
final File dataSetFile = new File(path); createRegistrator(dataSetFile);
registrator.register();
// set up the expectations context.assertIsSatisfied();
context.checking(new Expectations()
{
{
// Register the metadata data set
one(delegator).handleDataSet(with(dataSetFile),
with(new MatcherNoDesc<DataSetInformation>()
{
public boolean matches(Object item)
{
if (item instanceof DataSetInformation)
{
DataSetInformation dataSetInfo =
(DataSetInformation) item;
assertEquals(
metadataDataSetTypeWithTerms.getDataSetType(),
dataSetInfo.getDataSetType());
assertEquals(GRID_SAMPLE_CODE,
dataSetInfo.getSampleCode());
return true;
}
return false;
}
}));
will(returnValue(Collections.singletonList(dataSetInformation)));
}
});
} }
private void createRegistrator(final File dataSet) private void createRegistrator(final File dataSet)
...@@ -475,46 +113,8 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase ...@@ -475,46 +113,8 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
registrator = new GridPreparationRegistrator(createBundleRegistrationState(), dataSet); registrator = new GridPreparationRegistrator(createBundleRegistrationState(), dataSet);
} }
private void setupCallerDataSetInfoExpectations()
{
final DataSetInformation callerDataSetInfo = new DataSetInformation();
callerDataSetInfo.setSpaceCode(SPACE_CODE);
callerDataSetInfo.setInstanceCode(DB_CODE);
callerDataSetInfo.setExperimentIdentifier(new ExperimentIdentifierFactory(
EXPERIMENT_IDENTIFIER).createIdentifier());
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).getCallerDataSetInformation();
will(returnValue(callerDataSetInfo));
}
});
}
private void setupSessionContextExpectations()
{
final SessionContextDTO sessionContext = new SessionContextDTO();
sessionContext.setSessionToken(SESSION_TOKEN);
sessionContext.setUserEmail("test@test.bar");
sessionContext.setUserName(TEST_USER_NAME);
// set up the expectations
context.checking(new Expectations()
{
{
one(delegator).getSessionContext();
will(returnValue(sessionContext));
}
});
}
private BundleRegistrationState createBundleRegistrationState() private BundleRegistrationState createBundleRegistrationState()
{ {
return new BundleRegistrationState(delegator, openbisService); return new BundleRegistrationState(delegator, openbisService);
} }
} }
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