1 9 package test.ozoneDB.tools.OPP.srcgen.resolve; 10 11 import junit.framework.TestCase; 12 import org.ozoneDB.tools.OPP.srcgen.resolve.SourceUpdateMethodResolver; 13 import org.ozoneDB.tools.OPP.srcgen.resolve.UpdateMethodBagMapAdapter; 14 import org.ozoneDB.tools.OPP.srcgen.MethodResolver; 15 import org.ozoneDB.tools.OPP.srcgen.ResolverException; 16 import org.ozoneDB.tools.OPP.message.MessageWriter; 17 import org.ozoneDB.tools.OPP.message.StdOutMessageWriter; 18 import org.ozoneDB.core.Lock; 19 import test.ozoneDB.tools.OPP.srcgen.streamfactory.MockInputStreamFactory; 20 import test.ozoneDB.tools.OPP.srcgen.query.MockClassQuery; 21 22 import java.io.StringWriter ; 23 import java.io.PrintWriter ; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 27 import com.mockobjects.util.Verifier; 28 29 34 public class TestSourceUpdateMethodReslover extends TestCase { 35 private MockInputStreamFactory isFactory; 36 private MockClassQuery classQuery; 37 private MessageWriter messageWriter; 38 39 public TestSourceUpdateMethodReslover(String s) { 40 super(s); 41 } 42 43 protected void setUp() { 44 isFactory = new MockInputStreamFactory(); 45 messageWriter = new StdOutMessageWriter(false, true); 46 classQuery = new MockClassQuery(); 47 } 48 49 54 private void setupSimpleScenario() { 55 56 String myOzoneObjectImplInterfaces[] = {"MyOzoneObject"}; 59 classQuery.setupGetInterfaces("MyOzoneObjectImpl", myOzoneObjectImplInterfaces); 60 61 String myOzoneObjectInterfaces[] = {"org.ozoneDB.OzoneRemote"}; 63 classQuery.setupGetInterfaces("MyOzoneObject", myOzoneObjectInterfaces); 64 65 classQuery.setupIsAssignable("org.ozoneDB.OzoneRemote", "MyOzoneObject", true); 67 classQuery.setupIsAssignable("org.ozoneDB.OzoneRemote", "MyOzoneObjectImpl", true); 68 } 69 70 71 public void testUpdateMethodDetectionInImpl() throws ResolverException { 72 setupSimpleScenario(); 73 74 StringWriter ifWr = new StringWriter (); 75 PrintWriter ifPWr = new PrintWriter (ifWr); 76 77 ifPWr.println("import org.ozoneDB.*;"); 79 ifPWr.println("public interface MyOzoneObject extends OzoneRemote {"); 80 ifPWr.println(" public void myRegularMethod();"); 81 ifPWr.println(" public void myUpdateMethod();"); 82 ifPWr.println(" public void myUpdateMethod2();"); 83 ifPWr.println(" public void myUpdateMethod3();"); 84 ifPWr.println(" public void myRegularMethod2();"); 85 ifPWr.println("}"); 86 ifPWr.flush(); 87 88 StringWriter obWr = new StringWriter (); 89 PrintWriter obPWr = new PrintWriter (obWr); 90 91 obPWr.println("import org.ozoneDB.*;"); 93 obPWr.println("public interface MyOzoneObject extends OzoneRemote {"); 94 obPWr.println(" public void myRegularMethod() {"); 95 obPWr.println(" }"); 96 obPWr.println(" public void myUpdateMethod() //update"); 97 obPWr.println(" {"); 98 obPWr.println(" }"); 99 obPWr.println(" public void myUpdateMethod2() /*update*/{"); 100 obPWr.println(" }"); 101 obPWr.println(" /**"); 102 obPWr.println(" * @update"); 103 obPWr.println(" */"); 104 obPWr.println(" public void myUpdateMethod3() {"); 105 obPWr.println(" }"); 106 obPWr.println(" public void myRegularMethod2() {"); 107 obPWr.println(" }"); 108 obPWr.println("}"); 109 obPWr.flush(); 110 111 isFactory.setupNewInstanceReturnValue("MyOzoneObject", ifWr.toString()); 113 isFactory.setupNewInstanceReturnValue("MyOzoneObjectImpl", obWr.toString()); 114 115 Map updateMethods = new HashMap (); 116 MethodResolver.UpdateMethodBag updateMethodBag = new UpdateMethodBagMapAdapter(updateMethods); 117 118 MethodResolver resolver = new SourceUpdateMethodResolver(isFactory, messageWriter, classQuery); 120 resolver.resolveMethods("MyOzoneObjectImpl", updateMethodBag); 121 122 Verifier.verifyObject(this); 124 125 assertTrue("Map does not contain myUpdateMethod", updateMethods.containsKey("myUpdateMethod")); 127 assertTrue("Map does not contain myUpdateMethod2", updateMethods.containsKey("myUpdateMethod2")); 128 assertTrue("Map does not contain myUpdateMethod3", updateMethods.containsKey("myUpdateMethod3")); 129 130 assertEquals("myUpdateMethod does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod")).intValue()); 132 assertEquals("myUpdateMethod2 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod2")).intValue()); 133 assertEquals("myUpdateMethod3 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod3")).intValue()); 134 } 135 136 public void testUpdateMethodDetectionInItf() throws ResolverException { 137 setupSimpleScenario(); 138 139 StringWriter ifWr = new StringWriter (); 140 PrintWriter ifPWr = new PrintWriter (ifWr); 141 142 ifPWr.println("import org.ozoneDB.*;"); 144 ifPWr.println("public interface MyOzoneObject extends OzoneRemote {"); 145 ifPWr.println(" public void myRegularMethod();"); 146 ifPWr.println(" public void myUpdateMethod(); //update"); 147 ifPWr.println(" public void myUpdateMethod2(); /*update*/"); 148 ifPWr.println(" /**"); 149 ifPWr.println(" * @update"); 150 ifPWr.println(" */"); 151 ifPWr.println(" public void myUpdateMethod3(); "); 152 ifPWr.println(" public void myRegularMethod2();"); 153 ifPWr.println("}"); 154 ifPWr.flush(); 155 156 StringWriter obWr = new StringWriter (); 157 PrintWriter obPWr = new PrintWriter (obWr); 158 159 obPWr.println("import org.ozoneDB.*;"); 161 obPWr.println("public interface MyOzoneObject extends OzoneRemote {"); 162 obPWr.println(" public void myRegularMethod() {"); 163 obPWr.println(" }"); 164 obPWr.println(" public void myUpdateMethod() {"); 165 obPWr.println(" "); 166 obPWr.println(" }"); 167 obPWr.println(" public void myUpdateMethod2() {"); 168 obPWr.println(" }"); 169 obPWr.println(" public void myUpdateMethod3() {"); 170 obPWr.println(" }"); 171 obPWr.println(" public void myRegularMethod2() {"); 172 obPWr.println(" }"); 173 obPWr.println("}"); 174 obPWr.flush(); 175 176 isFactory.setupNewInstanceReturnValue("MyOzoneObject", ifWr.toString()); 178 isFactory.setupNewInstanceReturnValue("MyOzoneObjectImpl", obWr.toString()); 179 180 Map updateMethods = new HashMap (); 181 MethodResolver.UpdateMethodBag updateMethodBag = new UpdateMethodBagMapAdapter(updateMethods); 182 183 MethodResolver resolver = new SourceUpdateMethodResolver(isFactory, messageWriter, classQuery); 185 resolver.resolveMethods("MyOzoneObjectImpl", updateMethodBag); 186 187 Verifier.verifyObject(this); 189 190 assertTrue("Map does not contain myUpdateMethod", updateMethods.containsKey("myUpdateMethod")); 192 assertTrue("Map does not contain myUpdateMethod2", updateMethods.containsKey("myUpdateMethod2")); 193 assertTrue("Map does not contain myUpdateMethod3", updateMethods.containsKey("myUpdateMethod3")); 194 195 assertEquals("myUpdateMethod does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod")).intValue()); 197 assertEquals("myUpdateMethod2 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod2")).intValue()); 198 assertEquals("myUpdateMethod3 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer ) updateMethods.get("myUpdateMethod3")).intValue()); 199 } 200 } 201 | Popular Tags |