Package org.apache.commons.mail

Examples of org.apache.commons.mail.DataSourceResolver


        assertNull(dataSourceResolver.resolve("./images/does-not-exist.gif"));
    }

    public void testResolvingFileNonLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver = new DataSourceFileResolver(new File("."), false);
        assertNotNull(dataSourceResolver.resolve("./src/test/resources/images/asf_logo_wide.gif"));

        try
        {
            dataSourceResolver.resolve("asf_logo_wide.gif");
            fail("Expecting an IOException");
        }
        catch(IOException e)
        {
            return;
View Full Code Here


     *
     * @throws Exception the test failed
     */
    public void testResolvingFilesLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new File("./src/test/resources").toURI().toURL(), true);
        assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
        assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
        assertNull(dataSourceResolver.resolve("./images/does-not-exist.gif"));
        assertNull(dataSourceResolver.resolve("/images/asf_logo_wide.gif"));
    }
View Full Code Here

     *
     * @throws Exception the test failed
     */
    public void testResolvingHttpLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), true);
        assertTrue(toByteArray(dataSourceResolver.resolve("http://www.apache.org/images/feather-small.gif")).length > 1);
        assertTrue(toByteArray(dataSourceResolver.resolve("images/feather-small.gif")).length > 1);
        assertTrue(toByteArray(dataSourceResolver.resolve("./images/feather-small.gif")).length > 1);
        assertTrue(toByteArray(dataSourceResolver.resolve("/images/feather-small.gif")).length > 1);
        assertNull(toByteArray(dataSourceResolver.resolve("/images/does-not-exist.gif")));
    }
View Full Code Here

     *
     * @throws Exception the test failed
     */
    public void testResolvingHttpNonLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));

        try
        {
            dataSourceResolver.resolve("images/does-not-exist.gif");
            fail("Expecting an IOException");
        }
        catch(IOException e)
        {
            // expected
View Full Code Here

    // Start of Tests
    // ======================================================================
   
    public void testResolvingClassPathLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver;

        dataSourceResolver = new DataSourceClassPathResolver("/", true);
        assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
        assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
        assertTrue(toByteArray(dataSourceResolver.resolve("/images/asf_logo_wide.gif")).length == IMG_SIZE);
        assertNull(dataSourceResolver.resolve("/asf_logo_wide.gif"));

        dataSourceResolver = new DataSourceClassPathResolver("/images", true);
        assertTrue(toByteArray(dataSourceResolver.resolve("asf_logo_wide.gif")).length == IMG_SIZE);
        assertTrue(toByteArray(dataSourceResolver.resolve("./asf_logo_wide.gif")).length == IMG_SIZE);
        assertTrue(toByteArray(dataSourceResolver.resolve("/asf_logo_wide.gif")).length == IMG_SIZE);
        assertNull(dataSourceResolver.resolve("./images/asf_logo_wide.gif"));
    }
View Full Code Here

    /** {@inheritDoc} */
    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
    {
        for (int i = 0; i < getDataSourceResolvers().length; i++)
        {
            DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i];
            DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient);

            if (dataSource != null)
            {
                return dataSource;
            }
View Full Code Here

        assertNull(dataSourceResolver.resolve("./images/asf_logo_wide.gif"));
    }

    public void testResolvingClassPathNonLenient() throws Exception
    {
        DataSourceResolver dataSourceResolver;

        dataSourceResolver = new DataSourceClassPathResolver("/", false);
        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));

        try
        {
            dataSourceResolver.resolve("asf_logo_wide.gif");
            fail("Expecting an IOException");
        }
        catch(IOException e)
        {
            return;
View Full Code Here

        super(name);
    }

    public void testResolvingFilesLenient() throws Exception
    {
        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images", false);
        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver, classPathResolver };
        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);
    }
View Full Code Here

        assertTrue(toByteArray(dataSourceResolver.resolve("/contentTypeTest.gif")).length > 0);
    }

    public void testResolvingFilesNonLenient() throws Exception
    {
        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images", false);
        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver, classPathResolver };
        DataSourceResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, false);

        try
        {
            dataSourceResolver.resolve("./image/does-not-exist.gif");
            fail("Expected an IOException");
        }
        catch(IOException e)
        {
            // expected
View Full Code Here

        }
    }

    public void testExternalModification() throws Exception
    {
        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images", false);
        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver, classPathResolver };
        DataSourceCompositeResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, true);

        DataSourceResolver[] arr = dataSourceResolver.getDataSourceResolvers();
       
View Full Code Here

TOP

Related Classes of org.apache.commons.mail.DataSourceResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.