@Test public void writeToFileTest() throws KettleException, IOException { doCallRealMethod().when( sharedObjectsMock ).writeToFile( any( FileObject.class ), anyString() ); when( sharedObjectsMock.initOutputStreamUsingKettleVFS( any( FileObject.class ) ) ).thenThrow( new RuntimeException() ); try { sharedObjectsMock.writeToFile( any( FileObject.class ), anyString() ); } catch ( KettleException e ) { } verify( sharedObjectsMock ).restoreFileFromBackup( anyString() ); }
@VisibleForTesting protected void writeToFile( FileObject fileObject, String backupFileName ) throws IOException, KettleException { OutputStream outputStream = null; PrintStream out = null; try { outputStream = initOutputStreamUsingKettleVFS( fileObject ); out = new PrintStream( outputStream ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( "<" + XML_TAG + ">" ); Collection<SharedObjectInterface> collection = objectsMap.values(); for ( SharedObjectInterface sharedObject : collection ) { String xmlContent = sharedObject.getXML(); out.println( xmlContent ); } out.println( "</" + XML_TAG + ">" ); } catch ( Exception e ) { boolean isRestored = false; if ( backupFileName != null ) { restoreFileFromBackup( backupFileName ); isRestored = true; } throw new KettleException( BaseMessages.getString( PKG, "SharedOjects.WriteToFile.ErrorWritingFile", isRestored ), e ); } finally { if ( out != null ) { out.flush(); } if ( out != null ) { out.close(); } if ( out != null ) { outputStream.close(); } } }
SharedObjects { @VisibleForTesting protected void writeToFile( FileObject fileObject, String backupFileName ) throws IOException, KettleException { OutputStream outputStream = null; PrintStream out = null; try { outputStream = initOutputStreamUsingKettleVFS( fileObject ); out = new PrintStream( outputStream ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( "<" + XML_TAG + ">" ); Collection<SharedObjectInterface> collection = objectsMap.values(); for ( SharedObjectInterface sharedObject : collection ) { String xmlContent = sharedObject.getXML(); out.println( xmlContent ); } out.println( "</" + XML_TAG + ">" ); } catch ( Exception e ) { boolean isRestored = false; if ( backupFileName != null ) { restoreFileFromBackup( backupFileName ); isRestored = true; } throw new KettleException( BaseMessages.getString( PKG, "SharedOjects.WriteToFile.ErrorWritingFile", isRestored ), e ); } finally { if ( out != null ) { out.flush(); } if ( out != null ) { out.close(); } if ( out != null ) { outputStream.close(); } } } }
SharedObjects { @VisibleForTesting protected void writeToFile( FileObject fileObject, String backupFileName ) throws IOException, KettleException { OutputStream outputStream = null; PrintStream out = null; try { outputStream = initOutputStreamUsingKettleVFS( fileObject ); out = new PrintStream( outputStream ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( "<" + XML_TAG + ">" ); Collection<SharedObjectInterface> collection = objectsMap.values(); for ( SharedObjectInterface sharedObject : collection ) { String xmlContent = sharedObject.getXML(); out.println( xmlContent ); } out.println( "</" + XML_TAG + ">" ); } catch ( Exception e ) { boolean isRestored = false; if ( backupFileName != null ) { restoreFileFromBackup( backupFileName ); isRestored = true; } throw new KettleException( BaseMessages.getString( PKG, "SharedOjects.WriteToFile.ErrorWritingFile", isRestored ), e ); } finally { if ( out != null ) { out.flush(); } if ( out != null ) { out.close(); } if ( out != null ) { outputStream.close(); } } } SharedObjects( String sharedObjectsFile );  SharedObjects(); }
SharedObjects { @VisibleForTesting protected void writeToFile( FileObject fileObject, String backupFileName ) throws IOException, KettleException { OutputStream outputStream = null; PrintStream out = null; try { outputStream = initOutputStreamUsingKettleVFS( fileObject ); out = new PrintStream( outputStream ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( "<" + XML_TAG + ">" ); Collection<SharedObjectInterface> collection = objectsMap.values(); for ( SharedObjectInterface sharedObject : collection ) { String xmlContent = sharedObject.getXML(); out.println( xmlContent ); } out.println( "</" + XML_TAG + ">" ); } catch ( Exception e ) { boolean isRestored = false; if ( backupFileName != null ) { restoreFileFromBackup( backupFileName ); isRestored = true; } throw new KettleException( BaseMessages.getString( PKG, "SharedOjects.WriteToFile.ErrorWritingFile", isRestored ), e ); } finally { if ( out != null ) { out.flush(); } if ( out != null ) { out.close(); } if ( out != null ) { outputStream.close(); } } } SharedObjects( String sharedObjectsFile );  SharedObjects(); static final String createFilename( String sharedObjectsFile ); Map<SharedEntry, SharedObjectInterface> getObjectsMap(); void setObjectsMap( Map<SharedEntry, SharedObjectInterface> objects ); void storeObject( SharedObjectInterface sharedObject ); void removeObject( SharedObjectInterface sharedObject ); void saveToFile(); SharedObjectInterface getSharedObject( Class<SharedObjectInterface> clazz, String objectName ); SharedObjectInterface getSharedObject( String className, String objectName ); DatabaseMeta getSharedDatabase( String name ); String getFilename(); void setFilename( String filename ); @Override String toString(); }
SharedObjects { @VisibleForTesting protected void writeToFile( FileObject fileObject, String backupFileName ) throws IOException, KettleException { OutputStream outputStream = null; PrintStream out = null; try { outputStream = initOutputStreamUsingKettleVFS( fileObject ); out = new PrintStream( outputStream ); out.print( XMLHandler.getXMLHeader( Const.XML_ENCODING ) ); out.println( "<" + XML_TAG + ">" ); Collection<SharedObjectInterface> collection = objectsMap.values(); for ( SharedObjectInterface sharedObject : collection ) { String xmlContent = sharedObject.getXML(); out.println( xmlContent ); } out.println( "</" + XML_TAG + ">" ); } catch ( Exception e ) { boolean isRestored = false; if ( backupFileName != null ) { restoreFileFromBackup( backupFileName ); isRestored = true; } throw new KettleException( BaseMessages.getString( PKG, "SharedOjects.WriteToFile.ErrorWritingFile", isRestored ), e ); } finally { if ( out != null ) { out.flush(); } if ( out != null ) { out.close(); } if ( out != null ) { outputStream.close(); } } } SharedObjects( String sharedObjectsFile );  SharedObjects(); static final String createFilename( String sharedObjectsFile ); Map<SharedEntry, SharedObjectInterface> getObjectsMap(); void setObjectsMap( Map<SharedEntry, SharedObjectInterface> objects ); void storeObject( SharedObjectInterface sharedObject ); void removeObject( SharedObjectInterface sharedObject ); void saveToFile(); SharedObjectInterface getSharedObject( Class<SharedObjectInterface> clazz, String objectName ); SharedObjectInterface getSharedObject( String className, String objectName ); DatabaseMeta getSharedDatabase( String name ); String getFilename(); void setFilename( String filename ); @Override String toString();  }