@Test public void createScriptFileWithEnvVariablesTest() { String expectedFile = "file"; String variable = "FileVariable"; Variables variables = new Variables(); variables.setVariable( variable, expectedFile ); setInternalState( teraDataBulkLoaderMock, "variables", variables ); when( teraDataBulkLoaderMetaMock.getExistingScriptFile() ).thenReturn( "${" + variable + "}" ); when( teraDataBulkLoaderMock.environmentSubstitute( anyString() ) ).thenCallRealMethod(); File file = new File( expectedFile ); try { file.createNewFile(); file.deleteOnExit(); String script = teraDataBulkLoaderRoutines.createScriptFile(); assertTrue( script.contains( expectedFile ) ); } catch ( Exception ex ) { fail( ex.getMessage() ); } finally { file.delete(); } }
public String createScriptFile() throws Exception { File tempScriptFile; if ( meta.getGenerateScript() ) { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getScriptFileName() ) ), "" ); } else { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getExistingScriptFile() ) ), "" ); } tempScriptFile.deleteOnExit(); try { scriptFile = FileUtils.openOutputStream( tempScriptFile ); scriptFilePrintStream = new PrintStream( scriptFile ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "TeraDataBulkLoaderMeta.Exception.OpenScriptFile", scriptFile ), e ); } if ( meta.getGenerateScript() ) { createGeneratedScriptFile(); } else { createFromExistingScriptFile(); } scriptFilePrintStream.close(); IOUtils.closeQuietly( scriptFile ); return tempScriptFile.getAbsolutePath(); }
TeraDataBulkLoaderRoutines { public String createScriptFile() throws Exception { File tempScriptFile; if ( meta.getGenerateScript() ) { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getScriptFileName() ) ), "" ); } else { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getExistingScriptFile() ) ), "" ); } tempScriptFile.deleteOnExit(); try { scriptFile = FileUtils.openOutputStream( tempScriptFile ); scriptFilePrintStream = new PrintStream( scriptFile ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "TeraDataBulkLoaderMeta.Exception.OpenScriptFile", scriptFile ), e ); } if ( meta.getGenerateScript() ) { createGeneratedScriptFile(); } else { createFromExistingScriptFile(); } scriptFilePrintStream.close(); IOUtils.closeQuietly( scriptFile ); return tempScriptFile.getAbsolutePath(); } }
TeraDataBulkLoaderRoutines { public String createScriptFile() throws Exception { File tempScriptFile; if ( meta.getGenerateScript() ) { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getScriptFileName() ) ), "" ); } else { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getExistingScriptFile() ) ), "" ); } tempScriptFile.deleteOnExit(); try { scriptFile = FileUtils.openOutputStream( tempScriptFile ); scriptFilePrintStream = new PrintStream( scriptFile ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "TeraDataBulkLoaderMeta.Exception.OpenScriptFile", scriptFile ), e ); } if ( meta.getGenerateScript() ) { createGeneratedScriptFile(); } else { createFromExistingScriptFile(); } scriptFilePrintStream.close(); IOUtils.closeQuietly( scriptFile ); return tempScriptFile.getAbsolutePath(); } TeraDataBulkLoaderRoutines( TeraDataBulkLoader parent, TeraDataBulkLoaderMeta meta ); }
TeraDataBulkLoaderRoutines { public String createScriptFile() throws Exception { File tempScriptFile; if ( meta.getGenerateScript() ) { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getScriptFileName() ) ), "" ); } else { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getExistingScriptFile() ) ), "" ); } tempScriptFile.deleteOnExit(); try { scriptFile = FileUtils.openOutputStream( tempScriptFile ); scriptFilePrintStream = new PrintStream( scriptFile ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "TeraDataBulkLoaderMeta.Exception.OpenScriptFile", scriptFile ), e ); } if ( meta.getGenerateScript() ) { createGeneratedScriptFile(); } else { createFromExistingScriptFile(); } scriptFilePrintStream.close(); IOUtils.closeQuietly( scriptFile ); return tempScriptFile.getAbsolutePath(); } TeraDataBulkLoaderRoutines( TeraDataBulkLoader parent, TeraDataBulkLoaderMeta meta ); String dropTable( boolean isPreview, String user, String suffix ); String createScriptFile(); void createFromExistingScriptFile(); String createGeneratedScriptFile(); String createGeneratedScriptFile( Map<String, Integer> inputFieldTypes, Map<String, Integer> inputFieldLength ); }
TeraDataBulkLoaderRoutines { public String createScriptFile() throws Exception { File tempScriptFile; if ( meta.getGenerateScript() ) { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getScriptFileName() ) ), "" ); } else { tempScriptFile = File.createTempFile( FilenameUtils.getBaseName( parent.environmentSubstitute( meta.getExistingScriptFile() ) ), "" ); } tempScriptFile.deleteOnExit(); try { scriptFile = FileUtils.openOutputStream( tempScriptFile ); scriptFilePrintStream = new PrintStream( scriptFile ); } catch ( IOException e ) { throw new KettleException( BaseMessages.getString( PKG, "TeraDataBulkLoaderMeta.Exception.OpenScriptFile", scriptFile ), e ); } if ( meta.getGenerateScript() ) { createGeneratedScriptFile(); } else { createFromExistingScriptFile(); } scriptFilePrintStream.close(); IOUtils.closeQuietly( scriptFile ); return tempScriptFile.getAbsolutePath(); } TeraDataBulkLoaderRoutines( TeraDataBulkLoader parent, TeraDataBulkLoaderMeta meta ); String dropTable( boolean isPreview, String user, String suffix ); String createScriptFile(); void createFromExistingScriptFile(); String createGeneratedScriptFile(); String createGeneratedScriptFile( Map<String, Integer> inputFieldTypes, Map<String, Integer> inputFieldLength );  }