use of org.hisp.dhis.tracker.TrackerIdentifierParams in project dhis2-core by dhis2.
the class TrackerImportParamsSerdeTest method testJsonDeserialization.
@Test
void testJsonDeserialization() throws IOException {
final String json = "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":true," + "\"skipSideEffects\":true," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}";
final TrackerImportParams trackerImportParams = renderService.fromJson(json, TrackerImportParams.class);
assertThat(trackerImportParams.getImportMode(), is(TrackerBundleMode.COMMIT));
assertThat(trackerImportParams.getImportStrategy(), is(TrackerImportStrategy.DELETE));
assertThat(trackerImportParams.getAtomicMode(), is(AtomicMode.OBJECT));
assertThat(trackerImportParams.getFlushMode(), is(FlushMode.OBJECT));
assertThat(trackerImportParams.getValidationMode(), is(ValidationMode.SKIP));
assertThat(trackerImportParams.isSkipPatternValidation(), is(true));
assertThat(trackerImportParams.isSkipSideEffects(), is(true));
assertThat(trackerImportParams.isSkipRuleEngine(), is(true));
assertThat(trackerImportParams.getUser(), is(nullValue()));
TrackerIdentifierParams identifiers = trackerImportParams.getIdentifiers();
assertThat(identifiers.getIdScheme(), is(TrackerIdentifier.CODE));
assertThat(identifiers.getProgramIdScheme().getIdScheme(), is(TrackerIdScheme.ATTRIBUTE));
assertThat(identifiers.getProgramIdScheme().getValue(), is("aaaa"));
}
use of org.hisp.dhis.tracker.TrackerIdentifierParams in project dhis2-core by dhis2.
the class TrackerImportParamsSerdeTest method testJsonSerialization.
@Test
void testJsonSerialization() throws JSONException {
TrackerIdentifierParams identifierParams = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.builder().idScheme(TrackerIdScheme.ATTRIBUTE).value("aaaa").build()).build();
TrackerImportParams trackerImportParams = TrackerImportParams.builder().identifiers(identifierParams).atomicMode(AtomicMode.OBJECT).flushMode(FlushMode.OBJECT).skipRuleEngine(true).importStrategy(TrackerImportStrategy.DELETE).validationMode(ValidationMode.SKIP).build();
String json = renderService.toJsonAsString(trackerImportParams);
JSONAssert.assertEquals(json, "" + "{\"importMode\":\"COMMIT\"," + "\"identifiers\":{\"dataElementIdScheme\":{\"idScheme\":\"UID\"}," + "\"orgUnitIdScheme\":{\"idScheme\":\"UID\"}," + "\"programIdScheme\":{\"idScheme\":\"ATTRIBUTE\",\"value\":\"aaaa\"}," + "\"programStageIdScheme\":{\"idScheme\":\"UID\"}," + "\"idScheme\":{\"idScheme\":\"CODE\"}," + "\"categoryOptionComboIdScheme\":{\"idScheme\":\"UID\"}," + "\"categoryOptionIdScheme\":{\"idScheme\":\"UID\"}}," + "\"importStrategy\":\"DELETE\"," + "\"atomicMode\":\"OBJECT\"," + "\"flushMode\":\"OBJECT\"," + "\"validationMode\":\"SKIP\"," + "\"skipPatternValidation\":false," + "\"skipSideEffects\":false," + "\"skipRuleEngine\":true," + "\"trackedEntities\":[]," + "\"enrollments\":[]," + "\"events\":[]," + "\"relationships\":[]," + "\"username\":\"system-process\"}", JSONCompareMode.LENIENT);
}
use of org.hisp.dhis.tracker.TrackerIdentifierParams in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method succeedsWhenDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode.
@Test
void succeedsWhenDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode() {
TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.CODE).build();
when(context.getIdentifiers()).thenReturn(params);
DataElement dataElement = dataElement();
dataElement.setCode("DE_424050");
when(context.getDataElement(dataElement.getCode())).thenReturn(dataElement);
ProgramStage programStage = programStage(dataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue dataValue = dataValue();
dataValue.setDataElement("DE_424050");
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(dataValue)).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.TrackerIdentifierParams in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method succeedsWhenMandatoryDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode.
@Test
void succeedsWhenMandatoryDataElementIsPartOfProgramStageAndIdSchemeIsSetToCode() {
TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.CODE).build();
when(context.getIdentifiers()).thenReturn(params);
DataElement dataElement = dataElement();
dataElement.setCode("DE_424050");
when(context.getDataElement(dataElement.getCode())).thenReturn(dataElement);
ProgramStage programStage = programStage(dataElement, true);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue dataValue = dataValue();
dataValue.setDataElement("DE_424050");
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(dataValue)).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.TrackerIdentifierParams in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method setUpIdentifiers.
private void setUpIdentifiers() {
TrackerIdentifierParams params = TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.UID).programIdScheme(TrackerIdentifier.UID).programStageIdScheme(TrackerIdentifier.UID).dataElementIdScheme(TrackerIdentifier.UID).build();
when(context.getIdentifiers()).thenReturn(params);
}
Aggregations