Search in sources :

Example 1 with E4051

use of org.hisp.dhis.feedback.ErrorCode.E4051 in project dhis2-core by dhis2.

the class ProgramRuleVariableObjectBundleHookTest method shouldFailUpdateExistingDifferentUid.

@Test
void shouldFailUpdateExistingDifferentUid() {
    when(programRuleVariable.getProgram()).thenReturn(program);
    when(objectBundle.getImportMode()).thenReturn(ImportStrategy.CREATE_AND_UPDATE);
    ProgramRuleVariable existingProgramRuleVariable = new ProgramRuleVariable();
    existingProgramRuleVariable.setName("word");
    existingProgramRuleVariable.setUid("uid1");
    when(query.getResultList()).thenReturn(Collections.singletonList(existingProgramRuleVariable));
    when(programRuleVariable.getName()).thenReturn("word");
    when(programRuleVariable.getUid()).thenReturn("uid2");
    List<ErrorReport> errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
    assertEquals(1, errorReports.size());
    assertTrue(errorReports.stream().anyMatch(e -> e.getErrorCode().equals(E4051)));
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) ErrorReport(org.hisp.dhis.feedback.ErrorReport) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) ErrorReport(org.hisp.dhis.feedback.ErrorReport) Mock(org.mockito.Mock) Session(org.hibernate.Session) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Captor(org.mockito.Captor) Program(org.hisp.dhis.program.Program) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ImmutableList(com.google.common.collect.ImmutableList) Query(org.hibernate.query.Query) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) E4051(org.hisp.dhis.feedback.ErrorCode.E4051) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) E4052(org.hisp.dhis.feedback.ErrorCode.E4052) PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS(org.hisp.dhis.dxf2.Constants.PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS) SessionFactory(org.hibernate.SessionFactory) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Collections (java.util.Collections)1 List (java.util.List)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 Query (org.hibernate.query.Query)1 PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS (org.hisp.dhis.dxf2.Constants.PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS)1 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)1 E4051 (org.hisp.dhis.feedback.ErrorCode.E4051)1 E4052 (org.hisp.dhis.feedback.ErrorCode.E4052)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)1 Program (org.hisp.dhis.program.Program)1 ProgramRuleVariable (org.hisp.dhis.programrule.ProgramRuleVariable)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1