commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r1029898 [3/3] - in /commons/proper/email/trunk/src: changes/ java/org/apache/commons/mail/ java/org/apache/commons/mail/impl/ java/org/apache/commons/mail/util/ test/eml/ test/org/apache/commons/mail/ test/org/apache/commons/mail/util/
Date Mon, 01 Nov 2010 23:59:17 GMT
Added: commons/proper/email/trunk/src/test/eml/simple.eml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/eml/simple.eml?rev=1029898&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/eml/simple.eml (added)
+++ commons/proper/email/trunk/src/test/eml/simple.eml Mon Nov  1 23:59:16 2010
@@ -0,0 +1,15 @@
+Date: Mon, 1 Nov 2010 17:26:01 +0100 (CET)
+From: "test_from@apache.org" <test_from@apache.org>
+To: "test_from@apache.org" <test_from@apache.org>
+Message-ID: <1313946977.21.1288628761097.JavaMail.sgoeschl@deathmarch.local>
+Subject: Test HTML Send #1 Subject (wo charset)
+MIME-Version: 1.0
+Content-Type: multipart/mixed; 
+	boundary="----=_Part_20_1024180126.1288628761095"
+
+------=_Part_20_1024180126.1288628761095
+Content-Type: text/plain; charset=us-ascii
+Content-Transfer-Encoding: 7bit
+
+Test message
+------=_Part_20_1024180126.1288628761095--
\ No newline at end of file

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/BaseEmailTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/BaseEmailTestCase.java?rev=1029898&r1=1029897&r2=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/BaseEmailTestCase.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/BaseEmailTestCase.java Mon
Nov  1 23:59:16 2010
@@ -37,8 +37,6 @@ import org.apache.commons.mail.settings.
 import org.subethamail.wiser.Wiser;
 import org.subethamail.wiser.WiserMessage;
 
-
-
 /**
  * Base test case for Email test classes
  *
@@ -52,6 +50,7 @@ public abstract class BaseEmailTestCase 
 {
     /** Padding at end of body added by wiser/send */
     public static final int BODY_END_PAD = 3;
+
     /** Padding at start of body added by wiser/send */
     public static final int BODY_START_PAD = 2;
 
@@ -65,15 +64,20 @@ public abstract class BaseEmailTestCase 
     protected Wiser fakeMailServer;
 
     /** Mail server used for testing */
-    protected String strTestMailServer = EmailConfiguration.MAIL_SERVER;
+    protected String strTestMailServer = "localhost";
+
     /** From address for the test email */
-    protected String strTestMailFrom = EmailConfiguration.TEST_FROM;
+    protected String strTestMailFrom = "test_from@apache.org";
+
     /** Destination address for the test email */
-    protected String strTestMailTo = EmailConfiguration.TEST_TO;
+    protected String strTestMailTo = "test_to@apache.org";
+
     /** Mailserver username (set if needed) */
-    protected String strTestUser = EmailConfiguration.TEST_USER;
+    protected String strTestUser = "user";
+
     /** Mailserver strTestPasswd (set if needed) */
-    protected String strTestPasswd = EmailConfiguration.TEST_PASSWD;
+    protected String strTestPasswd = "password";
+
     /** URL to used to test URL attachmetns (Must be valid) */
     protected String strTestURL = EmailConfiguration.TEST_URL;
 

Copied: commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java
(from r1006345, commons/proper/email/trunk/src/test/org/apache/commons/mail/DefaultAuthenticatorTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java?p2=commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java&p1=commons/proper/email/trunk/src/test/org/apache/commons/mail/DefaultAuthenticatorTest.java&r1=1006345&r2=1029898&rev=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/DefaultAuthenticatorTest.java
(original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java
Mon Nov  1 23:59:16 2010
@@ -16,46 +16,33 @@
  */
 package org.apache.commons.mail;
 
-import javax.mail.PasswordAuthentication;
-
 import junit.framework.TestCase;
+import org.apache.commons.mail.impl.DataSourceResolverImpl;
+
+import java.io.File;
 
 /**
- * JUnit test case for DefaultAuthenticator Class
+ * JUnit test case for DateSourceResolver.
  *
- * @since 1.0
- * @author <a href="mailto:corey.scott@gmail.com">Corey Scott</a>
- * @version $Id$
+ * @since 1.3
  */
 
-public class DefaultAuthenticatorTest extends TestCase
+public class DataSourceResolverTest extends TestCase
 {
-    /**
-     * @param name name
-     */
-    public DefaultAuthenticatorTest(String name)
+    public DataSourceResolverTest(String name)
     {
         super(name);
     }
 
-    /** */
-    public void testDefaultAuthenticatorConstructor()
+    // ======================================================================
+    // Start of Tests
+    // ======================================================================
+    
+    public void testResolvingFiles() throws Exception
     {
-        //insert code testing basic functionality
-        String strUsername = "user.name";
-        String strPassword = "user.pwd";
-        DefaultAuthenticator authenicator =
-            new DefaultAuthenticator(strUsername, strPassword);
-
-        assertTrue(
-            PasswordAuthentication.class.isInstance(
-                authenicator.getPasswordAuthentication()));
-        assertEquals(
-            strUsername,
-            authenicator.getPasswordAuthentication().getUserName());
-        assertEquals(
-            strPassword,
-            authenicator.getPasswordAuthentication().getPassword());
+        DataSourceResolver dataSourceResolver = new DataSourceResolverImpl(new File("./src/test").toURI().toURL(),
true);
+        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));
+        assertNotNull(dataSourceResolver.resolve("./images/asf_logo_wide.gif"));
+        assertNull(dataSourceResolver.resolve("./images/does not exist gif"));
     }
-
 }

Propchange: commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailAttachmentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailAttachmentTest.java?rev=1029898&r1=1029897&r2=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailAttachmentTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailAttachmentTest.java Mon
Nov  1 23:59:16 2010
@@ -89,11 +89,10 @@ public class EmailAttachmentTest extends
             {
                 "http://localhost/",
                 "http://www.apache.org/",
-                "http://example.invalid" };
+                "http://foo.notexisting.org" };
 
         for (int i = 0; i < tests.length; i++)
         {
-            // TODO: Document why malformed url is ok, or remove the catch
             try
             {
                 URL testURL = new URL(tests[i]);
@@ -102,8 +101,7 @@ public class EmailAttachmentTest extends
             }
             catch (MalformedURLException e)
             {
-                e.printStackTrace();
-                continue;
+                fail(e.getMessage());
             }
         }
     }

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java?rev=1029898&r1=1029897&r2=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java Mon Nov
 1 23:59:16 2010
@@ -18,6 +18,7 @@ package org.apache.commons.mail;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.impl.DataSourceResolverImpl;
 import org.apache.commons.mail.settings.EmailConfiguration;
 
 import javax.activation.DataSource;
@@ -252,8 +253,9 @@ public class EmailLiveTest extends BaseE
         String htmlMsg1 = FileUtils.readFileToString(htmlFile);
 
         ImageHtmlEmail email = (ImageHtmlEmail) create(ImageHtmlEmail.class);
+        email.setDataSourceResolver(new DataSourceResolverImpl(htmlFile.toURI().toURL(),
true));
         email.setSubject("[testImageHtmlEmail] 1.Test: simple html content");
-        email.setHtmlMsg(htmlMsg1, htmlFile.toURI().toURL(), false);
+        email.setHtmlMsg(htmlMsg1);
 
         EmailUtils.writeMimeMessage( new File("./target/test-emails/testImageHtmlEmailLocal.eml"),
send(email).getMimeMessage());
     }
@@ -270,12 +272,14 @@ public class EmailLiveTest extends BaseE
     {
         if(EmailConfiguration.MAIL_FORCE_SEND)
         {
-            URL url = new URL("http://www.apache.org");
+            // URL url = new URL("http://commons.apache.org/email/");
+            URL url = new URL("http://nemo.sonarsource.org/project/index/221295?page_id=2");
             String htmlMsg = getFromUrl(url);
 
             ImageHtmlEmail email = (ImageHtmlEmail) create(ImageHtmlEmail.class);
+            email.setDataSourceResolver(new DataSourceResolverImpl(url, true));
             email.setSubject("[testImageHtmlEmail] 2.Test: complex html content");
-            email.setHtmlMsg(htmlMsg, url, true);
+            email.setHtmlMsg(htmlMsg);
 
             EmailUtils.writeMimeMessage( new File("./target/test-emails/testImageHtmlEmailRemote.eml"),
send(email).getMimeMessage());
         }

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java?rev=1029898&r1=1029897&r2=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java Mon Nov
 1 23:59:16 2010
@@ -32,7 +32,6 @@ import org.apache.commons.mail.settings.
  * @author <a href="mailto:corey.scott@gmail.com">Corey Scott</a>
  * @version $Id$
  */
-
 public class HtmlEmailTest extends BaseEmailTestCase
 {
     /** */

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java?rev=1029898&r1=1029897&r2=1029898&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java Mon
Nov  1 23:59:16 2010
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.mail;
 
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,12 +26,13 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.activation.DataHandler;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.impl.DataSourceResolverImpl;
 import org.apache.commons.mail.mocks.MockImageHtmlEmailConcrete;
+import org.apache.commons.mail.util.MimeMessageParser;
 import org.subethamail.wiser.WiserMessage;
 
 public class ImageHtmlEmailTest extends HtmlEmailTest {
@@ -43,22 +42,22 @@ public class ImageHtmlEmailTest extends 
     private static final File TEST_IMAGE_DIR = new File(TEST_IMAGE_URL.getPath()).getParentFile();
     private static final URL TEST_HTML_URL = ImageHtmlEmailTest.class.getResource("/attachments/download_email.cgi.html");
 
+    private MockImageHtmlEmailConcrete email;
+
     public ImageHtmlEmailTest(String name) throws IOException {
 		super(name);
 	}
 
-	/** */
-	private MockImageHtmlEmailConcrete email;
-
-	/**
-	 * @throws Exception
-	 */
 	protected void setUp() throws Exception {
 		super.setUp();
 		// reusable objects to be used across multiple tests
 		email = new MockImageHtmlEmailConcrete();
 	}
 
+    // ======================================================================
+    // Start of Tests
+    // ======================================================================
+
 	public void testSendHtml() throws Exception {
 
 		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
@@ -69,6 +68,7 @@ public class ImageHtmlEmailTest extends 
 		String strSubject = "Test HTML Send default";
 
 		email = new MockImageHtmlEmailConcrete();
+        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(),
TEST_IS_LENIENT));
 		email.setHostName(strTestMailServer);
 		email.setSmtpPort(getMailServerPort());
 		email.setFrom(strTestMailFrom);
@@ -90,35 +90,21 @@ public class ImageHtmlEmailTest extends 
 		String html = str.toString();
 
 		// set the html message
-		email.setHtmlMsg(html, TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT);
+		email.setHtmlMsg(html);
 
 		// set the alternative message
-		//email.setTextMsg("Your email client does not support HTML messages");
+		email.setTextMsg("Your email client does not support HTML messages");
 
 		// send the email
 		email.send();
 
 		fakeMailServer.stop();
 
-		// Cannot validate as the HTML is changed during inclusion
-		// validate html message
-		//validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
-		//		email.getFromAddress(), email.getToAddresses(),
-		//		email.getCcAddresses(), email.getBccAddresses(), false);
 		assertEquals(1, fakeMailServer.getMessages().size());
 		MimeMessage mimeMessage = ((WiserMessage) fakeMailServer.getMessages().get(0)).getMimeMessage();
-
-		DataHandler dataHandler = mimeMessage.getDataHandler();
-		ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
-		BufferedOutputStream buffOs = new BufferedOutputStream(byteArrayOutStream);
-		dataHandler.writeTo(buffOs);
-		buffOs.flush();
-
-		String msg = new String(byteArrayOutStream.toByteArray());
-		// the mail should contain Content-ID-Entries
-		assertTrue(msg, msg.contains("\"cid:"));
-		// at least the logo that we store locally should be replaced by an included cid now
-		assertFalse(msg, msg.contains("\"asf_logo_wide.gif\""));
+        MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse();
+        assertTrue(mimeMessageParser.getHtmlContent().contains("\"cid:"));
+        assertTrue(mimeMessageParser.getAttachmentList().size() == 2);
 	}
 
 	public void testSendEmptyHTML() throws Exception {
@@ -129,7 +115,7 @@ public class ImageHtmlEmailTest extends 
 
 		// set the html message
 		try {
-			email.setHtmlMsg(null, new File("/tmp").toURI().toURL(), TEST_IS_LENIENT);
+			email.setHtmlMsg(null);
 			fail("Should fail here!");
 		} catch (EmailException e) {
 			assertTrue(e.getMessage(), e.getMessage().contains(
@@ -145,7 +131,7 @@ public class ImageHtmlEmailTest extends 
 
 		// set the html message
 		try {
-			email.setHtmlMsg("", new File("/tmp").toURI().toURL(), TEST_IS_LENIENT);
+			email.setHtmlMsg("");
 			fail("Should fail here!");
 		} catch (EmailException e) {
 			assertTrue(e.getMessage(), e.getMessage().contains(
@@ -168,11 +154,11 @@ public class ImageHtmlEmailTest extends 
 		email.setFrom(strTestMailFrom);
 		email.addTo(strTestMailTo);
 		email.setSubject(strSubject);
+        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(),
TEST_IS_LENIENT));
 
 		// set the html message
 		email.setHtmlMsg(
-            "<html><body><img src=\"http://www.apache.org/images/feather.gif\"/></body></html>",
-            TEST_IS_LENIENT
+            "<html><body><img src=\"http://www.apache.org/images/feather.gif\"/></body></html>"
             );
 
 		// send the email
@@ -200,6 +186,7 @@ public class ImageHtmlEmailTest extends 
 		email.setFrom(strTestMailFrom);
 		email.addTo(strTestMailTo);
 		email.setSubject(strSubject);
+        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(),
TEST_IS_LENIENT));
 
 		File file = File.createTempFile("emailtest", ".tst");
 		FileUtils.writeStringToFile(file,
@@ -207,7 +194,8 @@ public class ImageHtmlEmailTest extends 
 
 		// set the html message
 		email.setHtmlMsg("<html><body><img src=\"" + file.getAbsolutePath()
-				+ "\"/></body></html>", new File("").toURI().toURL(), TEST_IS_LENIENT);
+				+ "\"/></body></html>"
+            );
 
 		// send the email
 		email.send();

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/util/MimeMessageParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/util/MimeMessageParserTest.java?rev=1029898&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/util/MimeMessageParserTest.java
(added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/util/MimeMessageParserTest.java
Mon Nov  1 23:59:16 2010
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.mail.util;
+
+import junit.framework.TestCase;
+
+import javax.activation.DataSource;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Testing the MimeMessageParser.
+ */
+public class MimeMessageParserTest
+    extends TestCase
+{
+    /**
+     * Defines the test case name for JUnit.
+     *
+     * @param name the test case's name.
+     */
+    public MimeMessageParserTest(String name)
+    {
+        super(name);
+    }
+
+    // ======================================================================
+    // Start of Tests
+    // ======================================================================
+
+    public void testParseSimpleEmail() throws Exception
+    {
+        Session session = Session.getDefaultInstance(new Properties());
+        MimeMessage message = MimeMessageUtils.createMimeMessage(session, new File("./src/test/eml/simple.eml"));
+        MimeMessageParser mimeMessageParser = new MimeMessageParser(message);
+
+        mimeMessageParser.parse();
+
+        assertEquals("Test HTML Send #1 Subject (wo charset)", mimeMessageParser.getSubject());
+        assertNotNull(mimeMessageParser.getMimeMessage());
+        assertTrue(mimeMessageParser.isMultipart());
+        assertFalse(mimeMessageParser.hasHtmlContent());
+        assertTrue(mimeMessageParser.hasPlainContent());
+        assertNotNull(mimeMessageParser.getPlainContent());
+        assertNull(mimeMessageParser.getHtmlContent());
+        assertTrue(mimeMessageParser.getTo().size() == 1);
+        assertTrue(mimeMessageParser.getCc().size() == 0);
+        assertTrue(mimeMessageParser.getBcc().size() == 0);
+        assertEquals("test_from@apache.org", mimeMessageParser.getFrom());
+        assertEquals("test_from@apache.org", mimeMessageParser.getReplyTo());
+        assertFalse(mimeMessageParser.hasAttachments());
+    }
+
+    public void testParseHtmlEmailWithAttachments() throws Exception
+    {
+        DataSource dataSource;
+        Session session = Session.getDefaultInstance(new Properties());
+        MimeMessage message = MimeMessageUtils.createMimeMessage(session, new File("./src/test/eml/html-attachment.eml"));
+        MimeMessageParser mimeMessageParser = new MimeMessageParser(message);
+
+        mimeMessageParser.parse();
+
+        assertEquals("Test", mimeMessageParser.getSubject());
+        assertNotNull(mimeMessageParser.getMimeMessage());        
+        assertTrue(mimeMessageParser.isMultipart());
+        assertTrue(mimeMessageParser.hasHtmlContent());
+        assertTrue(mimeMessageParser.hasPlainContent());
+        assertNotNull(mimeMessageParser.getPlainContent());
+        assertNotNull(mimeMessageParser.getHtmlContent());
+        assertTrue(mimeMessageParser.getTo().size() == 1);
+        assertTrue(mimeMessageParser.getCc().size() == 0);
+        assertTrue(mimeMessageParser.getBcc().size() == 0);
+        assertEquals("siegfried.goeschl@it20one.at", mimeMessageParser.getFrom());
+        assertEquals("siegfried.goeschl@it20one.at", mimeMessageParser.getReplyTo());
+        assertTrue(mimeMessageParser.hasAttachments());
+        List attachmentList = mimeMessageParser.getAttachmentList();
+        assertTrue(attachmentList.size() == 2);
+
+        dataSource = mimeMessageParser.findAttachmentByName("Wasserlilien.jpg");
+        assertNotNull(dataSource);
+        assertEquals("image/jpeg", dataSource.getContentType());
+
+        dataSource = mimeMessageParser.findAttachmentByName("it20one.pdf");
+        assertNotNull(dataSource);
+        assertEquals("application/pdf", dataSource.getContentType());
+    }
+}

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java?rev=1029898&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java (added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java Mon
Nov  1 23:59:16 2010
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.mail.util;
+
+import junit.framework.TestCase;
+import org.apache.commons.mail.DefaultAuthenticator;
+
+import javax.mail.PasswordAuthentication;
+import java.io.File;
+import java.net.URL;
+
+/**
+ * JUnit test case for DefaultAuthenticator Class
+ *
+ * @since 1.0
+ * @author <a href="mailto:corey.scott@gmail.com">Corey Scott</a>
+ * @version $Id: DefaultAuthenticatorTest.java 480401 2006-11-29 04:40:04Z bayard $
+ */
+
+public class URLFactoryTest extends TestCase
+{
+    public URLFactoryTest(String name)
+    {
+        super(name);
+    }
+
+    // ======================================================================
+    // Start of Tests
+    // ======================================================================
+    
+    public void testCreateUrl() throws Exception
+    {
+        URL url;
+        URL baseUrl;
+        String location;
+
+        // base URL + relative file name
+        location = "pom.xml";
+        baseUrl = new File("").toURI().toURL();
+        url = URLFactory.createUrl(baseUrl, location);
+        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
+
+        // base URL  + file URL
+        location = new File("pom.xml").toURI().toURL().toExternalForm();
+        baseUrl = new File("").toURI().toURL();
+        url = URLFactory.createUrl(baseUrl, location);
+        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
+
+        // file URL only
+        location = new File("pom.xml").toURI().toURL().toExternalForm();
+        baseUrl = null;
+        url = URLFactory.createUrl(baseUrl, location);
+        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
+    }
+}



Mime
View raw message