1 package org.apache.torque.om; 2 3 21 22 import junit.framework.Assert; 23 import junit.framework.Test; 24 import junit.framework.TestCase; 25 import junit.framework.TestSuite; 26 27 33 public class ComboKeyTest extends TestCase 34 { 35 private ComboKey c1a = new ComboKey( 36 new SimpleKey[]{new StringKey("key1"), new StringKey("key2")}); 37 private ComboKey c1b = new ComboKey( 38 new SimpleKey[]{new StringKey("key1"), new StringKey("key2")}); 39 private ComboKey c2a = new ComboKey( 40 new SimpleKey[]{new StringKey("key3"), new StringKey("key4")}); 41 private java.util.Date now = new java.util.Date (); 43 private ComboKey c3a = new ComboKey( 44 new SimpleKey[]{new StringKey("key1"), null, new DateKey(now)}); 45 private ComboKey c4a = new ComboKey( 46 new SimpleKey[]{new StringKey("key1"), null, new NumberKey(123456)}); 47 48 53 public ComboKeyTest(String name) 54 { 55 super(name); 56 } 57 58 62 public static void main(java.lang.String [] args) 63 { 64 junit.textui.TestRunner.run(suite()); 65 } 66 67 71 public static Test suite() 72 { 73 TestSuite suite = new TestSuite(ComboKeyTest.class); 74 75 return suite; 76 } 77 78 82 public void testReflexive() 83 { 84 Assert.assertTrue(c1a.equals(c1a)); 85 Assert.assertTrue(c3a.looseEquals(c3a)); 89 } 90 91 95 public void testSymmetric() 96 { 97 Assert.assertTrue(c1a.equals(c1b)); 98 Assert.assertTrue(c1b.equals(c1a)); 99 } 100 101 105 public void testNull() 106 { 107 Assert.assertTrue(!c1a.equals(null)); 108 } 109 110 114 public void testNotEqual() 115 { 116 Assert.assertTrue(!c1a.equals(c2a)); 117 } 118 119 123 public void testRoundTripWithStringKeys() 124 { 125 ComboKey oldKey = new ComboKey( 127 new SimpleKey[]{new StringKey("key1"), new StringKey("key2")}); 128 ComboKey newKey = null; 129 String stringValue = oldKey.toString(); 130 try 131 { 132 newKey = new ComboKey(stringValue); 133 } 134 catch(Exception e) 135 { 136 fail("Exception " + e.getClass().getName() 137 + " thrown on new ComboKey(" + stringValue + "):" 138 + e.getMessage()); 139 } 140 Assert.assertEquals(oldKey,newKey); 141 } 142 143 147 public void testRoundTripWithComplexKey() 148 { 149 ComboKey oldKey = new ComboKey( 151 new SimpleKey[]{new StringKey("key1"), new NumberKey(12345), 152 new DateKey(new java.util.Date ())}); 153 ComboKey newKey = null; 154 String stringValue = oldKey.toString(); 155 try 156 { 157 newKey = new ComboKey(stringValue); 158 } 159 catch (Exception e) 160 { 161 fail("Exception " + e.getClass().getName() 162 + " thrown on new ComboKey(" 163 + stringValue + "):" + e.getMessage()); 164 } 165 Assert.assertEquals(oldKey,newKey); 166 } 167 168 172 public void testRoundTripWithNullKey() 173 { 174 ComboKey oldKey = new ComboKey( 176 new SimpleKey[]{new StringKey("key1"), null}); 177 ComboKey newKey = null; 178 String stringValue = oldKey.toString(); 179 try 180 { 181 newKey = new ComboKey(stringValue); 182 } 183 catch (Exception e) 184 { 185 fail("Exception " + e.getClass().getName() 186 + " thrown on new ComboKey(" 187 + stringValue + "):" + e.getMessage()); 188 } 189 Assert.assertTrue(oldKey.looseEquals(newKey)); 192 } 193 194 195 198 public void testAppendTo() 199 { 200 StringBuffer sb = new StringBuffer (); 201 c1a.appendTo(sb); 202 Assert.assertEquals("Skey1:Skey2:", sb.toString()); 203 } 204 205 208 public void testToString() 209 { 210 Assert.assertEquals("Skey1::N123456:", c4a.toString()); 211 } 212 } 213 | Popular Tags |