@Test
public void testShouldDownloadMetadataVersion()
    throws Exception
{

    when( metadataSystemSettingService.getRemoteInstanceUserName() ).thenReturn( username );
    when( metadataSystemSettingService.getRemoteInstancePassword() ).thenReturn( password );
    MetadataVersion metadataVersion = new MetadataVersion( "testVersion", VersionType.BEST_EFFORT );
    metadataVersion.setHashCode( "12wa32d4f2et3tyt5yu6i" );
    String url = "http://localhost:9080/api/metadata/version/testVersion/data.gz";
    String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    when( metadataSystemSettingService.getDownloadVersionSnapshotURL( "testVersion" ) ).thenReturn( url );
    AvailabilityStatus availabilityStatus = new AvailabilityStatus( true, "test_message", null );
    DhisHttpResponse dhisHttpResponse = new DhisHttpResponse( httpResponse, response, HttpStatus.OK.value() );
    when( synchronizationManager.isRemoteServerAvailable() ).thenReturn( availabilityStatus );
    PowerMockito.when( HttpUtils.httpGET( downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true ) )
        .thenReturn( dhisHttpResponse );
    String actualVersionSnapShot = target.downloadMetadataVersionSnapshot( metadataVersion );
    assertEquals( response, actualVersionSnapShot );
}