Skip to content
Snippets Groups Projects
Commit 997250e0 authored by anttil's avatar anttil
Browse files

BIS-51 / SP-175: Re-enable tests that were disabled because authorization was...

BIS-51 / SP-175: Re-enable tests that were disabled because authorization was previously done by Identifier objects.

SVN: 26058
parent 50914be2
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; ...@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPropertyPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPropertyPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePropertyTypePE; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePropertyTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSession;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE; import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
...@@ -472,6 +473,49 @@ public final class ExperimentBOTest extends AbstractBOTest ...@@ -472,6 +473,49 @@ public final class ExperimentBOTest extends AbstractBOTest
assertEquals(newProject.getSpace(), assignedSample.getSpace()); assertEquals(newProject.getSpace(), assignedSample.getSpace());
} }
@Test
public final void testEditSamples()
{
// we test if this sample will stay assigned to the experiment if it was assigned before
SamplePE untouchedSample = createSampleWithCode("untouchedSample");
// we test unasignment of this sample from the experiment
SamplePE unassignedSample = createSampleWithCode("unassignedSample");
// we test if this sample will be assigned to the experiment
SamplePE assignedSample = createSampleWithCode("assignedSample");
final ExperimentIdentifier identifier = CommonTestUtils.createExperimentIdentifier();
final ExperimentPE exp = CommonTestUtils.createExperiment(identifier);
exp.setSamples(Arrays.asList(untouchedSample, unassignedSample));
prepareLoadExperimentByIdentifier(identifier, exp);
prepareTryFindSample(exp.getProject().getSpace(), assignedSample.getCode(), assignedSample);
prepareNoDatasetsFound();
final ExperimentBO expBO = loadExperiment(identifier, exp);
String[] editedSamples = new String[]
{ untouchedSample.getCode(), assignedSample.getCode() };
expBO.setExperimentSamples(editedSamples);
assertEquals(exp, untouchedSample.getExperiment());
}
private void prepareNoDatasetsFound()
{
context.checking(new Expectations()
{
{
allowing(dataDAO).hasDataSet((with(any(SamplePE.class))));
will(returnValue(false));
one(relationshipService).assignSampleToExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)),
with(any(ExperimentPE.class)));
one(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
}
});
}
@Test @Test
public final void testEditSamplesAddingAssignedSampleFails() public final void testEditSamplesAddingAssignedSampleFails()
{ {
......
...@@ -49,6 +49,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; ...@@ -49,6 +49,7 @@ 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.DatabaseInstancePE; 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.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;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
...@@ -61,6 +62,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceId ...@@ -61,6 +62,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceId
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory;
/** /**
* Test cases for corresponding {@link SampleBO} class. * Test cases for corresponding {@link SampleBO} class.
...@@ -377,6 +379,156 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -377,6 +379,156 @@ public final class SampleBOTest extends AbstractBOTest
createSampleBO().define(newSample); createSampleBO().define(newSample);
} }
@SuppressWarnings("unchecked")
@Test
public final void testDetachFromExperiment()
{
final SamplePE sample = createAnySample();
sample.setExperiment(new ExperimentPE());
sample.setId(SAMPLE_TECH_ID.getId());
prepareExperimentUpdateOnly(sample);
context.checking(new Expectations()
{
{
one(entityOperationChecker).assertInstanceSampleUpdateAllowed(
with(any(IAuthSession.class)), with(any(List.class)));
one(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
}
});
ExperimentIdentifier experimentIdentifier = null;
updateSampleExperiment(SAMPLE_TECH_ID, sample, experimentIdentifier);
context.assertIsSatisfied();
}
@SuppressWarnings("unchecked")
@Test
public final void testDetachFromExperimentWithDatasetsFails()
{
final SamplePE sample = createAnySample();
sample.setExperiment(new ExperimentPE());
sample.setId(SAMPLE_TECH_ID.getId());
prepareTryToLoadOfSampleWithId(sample);
prepareNoPropertiesToUpdate(sample);
context.checking(new Expectations()
{
{
allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(true));
one(entityOperationChecker).assertInstanceSampleUpdateAllowed(
with(any(IAuthSession.class)), with(any(List.class)));
}
});
ExperimentIdentifier experimentIdentifier = null;
String errorMsg =
"Cannot detach the sample 'CODE:/XX' from the experiment because there are already datasets attached to the sample.";
try
{
updateSampleExperiment(SAMPLE_TECH_ID, sample, experimentIdentifier);
} catch (UserFailureException e)
{
assertEquals(errorMsg, e.getMessage());
return;
}
fail("Following exception expected: " + errorMsg);
}
@Test
public final void testEditSampleChangeGroupToShared()
{
final SamplePE sample = createSample("sampleCode", EXAMPLE_GROUP);
Date now = new Date();
sample.setModificationDate(now);
prepareTryToLoadOfSampleWithId(sample);
prepareNoPropertiesToUpdate(sample);
context.checking(new Expectations()
{
{
allowing(daoFactory).getHomeDatabaseInstance();
will(returnValue(EXAMPLE_DATABASE_INSTANCE));
allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(false));
allowing(relationshipService).unassignSampleFromExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)));
one(relationshipService).shareSample(with(any(IAuthSession.class)),
with(any(SamplePE.class)));
}
});
String newSampleIdentifierWithoutDb = "/" + sample.getCode();
assertNotNull(sample.getSpace());
createSampleBO().update(
new SampleUpdatesDTO(SAMPLE_TECH_ID, null, null, Collections
.<NewAttachment> emptyList(), now, SampleIdentifierFactory
.parse(newSampleIdentifierWithoutDb), null, null));
context.assertIsSatisfied();
}
@Test
public final void testEditExperiment()
{
final ProjectPE project = createProject();
// create experiment which we will attach the sample
final ExperimentPE experimentToAttach = new ExperimentPE();
experimentToAttach.setCode("exp1");
experimentToAttach.setProject(project);
final ExperimentIdentifier experimentIdentifier = new ExperimentIdentifier();
experimentIdentifier.setExperimentCode("exp1");
experimentIdentifier.setProjectCode(project.getCode());
experimentIdentifier.setSpaceCode(project.getSpace().getCode());
experimentIdentifier.setDatabaseInstanceCode(project.getSpace().getDatabaseInstance()
.getCode());
// create a sample already attached to an experiment
final ExperimentPE sampleExperiment = new ExperimentPE();
sampleExperiment.setCode("exp2");
sampleExperiment.setProject(project);
final SamplePE sample = new SamplePE();
sample.setId(SAMPLE_TECH_ID.getId());
sample.setCode("sampleCode");
sample.setExperiment(sampleExperiment);
sample.setSpace(EXAMPLE_GROUP);
sample.setSampleType(createSampleTypePE(SAMPLE_TYPE));
Date now = new Date();
sample.setModificationDate(now);
prepareTryToLoadOfSampleWithId(sample);
prepareNoPropertiesToUpdate(sample);
context.checking(new Expectations()
{
{
one(projectDAO).tryFindProject(experimentIdentifier.getDatabaseInstanceCode(),
experimentIdentifier.getSpaceCode(),
experimentIdentifier.getProjectCode());
will(returnValue(project));
one(experimentDAO).tryFindByCodeAndProject(project,
experimentIdentifier.getExperimentCode());
will(returnValue(experimentToAttach));
one(relationshipService).assignSampleToExperiment(
with(any(IAuthSession.class)), with(any(SamplePE.class)),
with(any(ExperimentPE.class)));
}
});
createSampleBO().update(
new SampleUpdatesDTO(SAMPLE_TECH_ID, null, experimentIdentifier, Collections
.<NewAttachment> emptyList(), now, null, null, null));
context.assertIsSatisfied();
}
@Test @Test
public final void testEditSampleParent() public final void testEditSampleParent()
{ {
...@@ -634,6 +786,43 @@ public final class SampleBOTest extends AbstractBOTest ...@@ -634,6 +786,43 @@ public final class SampleBOTest extends AbstractBOTest
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@Test
public final void testEditSampleNoExperimentForSampleWithDatasets()
{
final SamplePE sample = createSample("sampleCode", EXAMPLE_GROUP);
sample.setExperiment(new ExperimentPE());
Date now = new Date();
sample.setModificationDate(now);
prepareTryToLoadOfSampleWithId(sample);
prepareNoPropertiesToUpdate(sample);
context.checking(new Expectations()
{
{
allowing(dataDAO).hasDataSet(with(sample));
will(returnValue(true));
}
});
boolean exceptionThrown = false;
try
{
createSampleBO().update(
new SampleUpdatesDTO(SAMPLE_TECH_ID, null, null, Collections
.<NewAttachment> emptyList(), now, null, null, null));
} catch (UserFailureException ex)
{
exceptionThrown = true;
assertTrue(ex
.getMessage()
.contains(
"from the experiment because there are already datasets attached to the sample"));
}
assertTrue(exceptionThrown);
context.assertIsSatisfied();
}
@Test @Test
public final void testEditStaleSampleFails() public final void testEditStaleSampleFails()
{ {
......
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