1   package org.apache.torque.engine.database;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.TestCase;
20  
21  import org.apache.torque.engine.database.model.Database;
22  import org.apache.torque.engine.database.model.Table;
23  import org.apache.torque.engine.database.transform.XmlToAppData;
24  
25  /***
26   * Tests for package handling.
27   *
28   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
29   * @version $Id: TestPackageHandling.java 239624 2005-08-24 12:18:03Z henning $
30   */
31  public class TestPackageHandling extends TestCase
32  {
33      private XmlToAppData xmlToAppData = null;
34      private Database database = null;
35  
36      public TestPackageHandling(String name)
37      {
38          super(name);
39      }
40  
41      protected void setUp() throws Exception
42      {
43          super.setUp();
44      }
45  
46      protected void tearDown() throws Exception
47      {
48          xmlToAppData = null;
49          super.tearDown();
50      }
51  
52      /***
53       * test if the tables get the package name from the properties file
54       */
55      public void testDefaultPackageName()
56              throws Exception
57      {
58          xmlToAppData = new XmlToAppData("mysql", "defaultpackage");
59          database = xmlToAppData.parseFile(
60              "src/test/org/apache/torque/engine/database/package-schema.xml");
61          assertEquals("defaultpackage", database.getPackage());
62          Table table = database.getTable("table_a");
63          assertEquals("defaultpackage", table.getPackage());
64      }
65  
66      /***
67       * test if the tables get the package name from the database tag
68       */
69      public void testDatabasePackageName()
70              throws Exception
71      {
72          xmlToAppData = new XmlToAppData("mysql", "defaultpackage");
73          database = xmlToAppData.parseFile(
74              "src/test/org/apache/torque/engine/database/package2-schema.xml");
75          assertEquals("packagefromdb", database.getPackage());
76          Table table = database.getTable("table_a");
77          assertEquals("packagefromdb", table.getPackage());
78      }
79  
80  }