db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject cvs commit: db-torque/src/rttest/org/apache/torque BaseRuntimeTestCase.java DocsTest.java DataTest.java BaseTestCase.java
Date Sat, 19 Mar 2005 06:25:27 GMT
tfischer    2005/03/18 22:25:27

  Modified:    src/rttest/org/apache/torque/util LargeSelectTest.java
                        CopyTest.java
               src/rttest/org/apache/torque DocsTest.java DataTest.java
  Added:       src/rttest/org/apache/torque/engine/database/transform
                        SQLToAppDataRuntimeTest.java
               src/rttest/org/apache/torque BaseRuntimeTestCase.java
  Removed:     src/rttest/org/apache/torque/engine/database/transform
                        SQLToAppDataTest.java
               src/rttest/org/apache/torque BaseTestCase.java
  Log:
  Made fully qualified class names unique within the project. This involved the renaming of
two classes:
  src/rttest/org/apache/torque/BaseTestCase.java to src/rttest/org/apache/torque/BaseRuntimeTestCase.java
  and
  src/rttest/org/apache/torque/engine/database/transform/SQLToAppDataTest.java to src/rttest/org/apache/torque/engine/database/transform/SQLToAppDataRuntimeTest.java
  
  Revision  Changes    Path
  1.6       +3 -3      db-torque/src/rttest/org/apache/torque/util/LargeSelectTest.java
  
  Index: LargeSelectTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/util/LargeSelectTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LargeSelectTest.java	31 Jan 2005 19:43:59 -0000	1.5
  +++ LargeSelectTest.java	19 Mar 2005 06:25:27 -0000	1.6
  @@ -16,7 +16,7 @@
    * limitations under the License.
    */
   
  -import org.apache.torque.BaseTestCase;
  +import org.apache.torque.BaseRuntimeTestCase;
   import org.apache.torque.TorqueException;
   import org.apache.torque.test.Author;
   import org.apache.torque.test.AuthorPeer;
  @@ -29,7 +29,7 @@
    * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
    * @version $Id$
    */
  -public class LargeSelectTest extends BaseTestCase
  +public class LargeSelectTest extends BaseRuntimeTestCase
   {
       private static final int TEST_PAGE_SIZE = 9;
       private static final int TEST_PAGES = 9;
  
  
  
  1.5       +3 -3      db-torque/src/rttest/org/apache/torque/util/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/util/CopyTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CopyTest.java	31 Jan 2005 19:43:59 -0000	1.4
  +++ CopyTest.java	19 Mar 2005 06:25:27 -0000	1.5
  @@ -16,7 +16,7 @@
    * limitations under the License.
    */
   
  -import org.apache.torque.BaseTestCase;
  +import org.apache.torque.BaseRuntimeTestCase;
   import org.apache.torque.test.Author;
   import org.apache.torque.test.AuthorPeer;
   import org.apache.torque.test.Book;
  @@ -27,7 +27,7 @@
    * @author <a href="mailto:torque@kivus.myip.org">Rafal Maczewski</a>
    * @version $Id$
    */
  -public class CopyTest extends BaseTestCase
  +public class CopyTest extends BaseRuntimeTestCase
   {
       /**
        * Creates a new instance.
  
  
  
  1.1                  db-torque/src/rttest/org/apache/torque/engine/database/transform/SQLToAppDataRuntimeTest.java
  
  Index: SQLToAppDataRuntimeTest.java
  ===================================================================
  package org.apache.torque.engine.database.transform;
  
  /*
   * Copyright 2001,2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
  
  import java.io.*;
  import java.util.Vector;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.FactoryConfigurationError;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.apache.torque.BaseRuntimeTestCase;
  import org.apache.torque.engine.database.model.Database;
  import org.apache.torque.engine.sql.ParseException;
  import org.w3c.dom.Document;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.SAXException;
  
  /**
   * @author <a href="mailto:andyhot@di.uoa.gr">Andreas Andreou</a>
   * @version $Id: SQLToAppDataRuntimeTest.java,v 1.1 2005/03/19 06:25:27 tfischer Exp $
   */
  public class SQLToAppDataRuntimeTest extends BaseRuntimeTestCase
  {
      /** The path to the configuration file. */
      private static final String SQL_FOLDER = "target/test/rttest/sql";
  
      private Vector files;
  
      /**
       * Creates a new instance.
       */
      public SQLToAppDataRuntimeTest(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
          // this may not be needed
          //super.setUp();
          // init the vector
          files = new Vector();
          // find all sql files to test
          File sqlFolder = new File(SQL_FOLDER);
          if (sqlFolder != null && sqlFolder.isDirectory())
          {
              File allFiles[] = sqlFolder.listFiles();
              for (int i = 0; i < allFiles.length; i++)
              {
                  File thisFile = allFiles[i];
                  if (!thisFile.isDirectory() &&
                          thisFile.getName().toUpperCase().endsWith("SQL"))
                  {
                      System.out.println("Adding file:" + thisFile.getName());
                      files.add(thisFile);
                  }
              }
          }
          if (files.size() == 0)
          {
              System.out.println("No files where found to test the sql2xml task");
          }
      }
  
      public void testConvertToXml()
      {
          try
          {
              for (int i = 0; i < files.size(); i++)
              {
                  File file = (File) files.elementAt(i);
                  String filename = file.getAbsolutePath();
                  // load the sql file
                  SQLToAppData s2a = new SQLToAppData(filename);
                  Database ad = s2a.execute();
                  // write the output to a new xml file
                  String xmlFilename = filename + ".xml";
                  PrintWriter out = new PrintWriter(
                          new FileOutputStream(xmlFilename, false),true);
                  out.println(ad);
                  out.close();
                  // compare result
                  compareXmlFiles(filename + ".ref.xml", xmlFilename);
              }
          }
          catch (IOException expIo)
          {
              expIo.printStackTrace(System.out);
          }
          catch (ParseException expParse)
          {
              expParse.printStackTrace(System.out);
          }
      }
  
      private void renameDTD(String sFile)
      {
          try
          {
              BufferedReader reader = new BufferedReader(new FileReader(sFile));
              String line;
              StringBuffer sb = new StringBuffer(5000);
              while ((line=reader.readLine())!=null)
              {
                  sb.append(line).append("\n");
              }
              reader.close();
              String data=sb.toString();
              if (data == null || data.length() == 0)
                  return;
              int index=data.indexOf("<!DOCTYPE");
              if (index != -1)
              {
                  int index2 = data.indexOf(">", index);
                  if (index2 != -1)
                  {
                      data = data.substring(0, index - 1)
                              + data.substring(index2 + 1);
                  }
              }
              //data.replaceFirst("/database.dtd","/database.xxx");
  
              BufferedWriter writer = new BufferedWriter(
                      new FileWriter(sFile, false));
              writer.write(data);
              writer.close();
          }
          catch (FileNotFoundException e)
          {
              e.printStackTrace();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
      }
  
      private void compareXmlFiles(String refFile, String newFile)
      {
          System.out.println("Comparing " + newFile + " against " + refFile);
          //System.out.println("Rename DTD to disable checking for default values...");
          // The dom parser uses the DTD to add default values to the xml nodes.
          // This makes difficult comparing the xml files.
          // Since I couldn't find any way to disable this behavior,
          // I chose to delete the DTD declaration from the xml files.
          renameDTD(refFile);
          renameDTD(newFile);
  
          try
          {
              DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
              docFactory.setExpandEntityReferences(false);
              docFactory.setValidating(false);
  
              DocumentBuilder doc = docFactory.newDocumentBuilder();
  
              Document refDoc = doc.parse(new File(refFile));
              Document newDoc = doc.parse(new File(newFile));
  
              NodeList refList = refDoc.getElementsByTagName("database");
              NodeList newList = newDoc.getElementsByTagName("database");
  
              assertNotNull(refList);
              assertNotNull(newList);
  
              for (int i = 0; i < refList.getLength(); i++)
              {
                  Node refNode = refList.item(i);
                  Node newNode = newList.item(i);
  
                  checkNodes(refNode, newNode);
  
                  refNode = refNode.getFirstChild();
                  newNode = newNode.getFirstChild();
  
              }
          }
          catch (ParserConfigurationException e)
          {
              e.printStackTrace(System.out);
          }
          catch (FactoryConfigurationError factoryConfigurationError)
          {
              factoryConfigurationError.printStackTrace(System.out);
          }
          catch (SAXException e)
          {
              e.printStackTrace(System.out);
          }
          catch (IOException e)
          {
              e.printStackTrace(System.out);
          }
      }
  
      private void checkNodes(Node refNodeStart, Node newNodeStart)
      {
          Node refNode = refNodeStart;
          Node newNode = newNodeStart;
          while (refNode != null)
          {
              assertNotNull(newNode);
              if (refNode.getNodeType() != Node.TEXT_NODE)
              {
                  // check matching names
                  System.out.println(refNode.getNodeName() + " : "
                          + newNode.getNodeName());
                  assertEquals(refNode.getNodeName(), newNode.getNodeName());
                  // check matching attributes
                  NamedNodeMap refNnm = refNode.getAttributes();
                  NamedNodeMap newNnm = newNode.getAttributes();
                  for (int j = 0; j < refNnm.getLength(); j++)
                  {
                      Node refItem = refNnm.item(j);
                      String refName = refItem.getNodeName();
  
                      Node newItem = newNnm.getNamedItem(refName);
                      // check existance
                      assertNotNull(newItem);
  
                      // check matching value
                      System.out.println("    " + refName + " : "
                              + refItem.getNodeValue()+" -> "
                              + newItem.getNodeValue());
                      assertEquals(refItem.getNodeValue(), newItem.getNodeValue());
                  }
              }
  
              Node refChild = refNode.getFirstChild();
              Node newChild = newNode.getFirstChild();
              if (refChild != null)
              {
                  assertNotNull(newChild);
                  checkNodes(refChild, newChild);
              }
  
              // check matching siblings
              refNode = refNode.getNextSibling();
              newNode = newNode.getNextSibling();
          }
      }
  
      // just for internal test
      public static void main(String args[])
      {
          SQLToAppDataRuntimeTest test = new SQLToAppDataRuntimeTest("inner test");
          //test.compareXmlFiles("c:/schema.sql.xml", "c:/schema.sql.xml.new");
          test.compareXmlFiles(
                  "C:/java/projects/jakarta-turbine-torque/jakarta-turbine-torque/target/test/rttest/sql/schema.sql.ref.xml",
                  "C:/java/projects/jakarta-turbine-torque/jakarta-turbine-torque/target/test/rttest/sql/schema.sql.xml");
      }
  }
  
  
  
  1.4       +2 -2      db-torque/src/rttest/org/apache/torque/DocsTest.java
  
  Index: DocsTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DocsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DocsTest.java	8 Feb 2005 10:12:19 -0000	1.3
  +++ DocsTest.java	19 Mar 2005 06:25:27 -0000	1.4
  @@ -32,7 +32,7 @@
    * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
    * @version $Id$
    */
  -public class DocsTest extends BaseTestCase
  +public class DocsTest extends BaseRuntimeTestCase
   {
       public static final String AUTHOR_1_NAME = "Joshua Bloch";
       
  
  
  
  1.13      +2 -2      db-torque/src/rttest/org/apache/torque/DataTest.java
  
  Index: DataTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DataTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DataTest.java	4 Mar 2005 06:38:54 -0000	1.12
  +++ DataTest.java	19 Mar 2005 06:25:27 -0000	1.13
  @@ -51,7 +51,7 @@
    * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
    * @version $Id$
    */
  -public class DataTest extends BaseTestCase
  +public class DataTest extends BaseRuntimeTestCase
   {
       /**
        * Creates a new instance.
  
  
  
  1.1                  db-torque/src/rttest/org/apache/torque/BaseRuntimeTestCase.java
  
  Index: BaseRuntimeTestCase.java
  ===================================================================
  package org.apache.torque;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed 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.
   */
  
  import junit.framework.TestCase;
  
  /**
   * Base functionality to be extended by all Torque test cases.  Test
   * case implementations are used to automate unit testing via JUnit.
   *
   * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
   * @version $Id: BaseRuntimeTestCase.java,v 1.1 2005/03/19 06:25:27 tfischer Exp $
   */
  public abstract class BaseRuntimeTestCase extends TestCase
  {
      /** The path to the configuration file. */
      private static final String CONFIG_FILE
              = "target/test/rttest/Torque.properties";
  
      /** Whether torque has been initialized. */
      static boolean hasInitialized = false;
  
      /**
       * Creates a new instance.
       */
      public BaseRuntimeTestCase(String name)
      {
          super(name);
      }
  
      /**
       * Initialize Torque on the first setUp().  Subclasses which override
       * setUp() must call super.setUp() as their first action.
       */
      public void setUp()
      {
          synchronized (BaseRuntimeTestCase.class)
          {
              if (!hasInitialized)
              {
                  try
                  {
                      Torque.init(CONFIG_FILE);
                      hasInitialized = true;
                  }
                  catch (Exception e)
                  {
                      fail("Couldn't initialize Torque: " + e.getMessage());
                  }
              }
          }
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message