/** {@inheritDoc} */ @Override public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException { for (int i = 0; i < getDataSourceResolvers().length; i++) { final DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i]; final DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient); if (dataSource != null) { return dataSource; } } if (isLenient) { return null; } throw new IOException("The following resource was not found : " + resourceLocation); } }
/** {@inheritDoc} */ @Override public DataSource resolve(final String resourceLocation) throws IOException { final DataSource result = resolve(resourceLocation, true); if (isLenient() || result != null) { return result; } throw new IOException("The following resource was not found : " + resourceLocation); }
@Test public void testExternalModification() throws Exception { final DataSourceCompositeResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, true); final DataSourceResolver[] arr = dataSourceResolver.getDataSourceResolvers(); // modify an element in the returned array arr[0] = null; final DataSourceResolver[] arr2 = dataSourceResolver.getDataSourceResolvers(); // assert that the external modification is not propagated to the internal array assertNotNull(arr2[0]); }
@Test(expected = IOException.class) public void testResolvingFilesNonLenient() throws Exception { final DataSourceResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, false); dataSourceResolver.resolve("./image/does-not-exist.gif"); }
@Test public void testResolvingFilesLenient() throws Exception { final DataSourceResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, true); // resolve using HTTP assertTrue(toByteArray(dataSourceResolver.resolve("/images/feather-small.gif")).length > 0); // resolve using class path assertTrue(toByteArray(dataSourceResolver.resolve("/contentTypeTest.gif")).length > 0); }
/** {@inheritDoc} */ @Override public DataSource resolve(final String resourceLocation) throws IOException { final DataSource result = resolve(resourceLocation, true); if (isLenient() || result != null) { return result; } throw new IOException("The following resource was not found : " + resourceLocation); }
/** {@inheritDoc} */ @Override public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException { for (int i = 0; i < getDataSourceResolvers().length; i++) { final DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i]; final DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient); if (dataSource != null) { return dataSource; } } if (isLenient) { return null; } throw new IOException("The following resource was not found : " + resourceLocation); } }
dataSourceResolvers[1] = new DataSourceClassPathResolver("/", true); email.setDataSourceResolver(new DataSourceCompositeResolver(dataSourceResolvers)); email.setHostName(strTestMailServer); email.setSmtpPort(getMailServerPort());