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

BIS-173 make validation script tests more flexible

SVN: 26534
parent 97e28573
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; ...@@ -38,6 +38,7 @@ 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.Sample; 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.basic.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Script;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; 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.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
...@@ -52,12 +53,13 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFa ...@@ -52,12 +53,13 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFa
@Transactional(propagation = Propagation.NOT_SUPPORTED) @Transactional(propagation = Propagation.NOT_SUPPORTED)
public class EntityValidationTest extends GenericSystemTestCase public class EntityValidationTest extends GenericSystemTestCase
{ {
// create sample of a type, that has attached script that forbids creation
private static final String IMPOSSIBLE_TYPE = "IMPOSSIBLE"; private static final String IMPOSSIBLE_TYPE = "IMPOSSIBLE";
private static final String IMPOSSIBLE_TO_UPDATE_TYPE = "IMPOSSIBLE_TO_UPDATE"; private static final String IMPOSSIBLE_TO_UPDATE_TYPE = "IMPOSSIBLE_TO_UPDATE";
private static final int TEST_SCRIPT_ID = 8;
/** /**
* shortcut for registerNewSample(identifier, type, null) * shortcut for registerNewSample(identifier, type, null)
*/ */
...@@ -145,6 +147,7 @@ public class EntityValidationTest extends GenericSystemTestCase ...@@ -145,6 +147,7 @@ public class EntityValidationTest extends GenericSystemTestCase
@Test @Test
public void testSampleUpdateTriggerValidationOfParentsChildren() public void testSampleUpdateTriggerValidationOfParentsChildren()
{ {
updateTestScript(" for childRelation in entity.entityPE().getChildRelationships():\n requestValidation(childRelation.getChildSample()) ");
// setting the parent of this sample, forces the validation of parent (as it is aslo being // setting the parent of this sample, forces the validation of parent (as it is aslo being
// changed) // changed)
// as the consequence validation of INVALID sample is forced - via the validation script of // as the consequence validation of INVALID sample is forced - via the validation script of
...@@ -165,6 +168,27 @@ public class EntityValidationTest extends GenericSystemTestCase ...@@ -165,6 +168,27 @@ public class EntityValidationTest extends GenericSystemTestCase
} }
} }
@Test
public void testSampleUpdateTriggerValidationOfParentsChildrenDoesNotHappen()
{
updateTestScript(" pass");
Sample sample = getSampleFromSpaceAndType("TEST-SPACE", "WELL", "EV-NOT_INVALID");
SampleUpdatesDTO update = createSampleUpdates(sample, "EV-PARENT");
etlService.updateSample(systemSessionToken, update);
}
// this updates the script that validates the EV-PARENT sample
private void updateTestScript(String validationFunctionBody)
{
Script script = commonServer.getScriptInfo(systemSessionToken, new TechId(TEST_SCRIPT_ID));
script.setScript("def validate(entity, isNew):\n" + validationFunctionBody + "\n");
commonServer.updateScript(systemSessionToken, script);
}
private SampleUpdatesDTO createSampleUpdates(Sample sample, String parentCode) private SampleUpdatesDTO createSampleUpdates(Sample sample, String parentCode)
{ {
String[] modifiedParentCodesOrNull = new String[] String[] modifiedParentCodesOrNull = new String[]
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
7 DYNAMIC_PLATE Dynamic 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 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 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 10 TEST_VALIDATION Update validation script before validating 1 t 1 0 2009-03-23 15:34:44.462776+01 f S f f 8 f
\ No newline at end of file \ No newline at end of file
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
5 1 validateOK \N def validate(entity, isNew):\n pass\n 2010-10-27 15:16:48.994831+02 2 \N ENTITY_VALIDATION 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 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 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 8 1 testScript \N def validate(entity, isNew):\n raise "Update this script before using"\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