Skip to content
Snippets Groups Projects
Commit 0303fc3e authored by jakubs's avatar jakubs
Browse files

BIS-173 add tests for entity validation forcing

SVN: 26532
parent bacad66a
No related branches found
No related tags found
No related merge requests found
......@@ -42,8 +42,6 @@ public class EntityValidationCalculator extends AbstractCalculator
public void requestValidation(Object o);
}
private IValidationRequestDelegate validationRequested;
/**
* Creates a calculator for given <code>expression</code>.
* <p>
......
......@@ -16,7 +16,6 @@
package ch.systemsx.cisd.openbis.systemtest.plugin.generic;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
......@@ -32,6 +31,7 @@ import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DeletionType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
......@@ -41,6 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO;
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.SampleIdentifierFactory;
/**
* Tests that the entity validation scripts are called when creating or updating the entities
......@@ -57,13 +58,25 @@ public class EntityValidationTest extends GenericSystemTestCase
private static final String IMPOSSIBLE_TO_UPDATE_TYPE = "IMPOSSIBLE_TO_UPDATE";
/**
* shortcut for registerNewSample(identifier, type, null)
*/
private void registerNewSample(String identifier, String type)
{
registerNewSample(identifier, type, null);
}
private void registerNewSample(String identifier, String type, String experimentIdentifierOrNull)
{
final NewSample newSample = new NewSample();
newSample.setIdentifier(identifier);
final SampleType sampleType = new SampleType();
sampleType.setCode(type);
newSample.setSampleType(sampleType);
if (experimentIdentifierOrNull != null)
{
newSample.setExperimentIdentifier(experimentIdentifierOrNull);
}
genericClientService.registerSample(systemSessionToken, newSample);
}
......@@ -105,30 +118,41 @@ public class EntityValidationTest extends GenericSystemTestCase
{
registerNewSample("/CISD/EVT1", IMPOSSIBLE_TO_UPDATE_TYPE);
ListSampleCriteria listCriteria = new ListSampleCriteria();
listCriteria.setIncludeSpace(true);
listCriteria.setSpaceCode("CISD");
listCriteria.setSampleType(getSampleType(IMPOSSIBLE_TO_UPDATE_TYPE));
Sample sample = getSampleFromSpaceAndType("CISD", IMPOSSIBLE_TO_UPDATE_TYPE, "EVT1");
List<Sample> samples = etlService.listSamples(systemSessionToken, listCriteria);
SampleUpdatesDTO update = createSampleUpdates(sample, "DYNA-TEST-1");
assertEquals("one sample should be registered", 1, samples.size());
try
{
etlService.updateSample(systemSessionToken, update);
fail("update of sample with impossible to update type should fail");
} catch (Exception ufe)
{
assertTrue(ufe.getMessage(), ufe.getMessage().contains("Validation of sample"));
}
Sample sample = samples.get(0);
deleteSample(sample);
}
String[] modifiedParentCodesOrNull = new String[]
{ "DYNA-TEST-1" };
String containerIdentifierOrNull = null;
SampleIdentifier sampleIdentifier = SampleIdentifier.create("CISD", "EVT1");
Date version = sample.getModificationDate();
ExperimentIdentifier experimentIdentifierOrNull = null;
TechId sampleId = new TechId(sample.getId());
List<IEntityProperty> properties = Collections.emptyList();
Collection<NewAttachment> attachments = Collections.emptyList();
SampleUpdatesDTO update =
new SampleUpdatesDTO(sampleId, properties, experimentIdentifierOrNull, attachments,
version, sampleIdentifier, containerIdentifierOrNull,
modifiedParentCodesOrNull);
private void deleteSample(Sample sample)
{
// cleanup
commonServer.deleteSamples(systemSessionToken,
Collections.singletonList(new TechId(sample.getId())), "Yup",
DeletionType.PERMANENT);
}
@Test
public void testSampleUpdateTriggerValidationOfParentsChildren()
{
// setting the parent of this sample, forces the validation of parent (as it is aslo being
// changed)
// as the consequence validation of INVALID sample is forced - via the validation script of
// the parent
// the validation of INVALID sample should fail
Sample sample = getSampleFromSpaceAndType("TEST-SPACE", "WELL", "EV-NOT_INVALID");
SampleUpdatesDTO update = createSampleUpdates(sample, "EV-PARENT");
try
{
......@@ -137,10 +161,50 @@ public class EntityValidationTest extends GenericSystemTestCase
} catch (Exception ufe)
{
assertTrue(ufe.getMessage(), ufe.getMessage().contains("Validation of sample"));
assertTrue(ufe.getMessage(), ufe.getMessage().contains("Cannot update this entity"));
}
}
// cleanup
commonServer.deleteSamples(systemSessionToken, Collections.singletonList(sampleId), "Yup",
DeletionType.PERMANENT);
private SampleUpdatesDTO createSampleUpdates(Sample sample, String parentCode)
{
String[] modifiedParentCodesOrNull = new String[]
{ parentCode };
String containerIdentifierOrNull = null;
SampleIdentifier sampleIdentifier = SampleIdentifierFactory.parse(sample);
Date version = sample.getModificationDate();
Experiment experiment = sample.getExperiment();
ExperimentIdentifier experimentIdentifierOrNull =
(experiment == null) ? null : new ExperimentIdentifier(experiment);
List<IEntityProperty> properties = Collections.emptyList();
Collection<NewAttachment> attachments = Collections.emptyList();
SampleUpdatesDTO update =
new SampleUpdatesDTO(new TechId(sample.getId()), properties,
experimentIdentifierOrNull, attachments, version, sampleIdentifier,
containerIdentifierOrNull, modifiedParentCodesOrNull);
return update;
}
/**
* finds given sample via ETL service
*/
private Sample getSampleFromSpaceAndType(String spaceCode, String sampleType, String sampleCode)
{
ListSampleCriteria listCriteria = new ListSampleCriteria();
listCriteria.setIncludeSpace(true);
listCriteria.setSpaceCode(spaceCode);
listCriteria.setSampleType(getSampleType(sampleType));
List<Sample> samples = etlService.listSamples(systemSessionToken, listCriteria);
for (Sample sample : samples)
{
if (sample.getCode().equals(sampleCode))
{
return sample;
}
}
fail(String
.format("No sample %s (%s) found in space %s", sampleCode, sampleType, spaceCode));
return null;
}
}
......@@ -44,3 +44,4 @@
35 974 2 985 2 \N 2012-05-31 15:01:16.531617+02 2012-05-31 15:01:16.531617+02
32 974 2 982 1 \N 2012-05-31 15:01:16.531617+02 2012-05-31 15:01:16.531617+02
43 977 1 984 2 \N 2012-05-31 15:01:16.531617+02 2012-05-31 15:01:16.531617+02
48 1058 1 1056 \N \N 2012-05-31 15:01:16.531617+02 2012-05-31 15:01:16.531617+02
\ No newline at end of file
......@@ -6,4 +6,5 @@
4 REINFECT_PLATE Re-infection Plate 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 5 f
7 DYNAMIC_PLATE Dynamic Plate 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 5 f
8 IMPOSSIBLE Impossible to create 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 6 f
9 IMPOSSIBLE_TO_UPDATE Impossible to update 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 7 f
\ No newline at end of file
9 IMPOSSIBLE_TO_UPDATE Impossible to update 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 7 f
10 REQUIRE_CHILD_VALIDATION Revalidated the child 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 8 f
\ No newline at end of file
......@@ -1022,4 +1022,8 @@
1051 WELL-A01 6 2009-02-09 12:09:50.077973+01 2 \N \N 1 1050 2009-08-18 17:54:36.929+02 21 200902091250077-1051 \N
1052 WELL-A02 6 2009-02-09 12:09:50.077973+01 2 \N \N 1 1050 2009-08-18 17:54:36.929+02 21 200902091250077-1052 \N
1053 DYNA-TEST-1 7 2009-02-09 12:09:19.327518+01 2 \N \N 1 \N 2009-08-18 17:54:11.56+02 18 200902091219327-1053 \N
1054 FV-TEST 3 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1025 \N
1054 FV-TEST 3 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1054 \N
1055 EV-TEST 10 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1055 \N
1056 EV-INVALID 9 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1056 \N
1057 EV-NOT_INVALID 6 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1057 \N
1058 EV-PARENT 10 2009-02-09 12:09:19.327518+01 2 \N \N 3 \N 2009-08-18 17:54:11.56+02 23 201206191219327-1058 \N
......@@ -4,4 +4,5 @@
4 1 managed list \N fake script 2010-10-27 15:16:48.994831+02 2 \N MANAGED_PROPERTY
5 1 validateOK \N def validate(entity, isNew):\n pass\n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION
6 1 validateFAIL \N def validate(entity, isNew):\n return "This check always fail"\n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION
7 1 validateUpdateFAIL \N def validate(entity, isNew):\n if (not isNew):\n return "Cannot update this entity"\n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION
\ No newline at end of file
7 1 validateUpdateFAIL \N def validate(entity, isNew):\n if (not isNew):\n return "Cannot update this entity"\n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION
8 1 validateChildren \N def validate(entity, isNew):\n for childRelation in entity.entityPE().getChildRelationships():\n requestValidation(childRelation.getChildSample()) \n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION
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