SchedulerOutputPathResolver { public String resolveOutputFilePath() { String fileName = RepositoryFilenameUtils.getBaseName( scheduleRequest.getInputFile() ); if ( !StringUtils.isEmpty( scheduleRequest.getJobName() ) ) { fileName = scheduleRequest.getJobName(); } String fileNamePattern = "/" + fileName + ".*"; String outputFilePath = scheduleRequest.getOutputFile(); if ( outputFilePath != null && outputFilePath.endsWith( fileNamePattern ) ) { outputFilePath = outputFilePath.substring( 0, outputFilePath.indexOf( fileNamePattern ) ); } if ( StringUtils.isNotBlank( outputFilePath ) && isValidOutputPath( outputFilePath ) ) { return outputFilePath + fileNamePattern; } String[] fallBackPaths = new String[] { getUserSettingOutputPath(), getSystemSettingOutputPath(), getUserHomeDirectoryPath() }; for ( String path : fallBackPaths ) { if ( StringUtils.isNotBlank( path ) && isValidOutputPath( path ) ) { return path + fileNamePattern; } } return null; } SchedulerOutputPathResolver( JobScheduleRequest scheduleRequest ); String resolveOutputFilePath();  }
@Test public void testResolveOutputFilePath() throws Exception { JobScheduleRequest scheduleRequest = new JobScheduleRequest(); String inputFile = "/home/admin/test.prpt"; String outputFolder = "/home/admin/output"; scheduleRequest.setInputFile( inputFile ); scheduleRequest.setOutputFile( outputFolder ); RepositoryFile repoFile = mock( RepositoryFile.class ); when( repo.getFile( outputFolder ) ).thenReturn( repoFile ); when( repoFile.isFolder() ).thenReturn( true ); schedulerOutputPathResolver = new SchedulerOutputPathResolver( scheduleRequest ); String outputFilePath = schedulerOutputPathResolver.resolveOutputFilePath(); assertEquals( "/home/admin/output/test.*", outputFilePath ); verify( repo ).getFile( outputFolder ); }
@Test public void testResolveOutputFilePath_ContainsPatternAlready() throws Exception { JobScheduleRequest scheduleRequest = new JobScheduleRequest(); String inputFile = "/home/admin/test.prpt"; String outputFolder = "/home/admin/output/test.*"; scheduleRequest.setInputFile( inputFile ); scheduleRequest.setOutputFile( outputFolder ); RepositoryFile repoFile = mock( RepositoryFile.class ); when( repo.getFile( anyString() ) ).thenReturn( repoFile ); when( repoFile.isFolder() ).thenReturn( true ); schedulerOutputPathResolver = new SchedulerOutputPathResolver( scheduleRequest ); String outputFilePath = schedulerOutputPathResolver.resolveOutputFilePath(); assertEquals( "/home/admin/output/test.*", outputFilePath ); verify( repo ).getFile( "/home/admin/output" ); }