MetaStoreImportHandler implements IPlatformImportHandler { @Override public void importFile( IPlatformImportBundle bundle ) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException { InputStream inputStream = bundle.getInputStream(); Path path = Files.createTempDirectory( METASTORE ); path.toFile().deleteOnExit(); ZipInputStream zis = new ZipInputStream( inputStream ); ZipEntry entry; while ( ( entry = zis.getNextEntry() ) != null ) { try { String filePath = path.toString() + File.separator + entry.getName(); if ( entry.isDirectory() ) { File dir = new File( filePath ); dir.mkdir(); } else { File file = new File( filePath ); file.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream( filePath ); IOUtils.copy( zis, fos ); IOUtils.closeQuietly( fos ); } } finally { zis.closeEntry(); } } IOUtils.closeQuietly( zis ); IMetaStore metastore = getRepoMetaStore(); if ( metastore != null ) { try { if ( tmpXmlMetaStore == null ) { tmpXmlMetaStore = new XmlMetaStore( path.toString() ); } else { tmpXmlMetaStore.setRootFolder( path.toString() + File.separator + METASTORE ); } tmpXmlMetaStore.setName( bundle.getName() ); String desc = bundle.getProperty( "description" ) == null ? null : bundle.getProperty( "description" ).toString(); tmpXmlMetaStore.setDescription( desc ); MetaStoreUtil.copy( tmpXmlMetaStore, metastore, bundle.overwriteInRepository() ); } catch ( MetaStoreException e ) { log.error( "Could not restore the MetaStore" ); log.debug( "Error restoring the MetaStore", e ); } } } MetaStoreImportHandler();  MetaStoreImportHandler( List<IMimeType> mimeTypes ); @Override void importFile( IPlatformImportBundle bundle ); void setMimeTypes( List<IMimeType> mimeTypes ); @Override List<IMimeType> getMimeTypes();  }
@Test public void testImportFile() throws Exception { IPlatformImportBundle bundle = mock( IPlatformImportBundle.class ); InputStream ios = mock( InputStream.class ); byte[] bytes = new byte[]{}; when( ios.read( any( bytes.getClass() ), anyInt(), anyInt() ) ).thenReturn( -1 ); when( bundle.getInputStream() ).thenReturn( ios ); when( bundle.getName() ).thenReturn( "metastore" ); when( bundle.getProperty( "description" ) ).thenReturn( "bundle description" ); handler.tmpXmlMetaStore = fromMetaStore; handler.importFile( bundle ); verify( metastore ).createNamespace( "pentaho" ); verify( metastore ).createNamespace( "hitachi" ); verify( fromMetaStore ).setRootFolder( anyString() ); }