MetadataVersionDelegate { public String downloadMetadataVersionSnapshot(MetadataVersion version ) throws MetadataVersionServiceException { String downloadVersionSnapshotURL = metadataSystemSettingService.getDownloadVersionSnapshotURL( version.getName() ); DhisHttpResponse dhisHttpResponse = getDhisHttpResponse( downloadVersionSnapshotURL, DOWNLOAD_TIMEOUT ); if ( isValidDhisHttpResponse( dhisHttpResponse ) ) { return dhisHttpResponse.getResponse(); } return null; } MetadataVersionDelegate( DefaultMetadataSystemSettingService metadataSystemSettingService,
        SynchronizationManager synchronizationManager, RenderService renderService,
        MetadataVersionService metadataVersionService ); MetadataVersion getRemoteMetadataVersion( String versionName ); List<MetadataVersion> getMetaDataDifference( MetadataVersion metadataVersion ); String downloadMetadataVersionSnapshot(MetadataVersion version ); synchronized void addNewMetadataVersion( MetadataVersion version );  }
@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: 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 ); }
@Test public void testShouldNotDownloadMetadataVersion() { MetadataVersion metadataVersion = new MetadataVersion( "testVersion", VersionType.BEST_EFFORT ); metadataVersion.setHashCode( "12wa32d4f2et3tyt5yu6i" ); String url = "http: when( metadataSystemSettingService.getDownloadVersionSnapshotURL( "testVersion" ) ).thenReturn( url ); AvailabilityStatus availabilityStatus = new AvailabilityStatus( true, "test_message", null ); when( synchronizationManager.isRemoteServerAvailable() ).thenReturn( availabilityStatus ); String actualMetadataVersionSnapshot = target.downloadMetadataVersionSnapshot( metadataVersion ); assertNull(actualMetadataVersionSnapshot); }