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

📄 dynamicproxytest.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
字号:
package org.codehaus.xfire.aegis.type.basic;import javax.xml.namespace.QName;import org.codehaus.xfire.MessageContext;import org.codehaus.xfire.aegis.stax.ElementReader;import org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry;import org.codehaus.xfire.aegis.type.TypeMapping;import org.codehaus.xfire.aegis.type.TypeMappingRegistry;import org.codehaus.xfire.test.AbstractXFireTest;public class DynamicProxyTest    extends AbstractXFireTest{    TypeMapping mapping;    public void setUp()        throws Exception    {        super.setUp();        TypeMappingRegistry reg = new DefaultTypeMappingRegistry(true);        mapping = reg.createTypeMapping(true);    }    public interface IMyInterface    {        public String getName();        public void setName(String name);        public boolean isUseless();        public void setUseless(boolean useless);        public String getNameById(int id);        public void setNameNoParams();        public void doSomething();        public String get();        public Integer set();        public String getType();                public String getFOO();                public int getNonSpecifiedInt();    }    public interface IMyInterface2    {        public IMyInterface getMyInterface();    }    public void testDynamicProxy()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:MyInterface", "data"));        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface.xml"));        IMyInterface data = (IMyInterface) type.readObject(reader, new MessageContext());        assertEquals("junk", data.getName());        assertEquals(true, data.isUseless());        data.setName("bigjunk");        data.setUseless(false);        assertEquals("bigjunk", data.getName());        assertEquals(false, data.isUseless());        assertTrue(data.hashCode() != 0);        assertTrue(data.equals(data));        assertFalse(data.equals(null));        assertFalse(data.equals(new String("bigjunk")));        assertNotNull(data.toString());                assertEquals("foo", data.getFOO());                assertEquals(0, data.getNonSpecifiedInt());    }    public void testDynamicProxyNonStandardGetter()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:MyInterface", "data"));        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface.xml"));        IMyInterface data = (IMyInterface) type.readObject(reader, new MessageContext());        try        {            data.getNameById(0);            fail(IllegalAccessError.class + " should be thrown.");        }        catch (IllegalAccessError e)        {        }        try        {            data.get();            fail(IllegalAccessError.class + " should be thrown.");        }        catch (IllegalAccessError e)        {        }    }    public void testDynamicProxyNonStandardSetter()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:MyInterface", "data"));        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface.xml"));        IMyInterface data = (IMyInterface) type.readObject(reader, new MessageContext());        try        {            data.setNameNoParams();            fail(IllegalAccessError.class + " should be thrown.");        }        catch (IllegalAccessError e)        {        }        try        {            data.set();            fail(IllegalAccessError.class + " should be thrown.");        }        catch (IllegalAccessError e)        {        }    }    public void testDynamicProxyNonGetterSetter()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:MyInterface", "data"));        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface.xml"));        IMyInterface data = (IMyInterface) type.readObject(reader, new MessageContext());        try        {            data.doSomething();            fail(IllegalAccessError.class + " should be thrown.");        }        catch (IllegalAccessError e)        {        }    }    public void testDynamicProxyMissingAttribute()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:MyInterface", "data"));        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface.xml"));        IMyInterface data = (IMyInterface) type.readObject(reader, new MessageContext());        assertEquals("junk", data.getName());        assertNull(data.getType());    }    public void testDynamicProxyNested()        throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(IMyInterface.class);        type.setSchemaType(new QName("urn:MyInterface", "myInterface"));        type.setTypeMapping(mapping);        BeanType type2 = new BeanType();        type2.setTypeClass(IMyInterface2.class);        type2.setSchemaType(new QName("urn:MyInterface2", "myInterface2"));        type2.setTypeMapping(mapping);        type2.getTypeInfo().mapType(new QName("urn:MyInterface", "myInterface"), type);        ElementReader reader = new ElementReader(                getResourceAsStream("/org/codehaus/xfire/aegis/type/basic/MyInterface2.xml"));        IMyInterface2 data = (IMyInterface2) type2.readObject(reader, new MessageContext());        assertNotNull(data.getMyInterface());        assertEquals("junk", data.getMyInterface().getName());        assertEquals(true, data.getMyInterface().isUseless());    }}

⌨️ 快捷键说明

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