KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > standalone > driver > DriverTest


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Mathieu Peltier.
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.standalone.driver;
26
27 import java.io.File JavaDoc;
28 import java.io.FileReader JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.sql.SQLException JavaDoc;
31
32 import org.objectweb.cjdbc.driver.Driver;
33 import org.objectweb.cjdbc.scenario.templates.NoTemplate;
34 import org.objectweb.cjdbc.scenario.tools.util.MyBufferedReader;
35
36 /**
37  * <code>Driver</code> test class.
38  *
39  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
40  * @see org.objectweb.cjdbc.driver.Driver
41  */

42 public class DriverTest extends NoTemplate
43 {
44   /** File name containing the C-JDBC URLs to test. */
45   public static final String JavaDoc URLS_FILE = getTextPath("urls.txt");
46
47   /** Driver to test. */
48   private Driver driver;
49
50   /**
51    * @see junit.framework.TestCase#setUp()
52    */

53   protected void setUp()
54   {
55     driver = new Driver();
56   }
57
58   /**
59    * @see org.objectweb.cjdbc.driver.Driver#acceptsURL(String)
60    */

61   public void testAcceptURL()
62   {
63     String JavaDoc url = null;
64     int countTest = 0;
65     try
66     {
67       File JavaDoc file = new File JavaDoc(URLS_FILE);
68       MyBufferedReader in = new MyBufferedReader(new FileReader JavaDoc(file), "URLs");
69       String JavaDoc line;
70       while ((line = in.readLine()) != null)
71       {
72         if (line.equals("") || line.startsWith("//"))
73           continue;
74         url = line;
75         System.out.println("Test[" + (countTest++) + "]:" + url);
76         boolean valid = in.readBoolean();
77         try
78         {
79           if (valid)
80           {
81             assertTrue("Failed to accept a valid URL", driver.acceptsURL(url));
82             in.readLine();
83             in.readLine();
84             in.readLine();
85           }
86           else
87           {
88             assertFalse("Accepted an incorrect URL", driver.acceptsURL(url));
89           }
90         }
91         catch (SQLException JavaDoc e)
92         {
93           fail("Unexpected exception thrown: " + e);
94         }
95       }
96     }
97     catch (IOException JavaDoc e)
98     {
99       if (url == null)
100         fail("An error occurs while parsing urls file: " + e);
101       else
102         fail("An error occurs while parsing urls file: " + e + " (URL: '" + url
103             + "')");
104     }
105   }
106 }
107
Popular Tags