Author: sagara Date: Thu Jul 12 08:59:02 2012 New Revision: 1360587 URL: http://svn.apache.org/viewvc?rev=1360587&view=rev Log: Added more test coverage to test XSD element @default.
Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java (with props) Modified: axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/xsd/fixed_value.xsd Modified: axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/xsd/fixed_value.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/xsd/fixed_value.xsd?rev=1360587&r1=1360586&r2=1360587&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/xsd/fixed_value.xsd (original) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/xsd/fixed_value.xsd Thu Jul 12 08:59:02 2012 @@ -12,10 +12,17 @@ ~ under the License. --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="fixedStringElement" type="fixedString" /> + <xs:element name="defaultStringElement" type="defaultString" /> <xs:complexType name="fixedString"> <xs:sequence> <xs:element minOccurs="0" name="msg" fixed="ABC" type="xs:string" /> </xs:sequence> </xs:complexType> + <xs:complexType name="defaultString"> + <xs:sequence> + <xs:element minOccurs="0" name="msg" default="ABC" + type="xs:string" /> + </xs:sequence> + </xs:complexType> </xs:schema> \ No newline at end of file Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java?rev=1360587&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java (added) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java Thu Jul 12 08:59:02 2012 @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.schema.fix; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; + +import axis2.apache.org.DefaultString; +import axis2.apache.org.DefaultStringElement; +import axis2.apache.org.FixedStringElement; + +import junit.framework.TestCase; + +public class DefaultValueTest extends TestCase { + + public static String ERROR_MSG = "Input values do not follow defined XSD restrictions"; + + public void testDefaultStringElement1() throws Exception { + DefaultStringElement defaultElement = new DefaultStringElement(); + DefaultString defaultString = new DefaultString(); + defaultString.setMsg("XYZ"); + defaultElement.setDefaultStringElement(defaultString); + OMElement omElement = defaultElement.getOMElement(FixedStringElement.MY_QNAME, + OMAbstractFactory.getSOAP11Factory()); + } + + public void testDefaultStringElement2() throws Exception { + DefaultStringElement defaultElement = new DefaultStringElement(); + DefaultString defaultString = new DefaultString(); + defaultString.setMsg("XYZ"); + defaultElement.setDefaultStringElement(defaultString); + OMElement omElement = defaultElement.getOMElement(FixedStringElement.MY_QNAME, + OMAbstractFactory.getSOAP11Factory()); + } + + public void testDefaultStringElementParse1() throws Exception { + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement element = factory.createOMElement(new QName("", "defaultStringElement")); + OMElement msg = factory.createOMElement(new QName("", "msg")); + element.addChild(msg); + DefaultStringElement defaultStringElement = DefaultStringElement.Factory.parse(element + .getXMLStreamReader()); + assertNotNull(defaultStringElement.getDefaultStringElement().getMsg()); + assertEquals("", defaultStringElement.getDefaultStringElement().getMsg()); + } + + public void testDefaultStringElementParse2() throws Exception { + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement element = factory.createOMElement(new QName("", "defaultStringElement")); + OMElement msg = factory.createOMElement(new QName("", "msg")); + msg.setText("xyz"); + element.addChild(msg); + DefaultStringElement defaultStringElement = DefaultStringElement.Factory.parse(element + .getXMLStreamReader()); + System.out.println(defaultStringElement.getDefaultStringElement().getMsg()); + assertNotNull(defaultStringElement.getDefaultStringElement().getMsg()); + assertEquals("xyz", defaultStringElement.getDefaultStringElement().getMsg()); + + } + + public void testDefaultStringElementParse3() throws Exception { + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMElement element = factory.createOMElement(new QName("", "defaultStringElement")); + DefaultStringElement defaultStringElement = DefaultStringElement.Factory.parse(element + .getXMLStreamReader()); + assertNotNull(defaultStringElement.getDefaultStringElement().getMsg()); + assertEquals("ABC", defaultStringElement.getDefaultStringElement().getMsg()); + + } + +} \ No newline at end of file Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/fix/DefaultValueTest.java ------------------------------------------------------------------------------ svn:eol-style = native