1 8 9 package com.triactive.jdo.model.test.widgets; 10 11 import com.triactive.jdo.model.*; 12 import java.util.Random ; 13 import junit.framework.Assert; 14 15 16 23 24 public class SelfReferencingWidget extends Widget 25 { 26 private SelfReferencingWidget srWidgetField = null; 27 28 29 32 33 public SelfReferencingWidget() 34 { 35 super(); 36 } 37 38 private static Random r = new Random (0); 39 40 41 46 47 public void fillRandom() 48 { 49 super.fillRandom(); 50 51 srWidgetField = r.nextBoolean() ? null : new SelfReferencingWidget(); 52 } 53 54 55 66 67 public boolean equals(Object obj) 68 { 69 if (this == obj) 70 return true; 71 72 if (!(obj instanceof SelfReferencingWidget) || !super.equals(obj)) 73 return false; 74 75 SelfReferencingWidget w = (SelfReferencingWidget)obj; 76 77 if (srWidgetField == null) { if (w.srWidgetField != null) return false; } 78 else if (!srWidgetField.equals(w.srWidgetField)) return false; 79 80 return true; 81 } 82 83 84 89 90 public int hashCode() 91 { 92 97 98 return super.hashCode() 99 ^ (srWidgetField == null ? 0 : srWidgetField.hashCode()); 100 } 101 102 103 109 110 public String toString() 111 { 112 StringBuffer s = new StringBuffer (super.toString()); 113 114 s.append(" srWidgetField = ").append(srWidgetField); 115 s.append('\n'); 116 117 return s.toString(); 118 } 119 120 121 127 128 public static void assertValidMetaData(ClassMetaData cmd, Assert test) 129 { 130 test.assertNotNull("Metadata", cmd); 131 test.assertEquals(SelfReferencingWidget.class, cmd.getPCClass()); 132 test.assertEquals("com.triactive.jdo.model.test.widgets", cmd.getPackageName()); 133 test.assertTrue("Source URL", cmd.getSourceURL().toString().indexOf("package.jdo") >= 0); 134 test.assertEquals("Superclass", Widget.class, cmd.getPCSuperclass()); 135 test.assertEquals("Identity type", ClassMetaData.DATASTORE_IDENTITY, cmd.getIdentityType()); 136 test.assertNull("Identity class", cmd.getIdentityClass()); 137 138 String [] sortedFieldNames = new String [] 139 { 140 "srWidgetField" 141 }; 142 143 int[] nullValueHandlings = new int[] 144 { 145 FieldMetaData.NULL_VALUE_NONE 146 }; 147 148 test.assertEquals("Field count", sortedFieldNames.length, cmd.getFieldCount()); 149 150 for (int i = 0; i < sortedFieldNames.length; ++i) 151 { 152 FieldMetaData fmd = cmd.getFieldRelative(i); 153 String s = sortedFieldNames[i]; 154 155 test.assertEquals(s, fmd.getName()); 156 test.assertEquals(s + " persistence modifier", FieldMetaData.PERSISTENCE_MODIFIER_PERSISTENT, fmd.getPersistenceModifier()); 157 test.assertEquals(s + " primary key", false, fmd.isPrimaryKeyPart()); 158 test.assertEquals(s + " null value handling", nullValueHandlings[i], fmd.getNullValueHandling()); 159 test.assertEquals(s + " default fetch group", false, fmd.isInDefaultFetchGroup()); 160 test.assertNull(s + " array metadata", fmd.getArrayMetaData()); 161 test.assertNull(s + " collection metadata", fmd.getCollectionMetaData()); 162 test.assertNull(s + " map metadata", fmd.getMapMetaData()); 163 } 164 } 165 } 166 | Popular Tags |