@Test void cantGetJobsDirWhenJobsDirInvalid() throws IOException { final ResourceLoader resourceLoader = Mockito.mock(ResourceLoader.class); final URI jobsDirLocation = URI.create("file:/" + UUID.randomUUID().toString()); final JobsProperties jobsProperties = JobsProperties.getJobsPropertiesDefaults(); jobsProperties.getLocations().setJobs(jobsDirLocation); final Resource tmpResource = Mockito.mock(Resource.class); Mockito.when(resourceLoader.getResource(jobsDirLocation.toString())).thenReturn(tmpResource); Mockito.when(tmpResource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(tmpResource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(false); Assertions .assertThatIllegalStateException() .isThrownBy(() -> this.apisAutoConfiguration.jobsDir(resourceLoader, jobsProperties)) .withMessage(jobsDirLocation + " exists but isn't a directory. Unable to continue"); final String localJobsDir = jobsDirLocation + "/"; Mockito.when(file.isDirectory()).thenReturn(true); final Resource jobsDirResource = Mockito.mock(Resource.class); Mockito.when(resourceLoader.getResource(localJobsDir)).thenReturn(jobsDirResource); Mockito.when(tmpResource.exists()).thenReturn(false); Mockito.when(jobsDirResource.exists()).thenReturn(false); Mockito.when(jobsDirResource.getFile()).thenReturn(file); Mockito.when(file.mkdirs()).thenReturn(false); Assertions .assertThatIllegalStateException() .isThrownBy(() -> this.apisAutoConfiguration.jobsDir(resourceLoader, jobsProperties)) .withMessage("Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist."); }
@Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir( final ResourceLoader resourceLoader, final JobsProperties jobsProperties ) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs().toString(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist." ); } } return jobsDirResource; }
ApisAutoConfiguration { @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir( final ResourceLoader resourceLoader, final JobsProperties jobsProperties ) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs().toString(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist." ); } } return jobsDirResource; } }
ApisAutoConfiguration { @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir( final ResourceLoader resourceLoader, final JobsProperties jobsProperties ) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs().toString(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist." ); } } return jobsDirResource; }  }
ApisAutoConfiguration { @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir( final ResourceLoader resourceLoader, final JobsProperties jobsProperties ) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs().toString(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist." ); } } return jobsDirResource; }  @Bean @ConditionalOnMissingBean(ResourceLoader.class) ResourceLoader resourceLoader(); @Bean @ConditionalOnMissingBean(name = "genieRestTemplate") RestTemplate genieRestTemplate(
        final HttpProperties httpProperties,
        final RestTemplateBuilder restTemplateBuilder
    ); @Bean @ConditionalOnMissingBean(name = "genieRetryTemplate") RetryTemplate genieRetryTemplate(final RetryProperties retryProperties); @Bean @ConditionalOnMissingBean(DirectoryWriter.class) DefaultDirectoryWriter directoryWriter(); @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) Resource jobsDir(
        final ResourceLoader resourceLoader,
        final JobsProperties jobsProperties
    ); @Bean CharacterEncodingFilter characterEncodingFilter(); @Bean Jackson2ObjectMapperBuilderCustomizer apisObjectMapperCustomizer(); }
ApisAutoConfiguration { @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir( final ResourceLoader resourceLoader, final JobsProperties jobsProperties ) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs().toString(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist." ); } } return jobsDirResource; }  @Bean @ConditionalOnMissingBean(ResourceLoader.class) ResourceLoader resourceLoader(); @Bean @ConditionalOnMissingBean(name = "genieRestTemplate") RestTemplate genieRestTemplate(
        final HttpProperties httpProperties,
        final RestTemplateBuilder restTemplateBuilder
    ); @Bean @ConditionalOnMissingBean(name = "genieRetryTemplate") RetryTemplate genieRetryTemplate(final RetryProperties retryProperties); @Bean @ConditionalOnMissingBean(DirectoryWriter.class) DefaultDirectoryWriter directoryWriter(); @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) Resource jobsDir(
        final ResourceLoader resourceLoader,
        final JobsProperties jobsProperties
    ); @Bean CharacterEncodingFilter characterEncodingFilter(); @Bean Jackson2ObjectMapperBuilderCustomizer apisObjectMapperCustomizer();  }