1 23 24 package org.objectweb.jorm.mapper.rdb.lib; 25 26 import junit.framework.TestCase; 27 import org.objectweb.jorm.api.PException; 28 import org.objectweb.util.monolog.api.Logger; 29 import org.objectweb.util.monolog.wrapper.printwriter.LoggerImpl; 30 31 32 38 public class TestRdbPMappingStructuresManager extends TestCase { 39 private final static String JCN1 = "org.objectweb.test.C1"; 40 private final static String JCN2 = "org.objectweb.test.C2"; 41 42 private final static String TN1 = "T1"; 43 private final static String T1CN1 = "C11"; 44 private final static String T1CT1 = "INTEGER"; 45 private final static boolean T1CNN1 = true; 46 private final static String T1CN2 = "C12"; 47 private final static String T1CT2 = "CHAR(20)"; 48 private final static boolean T1CNN2 = false; 49 private final static String TN2 = "T2"; 50 private final static String T2CN1 = "C21"; 51 private final static String T2CT1 = "INTEGER"; 52 private final static boolean T2CNN1 = true; 53 private final static String T2CN2 = "C22"; 54 private final static String T2CT2 = "CHAR(20)"; 55 private final static boolean T2CNN2 = false; 56 private Logger logger = new LoggerImpl(); 57 58 public TestRdbPMappingStructuresManager(String testname) { 59 super(testname); 60 } 61 62 protected void setUp() { 63 64 } 65 66 protected void tearDown() { 67 68 } 69 70 public void testClusterWith1Class1Table1Column() { 71 try { 72 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 73 man.setLogger(logger); 74 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 75 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 76 assertTrue("Cluster has not been created for " + JCN1, cl != null); 77 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 78 assertTrue("Column " + T1CN1 + " into table " + JCN1 + " does not exist in cluster", 79 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 80 } catch (PException e) { 81 e.printStackTrace(); 82 fail(e.getMessage()); 83 } 84 } 85 86 public void testClusterWith1Class1Table1ColumnDupOK() { 87 try { 88 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 89 man.setLogger(logger); 90 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 91 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, false); 92 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 93 assertTrue("Cluster has not been created for " + JCN1, cl != null); 94 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 95 assertTrue("Column " + T1CN1 + " into table " + JCN1 + " does not exist in cluster", 96 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 97 } catch (PException e) { 98 e.printStackTrace(); 99 fail(e.getMessage()); 100 } 101 } 102 103 public void testClusterWith1Class1Table1ColumnDupKOnotnull() { 104 try { 105 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 106 man.setLogger(logger); 107 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 108 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, ! T1CNN1, false, true); 109 fail("Duplicate column definition with incompatible notnull"); 110 } catch (PException e) { 111 assertTrue(e.getMessage(), true); 112 } 113 } 114 115 public void testClusterWith1Class1Table1ColumnDupKOtype() { 116 try { 117 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 118 man.setLogger(logger); 119 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 120 man.addTableColumn(JCN1, TN1, T1CN1, T1CT2, T1CNN1, false, true); 121 fail("Duplicate column definition with incompatible type"); 122 } catch (PException e) { 123 assertTrue(e.getMessage(), true); 124 } 125 } 126 127 public void testClusterWith1Class1Table2Column() { 128 try { 129 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 130 man.setLogger(logger); 131 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 132 man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, false); 133 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 134 assertTrue("Cluster has not been created for " + JCN1, cl != null); 135 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 136 assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster", 137 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 138 assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster", 139 cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2)); 140 } catch (PException e) { 141 e.printStackTrace(); 142 fail(e.getMessage()); 143 } 144 } 145 146 public void testClusterWith1Class2Table2Column() { 147 try { 148 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 149 man.setLogger(logger); 150 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 151 man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true); 152 man.addTableColumn(JCN1, TN2, T2CN1, T2CT1, T2CNN1, false, true); 153 man.addTableColumn(JCN1, TN2, T2CN2, T2CT2, T2CNN2, false, true); 154 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 155 assertTrue("Cluster has not been created for " + JCN1, cl != null); 156 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 157 assertTrue("Table " + TN2 + " does not exist in cluster", cl.containTable(TN2)); 158 assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster", 159 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 160 assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster", 161 cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2)); 162 assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster", 163 cl.containColumn(TN2, T2CN1, T2CT1, T2CNN1)); 164 assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster", 165 cl.containColumn(TN2, T2CN2, T2CT2, T2CNN2)); 166 } catch (PException e) { 167 e.printStackTrace(); 168 fail(e.getMessage()); 169 } 170 } 171 172 public void testClusterWith2Class2Table2ColumnNoMerge() { 173 try { 174 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 175 man.setLogger(logger); 176 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 177 man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true); 178 man.addTableColumn(JCN2, TN2, T2CN1, T2CT1, T2CNN1, false, true); 179 man.addTableColumn(JCN2, TN2, T2CN2, T2CT2, T2CNN2, false, true); 180 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 181 RdbPMapCluster cl2 = (RdbPMapCluster) man.getPMapCluster(JCN2); 182 assertTrue("Cluster has not been created for " + JCN1, cl != null); 183 assertTrue("Cluster has not been created for " + JCN2, cl2 != null); 184 assertTrue("The two classes are into the same cluster", cl != cl2); 185 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 186 assertTrue("Table " + TN2 + " does not exist in cluster", cl2.containTable(TN2)); 187 assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster", 188 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 189 assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster", 190 cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2)); 191 assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster", 192 cl2.containColumn(TN2, T2CN1, T2CT1, T2CNN1)); 193 assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster", 194 cl2.containColumn(TN2, T2CN2, T2CT2, T2CNN2)); 195 } catch (PException e) { 196 e.printStackTrace(); 197 fail(e.getMessage()); 198 } 199 } 200 201 public void testClusterWith2Class2Table2ColumnMerge() { 202 try { 203 RdbPMappingStructuresManager man = new RdbPMappingStructuresManager(); 204 man.setLogger(logger); 205 man.addTableColumn(JCN1, TN1, T1CN1, T1CT1, T1CNN1, false, true); 206 man.addTableColumn(JCN1, TN1, T1CN2, T1CT2, T1CNN2, false, true); 207 man.addTableColumn(JCN1, TN2, T2CN2, T2CT2, T2CNN2, false, true); 208 man.addTableColumn(JCN2, TN2, T2CN1, T2CT1, T2CNN1, false, true); 209 man.addTableColumn(JCN2, TN2, T2CN2, T2CT2, T2CNN2, false, false); 210 RdbPMapCluster cl = (RdbPMapCluster) man.getPMapCluster(JCN1); 211 RdbPMapCluster cl2 = (RdbPMapCluster) man.getPMapCluster(JCN2); 212 assertTrue("Cluster has not been created for " + JCN1, cl != null); 213 assertTrue("Cluster has not been created for " + JCN2, cl2 != null); 214 assertTrue("The two classes are not into the same cluster", cl == cl2); 215 assertTrue("Table " + TN1 + " does not exist in cluster", cl.containTable(TN1)); 216 assertTrue("Table " + TN2 + " does not exist in cluster", cl.containTable(TN2)); 217 assertTrue("Column " + T1CN1 + " into table " + TN1 + " does not exist in cluster", 218 cl.containColumn(TN1, T1CN1, T1CT1, T1CNN1)); 219 assertTrue("Column " + T1CN2 + " into table " + TN1 + " does not exist in cluster", 220 cl.containColumn(TN1, T1CN2, T1CT2, T1CNN2)); 221 assertTrue("Column " + T2CN1 + " into table " + TN2 + " does not exist in cluster", 222 cl.containColumn(TN2, T2CN1, T2CT1, T2CNN1)); 223 assertTrue("Column " + T2CN2 + " into table " + TN2 + " does not exist in cluster", 224 cl.containColumn(TN2, T2CN2, T2CT2, T2CNN2)); 225 } catch (PException e) { 226 e.printStackTrace(); 227 fail(e.getMessage()); 228 } 229 } 230 } 231 | Popular Tags |