1 23 24 package org.objectweb.jorm.runtime.multitable; 25 26 import org.objectweb.jorm.runtime.TestRuntimeHelper; 27 import org.objectweb.jorm.runtime.PolyIdPNG; 28 import org.objectweb.jorm.naming.api.PBinder; 29 import org.objectweb.jorm.naming.api.PNameCoder; 30 import org.objectweb.jorm.facility.naming.basidir.BasidBinder; 31 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdBinder; 32 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdPNG; 33 import org.objectweb.jorm.api.PException; 34 import org.objectweb.jorm.api.PBinding; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 import java.util.Map ; 38 import java.util.HashMap ; 39 40 47 public class TestClassRefMultitable extends TestRuntimeHelper { 48 49 private final static String LOGGER_NAME 50 = "test.org.objectweb.jorm.multitable.classref"; 51 52 private final static String ClassRef_SN_MT 53 = "org.objectweb.jorm.pobject.multitable.ClassRef_SN_MT"; 54 private final static String ClassRef_CN_MT 55 = "org.objectweb.jorm.pobject.multitable.ClassRef_CN_MT"; 56 57 private final static String StringReferencedClass_SN_MT 58 = "org.objectweb.jorm.pobject.multitable.StringReferencedClass_SN_MT"; 59 private final static String PolyIdReferencedClass_CN_MT 60 = "org.objectweb.jorm.pobject.multitable.PolyIdReferencedClass_CN_MT"; 61 62 Map cn2binder; 63 64 public TestClassRefMultitable(String s) throws Exception { 65 super(s); 66 cn2binder = new HashMap (1); 67 } 68 69 protected String getLoggerName() { 70 return LOGGER_NAME; 71 } 72 73 protected PBinder getBinder(String className) throws Exception { 74 PBinder binder = (PBinder) cn2binder.get(className); 75 if (binder != null) { 76 return binder; 77 } 78 try { 79 if (ClassRef_SN_MT.equals(className)) { 80 binder = new BasidBinder(); 81 binder.setNullPName(new Long (-1)); 82 ((BasidBinder) binder).setCodingType(PNameCoder.CTLONG); 83 } else if (ClassRef_CN_MT.equals(className) 84 || PolyIdReferencedClass_CN_MT.equals(className)) { 85 binder = new PolymorphIdBinder(); 86 binder.setNullPName(new PolyIdPNG()); 87 } else if (StringReferencedClass_SN_MT.equals(className)) { 88 binder = new BasidBinder(); 89 binder.setNullPName(null); 90 ((BasidBinder) binder).setCodingType(PNameCoder.CTSTRING); 91 } 92 } catch (PException e) { 93 Exception current = e; 94 while (current instanceof PException 95 && ((PException) current).getNestedException() != null) { 96 current = ((PException) current).getNestedException(); 97 } 98 throw current; 99 } 100 if (binder == null) { 101 throw new PException("Unmanaged class " + className); 102 } 103 cn2binder.put(className, binder); 104 return binder; 105 } 106 107 108 private void classRefTest(PBinding crPb, PBinding rc1Pb, PBinding rc2Pb) { 109 110 ReferencedClass_MT rc1Accw = new ReferencedClass_MT(); 112 rc1Accw.f1 = 10; 113 ReferencedClass_MT rc1Accr = new ReferencedClass_MT(); 114 logger.log(BasicLevel.DEBUG, "create and read referenced class 1"); 115 writeRead(rc1Pb, rc1Accw, rc1Accr); 116 assertEquals("bad referenced class (1) values", rc1Accw, rc1Accr); 117 118 ReferencedClass_MT rc2Accw = new ReferencedClass_MT(); 119 rc2Accw.f1 = 20; 120 ReferencedClass_MT rc2Accr = new ReferencedClass_MT(); 121 logger.log(BasicLevel.DEBUG, "create and read referenced class 2"); 122 writeRead(rc2Pb, rc2Accw, rc2Accr); 123 assertEquals("bad referenced class (2) values", rc2Accw, rc2Accr); 124 125 ClassRef_MT crAccw = new ClassRef_MT(rc1Pb.getPName(), rc2Pb.getPName()); 126 ClassRef_MT crAccr = new ClassRef_MT(); 127 logger.log(BasicLevel.DEBUG, "create and read classref"); 128 writeRead(crPb, crAccw, crAccr); 129 assertEquals("bad class reference values", crAccw, crAccr); 130 131 ClassRef_MT crAccw2 = new ClassRef_MT(rc2Pb.getPName(), rc1Pb.getPName()); 132 logger.log(BasicLevel.DEBUG, "update and read"); 133 writeRead(crPb, crAccw2, crAccr); 134 assertEquals("bad class reference values", crAccw2, crAccr); 135 136 logger.log(BasicLevel.DEBUG, "remove referenced class 1"); 137 unexport(rc1Pb, rc1Accw); 138 logger.log(BasicLevel.DEBUG, "remove referenced class 2"); 139 unexport(rc2Pb, rc2Accw); 140 logger.log(BasicLevel.DEBUG, "remove class reference"); 141 unexport(crPb, crAccw); 142 } 143 144 public void testClassRefSingle() { 145 changeLogger(LOGGER_NAME + ".single"); 146 logger.log(BasicLevel.DEBUG, "testClassRefSingle begin"); 147 classRefTest( 148 export(ClassRef_SN_MT, new Long (45)), 149 export(StringReferencedClass_SN_MT, "azerty"), 150 export(StringReferencedClass_SN_MT, "qsdfgh") 151 ); 152 logger.log(BasicLevel.DEBUG, "testClassRefSingle end"); 153 } 154 155 public void testClassRefComposite() { 156 changeLogger(LOGGER_NAME + ".composite"); 157 logger.log(BasicLevel.DEBUG, "testPrimitiveComposite begin"); 158 classRefTest( 159 export(ClassRef_CN_MT, new PolyIdPNG(12, 34)), 160 export(PolyIdReferencedClass_CN_MT, new PolyIdPNG(78, 90)), 161 export(PolyIdReferencedClass_CN_MT, new PolyIdPNG(13, 24)) 162 ); 163 logger.log(BasicLevel.DEBUG, "testPrimitiveComposite end"); 164 } 165 } 166 | Popular Tags |