DefaultMetadataSyncService implements MetadataSyncService { @Override public MetadataSyncParams getParamsFromMap( Map<String, List<String>> parameters ) { List<String> versionName = getVersionsFromParams( parameters ); MetadataImportParams importParams = new MetadataImportParams(); importParams.setMetadataSyncImport( true ); MetadataSyncParams syncParams = new MetadataSyncParams(); syncParams.setImportParams( importParams ); String versionNameStr = versionName.get( 0 ); if ( StringUtils.isNotEmpty( versionNameStr ) ) { MetadataVersion version; try { version = metadataVersionDelegate.getRemoteMetadataVersion( versionNameStr ); } catch ( MetadataVersionServiceException e ) { throw new MetadataSyncServiceException( e.getMessage(), e ); } if ( version == null ) { throw new MetadataSyncServiceException( "The MetadataVersion could not be fetched from the remote server for the versionName: " + versionNameStr ); } syncParams.setVersion( version ); } syncParams.setParameters( parameters ); return syncParams; } DefaultMetadataSyncService( MetadataVersionDelegate metadataVersionDelegate,
        MetadataVersionService metadataVersionService, MetadataSyncDelegate metadataSyncDelegate,
        MetadataSyncImportHandler metadataSyncImportHandler ); @Override MetadataSyncParams getParamsFromMap( Map<String, List<String>> parameters ); @Override synchronized MetadataSyncSummary doMetadataSync( MetadataSyncParams syncParams ); @Override boolean isSyncRequired( MetadataSyncParams syncParams );  }
@Test public void testShouldThrowExceptionWhenVersionNameNotPresentInParameters() throws MetadataSyncServiceException { expectedException.expect( MetadataSyncServiceException.class ); expectedException.expectMessage( "Missing required parameter: 'versionName'" ); metadataSyncService.getParamsFromMap( parameters ); }
@Test public void testShouldThrowExceptionWhenParametersAreNull() throws MetadataSyncServiceException { expectedException.expect( MetadataSyncServiceException.class ); expectedException.expectMessage( "Missing required parameter: 'versionName'" ); metadataSyncService.getParamsFromMap( null ); }
@Test public void testShouldThrowExceptionWhenParametersHaveVersionNameAsNull() throws MetadataSyncServiceException { parameters.put( "versionName", null ); expectedException.expect( MetadataSyncServiceException.class ); expectedException.expectMessage( "Missing required parameter: 'versionName'" ); metadataSyncService.getParamsFromMap( parameters ); }
@Test public void testShouldThrowExceptionWhenParametersHaveVersionNameAssignedToEmptyList() throws MetadataSyncServiceException { parameters.put( "versionName", new ArrayList<>() ); expectedException.expect( MetadataSyncServiceException.class ); expectedException.expectMessage( "Missing required parameter: 'versionName'" ); metadataSyncService.getParamsFromMap( parameters ); }
@Test public void testShouldReturnNullWhenVersionNameIsAssignedToListHavingNullEntry() { parameters.put( "versionName", new ArrayList<>() ); parameters.get( "versionName" ).add( null ); MetadataSyncParams paramsFromMap = metadataSyncService.getParamsFromMap( parameters ); assertNull( paramsFromMap.getVersion() ); }
@Test public void testShouldReturnNullWhenVersionNameIsAssignedToListHavingEmptyString() { parameters.put( "versionName", new ArrayList<>() ); parameters.get( "versionName" ).add( "" ); MetadataSyncParams paramsFromMap = metadataSyncService.getParamsFromMap( parameters ); assertNull( paramsFromMap.getVersion() ); }
@Test public void testShouldGetExceptionIfRemoteVersionIsNotAvailable() { parameters.put( "versionName", new ArrayList<>() ); parameters.get( "versionName" ).add( "testVersion" ); when( metadataVersionDelegate.getRemoteMetadataVersion( "testVersion" ) ).thenReturn( null ); expectedException.expect( MetadataSyncServiceException.class ); expectedException.expectMessage( "The MetadataVersion could not be fetched from the remote server for the versionName: testVersion" ); metadataSyncService.getParamsFromMap( parameters ); }
@Test public void testShouldGetMetadataVersionForGivenVersionName() { parameters.put( "versionName", new ArrayList<>() ); parameters.get( "versionName" ).add( "testVersion" ); MetadataVersion metadataVersion = new MetadataVersion( "testVersion", VersionType.ATOMIC ); when( metadataVersionDelegate.getRemoteMetadataVersion( "testVersion" ) ).thenReturn( metadataVersion ); MetadataSyncParams metadataSyncParams = metadataSyncService.getParamsFromMap( parameters ); assertEquals( metadataVersion, metadataSyncParams.getVersion() ); }