KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > tests > ClassTagInitializationMethodAttributeTests


1 package xdoclet.modules.ojb.tests;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import java.util.HashMap JavaDoc;
19
20 /**
21  * Tests for the ojb.class tag with the initialization-method attribute.
22  *
23  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
24  */

25 public class ClassTagInitializationMethodAttributeTests extends OjbTestBase
26 {
27     public ClassTagInitializationMethodAttributeTests(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     // Test: empty value
33
public void testInitializationMethod1()
34     {
35         addClass(
36             "test.A",
37             "package test;\n"+
38             "/** @ojb.class initialization-method=\"\" */\n"+
39             "public class A {}\n");
40
41         assertEqualsOjbDescriptorFile(
42             "<class-descriptor\n"+
43             " class=\"test.A\"\n"+
44             " table=\"A\"\n"+
45             ">\n"+
46             "</class-descriptor>",
47             runOjbXDoclet(OJB_DEST_FILE));
48         assertEqualsTorqueSchemaFile(
49             "<database name=\"ojbtest\">\n"+
50             " <table name=\"A\">\n"+
51             " </table>\n"+
52             "</database>",
53             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
54     }
55
56     // Test: normal use
57
public void testInitializationMethod2()
58     {
59         // note that we only recreate parts of the test class here
60
// (only the actual class is used in the method check)
61
addClass(
62             TestClass.class.getName(),
63             "package "+TestClass.class.getPackage().getName()+";\n"+
64             "/** @ojb.class initialization-method=\"initMethod1\" */\n"+
65             "public class "+TestClass.getShortName()+" {}\n");
66
67         assertEqualsOjbDescriptorFile(
68             "<class-descriptor\n"+
69             " class=\""+TestClass.class.getName()+"\"\n"+
70             " table=\""+TestClass.getShortName()+"\"\n"+
71             " initialization-method=\"initMethod1\"\n"+
72             ">\n"+
73             "</class-descriptor>",
74             runOjbXDoclet(OJB_DEST_FILE));
75         assertEqualsTorqueSchemaFile(
76             "<database name=\"ojbtest\">\n"+
77             " <table name=\""+TestClass.getShortName()+"\">\n"+
78             " </table>\n"+
79             "</database>",
80             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
81     }
82
83     // Test: method does not exist
84
public void testInitializationMethod3()
85     {
86         // note that we only recreate parts of the test class here
87
// (only the actual class is used in the method check)
88
addClass(
89             TestClass.class.getName(),
90             "package "+TestClass.class.getPackage().getName()+";\n"+
91             "/** @ojb.class initialization-method=\"initMethod\" */\n"+
92             "public class "+TestClass.getShortName()+" {}\n");
93
94         assertNull(runOjbXDoclet(OJB_DEST_FILE));
95         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
96     }
97
98     // Test: a method of that name exists but has parameters
99
public void testInitializationMethod4()
100     {
101         // note that we only recreate parts of the test class here
102
// (only the actual class is used in the method check)
103
addClass(
104             TestClass.class.getName(),
105             "package "+TestClass.class.getPackage().getName()+";\n"+
106             "/** @ojb.class initialization-method=\"initMethod2\" */\n"+
107             "public class "+TestClass.getShortName()+" {}\n");
108
109         assertNull(runOjbXDoclet(OJB_DEST_FILE));
110         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
111     }
112
113     // Test: method exists but is static
114
public void testInitializationMethod5()
115     {
116         // note that we only recreate parts of the test class here
117
// (only the actual class is used in the method check)
118
addClass(
119             TestClass.class.getName(),
120             "package "+TestClass.class.getPackage().getName()+";\n"+
121             "/** @ojb.class initialization-method=\"initMethod3\" */\n"+
122             "public class "+TestClass.getShortName()+" {}\n");
123
124         assertNull(runOjbXDoclet(OJB_DEST_FILE));
125         assertNull(runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
126     }
127
128     // Test: unknown method but strict is set to false
129
public void testInitializationMethod6()
130     {
131         addClass(
132             "test.A",
133             "package test;\n"+
134             "/** @ojb.class initialization-method=\"someMethod\" */\n"+
135             "public class A {}\n");
136
137         HashMap JavaDoc taskProps = new HashMap JavaDoc();
138         HashMap JavaDoc torqueSubTaskProps = new HashMap JavaDoc();
139         
140         taskProps.put(PROPERTY_CHECKS, "basic");
141         torqueSubTaskProps.put(PROPERTY_DATABASENAME, "ojbtest");
142
143         assertEqualsOjbDescriptorFile(
144             "<class-descriptor\n"+
145             " class=\"test.A\"\n"+
146             " table=\"A\"\n"+
147             " initialization-method=\"someMethod\"\n"+
148             ">\n"+
149             "</class-descriptor>",
150             runOjbXDoclet(OJB_DEST_FILE, taskProps, null));
151         assertEqualsTorqueSchemaFile(
152             "<database name=\"ojbtest\">\n"+
153             " <table name=\"A\">\n"+
154             " </table>\n"+
155             "</database>",
156             runTorqueXDoclet(TORQUE_DEST_FILE, taskProps, torqueSubTaskProps));
157     }
158 }
159
Popular Tags