Search in sources :

Example 41 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess10.

/**
 * program = DATA READ programStage = orgUnit = Accessible status = ERROR
 */
@Test
void testAddEventSimpleUserFullAccess10() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DATA_READ);
    programStageA.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    Event eventFromPsi = eventService.getEvent(programStageInstance);
    assertNotNull(eventFromPsi);
    assertEquals(event.getUid(), eventFromPsi.getEvent());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 42 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess1.

/**
 * program = DATA READ/WRITE programStage = DATA READ/WRITE orgUnit =
 * Accessible status = SUCCESS
 */
@Test
void testAddEventSimpleUserFullAccess1() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.updateNoAcl(programA);
    manager.updateNoAcl(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    userService.addUser(user);
    injectSecurityContext(user);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    // make sure data is flushed, so event service can access it
    manager.flush();
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 43 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsOk.

@Test
void testShouldSendSuccessEmailIfSyncSummaryIsOk() {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockRetryContext, dataVersion);
    assertFalse(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 44 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendEmailToAdminWithProperSubjectAndBody.

@Test
void testShouldSendEmailToAdminWithProperSubjectAndBody() {
    ImportReport importReport = mock(ImportReport.class);
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.getImportReport().setStatus(Status.OK);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockRetryContext, dataVersion);
    assertFalse(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext) Test(org.junit.jupiter.api.Test)

Example 45 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldReturnEmptyMetadataDifference.

@Test
void testShouldReturnEmptyMetadataDifference() {
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
    metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
    String url = "http://localhost:9080/api/metadata/version/history?baseline=testVersion";
    when(metadataSystemSettingService.getMetaDataDifferenceURL("testVersion")).thenReturn(url);
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.BAD_REQUEST.value());
    try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
        mocked.when(() -> HttpUtils.httpGET(baselineUrl, true, username, password, null, VERSION_TIMEOUT, true)).thenReturn(dhisHttpResponse);
        assertThrows(MetadataVersionServiceException.class, () -> target.getMetaDataDifference(metadataVersion), "Client Error. Http call failed with status code: 400 Caused by: " + dhisHttpResponse.getResponse());
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpUtils(org.hisp.dhis.system.util.HttpUtils) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)28 User (org.hisp.dhis.user.User)20 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)16 Event (org.hisp.dhis.dxf2.events.event.Event)14 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Period (org.hisp.dhis.period.Period)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5