LocaleImportHandler extends RepositoryFileImportFileHandler implements IPlatformImportHandler { public void importFile( IPlatformImportBundle bundle ) throws PlatformImportException { RepositoryFileImportBundle localeBundle = (RepositoryFileImportBundle) bundle; Properties localePropertiesFromIndex = loadPropertiesByXml( localeBundle ); RepositoryFile localeParent = getLocaleParent( localeBundle, localePropertiesFromIndex ); Properties localeProperties = buildLocaleProperties( localeBundle, localePropertiesFromIndex ); String bundleFileName = localeBundle.getFile() != null ? localeBundle.getFile().getName() : localeBundle.getName(); if ( localeParent != null && unifiedRepository != null && bundleFileName != null ) { String fullPath = RepositoryFilenameUtils.concat( localeBundle.getPath(), localeParent.getName() ); if ( ImportSession.getSession().getSkippedFiles().contains( fullPath ) ) { getLogger().trace( "Not importing Locale [" + bundleFileName + "] since parent file not written " ); } else { getLogger().trace( "Processing Locale [" + bundleFileName + "]" ); unifiedRepository .setLocalePropertiesForFile( localeParent, extractLocaleCode( localeBundle ), localeProperties ); } } } LocaleImportHandler( List<IMimeType> mimeTypes, List<String> artifacts ); void importFile( IPlatformImportBundle bundle );  }
@Test public void testValidImportIndexLocaleFile() { String localeContent = "<index><name>My name</name><description>My descript</description><icon>samples.png</icon><visible>true</visible><display-type>icons</display-type></index>"; RepositoryFileImportBundle importBundle = createBundle( localeContent, "index.xml" ); IUnifiedRepository unifiedRepository = initLocaleHandler( importBundle ); try { importer.importFile( importBundle ); verify( unifiedRepository, times( 1 ) ).getFile( anyString() ); verify( unifiedRepository, never() ).getChildren( anyInt() ); verify( unifiedRepository, times( 1 ) ).setLocalePropertiesForFile( any( RepositoryFile.class ), anyString(), any( Properties.class ) ); } catch ( PlatformImportException e ) { fail( e.getMessage() ); } }
@Test public void testInValidImportIndexLocaleFile() { String localeContent = "<index><name>%name</name><description>%description</description><icon>samples.png</icon><visible>true</visible><display-type>icons</display-type></index>"; RepositoryFileImportBundle importBundle = createBundle( localeContent, "index.xml" ); IUnifiedRepository unifiedRepository = initLocaleHandler( importBundle ); try { importer.importFile( importBundle ); verify( unifiedRepository, times( 1 ) ).getFile( anyString() ); verify( unifiedRepository, times( 1 ) ).getChildren( anyInt() ); verify( unifiedRepository, never() ).setLocalePropertiesForFile( any( RepositoryFile.class ), anyString(), any( Properties.class ) ); } catch ( PlatformImportException e ) { fail( e.getMessage() ); } }
@Test public void testImportNotLocaleFile() { String localeContent = "<index></display-type></index>"; RepositoryFileImportBundle importBundle = createBundle( localeContent, "test.xml" ); IUnifiedRepository unifiedRepository = initLocaleHandler( importBundle ); try { importer.importFile( importBundle ); verify( unifiedRepository, times( 1 ) ).getFile( anyString() ); verify( unifiedRepository, times( 1 ) ).getChildren( anyInt() ); verify( unifiedRepository, never() ).setLocalePropertiesForFile( any( RepositoryFile.class ), anyString(), any( Properties.class ) ); } catch ( PlatformImportException e ) { fail( e.getMessage() ); } }