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

SSDM-1621: tests fixed

SVN: 33713
parent 6419727a
No related branches found
No related tags found
No related merge requests found
...@@ -790,7 +790,13 @@ abstract class AbstractBusinessObject implements IDAOFactory ...@@ -790,7 +790,13 @@ abstract class AbstractBusinessObject implements IDAOFactory
{ {
assignmentManager.assignDataSetAndRelatedComponents(dataSet, sample, newExperiment); assignmentManager.assignDataSetAndRelatedComponents(dataSet, sample, newExperiment);
} }
relationshipService.assignSampleToExperiment(session, sample, newExperiment); if (newExperiment != null)
{
relationshipService.assignSampleToExperiment(session, sample, newExperiment);
} else
{
relationshipService.unassignSampleFromExperiment(session, sample);
}
assignmentManager.performAssignment(relationshipService, session); assignmentManager.performAssignment(relationshipService, session);
} }
......
...@@ -37,6 +37,7 @@ import org.testng.annotations.Test; ...@@ -37,6 +37,7 @@ import org.testng.annotations.Test;
import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException; import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool; import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool;
import ch.systemsx.cisd.openbis.generic.server.business.bo.util.DataSetTypeWithoutExperimentChecker;
import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils; import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType;
...@@ -47,6 +48,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; ...@@ -47,6 +48,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
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.ExperimentPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSession; import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSession;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
...@@ -361,17 +364,14 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -361,17 +364,14 @@ public final class SampleBOTest extends AbstractBOTest
@Test @Test
public final void testDetachFromExperiment() public final void testDetachFromExperiment()
{ {
final SamplePE sample = createAnySample(); final SamplePE sample = createSampleWithExperiment();
sample.setExperiment(new ExperimentPE());
sample.setId(SAMPLE_TECH_ID.getId());
prepareExperimentUpdateOnly(sample); prepareExperimentUpdateOnly(sample);
context.checking(new Expectations() context.checking(new Expectations()
{ {
{ {
one(entityOperationChecker).assertInstanceSampleUpdateAllowed(with(any(IAuthSession.class)), with(any(List.class))); one(entityOperationChecker).assertInstanceSampleUpdateAllowed(with(any(IAuthSession.class)), with(any(List.class)));
one(relationshipService).unassignSampleFromExperiment( one(relationshipService).unassignSampleFromExperiment(EXAMPLE_SESSION, sample);
with(any(IAuthSession.class)), with(any(SamplePE.class)));
} }
}); });
...@@ -385,10 +385,13 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -385,10 +385,13 @@ public final class SampleBOTest extends AbstractBOTest
@Test @Test
public final void testDetachFromExperimentWithDatasetsFails() public final void testDetachFromExperimentWithDatasetsFails()
{ {
final SamplePE sample = createAnySample(); final SamplePE sample = createSampleWithExperiment();
sample.setExperiment(new ExperimentPE()); DataPE dataset = new DataPE();
sample.setId(SAMPLE_TECH_ID.getId()); dataset.setCode("DS1");
DataSetTypePE dataSetType = new DataSetTypePE();
dataSetType.setCode("T");
dataset.setDataSetType(dataSetType);
sample.addDataSet(dataset);
prepareTryToLoadOfSampleWithId(sample); prepareTryToLoadOfSampleWithId(sample);
prepareNoPropertiesToUpdate(sample); prepareNoPropertiesToUpdate(sample);
context.checking(new Expectations() context.checking(new Expectations()
...@@ -400,18 +403,17 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -400,18 +403,17 @@ public final class SampleBOTest extends AbstractBOTest
will(returnValue(true)); will(returnValue(true));
} }
}); });
ExperimentIdentifier experimentIdentifier = null;
String errorMsg =
"Cannot detach the sample '/XX' from the experiment because there are already datasets attached to the sample.";
try try
{ {
updateSampleExperiment(SAMPLE_TECH_ID, sample, experimentIdentifier); updateSampleExperiment(SAMPLE_TECH_ID, sample, null);
fail("UserFailureException expected");
} catch (UserFailureException e) } catch (UserFailureException e)
{ {
assertEquals(errorMsg, e.getMessage()); assertEquals("The dataset 'DS1' cannot be connected to the sample '/XX' because the new sample "
return; + "is not connected to any experiment and the data set type (T) doesn't "
+ "match one of the following regular expressions: NE.*.", e.getMessage());
} }
fail("Following exception expected: " + errorMsg);
} }
@Test @Test
...@@ -430,8 +432,6 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -430,8 +432,6 @@ public final class SampleBOTest extends AbstractBOTest
allowing(dataDAO).hasDataSet(with(sample)); allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(false)); will(returnValue(false));
allowing(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
one(relationshipService).shareSample(with(any(IAuthSession.class)), one(relationshipService).shareSample(with(any(IAuthSession.class)),
with(any(SamplePE.class))); with(any(SamplePE.class)));
...@@ -453,6 +453,7 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -453,6 +453,7 @@ public final class SampleBOTest extends AbstractBOTest
final ProjectPE project = createProject(); final ProjectPE project = createProject();
// create experiment which we will attach the sample // create experiment which we will attach the sample
final ExperimentPE experimentToAttach = new ExperimentPE(); final ExperimentPE experimentToAttach = new ExperimentPE();
experimentToAttach.setId(1L);
experimentToAttach.setCode("exp1"); experimentToAttach.setCode("exp1");
experimentToAttach.setProject(project); experimentToAttach.setProject(project);
final ExperimentIdentifier experimentIdentifier = new ExperimentIdentifier(); final ExperimentIdentifier experimentIdentifier = new ExperimentIdentifier();
...@@ -462,6 +463,7 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -462,6 +463,7 @@ public final class SampleBOTest extends AbstractBOTest
// create a sample already attached to an experiment // create a sample already attached to an experiment
final ExperimentPE sampleExperiment = new ExperimentPE(); final ExperimentPE sampleExperiment = new ExperimentPE();
sampleExperiment.setId(2L);
sampleExperiment.setCode("exp2"); sampleExperiment.setCode("exp2");
sampleExperiment.setProject(project); sampleExperiment.setProject(project);
final SamplePE sample = new SamplePE(); final SamplePE sample = new SamplePE();
...@@ -488,9 +490,7 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -488,9 +490,7 @@ public final class SampleBOTest extends AbstractBOTest
experimentIdentifier.getExperimentCode()); experimentIdentifier.getExperimentCode());
will(returnValue(experimentToAttach)); will(returnValue(experimentToAttach));
one(relationshipService).assignSampleToExperiment( one(relationshipService).assignSampleToExperiment(EXAMPLE_SESSION, sample, experimentToAttach);
with(any(IAuthSession.class)), with(any(SamplePE.class)),
with(any(ExperimentPE.class)));
} }
}); });
createSampleBO().update( createSampleBO().update(
...@@ -531,9 +531,6 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -531,9 +531,6 @@ public final class SampleBOTest extends AbstractBOTest
allowing(dataDAO).hasDataSet(with(sample)); allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(false)); will(returnValue(false));
allowing(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
allowing(relationshipService).removeSampleFromContainer( allowing(relationshipService).removeSampleFromContainer(
with(any(IAuthSession.class)), with(any(SamplePE.class))); with(any(IAuthSession.class)), with(any(SamplePE.class)));
...@@ -598,9 +595,6 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -598,9 +595,6 @@ public final class SampleBOTest extends AbstractBOTest
allowing(dataDAO).hasDataSet(with(sample)); allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(false)); will(returnValue(false));
allowing(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
allowing(relationshipService).removeSampleFromContainer( allowing(relationshipService).removeSampleFromContainer(
with(any(IAuthSession.class)), with(any(SamplePE.class))); with(any(IAuthSession.class)), with(any(SamplePE.class)));
...@@ -706,9 +700,6 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -706,9 +700,6 @@ public final class SampleBOTest extends AbstractBOTest
one(propertiesConverter).checkMandatoryProperties(sample.getProperties(), one(propertiesConverter).checkMandatoryProperties(sample.getProperties(),
sample.getSampleType()); sample.getSampleType());
allowing(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
allowing(spaceDAO).tryFindSpaceByCode(with("MY_GROUP")); allowing(spaceDAO).tryFindSpaceByCode(with("MY_GROUP"));
will(returnValue(EXAMPLE_GROUP)); will(returnValue(EXAMPLE_GROUP));
...@@ -734,7 +725,15 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -734,7 +725,15 @@ public final class SampleBOTest extends AbstractBOTest
public final void testEditSampleNoExperimentForSampleWithDatasets() public final void testEditSampleNoExperimentForSampleWithDatasets()
{ {
final SamplePE sample = createSample("sampleCode", EXAMPLE_GROUP); final SamplePE sample = createSample("sampleCode", EXAMPLE_GROUP);
sample.setExperiment(new ExperimentPE()); DataPE dataset = new DataPE();
dataset.setCode("DS1");
DataSetTypePE dataSetType = new DataSetTypePE();
dataSetType.setCode("T");
dataset.setDataSetType(dataSetType);
sample.addDataSet(dataset);
ExperimentPE experiment = new ExperimentPE();
experiment.setId(123L);
sample.setExperiment(experiment);
sample.setVersion(VERSION); sample.setVersion(VERSION);
...@@ -748,21 +747,19 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -748,21 +747,19 @@ public final class SampleBOTest extends AbstractBOTest
will(returnValue(true)); will(returnValue(true));
} }
}); });
boolean exceptionThrown = false;
try try
{ {
createSampleBO().update( createSampleBO().update(
new SampleUpdatesDTO(SAMPLE_TECH_ID, null, null, Collections new SampleUpdatesDTO(SAMPLE_TECH_ID, null, null, Collections
.<NewAttachment> emptyList(), VERSION, null, null, null)); .<NewAttachment> emptyList(), VERSION, null, null, null));
fail("UserFailureException expected");
} catch (UserFailureException ex) } catch (UserFailureException ex)
{ {
exceptionThrown = true; assertEquals("The dataset 'DS1' cannot be connected to the sample '/MY_GROUP/sampleCode' "
assertTrue(ex + "because the new sample is not connected to any experiment and the data set type (T) "
.getMessage() + "doesn't match one of the following regular expressions: NE.*.", ex.getMessage());
.contains(
"from the experiment because there are already datasets attached to the sample"));
} }
assertTrue(exceptionThrown);
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
...@@ -997,7 +994,7 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -997,7 +994,7 @@ public final class SampleBOTest extends AbstractBOTest
private final SampleBO createSampleBO() private final SampleBO createSampleBO()
{ {
return new SampleBO(daoFactory, EXAMPLE_SESSION, propertiesConverter, relationshipService, return new SampleBO(daoFactory, EXAMPLE_SESSION, propertiesConverter, relationshipService,
entityOperationChecker, managedPropertyEvaluatorFactory, null); entityOperationChecker, managedPropertyEvaluatorFactory, new DataSetTypeWithoutExperimentChecker("NE.*"));
} }
private SampleType createSampleType(final String sampleTypeCode) private SampleType createSampleType(final String sampleTypeCode)
...@@ -1088,6 +1085,16 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -1088,6 +1085,16 @@ public final class SampleBOTest extends AbstractBOTest
}); });
} }
private SamplePE createSampleWithExperiment()
{
final SamplePE sample = createAnySample();
ExperimentPE experiment = new ExperimentPE();
experiment.setId(1234L);
sample.setExperiment(experiment);
sample.setId(SAMPLE_TECH_ID.getId());
return sample;
}
private void updateSampleExperiment(final TechId sampleId, final SamplePE sample, private void updateSampleExperiment(final TechId sampleId, final SamplePE sample,
ExperimentIdentifier experimentIdentifier) ExperimentIdentifier experimentIdentifier)
{ {
......
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