prickett 2002/10/11 10:37:21
Modified: periodicity/src/plugins-build/database project.xml
Added:
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/ant
GetDatabaseConnectionTask.java
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
GetDatabaseConnectionTest.java
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/util
JUnitUtils.java
Log:
Added a dependency to junit 3.7
Added a dependency to ant 1.4.1
Added a build tag in the project.xml file for the periodicity database plugin
Added an ant task to get a connection to a database
Added a junit test to get a connection to the database
Added a junit utility class to help with printing failures to system error
Revision Changes Path
1.3 +19 -0
jakarta-commons-sandbox/periodicity/src/plugins-build/database/project.xml
Index: project.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/project.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- project.xml 10 Oct 2002 22:43:08 -0000 1.2
+++ project.xml 11 Oct 2002 17:37:21 -0000 1.3
@@ -16,10 +16,29 @@
<repository>
<connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-commons-sandbox/periodicity/src/java/plugins-build/database</connection>
</repository>
+
<developers>
<developer>
<name>Jeff Prickett</name>
<id>prickett</id>
</developer>
</developers>
+
+ <dependencies>
+ <dependency>
+ <id>junit</id>
+ <version>3.7</version>
+ </dependency>
+ <dependency>
+ <id>ant</id>
+ <version>1.4.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <nagEmailAddress>[EMAIL PROTECTED]</nagEmailAddress>
+ <sourceDirectory>src/java</sourceDirectory>
+ <aspectSourceDirectory/>
+ </build>
+
</project>
1.1
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/ant/GetDatabaseConnectionTask.java
Index: GetDatabaseConnectionTask.java
===================================================================
package org.apache.commons.periodicity.task;
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/ant/GetDatabaseConnectionTask.java,v
1.1 2002/10/11 17:37:21 prickett Exp $
* $Revision: 1.1 $
* $Date: 2002/10/11 17:37:21 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.commons.periodicity.database.GetDatabaseConnectionTest;
public class GetDatabaseConnectionTask extends Task
{
public void setUrl(String newval)
{
if(newval != null)
{
System.setProperty(GetDatabaseConnectionTest.DATABASE_URL,
newval);
}
}
public void setUser(String newval)
{
if(newval != null)
{
System.setProperty(GetDatabaseConnectionTest.DATABASE_USER,
newval);
}
}
public void setPassword(String newval)
{
if(newval != null)
{
System.setProperty(GetDatabaseConnectionTest.DATABASE_PASSWORD,
newval);
}
}
public void execute() throws BuildException
{
GetDatabaseConnectionTest.runStatic();
}
}
1.1
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/GetDatabaseConnectionTest.java
Index: GetDatabaseConnectionTest.java
===================================================================
package org.apache.commons.periodicity.database;
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/GetDatabaseConnectionTest.java,v
1.1 2002/10/11 17:37:21 prickett Exp $
* $Revision: 1.1 $
* $Date: 2002/10/11 17:37:21 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.sql.DriverManager;
import java.sql.Connection;
import junit.framework.TestCase;
import junit.framework.TestResult;
import org.apache.commons.periodicity.util.JUnitUtils;
public class GetDatabaseConnectionTest extends TestCase
{
public static final String DATABASE_CONNECTION_TEST_NAME =
"getDatabaseConnection";
public static final String DATABASE_URL = "periodicity.database.url";
public static final String DATABASE_USER = "periodicity.database.user";
public static final String DATABASE_PASSWORD =
"periodicity.database.password";
private String databaseUrl = null;
private String databaseUser = null;
private String databasePassword = null;
public GetDatabaseConnectionTest(String name)
{
super(name);
}
public static void runStatic()
{
GetDatabaseConnectionTest connTest = new GetDatabaseConnectionTest(
GetDatabaseConnectionTest.DATABASE_CONNECTION_TEST_NAME);
TestResult connResult = connTest.run();
if(connResult != null)
{
if(connResult.failureCount() == 0)
{
System.err.println("Successfully got a database connection");
}
else
{
JUnitUtils.printFailuresToSystem(connResult);
}
}
}
protected void setUp() throws Exception
{
databaseUrl = System.getProperty(DATABASE_URL);
databaseUser = System.getProperty(DATABASE_USER);
databasePassword = System.getProperty(DATABASE_PASSWORD);
}
protected void runTest()
{
try
{
if(databaseUrl != null && databaseUser!= null &&
databasePassword != null)
{
Connection connection =
DriverManager.getConnection(databaseUrl, databaseUser,
databasePassword);
connection = null;
}
else if(databaseUrl == null)
{
fail("databaseUrl == null");
}
else if(databaseUser == null)
{
fail("databaseUser == null");
}
else if(databasePassword == null)
{
fail("databasePassword == null");
}
else
{
fail("Unexpected Exception");
}
}
catch(Exception e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
protected void tearDown() throws Exception
{
System.setProperty(DATABASE_URL, null);
System.setProperty(DATABASE_USER, null);
System.setProperty(DATABASE_PASSWORD, null);
}
}
1.1
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/util/JUnitUtils.java
Index: JUnitUtils.java
===================================================================
package org.apache.commons.periodicity.util;
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/util/JUnitUtils.java,v
1.1 2002/10/11 17:37:21 prickett Exp $
* $Revision: 1.1 $
* $Date: 2002/10/11 17:37:21 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
import java.util.Enumeration;
import junit.framework.TestResult;
import junit.framework.TestFailure;
public class JUnitUtils
{
public static void printFailuresToSystem(TestResult results)
{
if(results != null)
{
if(results.failureCount() > 0)
{
Enumeration enum = results.failures();
if(enum != null)
{
if(enum.hasMoreElements())
{
TestFailure failure =
(TestFailure) enum.nextElement();
printFailureToSystemError(failure);
}
else if(!enum.hasMoreElements())
{
System.err.println(
"enum != null but, enum has no elements");
}
else
{
System.err.println("Unexpected Exception");
}
while(enum.hasMoreElements())
{
TestFailure failure =
(TestFailure) enum.nextElement();
printFailureToSystemError(failure);
}
}
else if(enum == null)
{
System.err.println("enum == null");
}
else
{
System.err.println("Unexpected Exception");
}
}
else if(results.failureCount() == 0)
{
System.out.println("No failures to report.");
}
else if(results.failureCount() < 0)
{
System.err.println("results.failureCount < 0");
}
else
{
System.err.println("Unexpected Exception");
}
}
else if(results == null)
{
System.err.println("results == null");
}
else
{
System.err.println("Unexpected Exception");
}
}
public static void printFailureToSystemError(TestFailure failure)
{
if(failure != null)
{
System.err.println(failure);
}
else if(failure == null)
{
System.err.println("failure == null");
}
else
{
System.err.println("Unexpected Failure");
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>