KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
19  * Tests for the ojb.class tag with the attributes attribute.
20  *
21  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
22  */

23 public class ClassTagAttributesAttributeTests extends OjbTestBase
24 {
25     public ClassTagAttributesAttributeTests(String JavaDoc name)
26     {
27         super(name);
28     }
29
30     // Test of attributes attribute: no value
31
public void testAttributes1()
32     {
33         addClass(
34             "A",
35             "/** @ojb.class attributes=\"\" */\n"+
36             "public class A {}\n");
37
38         assertEqualsOjbDescriptorFile(
39             "<class-descriptor\n"+
40             " class=\"A\"\n"+
41             " table=\"A\"\n"+
42             ">\n"+
43             "</class-descriptor>",
44             runOjbXDoclet(OJB_DEST_FILE));
45         assertEqualsTorqueSchemaFile(
46             "<database name=\"ojbtest\">\n"+
47             " <table name=\"A\">\n"+
48             " </table>\n"+
49             "</database>",
50             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
51     }
52
53     // Test of attributes attribute: with one name-value pair
54
public void testAttributes2()
55     {
56         addClass(
57             "A",
58             "/** @ojb.class attributes=\"name=value\" */\n"+
59             "public class A {}\n");
60
61         assertEqualsOjbDescriptorFile(
62             "<class-descriptor\n"+
63             " class=\"A\"\n"+
64             " table=\"A\"\n"+
65             ">\n"+
66             " <attribute attribute-name=\"name\" attribute-value=\"value\"/>\n"+
67             "</class-descriptor>",
68             runOjbXDoclet(OJB_DEST_FILE));
69         assertEqualsTorqueSchemaFile(
70             "<database name=\"ojbtest\">\n"+
71             " <table name=\"A\">\n"+
72             " </table>\n"+
73             "</database>",
74             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
75     }
76
77     // Test of attributes attribute: with empty attribute
78
public void testAttributes3()
79     {
80         addClass(
81             "A",
82             "/** @ojb.class attributes=\"name=\" */\n"+
83             "public class A {}\n");
84
85         assertEqualsOjbDescriptorFile(
86             "<class-descriptor\n"+
87             " class=\"A\"\n"+
88             " table=\"A\"\n"+
89             ">\n"+
90             " <attribute attribute-name=\"name\" attribute-value=\"\"/>\n"+
91             "</class-descriptor>",
92             runOjbXDoclet(OJB_DEST_FILE));
93         assertEqualsTorqueSchemaFile(
94             "<database name=\"ojbtest\">\n"+
95             " <table name=\"A\">\n"+
96             " </table>\n"+
97             "</database>",
98             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
99     }
100
101     // Test of attributes attribute: with three name-value pairs, one without value
102
public void testAttributes4()
103     {
104         addClass(
105             "A",
106             "/** @ojb.class attributes=\"name1=value1,name2=,name3=value3\" */\n"+
107             "public class A {}\n");
108
109         assertEqualsOjbDescriptorFile(
110             "<class-descriptor\n"+
111             " class=\"A\"\n"+
112             " table=\"A\"\n"+
113             ">\n"+
114             " <attribute attribute-name=\"name1\" attribute-value=\"value1\"/>\n"+
115             " <attribute attribute-name=\"name2\" attribute-value=\"\"/>\n"+
116             " <attribute attribute-name=\"name3\" attribute-value=\"value3\"/>\n"+
117             "</class-descriptor>",
118             runOjbXDoclet(OJB_DEST_FILE));
119         assertEqualsTorqueSchemaFile(
120             "<database name=\"ojbtest\">\n"+
121             " <table name=\"A\">\n"+
122             " </table>\n"+
123             "</database>",
124             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
125     }
126
127     // Test of attributes attribute: with value, not inherited in subclass
128
public void testAttributes5()
129     {
130         addClass(
131             "A",
132             "/** @ojb.class attributes=\"name=value\" */\n"+
133             "public class A {}\n");
134         addClass(
135             "B",
136             "/** @ojb.class */\n"+
137             "public class B extends A {}\n");
138
139         assertEqualsOjbDescriptorFile(
140             "<class-descriptor\n"+
141             " class=\"A\"\n"+
142             " table=\"A\"\n"+
143             ">\n"+
144             " <extent-class class-ref=\"B\"/>\n"+
145             " <attribute attribute-name=\"name\" attribute-value=\"value\"/>\n"+
146             "</class-descriptor>\n"+
147             "<class-descriptor\n"+
148             " class=\"B\"\n"+
149             " table=\"B\"\n"+
150             ">\n"+
151             "</class-descriptor>",
152             runOjbXDoclet(OJB_DEST_FILE));
153         assertEqualsTorqueSchemaFile(
154             "<database name=\"ojbtest\">\n"+
155             " <table name=\"A\">\n"+
156             " </table>\n"+
157             " <table name=\"B\">\n"+
158             " </table>\n"+
159             "</database>",
160             runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
161     }
162
163 }
164
Popular Tags