Author: danny
Date: Tue Aug 14 07:35:51 2007
New Revision: 565774
URL: http://svn.apache.org/viewvc?view=rev&rev=565774
Log:
Added test tasks to build.xml
Added tests for o.a.m.MailAddress
Added:
james/mailet/trunk/src/test/
james/mailet/trunk/src/test/java/
james/mailet/trunk/src/test/java/org/
james/mailet/trunk/src/test/java/org/apache/
james/mailet/trunk/src/test/java/org/apache/mailet/
james/mailet/trunk/src/test/java/org/apache/mailet/MailAddressTest.java
james/mailet/trunk/src/test/resources/
Modified:
james/mailet/trunk/build.xml
james/mailet/trunk/default.properties
Modified: james/mailet/trunk/build.xml
URL:
http://svn.apache.org/viewvc/james/mailet/trunk/build.xml?view=diff&rev=565774&r1=565773&r2=565774
==============================================================================
--- james/mailet/trunk/build.xml (original)
+++ james/mailet/trunk/build.xml Tue Aug 14 07:35:51 2007
@@ -90,17 +90,11 @@
</copy>
<fixcrlf srcdir="${java.dir}" includes="**/*.java" eol="lf" tab="remove"
tablength="4" />
<fixcrlf srcdir="${java.dir}" includes="**/*.html" eol="lf" tab="remove"
tablength="4" />
- <!--
- <fixcrlf srcdir="${test.dir}" includes="**/*.java" eol="lf" tab="remove"
tablength="4" />
- -->
<fixcrlf srcdir="${xdocs.dir}" includes="**/*.xml" eol="lf" tab="remove"
tablength="4" />
- <!--
<fixcrlf srcdir="${conf.dir}" includes="**/*.xml" eol="lf" tab="remove"
tablength="4" />
- -->
<fixcrlf srcdir="." includes="build.sh" eol="lf"/>
<fixcrlf srcdir="." includes="build.bat" eol="crlf"/>
<fixcrlf srcdir="." includes="build.xml" eol="lf"/>
- <!--fixcrlf srcdir="${javacc.dir}" includes="**/*.jj*" eol="lf"
tab="remove" tablength="4" /-->
<mkdir dir="${build.src}"/>
</target>
@@ -126,7 +120,6 @@
<classpath refid="project.class.path"/>
<src path="${build.src}"/>
<src path="${java.dir}"/>
- <!-- <src path="${test.dir}"/> -->
<include name="org/apache/mailet/**"/>
<exclude name="**/samples/*/**"/>
</javac>
@@ -248,7 +241,7 @@
===================================================================
-->
- <target name="jar" depends="compile">
+ <target name="jar" depends="compile, test">
<mkdir dir="${build.lib}"/>
@@ -275,17 +268,7 @@
</manifest>
</jar>
-<!--
- <echo message="Making Mailet jUnit Jar (${name}-jUnit-${version}.jar)"/>
- <jar jarfile="${build.lib}/${name}-jUnit-${version}.jar"
basedir="${build.classes}">
- <include name="org/apache/mailet/junit/**"/>
- <manifest>
- <attribute name="Created-By" value='${creator}'/>
- <attribute name="X-Compile-Source-JDK" value='${jdk.source}'/>
- <attribute name="X-Compile-Target-JDK" value='${jdk.target}'/>
- </manifest>
- </jar>
- -->
+
</target>
<!--
@@ -293,9 +276,9 @@
Make dist directory with unpacked dist ready to run
===================================================================
-->
- <target name="dist-lite" depends="dist-lite-test"/>
+
- <target name="dist-lite-build" depends="jar">
+ <target name="dist-lite" depends="jar">
<echo message="Installing Mailet to ${dist.dir}"/>
@@ -305,50 +288,9 @@
<include name="*.jar"/>
</fileset>
</copy>
-
- <!--Copies the required support jars -->
- <!--copy todir="${dist.dir}/lib" file="${xercesImpl.jar}"/>
- <copy todir="${dist.dir}/lib" file="${xmlApis.jar}"/>
- <copy todir="${dist.dir}/lib" file="${javax-mail.jar}"/>
- <copy todir="${dist.dir}/lib" file="${javax-activation.jar}"/>
- <copy todir="${dist.dir}/lib" file="${commons-digester.jar}"/>
- <copy todir="${dist.dir}/lib" file="${commons-collections.jar}"/>
- <copy todir="${dist.dir}/lib" file="${commons-beanutils.jar}"/>
- <copy todir="${dist.dir}/lib" file="${commons-logging.jar}"/>
- <copy todir="${dist.dir}/lib" file="${jakarta-oro.jar}"/>
- <copy todir="${dist.dir}/lib" file="${log4j.jar}"/-->
-
- <!--Copies the configuration files -->
</target>
- <!--
- ===================================================================
- Test the dist-lite build
- ===================================================================
- -->
- <target name="dist-lite-test" depends="dist-lite-build">
- <echo message="Testing dist-lite build"/>
- <mkdir dir="${dist.dir}/reports"/>
- <!--
- <junit printsummary="yes" haltonfailure="yes" filtertrace="on">
- <classpath id="junit.class.path">
- <fileset dir="${dist.dir}/lib">
- <include name="**/*.jar"/>
- </fileset>
- <pathelement location="${dist.dir}/conf/"/>
- <pathelement path="${java.class.path}"/>
- <pathelement location="${junit.jar}"/>
- </classpath>
- <formatter type="plain"/>
- <batchtest fork="yes" todir="${dist.dir}/reports">
- <fileset dir="${build.classes}">
- <include name="**/junit/*Test*.class"/>
- <exclude name="**/junit/AllTests.class"/>
- </fileset>
- </batchtest>
- </junit>
- -->
- </target>
+
<!--
===================================================================
@@ -442,7 +384,7 @@
<echo message=" available targets are:"/>
<echo message=""/>
<echo message=" dist-lite --> generates unpacked distribution
(default)"/>
- <echo message=" test --> tests the jarred classes"/>
+ <echo message=" test --> tests the compiled classes"/>
<echo message=" website --> makes all the docs and javadocs"/>
<echo message=" compile --> compiles the source code"/>
<echo message=" dist --> generates all the Mailet
distributions, packed"/>
@@ -455,5 +397,60 @@
<echo message=""/>
<echo message=""/>
</target>
-
+
+ <!--
+ ===================================================================
+ Compile Tests
+ ===================================================================
+ -->
+ <target name="compile-tests" depends="junit-present, compile"
description="Compile the test code" if="junit.present">
+ <mkdir dir="${test.classes}"/>
+ <javac destdir="${test.classes}" excludes="**/package.html"
debug="true" deprecation="true" optimize="false">
+ <src>
+ <pathelement location="src/test/java"/>
+ </src>
+ <classpath>
+ <path refid="project.class.path"/>
+ </classpath>
+ </javac>
+ <copy todir="${test.classes}">
+ <fileset dir="src/test/resources"/>
+ </copy>
+ </target>
+ <!--
+ ===================================================================
+ Run Tests
+ ===================================================================
+ -->
+ <target name="test" depends="junit-present, compile-tests"
if="junit.present" description="Run the test cases">
+ <mkdir dir="${test.report}"/>
+ <junit printSummary="yes" haltonerror="true" haltonfailure="true"
fork="true" dir=".">
+ <sysproperty key="basedir" value="."/>
+ <formatter type="xml"/>
+ <formatter type="plain" usefile="false"/>
+ <classpath>
+ <path refid="project.class.path"/>
+ <pathelement location="${test.classes}"/>
+ </classpath>
+ <batchtest todir="${test.report}">
+ <fileset dir="src/test/java">
+ <include name="**/*Test.java"/>
+ <exclude name="**/*Abstract*Test.java"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+ <target name="test-junit-present">
+ <available classname="junit.framework.Test" property="junit.present"/>
+ </target>
+ <!--
+ ===================================================================
+ Find Junit
+ ===================================================================
+ -->
+ <target name="junit-present" depends="test-junit-present"
unless="junit.present">
+ <echo>================================= WARNING
================================</echo>
+ <echo> Junit isn't present in your $ANT_HOME/lib directory. Tests not
executed. </echo>
+
<echo>==========================================================================</echo>
+ </target>
</project>
Modified: james/mailet/trunk/default.properties
URL:
http://svn.apache.org/viewvc/james/mailet/trunk/default.properties?view=diff&rev=565774&r1=565773&r2=565774
==============================================================================
--- james/mailet/trunk/default.properties (original)
+++ james/mailet/trunk/default.properties Tue Aug 14 07:35:51 2007
@@ -70,6 +70,10 @@
xdocs.dir=${src.dir}/site/xdoc
docs.src=${xdocs.dir}
+test.dir=${build.dir}/test
+test.classes=${test.dir}/classes
+test.report=${test.dir}/report
+
#
# distribution directories
#
Added: james/mailet/trunk/src/test/java/org/apache/mailet/MailAddressTest.java
URL:
http://svn.apache.org/viewvc/james/mailet/trunk/src/test/java/org/apache/mailet/MailAddressTest.java?view=auto&rev=565774
==============================================================================
--- james/mailet/trunk/src/test/java/org/apache/mailet/MailAddressTest.java
(added)
+++ james/mailet/trunk/src/test/java/org/apache/mailet/MailAddressTest.java Tue
Aug 14 07:35:51 2007
@@ -0,0 +1,221 @@
+/*
+ * Created on 14 Aug 2007
+ *
+ * PVCS Workfile Details:
+ * $Workfile$
+ * $Revision$
+ * $Author$
+ * $Date$
+ * $Modtime$
+ */
+
+package org.apache.mailet;
+
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.ParseException;
+import junit.framework.TestCase;
+
+/**
+ * @author angusd
+ * @author $Author$
+ * @version $Revision$
+ */
+public class MailAddressTest extends TestCase {
+ private static final String GOOD_LOCAL_PART = "\"[EMAIL PROTECTED] part\"";
+ private static final String GOOD_QUOTED_LOCAL_PART = "\"[EMAIL PROTECTED]
part\"@james.apache.org";
+ private static final String BAD_LOCAL_PART_1 = "\"[EMAIL
PROTECTED]@james.apache.org";
+ private static final String BAD_LOCAL_PART_2 = "[EMAIL
PROTECTED]@james.apache.org";
+ private static final String BAD_LOCAL_PART_3 = "[EMAIL PROTECTED]";
+ private static final String GOOD_ADDRESS = "[EMAIL PROTECTED]";
+ private static final String GOOD_DOMAIN = "james.apache.org";
+
+ private static final String GOOD_DLIT = "[EMAIL PROTECTED]";
+ private static final String BAD_DLIT_1 = "[EMAIL PROTECTED]";
+ private static final String BAD_DLIT_2 = "[EMAIL PROTECTED]";
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#hashCode()}.
+ * @throws ParseException
+ */
+ public void testHashCode() throws ParseException {
+
+ MailAddress a = new MailAddress(GOOD_ADDRESS);
+ MailAddress b = new MailAddress(GOOD_ADDRESS);
+ assertTrue(a.hashCode()+" != "+ b.hashCode(),a.hashCode() ==
b.hashCode());
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#MailAddress(java.lang.String)}.
+ * @throws ParseException
+ */
+ public void testMailAddressString() throws ParseException {
+
+ MailAddress a = new MailAddress(GOOD_ADDRESS);
+ assertTrue(GOOD_ADDRESS.equals(a.toString()));
+ try{
+ a = new MailAddress(GOOD_QUOTED_LOCAL_PART);
+ }catch (ParseException e){
+ assertTrue(e.getMessage(), false);
+ }
+ try{
+ a = new MailAddress(GOOD_DLIT);
+ }catch (ParseException e){
+ assertTrue(e.getMessage(), false);
+ }
+ try{
+ a = new MailAddress(BAD_LOCAL_PART_1);
+ assertFalse(BAD_LOCAL_PART_1,true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+
+ try{
+ a = new MailAddress(BAD_LOCAL_PART_2);
+ assertFalse(BAD_LOCAL_PART_2,true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+
+ try{
+ a = new MailAddress(BAD_LOCAL_PART_3);
+ assertFalse(BAD_LOCAL_PART_3,true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+ try{
+ a = new MailAddress(BAD_DLIT_1);
+ assertFalse(BAD_DLIT_1,true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+ try{
+ a = new MailAddress(BAD_DLIT_2);
+ assertFalse(BAD_DLIT_2,true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#MailAddress(java.lang.String, java.lang.String)}.
+ */
+ public void testMailAddressStringString() {
+
+ try{
+ MailAddress a = new MailAddress("local-part", "domain");
+ }catch (ParseException e){
+ assertTrue(e.getMessage(), false);
+ }
+ try{
+ MailAddress a = new MailAddress("local-part", "-domain");
+ assertFalse(a.toString(),true);
+ }catch (ParseException e){
+ assertTrue(true);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#MailAddress(javax.mail.internet.InternetAddress)}.
+ */
+ public void testMailAddressInternetAddress() {
+
+ try{
+ MailAddress a = new MailAddress(new
InternetAddress(GOOD_QUOTED_LOCAL_PART));
+ }catch (AddressException e){
+ System.out.println("AddressException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }catch (ParseException e){
+ System.out.println("ParseException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#getDomain()}.
+ */
+ public void testGetDomain() {
+
+ try{
+ MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS));
+ assertTrue(a.getDomain()+" !=
"+GOOD_DOMAIN,a.getDomain().equals(GOOD_DOMAIN));
+ }catch (AddressException e){
+ System.out.println("AddressException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }catch (ParseException e){
+ System.out.println("ParseException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#getLocalPart()}.
+ */
+ public void testGetLocalPart() {
+
+ try{
+ MailAddress a = new MailAddress(new
InternetAddress(GOOD_QUOTED_LOCAL_PART));
+ assertTrue(GOOD_LOCAL_PART+" !=
"+a.getLocalPart(),a.getLocalPart().equals(GOOD_LOCAL_PART));
+ }catch (AddressException e){
+ System.out.println("AddressException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }catch (ParseException e){
+ System.out.println("ParseException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#toString()}.
+ */
+ public void testToString() {
+
+ try{
+ MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS));
+ assertTrue(a.toString()+" !=
"+GOOD_ADDRESS,a.toString().equals(GOOD_ADDRESS));
+ }catch (AddressException e){
+ System.out.println("AddressException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }catch (ParseException e){
+ System.out.println("ParseException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#toInternetAddress()}.
+ */
+ public void testToInternetAddress() {
+
+ try{
+ InternetAddress b = new InternetAddress(GOOD_ADDRESS);
+ MailAddress a = new MailAddress(b);
+ assertTrue(a.toInternetAddress().equals(b));
+ assertTrue(a.toString()+" !=
"+GOOD_ADDRESS,a.toString().equals(GOOD_ADDRESS));
+ }catch (AddressException e){
+ System.out.println("AddressException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }catch (ParseException e){
+ System.out.println("ParseException"+e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+
+ /**
+ * Test method for [EMAIL PROTECTED]
org.apache.mailet.MailAddress#equals(java.lang.Object)}.
+ * @throws ParseException
+ */
+ public void testEqualsObject() throws ParseException {
+
+ MailAddress a = new MailAddress(GOOD_ADDRESS);
+ MailAddress b = new MailAddress(GOOD_ADDRESS);
+
+ assertTrue(a.toString()+" != "+b.toString(),a.equals(b));
+ }
+}
+/*
+ *
+ * PVCS Log History:
+ * $Log$
+ *
+ */
\ No newline at end of file