⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsourceupdatemethodreslover.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by Joakim Ohlrogge are// Copyright (C) 1997-@year@ by Joakim Ohlrogge. All rights reserved.//// $Id$package test.ozoneDB.tools.OPP.srcgen.resolve;import junit.framework.TestCase;import org.ozoneDB.tools.OPP.srcgen.resolve.SourceUpdateMethodResolver;import org.ozoneDB.tools.OPP.srcgen.resolve.UpdateMethodBagMapAdapter;import org.ozoneDB.tools.OPP.srcgen.MethodResolver;import org.ozoneDB.tools.OPP.srcgen.ResolverException;import org.ozoneDB.tools.OPP.message.MessageWriter;import org.ozoneDB.tools.OPP.message.StdOutMessageWriter;import org.ozoneDB.core.Lock;import test.ozoneDB.tools.OPP.srcgen.streamfactory.MockInputStreamFactory;import test.ozoneDB.tools.OPP.srcgen.query.MockClassQuery;import java.io.StringWriter;import java.io.PrintWriter;import java.util.Map;import java.util.HashMap;import com.mockobjects.util.Verifier;/** * User: Jocke * Date: 2004-jan-02 * Time: 01:13:21 */public class TestSourceUpdateMethodReslover extends TestCase {    private MockInputStreamFactory isFactory;    private MockClassQuery classQuery;    private MessageWriter messageWriter;    public TestSourceUpdateMethodReslover(String s) {        super(s);    }    protected void setUp() {        isFactory = new MockInputStreamFactory();        messageWriter = new StdOutMessageWriter(false, true);        classQuery = new MockClassQuery();    }    /**     * Sets up the ClassQury for an extremely basic case of an ozone object.     * An ozone object implements an OznoneRemote extending interface.     *     */    private void setupSimpleScenario() {        // The SourceUpdateMethodResolver will ask for all interfaces of class MyOzoneObjectImpl        // we will return MyOzoneObject        String myOzoneObjectImplInterfaces[] = {"MyOzoneObject"};        classQuery.setupGetInterfaces("MyOzoneObjectImpl", myOzoneObjectImplInterfaces);        //MyOzoneObject extends OzoneRemote        String myOzoneObjectInterfaces[] = {"org.ozoneDB.OzoneRemote"};        classQuery.setupGetInterfaces("MyOzoneObject", myOzoneObjectInterfaces);        // Both MyOzoneObject and MyOzoneObjectImpl are assignable from OzoneRemote        classQuery.setupIsAssignable("org.ozoneDB.OzoneRemote", "MyOzoneObject", true);        classQuery.setupIsAssignable("org.ozoneDB.OzoneRemote", "MyOzoneObjectImpl", true);    }    public void testUpdateMethodDetectionInImpl() throws ResolverException {        setupSimpleScenario();        StringWriter ifWr = new StringWriter();        PrintWriter ifPWr = new PrintWriter(ifWr);        // Setup a very simple interface source        ifPWr.println("import org.ozoneDB.*;");        ifPWr.println("public interface MyOzoneObject extends OzoneRemote {");        ifPWr.println("   public void myRegularMethod();");        ifPWr.println("   public void myUpdateMethod();");        ifPWr.println("   public void myUpdateMethod2();");        ifPWr.println("   public void myUpdateMethod3();");        ifPWr.println("   public void myRegularMethod2();");        ifPWr.println("}");        ifPWr.flush();        StringWriter obWr = new StringWriter();        PrintWriter obPWr = new PrintWriter(obWr);        // Setup the OzoneObjectSource with 3 update methods        obPWr.println("import org.ozoneDB.*;");        obPWr.println("public interface MyOzoneObject extends OzoneRemote {");        obPWr.println("   public void myRegularMethod() {");        obPWr.println("   }");        obPWr.println("   public void myUpdateMethod() //update");        obPWr.println("   {");        obPWr.println("   }");        obPWr.println("   public void myUpdateMethod2() /*update*/{");        obPWr.println("   }");        obPWr.println("   /**");        obPWr.println("    * @update");        obPWr.println("    */");        obPWr.println("   public void myUpdateMethod3() {");        obPWr.println("   }");        obPWr.println("   public void myRegularMethod2() {");        obPWr.println("   }");        obPWr.println("}");        obPWr.flush();        // Add sources to the MockInputStreamFactory        isFactory.setupNewInstanceReturnValue("MyOzoneObject", ifWr.toString());        isFactory.setupNewInstanceReturnValue("MyOzoneObjectImpl", obWr.toString());        Map updateMethods = new HashMap();        MethodResolver.UpdateMethodBag updateMethodBag = new UpdateMethodBagMapAdapter(updateMethods);        // create the resolver and do the resolve        MethodResolver resolver = new SourceUpdateMethodResolver(isFactory, messageWriter, classQuery);        resolver.resolveMethods("MyOzoneObjectImpl", updateMethodBag);        // Verify that all mockobjects has returned all expected data        Verifier.verifyObject(this);        // verify that the resolver has identified all updatemethods as such        assertTrue("Map does not contain myUpdateMethod", updateMethods.containsKey("myUpdateMethod"));        assertTrue("Map does not contain myUpdateMethod2", updateMethods.containsKey("myUpdateMethod2"));        assertTrue("Map does not contain myUpdateMethod3", updateMethods.containsKey("myUpdateMethod3"));        // verify that the resolver has identified the appropriate locklevel for all methods        assertEquals("myUpdateMethod does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod")).intValue());        assertEquals("myUpdateMethod2 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod2")).intValue());        assertEquals("myUpdateMethod3 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod3")).intValue());    }    public void testUpdateMethodDetectionInItf() throws ResolverException {        setupSimpleScenario();        StringWriter ifWr = new StringWriter();        PrintWriter ifPWr = new PrintWriter(ifWr);        // Setup a very simple interface source        ifPWr.println("import org.ozoneDB.*;");        ifPWr.println("public interface MyOzoneObject extends OzoneRemote {");        ifPWr.println("   public void myRegularMethod();");        ifPWr.println("   public void myUpdateMethod(); //update");        ifPWr.println("   public void myUpdateMethod2(); /*update*/");        ifPWr.println("   /**");        ifPWr.println("    * @update");        ifPWr.println("    */");        ifPWr.println("   public void myUpdateMethod3(); ");        ifPWr.println("   public void myRegularMethod2();");        ifPWr.println("}");        ifPWr.flush();        StringWriter obWr = new StringWriter();        PrintWriter obPWr = new PrintWriter(obWr);        // Setup the OzoneObjectSource with 3 update methods        obPWr.println("import org.ozoneDB.*;");        obPWr.println("public interface MyOzoneObject extends OzoneRemote {");        obPWr.println("   public void myRegularMethod() {");        obPWr.println("   }");        obPWr.println("   public void myUpdateMethod() {");        obPWr.println("   ");        obPWr.println("   }");        obPWr.println("   public void myUpdateMethod2() {");        obPWr.println("   }");        obPWr.println("   public void myUpdateMethod3() {");        obPWr.println("   }");        obPWr.println("   public void myRegularMethod2() {");        obPWr.println("   }");        obPWr.println("}");        obPWr.flush();        // Add sources to the MockInputStreamFactory        isFactory.setupNewInstanceReturnValue("MyOzoneObject", ifWr.toString());        isFactory.setupNewInstanceReturnValue("MyOzoneObjectImpl", obWr.toString());        Map updateMethods = new HashMap();        MethodResolver.UpdateMethodBag updateMethodBag = new UpdateMethodBagMapAdapter(updateMethods);        // create the resolver and do the resolve        MethodResolver resolver = new SourceUpdateMethodResolver(isFactory, messageWriter, classQuery);        resolver.resolveMethods("MyOzoneObjectImpl", updateMethodBag);        // Verify that all mockobjects has returned all expected data        Verifier.verifyObject(this);        // verify that the resolver has identified all updatemethods as such        assertTrue("Map does not contain myUpdateMethod", updateMethods.containsKey("myUpdateMethod"));        assertTrue("Map does not contain myUpdateMethod2", updateMethods.containsKey("myUpdateMethod2"));        assertTrue("Map does not contain myUpdateMethod3", updateMethods.containsKey("myUpdateMethod3"));        // verify that the resolver has identified the appropriate locklevel for all methods        assertEquals("myUpdateMethod does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod")).intValue());        assertEquals("myUpdateMethod2 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod2")).intValue());        assertEquals("myUpdateMethod3 does not have lockLevel write", Lock.LEVEL_WRITE, ((Integer) updateMethods.get("myUpdateMethod3")).intValue());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -