Search in sources :

Example 1 with MetadataImportService

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

the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenParsingClassListMap.

@Test
public void testShouldThrowExceptionWhenParsingClassListMap() throws IOException {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    importReport.setStatus(Status.OK);
    when(renderService.fromMetadata(any(InputStream.class), eq(RenderFormat.JSON))).thenThrow(new IOException());
    expectedException.expect(MetadataSyncServiceException.class);
    expectedException.expectMessage("Exception occurred while trying to do JSON conversion while parsing class list map");
    metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(renderService).fromMetadata(any(InputStream.class), RenderFormat.JSON);
    verify(metadataImportService, never()).importMetadata(syncParams.getImportParams());
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) InputStream(java.io.InputStream) IOException(java.io.IOException) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with MetadataImportService

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

the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenClassListMapIsNull.

@Test
public void testShouldThrowExceptionWhenClassListMapIsNull() throws IOException {
    syncParams.setImportParams(new MetadataImportParams());
    syncParams.setVersion(metadataVersion);
    importReport.setStatus(Status.OK);
    when(renderService.fromMetadata(any(InputStream.class), eq(RenderFormat.JSON))).thenReturn(null);
    expectedException.expect(MetadataSyncServiceException.class);
    expectedException.expectMessage("ClassListMap can't be null");
    metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
    verify(renderService).fromMetadata(any(InputStream.class), RenderFormat.JSON);
    verify(metadataImportService, never()).importMetadata(syncParams.getImportParams());
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
    verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) InputStream(java.io.InputStream) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

InputStream (java.io.InputStream)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 IntegrationTest (org.hisp.dhis.IntegrationTest)2 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2 Test (org.junit.Test)2 IOException (java.io.IOException)1