1   package org.apache.torque.engine.database;
2   
3   /*
4    * Copyright 2001-2004 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.AppData;
22  import org.apache.torque.engine.database.model.Database;
23  import org.apache.torque.engine.database.model.Table;
24  import org.apache.torque.engine.database.transform.XmlToAppData;
25  
26  /***
27   * Tests for package handling.
28   *
29   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
30   * @version $Id: TestPackageHandling.java,v 1.3.2.2 2004/05/20 04:35:16 seade Exp $
31   */
32  public class TestPackageHandling extends TestCase
33  {
34      private XmlToAppData xmlToAppData = null;
35      private AppData appData = null;
36  
37      public TestPackageHandling(String name)
38      {
39          super(name);
40      }
41  
42      protected void setUp() throws Exception
43      {
44          super.setUp();
45      }
46  
47      protected void tearDown() throws Exception
48      {
49          xmlToAppData = null;
50          super.tearDown();
51      }
52  
53      /***
54       * test if the tables get the package name from the properties file
55       */
56      public void testDefaultPackageName()
57              throws Exception
58      {
59          xmlToAppData = new XmlToAppData("mysql", "defaultpackage", null);
60          appData = xmlToAppData.parseFile(
61              "src/test/org/apache/torque/engine/database/package-schema.xml");
62          Database db = appData.getDatabase("packagedb");
63          assertEquals("defaultpackage", db.getPackage());
64          Table table = db.getTable("table_a");
65          assertEquals("defaultpackage", table.getPackage());
66      }
67  
68      /***
69       * test if the tables get the package name from the database tag
70       */
71      public void testDatabasePackageName()
72              throws Exception
73      {
74          xmlToAppData = new XmlToAppData("mysql", "defaultpackage", null);
75          appData = xmlToAppData.parseFile(
76              "src/test/org/apache/torque/engine/database/package2-schema.xml");
77          Database db = appData.getDatabase("packagedb2");
78          assertEquals("packagefromdb", db.getPackage());
79          Table table = db.getTable("table_a");
80          assertEquals("packagefromdb", table.getPackage());
81      }
82  
83  }