1 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 33 public class ValueVisitorTest extends TestCase { 34 35 static public class ValueVisitorValidator implements ValueVisitor { 36 37 40 public Object accept(PrimitiveArray primitiveArray) { 41 return validate(PrimitiveArray.class,primitiveArray); 42 } 43 48 public Object accept(Bag bag) { 49 return validate(Bag.class, bag); 50 } 51 52 55 public Object accept(DependantValue value) { 56 return validate(DependantValue.class, value); 57 } 58 62 private Object validate(Class expectedClass, Object visitee) { 63 if (!visitee.getClass().getName().equals(expectedClass.getName())) { 64 throw new IllegalStateException (visitee.getClass().getName() 65 + " did not call proper accept method. Was " 66 + expectedClass.getName()); 67 } 68 return null; 69 } 70 71 76 public Object accept(IdentifierBag bag) { 77 return validate(IdentifierBag.class, bag); 78 79 } 80 81 86 public Object accept(List list) { 87 return validate(List.class, list); 88 89 } 90 91 96 public Object accept(Map map) { 97 return validate(Map.class, map); 98 99 } 100 101 104 public Object accept(Array list) { 105 return validate(Array.class, list); 106 } 107 112 public Object accept(OneToMany many) { 113 return validate(OneToMany.class, many); 114 } 115 116 121 public Object accept(Set set) { 122 return validate(Set.class, set); 123 } 124 125 130 public Object accept(Any any) { 131 return validate(Any.class, any); 132 133 } 134 135 140 public Object accept(SimpleValue value) { 141 return validate(SimpleValue.class, value); 142 143 } 144 145 148 public Object accept(Component component) { 149 return validate(Component.class, component); 150 } 151 152 155 public Object accept(ManyToOne mto) { 156 return validate(ManyToOne.class, mto); 157 } 158 159 162 public Object 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 |