Search in sources :

Example 6 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class MetadataSyncPostProcessorTest method testShouldSendSuccessEmailIfSyncSummaryIsError.

@Test
public void testShouldSendSuccessEmailIfSyncSummaryIsError() throws Exception {
    metadataSyncSummary.setImportReport(new ImportReport());
    metadataSyncSummary.getImportReport().setStatus(Status.ERROR);
    metadataSyncSummary.setMetadataVersion(dataVersion);
    MetadataRetryContext mockMetadataRetryContext = mock(MetadataRetryContext.class);
    RetryContext mockRetryContext = mock(RetryContext.class);
    when(mockMetadataRetryContext.getRetryContext()).thenReturn(mockRetryContext);
    boolean status = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, mockMetadataRetryContext, dataVersion);
    assertTrue(status);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) RetryContext(org.springframework.retry.RetryContext) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class MetadataRetryContextTest method testIfSummaryIsNotNull.

@Test
public void testIfSummaryIsNotNull() throws Exception {
    MetadataSyncSummary testSummary = new MetadataSyncSummary();
    ImportReport importReport = new ImportReport();
    importReport.setStatus(Status.ERROR);
    testSummary.setImportReport(importReport);
    metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, testSummary);
    verify(retryContext).setAttribute(testKey, testMessage);
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class MetadataSyncTaskTest method testHandleMetadataSyncIsThrowingException.

@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataSyncIsThrowingException() throws Exception {
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new MetadataSyncServiceException(""));
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    doNothing().when(metadataRetryContext).updateRetryContext(any(String.class), any(String.class), eq(metadataVersion));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    metadataSyncTask.runSyncTask(metadataRetryContext);
    verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleAggregateDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleEventDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService).doMetadataSync(any(MetadataSyncParams.class));
    verify(metadataSyncPostProcessor, never()).handleSyncNotificationsAndAbortStatus(metadataSyncSummary, metadataRetryContext, metadataVersion);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class MetadataRetryContextTest method testIfSummaryIsNull.

@Test
public void testIfSummaryIsNull() throws Exception {
    MetadataSyncSummary metadataSyncSummary = mock(MetadataSyncSummary.class);
    metadataRetryContext.updateRetryContext(testKey, testMessage, mockVersion, null);
    verify(retryContext).setAttribute(testKey, testMessage);
    verify(metadataSyncSummary, never()).getImportReport();
}
Also used : MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with MetadataSyncSummary

use of org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary in project dhis2-core by dhis2.

the class MetadataSyncImportHandlerTest method testShouldImportMetadata.

@Test
public void testShouldImportMetadata() {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    importReport.setStatus(Status.OK);
    when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
    metadataSyncSummary.setImportReport(importReport);
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    doNothing().when(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
    MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
    assertEquals(metadataSyncSummary.getImportReport(), actualMetadataSyncSummary.getImportReport());
    assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
    assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
    assertEquals(metadataSyncSummary.getMetadataVersion().getType(), actualMetadataSyncSummary.getMetadataVersion().getType());
    assertEquals(metadataSyncSummary.getImportReport().getStatus(), actualMetadataSyncSummary.getImportReport().getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Test (org.junit.Test)13 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)9 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)9 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)6 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)5 IntegrationTest (org.hisp.dhis.IntegrationTest)4 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)4 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)4 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)3 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)2 IOException (java.io.IOException)1 List (java.util.List)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 Email (org.hisp.dhis.email.Email)1 RemoteServerUnavailableException (org.hisp.dhis.exception.RemoteServerUnavailableException)1 Stats (org.hisp.dhis.feedback.Stats)1 Status (org.hisp.dhis.feedback.Status)1