use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AttributeOptionComboDateCheckTest method failOnCategoryOptionStartDateBeforeEventDate.
@Test
void failOnCategoryOptionStartDateBeforeEventDate() {
event.setEventDate("2019-05-01");
event.setDueDate("2019-05-10");
CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo("2020-01-01", true);
mockContext(categoryOptionCombo);
ImportSummary importSummary = rule.check(new ImmutableEvent(event), this.workContext);
assertHasError(importSummary, event, "Event date 2019-05-01 is before start date 2020-01-01 for attributeOption 'test'");
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionComboSupplierTest method setUp.
@BeforeEach
void setUp() {
this.subject = new CategoryOptionComboSupplier(jdbcTemplate, programSupplier, attributeOptionComboLoader, programStageInstanceSupplier);
programMap = new HashMap<>();
programStageInstanceMap = new HashMap<>();
// create a Program for the ProgramSupplier
program = new Program();
program.setId(999L);
program.setUid("prabcde");
programMap.put("prabcde", program);
// create a ProgramStageInstance for the ProgramStageInstanceSupplier
coc = new CategoryOptionCombo();
coc.setUid("coc1");
programStageInstance = new ProgramStageInstance();
programStageInstance.setId(888L);
programStageInstance.setUid("psuid1");
programStageInstance.setAttributeOptionCombo(coc);
programStageInstanceMap.put("psuid1", programStageInstance);
// create event to import
event = new Event();
event.setUid(CodeGenerator.generateUid());
event.setAttributeOptionCombo("aoc1234");
event.setProgram(program.getUid());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionComboSupplierTest method case1.
private void case1(ImportOptions importOptions) {
when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
CategoryOptionCombo coc = new CategoryOptionCombo();
coc.setUid(event.getAttributeOptionCombo());
when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), event.getAttributeOptionCombo())).thenReturn(coc);
Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(event));
CategoryOptionCombo categoryOptionCombo = map.get(event.getUid());
assertThat(categoryOptionCombo, is(notNullValue()));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionComboSupplierTest method case6.
private void case6(ImportOptions importOptions) {
when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
when(programStageInstanceSupplier.get(eq(importOptions), anyList())).thenReturn(programStageInstanceMap);
when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), programStageInstance.getAttributeOptionCombo().getUid())).thenReturn(coc);
Event eventWithoutAoc = new Event();
eventWithoutAoc.setUid("psuid1");
eventWithoutAoc.setProgram(program.getUid());
Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(eventWithoutAoc));
CategoryOptionCombo categoryOptionCombo = map.get(eventWithoutAoc.getUid());
assertThat(categoryOptionCombo, is(notNullValue()));
assertThat(categoryOptionCombo.getUid(), is(coc.getUid()));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionComboSupplierTest method case2.
private void case2(ImportOptions importOptions) {
when(programSupplier.get(eq(importOptions), anyList())).thenReturn(programMap);
CategoryOptionCombo coc = new CategoryOptionCombo();
coc.setUid("def123");
coc.setName("default ");
when(attributeOptionComboLoader.getCategoryOptionCombo(importOptions.getIdSchemes().getCategoryOptionComboIdScheme(), event.getAttributeOptionCombo())).thenReturn(null);
when(attributeOptionComboLoader.getDefault()).thenReturn(coc);
Map<String, CategoryOptionCombo> map = subject.get(importOptions, singletonList(event));
CategoryOptionCombo categoryOptionCombo = map.get(event.getUid());
assertThat(categoryOptionCombo, is(notNullValue()));
assertThat(categoryOptionCombo.getName(), is(coc.getName()));
}
Aggregations