1 23 package org.objectweb.jorm.runtime.colocated; 24 25 import org.objectweb.jorm.runtime.TestRuntimeHelper; 26 import org.objectweb.jorm.runtime.PolyIdPNG; 27 import org.objectweb.jorm.naming.api.PBinder; 28 import org.objectweb.jorm.naming.api.PNameCoder; 29 import org.objectweb.jorm.naming.api.PNamingContext; 30 import org.objectweb.jorm.facility.naming.basidir.BasidBinder; 31 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdBinder; 32 import org.objectweb.jorm.api.PException; 33 import org.objectweb.jorm.api.PBinding; 34 import org.objectweb.jorm.api.PAccessor; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.List ; 40 import java.util.ArrayList ; 41 42 46 public class TestOneMany2T extends TestRuntimeHelper { 47 48 private final static String LOGGER_NAME 49 = "test.org.objectweb.jorm.colocated.omemany2t"; 50 51 private final static String GenClassRef_SN_C 52 = "org.objectweb.jorm.pobject.colocated.GenClassRef_SN_C"; 53 private final static String GenClassRef_CN_C 54 = "org.objectweb.jorm.pobject.colocated.GenClassRef_CN_C"; 55 56 private final static String StringReferencedClass_C 57 = "org.objectweb.jorm.pobject.colocated.StringReferencedClass_C"; 58 private final static String PolyIdReferencedClass_C 59 = "org.objectweb.jorm.pobject.colocated.PolyIdReferencedClass_C"; 60 61 Map cn2binder; 62 63 public TestOneMany2T(String s) throws Exception { 64 super(s); 65 cn2binder = new HashMap (1); 66 } 67 68 protected String getLoggerName() { 69 return LOGGER_NAME; 70 } 71 72 protected PBinder getBinder(String className) throws Exception { 73 PBinder binder = (PBinder) cn2binder.get(className); 74 if (binder != null) { 75 return binder; 76 } 77 try { 78 if (className.startsWith(GenClassRef_SN_C)) { 79 binder = new BasidBinder( PNamingContext.CTLONG); 80 binder.setNullPName(new Long (-1)); 81 ((BasidBinder) binder).setCodingType(PNameCoder.CTLONG); 82 } else if (className.startsWith(GenClassRef_CN_C) 83 || className.startsWith(PolyIdReferencedClass_C)) { 84 binder = new PolymorphIdBinder(); 85 binder.setNullPName(new PolyIdPNG()); 86 } else if (className.startsWith(StringReferencedClass_C)) { 87 binder = new BasidBinder( PNamingContext.CTSTRING); 88 binder.setNullPName(null); 89 ((BasidBinder) binder).setCodingType(PNameCoder.CTSTRING); 90 } 91 } catch (PException e) { 92 Exception current = e; 93 while (current instanceof PException 94 && ((PException) current).getNestedException() != null) { 95 current = ((PException) current).getNestedException(); 96 } 97 throw current; 98 } 99 if (binder == null) { 100 throw new PException("Unmanaged class " + className); 101 } 102 logger.log(BasicLevel.DEBUG, 103 "className=" + className + " / binder=" + binder); 104 cn2binder.put(className, binder); 105 return binder; 106 } 107 108 private void genclassRefTestOrder1(PBinding gcrPb, PBinding gcPb, List rcPbs) { 109 110 List rcAccws = new ArrayList (); 112 List rcPns = new ArrayList (); 113 for(int i=0; i<rcPbs.size(); i++) { 114 rcPns.add(((PBinding) rcPbs.get(i)).getPName()); 115 ReferencedClass_C rcAccw = new ReferencedClass_C(); 116 rcAccws.add(rcAccw); 117 rcAccw.f1 = 10; 118 ReferencedClass_C rcAccr = new ReferencedClass_C(); 119 logger.log(BasicLevel.DEBUG, "create and read referenced class " + i); 120 writeRead((PBinding) rcPbs.get(i), rcAccw, rcAccr); 121 assertEquals("bad referenced class values", rcAccw, rcAccr); 122 } 123 124 GenClass_C gcAccw = new GenClass_C(rcPns); 126 GenClass_C gcAccr = new GenClass_C(rcPns.size()); 127 logger.log(BasicLevel.DEBUG, "create and read genclas"); 128 writeRead(gcPb, gcAccw, gcAccr); 129 assertEquals("bad gen class values", gcAccw, gcAccr); 130 131 GenClassRef_C gcrAccw = new GenClassRef_C(gcPb.getPName()); 133 GenClassRef_C gcrAccr = new GenClassRef_C(); 134 logger.log(BasicLevel.DEBUG, "create and read genclass"); 135 writeRead(gcrPb, gcrAccw, gcrAccr); 136 assertEquals("bad gen class values", gcrAccw, gcrAccr); 137 138 for(int i=0; i<rcPbs.size(); i++) { 139 logger.log(BasicLevel.DEBUG, "remove referenced class"); 140 unexport((PBinding) rcPbs.get(i), (PAccessor) rcAccws.get(i)); 141 } 142 logger.log(BasicLevel.DEBUG, "remove gen class"); 143 unexport(gcPb, gcAccw); 144 logger.log(BasicLevel.DEBUG, "remove gen class ref"); 145 unexport(gcrPb, gcrAccw); 146 } 147 148 private void genclassRefTestOrder2(PBinding gcrPb, PBinding gcPb, List rcPbs) { 149 150 List rcAccws = new ArrayList (); 152 List rcPns = new ArrayList (); 153 for(int i=0; i<rcPbs.size(); i++) { 154 rcPns.add(((PBinding) rcPbs.get(i)).getPName()); 155 ReferencedClass_C rcAccw = new ReferencedClass_C(); 156 rcAccws.add(rcAccw); 157 rcAccw.f1 = 10; 158 } 159 160 GenClass_C gcAccw = new GenClass_C(rcPns); 162 GenClass_C gcAccr = new GenClass_C(rcPns.size()); 163 logger.log(BasicLevel.DEBUG, "create and read genclas"); 164 writeRead(gcPb, gcAccw, gcAccr); 165 assertEquals("bad gen class values", gcAccw, gcAccr); 166 167 for(int i=0; i<rcPbs.size(); i++) { 168 ReferencedClass_C rcAccw = (ReferencedClass_C) rcAccws.get(i); 169 ReferencedClass_C rcAccr = new ReferencedClass_C(); 170 logger.log(BasicLevel.DEBUG, "create and read referenced class " + i); 171 writeRead((PBinding) rcPbs.get(i), rcAccw, rcAccr); 172 assertEquals("bad referenced class values", rcAccw, rcAccr); 173 } 174 175 GenClassRef_C gcrAccw = new GenClassRef_C(gcPb.getPName()); 177 GenClassRef_C gcrAccr = new GenClassRef_C(); 178 logger.log(BasicLevel.DEBUG, "create and read genclass"); 179 writeRead(gcrPb, gcrAccw, gcrAccr); 180 assertEquals("bad gen class values", gcrAccw, gcrAccr); 181 182 for(int i=0; i<rcPbs.size(); i++) { 183 logger.log(BasicLevel.DEBUG, "remove referenced class"); 184 unexport((PBinding) rcPbs.get(i), (PAccessor) rcAccws.get(i)); 185 } 186 logger.log(BasicLevel.DEBUG, "remove gen class"); 187 unexport(gcPb, gcAccw); 188 logger.log(BasicLevel.DEBUG, "remove gen class ref"); 189 unexport(gcrPb, gcrAccw); 190 } 191 192 public void testGenClassRefSingle1() { 193 changeLogger(LOGGER_NAME + ".single1"); 194 logger.log(BasicLevel.DEBUG, "testGenClassRefSingle2 begin"); 195 List rcPbs = new ArrayList (); 196 rcPbs.add(export(StringReferencedClass_C, "azerty")); 197 rcPbs.add(export(StringReferencedClass_C, "qsdfgh")); 198 genclassRefTestOrder1( 199 export(GenClassRef_SN_C, new Long (45)), 200 export(GenClassRef_SN_C + "/c", new Long (45)), 201 rcPbs); 202 logger.log(BasicLevel.DEBUG, "testGenClassRefSingle1 end"); 203 } 204 205 public void _testGenClassRefSingle2() { 206 changeLogger(LOGGER_NAME + ".single2"); 207 logger.log(BasicLevel.DEBUG, "testGenClassRefSingle2 begin"); 208 List rcPbs = new ArrayList (); 209 rcPbs.add(export(StringReferencedClass_C, "azerty")); 210 rcPbs.add(export(StringReferencedClass_C, "qsdfgh")); 211 genclassRefTestOrder2( 212 export(GenClassRef_SN_C, new Long (45)), 213 export(GenClassRef_SN_C + "/c", new Long (45)), 214 rcPbs); 215 logger.log(BasicLevel.DEBUG, "testGenClassRefSingle2 end"); 216 } 217 218 public void testGenClassRefComposite1() { 219 changeLogger(LOGGER_NAME + ".composite1"); 220 logger.log(BasicLevel.DEBUG, "testGenClassRefComposite1 begin"); 221 List rcPbs = new ArrayList (); 222 rcPbs.add(export(PolyIdReferencedClass_C, new PolyIdPNG(78, 90))); 223 rcPbs.add(export(PolyIdReferencedClass_C, new PolyIdPNG(13, 24))); 224 genclassRefTestOrder1( 225 export(GenClassRef_CN_C, new PolyIdPNG(12, 34)), 226 export(GenClassRef_CN_C + "/c", new PolyIdPNG(12, 34)), 227 rcPbs); 228 logger.log(BasicLevel.DEBUG, "testGenClassRefComposite1 end"); 229 } 230 231 public void _testGenClassRefComposite2() { 232 changeLogger(LOGGER_NAME + ".composite1"); 233 logger.log(BasicLevel.DEBUG, "testGenClassRefComposite1 begin"); 234 List rcPbs = new ArrayList (); 235 rcPbs.add(export(PolyIdReferencedClass_C, new PolyIdPNG(78, 90))); 236 rcPbs.add(export(PolyIdReferencedClass_C, new PolyIdPNG(13, 24))); 237 genclassRefTestOrder2( 238 export(GenClassRef_CN_C, new PolyIdPNG(12, 34)), 239 export(GenClassRef_CN_C + "/c", new PolyIdPNG(12, 34)), 240 rcPbs); 241 logger.log(BasicLevel.DEBUG, "testGenClassRefComposite1 end"); 242 } 243 244 } 245 | Popular Tags |