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.JoinedSubclass; 12 import org.hibernate.mapping.PersistentClassVisitor; 13 import org.hibernate.mapping.RootClass; 14 import org.hibernate.mapping.SingleTableSubclass; 15 import org.hibernate.mapping.Subclass; 16 import org.hibernate.mapping.UnionSubclass; 17 18 22 public class PersistentClassVisitorTest extends TestCase { 23 24 static public class PersistentClassVisitorValidator implements PersistentClassVisitor { 25 26 private Object validate(Class expectedClass, Object visitee) { 27 if (!visitee.getClass().getName().equals(expectedClass.getName())) { 28 throw new IllegalStateException (visitee.getClass().getName() 29 + " did not call proper accept method. Was " 30 + expectedClass.getName()); 31 } 32 return null; 33 } 34 35 public Object accept(RootClass class1) { 36 return validate(RootClass.class, class1); 37 } 38 39 public Object accept(UnionSubclass subclass) { 40 return validate(UnionSubclass.class, subclass); 41 } 42 43 public Object accept(SingleTableSubclass subclass) { 44 return validate(SingleTableSubclass.class, subclass); 45 } 46 47 public Object accept(JoinedSubclass subclass) { 48 return validate(JoinedSubclass.class, subclass); 49 } 50 51 public Object accept(Subclass subclass) { 52 return validate(Subclass.class, subclass); 53 } 54 55 56 }; 57 58 public void testProperCallbacks() { 59 60 PersistentClassVisitorValidator vv = new PersistentClassVisitorValidator(); 61 62 new RootClass().accept(vv); 63 new Subclass(new RootClass()).accept(vv); 64 new JoinedSubclass(new RootClass()).accept(vv); 65 new SingleTableSubclass(new RootClass()).accept(vv); 66 new UnionSubclass(new RootClass()).accept(vv); 67 68 } 69 70 public static Test suite() { 71 return new TestSuite(PersistentClassVisitorTest.class); 72 } 73 74 } 75 | Popular Tags |