@Test public void shouldGetFileRelativeToConfigLocationGivenAnAccessType() throws IOException { String configDir = "config" + File.separatorChar; ConfigLocation configLocation = new ConfigLocation(configDir); File file = configLocation.getFile("test.properties", ConfigLocation.FileAccessType.READABLE); assertNotNull(file); assertEquals(file.getAbsolutePath(), new ClassPathResource(configDir + "test.properties").getFile().getAbsolutePath()); }
public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } }
ConfigLocation { public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } } }
ConfigLocation { public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } } ConfigLocation(String configLocation); }
ConfigLocation { public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } } ConfigLocation(String configLocation); Resource toResource(); String getLocation(); UrlResource getUrlResource(); File getFile(String fileName, FileAccessType accessType); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); List<File> getExistingConfigFiles(); boolean hasPlatformConfigurationFile(); }
ConfigLocation { public File getFile(String fileName, FileAccessType accessType) { try { Resource resource = toResource().createRelative(fileName); if (accessType.isAccessible(resource)) { return resource.getFile(); } throw new MotechConfigurationException(String.format("%s file in the location %s is not %s.", fileName, configLocation, accessType.toString())); } catch (IOException e) { throw new MotechConfigurationException(String.format("Error while checking if file %s in the location %s is %s.", fileName, configLocation, accessType.toString()), e); } } ConfigLocation(String configLocation); Resource toResource(); String getLocation(); UrlResource getUrlResource(); File getFile(String fileName, FileAccessType accessType); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); List<File> getExistingConfigFiles(); boolean hasPlatformConfigurationFile();  }