KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > mapping > ValueVisitorTest


1 /*
2  * Created on 06-Dec-2004
3  *
4  */

5 package org.hibernate.test.mapping;
6
7 import junit.framework.Test;
8 import junit.framework.TestCase;
9 import junit.framework.TestSuite;
10
11 import org.hibernate.mapping.Any;
12 import org.hibernate.mapping.Array;
13 import org.hibernate.mapping.Bag;
14 import org.hibernate.mapping.Component;
15 import org.hibernate.mapping.DependantValue;
16 import org.hibernate.mapping.IdentifierBag;
17 import org.hibernate.mapping.List;
18 import org.hibernate.mapping.ManyToOne;
19 import org.hibernate.mapping.Map;
20 import org.hibernate.mapping.OneToMany;
21 import org.hibernate.mapping.OneToOne;
22 import org.hibernate.mapping.PrimitiveArray;
23 import org.hibernate.mapping.RootClass;
24 import org.hibernate.mapping.Set;
25 import org.hibernate.mapping.SimpleValue;
26 import org.hibernate.mapping.Table;
27 import org.hibernate.mapping.ValueVisitor;
28
29 /**
30  * @author max
31  *
32  */

33 public class ValueVisitorTest extends TestCase {
34
35     static public class ValueVisitorValidator implements ValueVisitor {
36
37         /* (non-Javadoc)
38          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.PrimitiveArray)
39          */

40         public Object JavaDoc accept(PrimitiveArray primitiveArray) {
41             return validate(PrimitiveArray.class,primitiveArray);
42         }
43         /*
44          * (non-Javadoc)
45          *
46          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Bag)
47          */

48         public Object JavaDoc accept(Bag bag) {
49             return validate(Bag.class, bag);
50         }
51
52         /* (non-Javadoc)
53          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.DependantValue)
54          */

55         public Object JavaDoc accept(DependantValue value) {
56             return validate(DependantValue.class, value);
57         }
58         /**
59          * @param expectedClass
60          * @param visitee
61          */

62         private Object JavaDoc validate(Class JavaDoc expectedClass, Object JavaDoc visitee) {
63             if (!visitee.getClass().getName().equals(expectedClass.getName())) {
64                 throw new IllegalStateException JavaDoc(visitee.getClass().getName()
65                         + " did not call proper accept method. Was "
66                         + expectedClass.getName());
67             }
68             return null;
69         }
70
71         /*
72          * (non-Javadoc)
73          *
74          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.IdentifierBag)
75          */

76         public Object JavaDoc accept(IdentifierBag bag) {
77             return validate(IdentifierBag.class, bag);
78
79         }
80
81         /*
82          * (non-Javadoc)
83          *
84          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.List)
85          */

86         public Object JavaDoc accept(List list) {
87             return validate(List.class, list);
88
89         }
90
91         /*
92          * (non-Javadoc)
93          *
94          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Map)
95          */

96         public Object JavaDoc accept(Map map) {
97             return validate(Map.class, map);
98
99         }
100
101         /* (non-Javadoc)
102          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Array)
103          */

104         public Object JavaDoc accept(Array list) {
105             return validate(Array.class, list);
106         }
107         /*
108          * (non-Javadoc)
109          *
110          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToMany)
111          */

112         public Object JavaDoc accept(OneToMany many) {
113             return validate(OneToMany.class, many);
114         }
115
116         /*
117          * (non-Javadoc)
118          *
119          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Set)
120          */

121         public Object JavaDoc accept(Set set) {
122             return validate(Set.class, set);
123         }
124
125         /*
126          * (non-Javadoc)
127          *
128          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Any)
129          */

130         public Object JavaDoc accept(Any any) {
131             return validate(Any.class, any);
132             
133         }
134
135         /*
136          * (non-Javadoc)
137          *
138          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.SimpleValue)
139          */

140         public Object JavaDoc accept(SimpleValue value) {
141             return validate(SimpleValue.class, value);
142
143         }
144
145         /* (non-Javadoc)
146          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.Component)
147          */

148         public Object JavaDoc accept(Component component) {
149             return validate(Component.class, component);
150         }
151
152         /* (non-Javadoc)
153          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.ManyToOne)
154          */

155         public Object JavaDoc accept(ManyToOne mto) {
156             return validate(ManyToOne.class, mto);
157         }
158
159         /* (non-Javadoc)
160          * @see org.hibernate.mapping.ValueVisitor#accept(org.hibernate.mapping.OneToOne)
161          */

162         public Object JavaDoc accept(OneToOne oto) {
163             return validate(OneToOne.class, oto);
164         }
165
166     };
167
168     public void testProperCallbacks() {
169
170         ValueVisitor vv = new ValueVisitorValidator();
171         
172         new Any(new Table()).accept(vv);
173         new Array(new RootClass()).accept(vv);
174         new Bag(new RootClass()).accept(vv);
175         new Component(new RootClass()).accept(vv);
176         new DependantValue(null,null).accept(vv);
177         new IdentifierBag(null).accept(vv);
178         new List(null).accept(vv);
179         new ManyToOne(null).accept(vv);
180         new Map(null).accept(vv);
181         new OneToMany(null).accept(vv);
182         new OneToOne(null, new RootClass() ).accept(vv);
183         new PrimitiveArray(null).accept(vv);
184         new Set(null).accept(vv);
185         new SimpleValue().accept(vv);
186     
187         
188     }
189
190     public static Test suite() {
191         return new TestSuite(ValueVisitorTest.class);
192     }
193
194
195 }
196
Popular Tags