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

📄 beantest.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                type.writeSchema(schema);        assertValid("//xsd:complexType[@name='bean']/xsd:attribute[@name='howdy']", schema);        assertValid("//xsd:complexType[@name='bean']/xsd:sequence/xsd:element[@name='bleh']", schema);    }        public void testNillableInt()        throws Exception    {        BeanTypeInfo info = new BeanTypeInfo(IntBean.class, "urn:Bean");        info.setTypeMapping(mapping);                BeanType type = new BeanType(info);        type.setTypeClass(IntBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:Bean", "bean"));                Element types = new Element("types", "xsd", SoapConstants.XSD);        Element schema = new Element("schema", "xsd", SoapConstants.XSD);        types.addContent(schema);                Document doc = new Document(types);                type.writeSchema(schema);        assertValid("//xsd:complexType[@name='bean']/xsd:sequence/xsd:element[@name='int1'][@nillable='true'][@minOccurs='0']", schema);        assertValid("//xsd:complexType[@name='bean']/xsd:sequence/xsd:element[@name='int2'][@minOccurs='0']", schema);        assertInvalid("//xsd:complexType[@name='bean']/xsd:sequence/xsd:element[@name='int2'][@nillable='true']", schema);    }           public void testNillableIntMinOccurs1()        throws Exception    {        reg = new DefaultTypeMappingRegistry();                Configuration config = reg.getConfiguration();        config.setDefaultMinOccurs(1);        config.setDefaultNillable(false);        reg.createDefaultMappings();        mapping = reg.createTypeMapping(true);        BeanType type = (BeanType) mapping.getTypeCreator().createType(IntBean.class);        type.setTypeClass(IntBean.class);        type.setTypeMapping(mapping);                Element types = new Element("types", "xsd", SoapConstants.XSD);        Element schema = new Element("schema", "xsd", SoapConstants.XSD);        types.addContent(schema);                Document doc = new Document(types);                type.writeSchema(schema);        assertValid("//xsd:complexType[@name='IntBean']/xsd:sequence/xsd:element[@name='int1']", schema);        assertInvalid("//xsd:complexType[@name='IntBean']/xsd:sequence/xsd:element[@name='int1'][@minOccurs]", schema);        assertInvalid("//xsd:complexType[@name='IntBean']/xsd:sequence/xsd:element[@name='int1'][@nillable]", schema);    }       public void testNullNonNillableWithDate()        throws Exception    {        BeanTypeInfo info = new BeanTypeInfo(DateBean.class, "urn:Bean");        info.setTypeMapping(mapping);                BeanType type = new BeanType(info);        type.setTypeClass(DateBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:Bean", "bean"));            DateBean bean = new DateBean();                // Test writing        Element element = new Element("root", "b", "urn:Bean");        Document doc = new Document(element);        type.writeObject(bean, new JDOMWriter(element), new MessageContext());        // Make sure the date doesn't have an element. Its non nillable so it just        // shouldn't be there.        assertInvalid("/b:root/b:date", element);        assertValid("/b:root", element);    }    public void testExtendedBean()        throws Exception    {        BeanTypeInfo info = new BeanTypeInfo(ExtendedBean.class, "urn:Bean");        info.setTypeMapping(mapping);                BeanType type = new BeanType(info);        type.setTypeClass(ExtendedBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:Bean", "bean"));            PropertyDescriptor[] pds = info.getPropertyDescriptors();        assertEquals(2, pds.length);                ExtendedBean bean = new ExtendedBean();        bean.setHowdy("howdy");                Element element = new Element("root", "b", "urn:Bean");        new Document(element);        type.writeObject(bean, new JDOMWriter(element), new MessageContext());        assertValid("/b:root/b:howdy[text()='howdy']", element);           }        public void testByteBean()        throws Exception    {        BeanTypeInfo info = new BeanTypeInfo(ByteBean.class, "urn:Bean");        info.setTypeMapping(mapping);                BeanType type = new BeanType(info);        type.setTypeClass(ByteBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:Bean", "bean"));            QName name = new QName("urn:Bean", "data");        Type dataType = type.getTypeInfo().getType(name);        assertNotNull(dataType);                assertTrue( type.getTypeInfo().isNillable(name) );                ByteBean bean = new ByteBean();                // Test writing        Element element = new Element("root", "b", "urn:Bean");        Document doc = new Document(element);        type.writeObject(bean, new JDOMWriter(element), new MessageContext());            // Make sure the date doesn't have an element. Its non nillable so it just        // shouldn't be there.                addNamespace("xsi", SoapConstants.XSI_NS);        assertValid("/b:root/b:data[@xsi:nil='true']", element);        bean = (ByteBean) type.readObject(new JDOMReader(element), new MessageContext());        assertNotNull(bean);        assertNull(bean.getData());    }            public void testGetSetRequired() throws Exception    {        BeanType type = new BeanType();        type.setTypeClass(GoodBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:foo", "BadBean"));                assertTrue(type.getTypeInfo().getElements().hasNext());                type = new BeanType();        type.setTypeClass(BadBean.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:foo", "BadBean"));                assertFalse(type.getTypeInfo().getElements().hasNext());                type = new BeanType();        type.setTypeClass(BadBean2.class);        type.setTypeMapping(mapping);        type.setSchemaType(new QName("urn:foo", "BadBean2"));                assertFalse(type.getTypeInfo().getElements().hasNext());    }        public static class DateBean    {        private Date date;        public Date getDate()         {            return date;        }        public void setDate(Date date)         {            this.date = date;        }    }        public static class IntBean    {        private Integer int1;        private int int2;                public Integer getInt1()        {            return int1;        }        public void setInt1(Integer int1)        {            this.int1 = int1;        }        public int getInt2()        {            return int2;        }        public void setInt2(int int2)        {            this.int2 = int2;        }    }    public static class ByteBean    {        private byte[] data;        public byte[] getData()        {            return data;        }        public void setData(byte[] data)        {            this.data = data;        }    }    // This class only has a read property, no write    public static class GoodBean    {        private String string;        public String getString()        {            return string;        }    }        public static class BadBean    {        public String delete()        {            return null;        }    }        public static class BadBean2    {        public void setString(String string)        {        }    }        public static class ExtendedBean extends SimpleBean     {        private String howdy;        public String getHowdy()        {            return howdy;        }        public void setHowdy(String howdy)        {            this.howdy = howdy;        }    }}

⌨️ 快捷键说明

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