You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sa...@apache.org on 2012/07/07 05:43:19 UTC
svn commit: r1358494 - in /axis/axis2/java/core/trunk/modules/adb-codegen:
src/org/apache/axis2/schema/ src/org/apache/axis2/schema/template/
src/org/apache/axis2/schema/writer/ test-resources/testsuite/
test/org/apache/axis2/schema/restriction/
Author: sagara
Date: Sat Jul 7 03:43:19 2012
New Revision: 1358494
URL: http://svn.apache.org/viewvc?rev=1358494&view=rev
Log:
- Fixed AXIS2-5357.
- Added toString() method to BeanWriterMetaInfoHolder for debugging purpose.
- Changed ADBBeanTemplate to return more descriptive error messages when validation fails.
- added new test coverage for AXIS2-5357.
Added:
axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java (with props)
Modified:
axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl
axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/testsuite/restrictions.xsd
Modified: axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=1358494&r1=1358493&r2=1358494&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java (original)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java Sat Jul 7 03:43:19 2012
@@ -253,8 +253,14 @@ public class BeanWriterMetaInfoHolder {
*/
public boolean isRestrictionBaseType(QName restrictionBaseType) {
QName baseTypeQName = this.elementToSchemaQNameMap.get(restrictionBaseType);
- return (this.restrictionBaseType != null) && (baseTypeQName != null) &&
- this.restrictionBaseType.equals(baseTypeQName);
+ if (restriction && simple && baseTypeQName != null && restrictionBaseType != null) {
+ return true;
+ } else if (this.restrictionBaseType != null && baseTypeQName != null
+ && this.restrictionBaseType.equals(baseTypeQName)) {
+ return true;
+
+ }
+ return false;
}
/**
@@ -933,4 +939,34 @@ public class BeanWriterMetaInfoHolder {
return this.xmlNameJavaNameMap.get(xmlName);
}
+ public QName getRestrictionBaseType() {
+ return restrictionBaseType;
+ }
+
+ @Override
+ public String toString() {
+ return "BeanWriterMetaInfoHolder [anonymous=" + anonymous + ", choice=" + choice
+ + ", elementQNameToDefulatValueMap=" + elementQNameToDefulatValueMap
+ + ", elementToJavaClassMap=" + elementToJavaClassMap + ", elementToSchemaQNameMap="
+ + elementToSchemaQNameMap + ", enumFacet=" + enumFacet + ", extension=" + extension
+ + ", extensionBaseType=" + extensionBaseType + ", extensionClassName="
+ + extensionClassName + ", hasParticleType=" + hasParticleType + ", isList="
+ + isList + ", isParticleClass=" + isParticleClass + ", isUnion=" + isUnion
+ + ", itemTypeClassName=" + itemTypeClassName + ", itemTypeQName=" + itemTypeQName
+ + ", lengthFacet=" + lengthFacet + ", maxExclusiveFacet=" + maxExclusiveFacet
+ + ", maxInclusiveFacet=" + maxInclusiveFacet + ", maxLengthFacet=" + maxLengthFacet
+ + ", memberTypes=" + memberTypes + ", memberTypesKeys=" + memberTypesKeys
+ + ", minExclusiveFacet=" + minExclusiveFacet + ", minInclusiveFacet="
+ + minInclusiveFacet + ", minLengthFacet=" + minLengthFacet + ", nillableQNameList="
+ + nillableQNameList + ", ordered=" + ordered + ", ownClassName=" + ownClassName
+ + ", ownQname=" + ownQname + ", parent=" + parent + ", patternFacet="
+ + patternFacet + ", qNameMaxOccursCountMap=" + qNameMaxOccursCountMap
+ + ", qNameMinOccursCountMap=" + qNameMinOccursCountMap + ", qNameOrderMap="
+ + qNameOrderMap + ", restriction=" + restriction + ", restrictionBaseType="
+ + restrictionBaseType + ", restrictionClassName=" + restrictionClassName
+ + ", simple=" + simple + ", specialTypeFlagMap=" + specialTypeFlagMap
+ + ", totalDigitsFacet=" + totalDigitsFacet + ", xmlNameJavaNameMap="
+ + xmlNameJavaNameMap + "]";
+ }
+
}
Modified: axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=1358494&r1=1358493&r2=1358494&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Sat Jul 7 03:43:19 2012
@@ -1410,8 +1410,27 @@ public class SchemaCompiler {
}
} else if (content instanceof XmlSchemaSimpleContent) {
- throw new SchemaCompilationException(
- SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror", "Simple Content"));
+
+ XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent) content;
+ if (simpleContent.getContent() instanceof XmlSchemaSimpleContentExtension) {
+ XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) simpleContent
+ .getContent();
+ // recursively call the copyMetaInfoHierarchy
+ // method
+ copyMetaInfoHierarchy(baseMetaInfoHolder,
+ extension.getBaseTypeName(), resolvedSchema);
+
+ } else if (simpleContent.getContent() instanceof XmlSchemaSimpleContentRestriction) {
+
+ XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) simpleContent
+ .getContent();
+ // recursively call the copyMetaInfoHierarchy
+ // method
+ copyMetaInfoHierarchy(baseMetaInfoHolder,
+ restriction.getBaseTypeName(), resolvedSchema);
+
+ }
+
} else {
throw new SchemaCompilationException(
SchemaCompilerMessages.getMessage("schema.unknowncontenterror"));
@@ -1539,6 +1558,10 @@ public class SchemaCompiler {
metaInfHolder,
parentSchema);
metaInfHolder.setSimple(true);
+
+ if (!SchemaConstants.XSD_BOOLEAN.equals(restriction.getBaseTypeName())){
+ processFacets(restriction.getFacets(), restriction.getBaseTypeName(), metaInfHolder, parentSchema);
+ }
}
}
@@ -1653,12 +1676,12 @@ public class SchemaCompiler {
* Process Facets.
*
* @param metaInfHolder
+ * @param facets
*/
- private void processFacets(XmlSchemaSimpleTypeRestriction restriction,
+ private void processFacets( XmlSchemaObjectCollection facets,QName restrictionName,
BeanWriterMetaInfoHolder metaInfHolder,
XmlSchema parentSchema) {
-
- XmlSchemaObjectCollection facets = restriction.getFacets();
+
Iterator facetIterator = facets.getIterator();
while (facetIterator.hasNext()) {
@@ -1681,7 +1704,7 @@ public class SchemaCompiler {
else if (obj instanceof XmlSchemaEnumerationFacet) {
XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet) obj;
- if (restriction.getBaseTypeName().equals(SchemaConstants.XSD_QNAME)) {
+ if (restrictionName.equals(SchemaConstants.XSD_QNAME)) {
// we have to process the qname here and shoud find the local part and namespace uri
String value = enumeration.getValue().toString();
String prefix = value.substring(0, value.indexOf(":"));
@@ -2535,7 +2558,7 @@ public class SchemaCompiler {
processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(), metaInfHolder, parentSchema);
//process facets
if (!SchemaConstants.XSD_BOOLEAN.equals(baseTypeName)){
- processFacets(restriction, metaInfHolder, parentSchema);
+ processFacets(restriction.getFacets(), restriction.getBaseTypeName(), metaInfHolder, parentSchema);
}
} else {
//recurse
Modified: axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl?rev=1358494&r1=1358493&r2=1358494&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl (original)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl Sat Jul 7 03:43:19 2012
@@ -461,7 +461,7 @@
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:when>
<xsl:when test="(@patternFacet)">
@@ -469,7 +469,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:when>
<xsl:when test="(@lenFacet)">
@@ -477,7 +477,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"/>");
}
</xsl:when>
<xsl:when test="(@maxLenFacet) or (@minLenFacet)">
@@ -486,7 +486,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:when>
<xsl:when test="(@totalDigitsFacet)">
@@ -495,7 +495,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:when>
<xsl:when test="@maxExFacet or @minExFacet or @maxInFacet or @minInFacet">
@@ -504,7 +504,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:if>
<xsl:if test="@minExFacet">
@@ -512,7 +512,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:if>
<xsl:if test="@maxInFacet">
@@ -520,7 +520,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:if>
<xsl:if test="@minInFacet">
@@ -528,7 +528,7 @@
this.<xsl:value-of select="$varName"/>=param;
}
else {
- throw new java.lang.RuntimeException();
+ throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions");
}
</xsl:if>
</xsl:when>
Modified: axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=1358494&r1=1358493&r2=1358494&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java (original)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java Sat Jul 7 03:43:19 2012
@@ -691,10 +691,26 @@ public class JavaBeanWriter implements B
// we should add parent class details only if it is
// an extension or simple restriction
// should not in complex restrictions
- if (metainf.getParent() != null && (!metainf.isRestriction() || (metainf.isRestriction() && metainf.isSimple())))
- {
- populateInfo(metainf.getParent(), model, rootElt, propertyNames,
- typeMap, groupTypeMap, true);
+ if (metainf.getParent() != null
+ && (!metainf.isRestriction() || (metainf.isRestriction() && metainf.isSimple()))) {
+
+ BeanWriterMetaInfoHolder parent = metainf.getParent();
+
+ /**
+ * Before we recursively call populateInfo() with parent (base)
+ * BeanWriterMetaInfoHolder we need to apply restrictions on current
+ * BeanWriterMetaInfoHolder to parent BeanWriterMetaInfoHolder.
+ * Otherwise those restrictions not available on generated code. see
+ * Axis2-
+ *
+ * TODO - Here just copy restrictions to parent
+ * BeanWriterMetaInfoHolder object, but may be the correct way to do
+ * this is create a new BeanWriterMetaInfoHolder with merging
+ * current and parent BeanWriterMetaInfoHolders.Decide best approach
+ * ?
+ */
+ mergeBeanWriterMetaInfoHolderForRestriction(metainf, parent);
+ populateInfo(parent, model, rootElt, propertyNames, typeMap, groupTypeMap, true);
}
addPropertyEntries(metainf, model, rootElt, propertyNames, typeMap, groupTypeMap,
isInherited);
@@ -1535,5 +1551,53 @@ public class JavaBeanWriter implements B
}
return xmlName;
}
+
+ private void mergeBeanWriterMetaInfoHolderForRestriction(BeanWriterMetaInfoHolder metainf,
+ BeanWriterMetaInfoHolder parent) {
+ parent.setRestriction(true);
+ if (metainf.getPatternFacet() != null) {
+ parent.setPatternFacet(metainf.getPatternFacet());
+ }
+ if (metainf.getMaxExclusiveFacet() != null) {
+ parent.setMaxExclusiveFacet(metainf.getMaxExclusiveFacet());
+ }
+ if (metainf.getMinExclusiveFacet() != null) {
+ parent.setMinExclusiveFacet(metainf.getMinExclusiveFacet());
+ }
+ if (metainf.getMinInclusiveFacet() != null) {
+ parent.setMinInclusiveFacet(metainf.getMinInclusiveFacet());
+ }
+ if (metainf.getMaxInclusiveFacet() != null) {
+ parent.setMaxInclusiveFacet(metainf.getMaxInclusiveFacet());
+ }
+ if (metainf.getLengthFacet() != -1) {
+ parent.setLengthFacet(metainf.getLengthFacet());
+
+ }
+ if (metainf.getMaxLengthFacet() != -1) {
+ parent.setMaxLengthFacet(metainf.getMaxLengthFacet());
+
+ }
+ if (metainf.getMinLengthFacet() != -1) {
+ parent.setMinLengthFacet(metainf.getMinLengthFacet());
+
+ }
+
+ if (metainf.getTotalDigitsFacet() != null) {
+ parent.setTotalDigitsFacet(metainf.getTotalDigitsFacet());
+
+ }
+
+ if (metainf.getTotalDigitsFacet() != null) {
+ parent.setTotalDigitsFacet(metainf.getTotalDigitsFacet());
+
+ }
+
+ if (metainf.getEnumFacet() != null && metainf.getEnumFacet().size() > 0) {
+ parent.getEnumFacet().addAll(metainf.getEnumFacet());
+
+ }
+
+ }
}
\ No newline at end of file
Modified: axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/testsuite/restrictions.xsd
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/testsuite/restrictions.xsd?rev=1358494&r1=1358493&r2=1358494&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/testsuite/restrictions.xsd (original)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/test-resources/testsuite/restrictions.xsd Sat Jul 7 03:43:19 2012
@@ -213,4 +213,29 @@
<xsd:attribute name="responseMessage" type="xsd:string" use="optional"/>
</xsd:attributeGroup>
+ <xsd:element name="LimitedString" type="tns:limitedString" />
+ <xsd:complexType name="limitedString">
+ <xsd:simpleContent>
+ <xsd:restriction base="tns:rating">
+ <xsd:minLength value="2" />
+ <xsd:maxLength value="4" />
+ <xsd:pattern value="([a-d])*" />
+ </xsd:restriction>
+ </xsd:simpleContent>
+ </xsd:complexType>
+ <xsd:complexType name="rating">
+ <xsd:simpleContent>
+ <xsd:restriction base="tns:anyString">
+ <xsd:minLength value="2" />
+ <xsd:maxLength value="8" />
+ <xsd:pattern value="([a-z])*" />
+ </xsd:restriction>
+ </xsd:simpleContent>
+ </xsd:complexType>
+ <xsd:complexType name="anyString">
+ <xsd:simpleContent>
+ <xsd:extension base="xs:string" />
+ </xsd:simpleContent>
+ </xsd:complexType>
+
</xsd:schema>
\ No newline at end of file
Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java?rev=1358494&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java (added)
+++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java Sat Jul 7 03:43:19 2012
@@ -0,0 +1,213 @@
+/*
+ * 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.restriction;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+
+import junit.framework.TestCase;
+
+public class SchemaRestrictionTest extends TestCase {
+
+ public static String ERROR_MSG = "Input values do not follow defined XSD restrictions";
+
+ public void testLimitedStringGetOMElement() throws Exception {
+ LimitedString limitedString = new LimitedString();
+ limitedString.setString("ab");
+ OMElement omElement = limitedString.getOMElement(LimitedStringE.MY_QNAME,
+ OMAbstractFactory.getSOAP11Factory());
+ }
+
+ public void testLimitedStringGetOMElement2() throws Exception {
+ Rating rating = new Rating();
+ rating.setString("abc");
+ OMElement omElement = rating.getOMElement(LimitedStringE.MY_QNAME,
+ OMAbstractFactory.getSOAP11Factory());
+ }
+
+ public void testLimitedStringParse1() throws Exception {
+ LimitedString limitedString = new LimitedString();
+ limitedString.setString("ab");
+ OMElement omElement = limitedString.getOMElement(LimitedStringE.MY_QNAME,
+ OMAbstractFactory.getOMFactory());
+ LimitedString.Factory.parse(omElement.getXMLStreamReader());
+ }
+
+ public void testLimitedStringParse2() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "LimitedString"));
+ element.setText("a");
+ try {
+ LimitedStringE.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testLimitedStringParse3() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "LimitedString"));
+ element.setText("abcde");
+ try {
+ LimitedString.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testLimitedStringParse4() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "LimitedString"));
+ element.setText("abx");
+ try {
+ LimitedString.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testLimitedStringParse5() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "LimitedString"));
+ element.setText("");
+ try {
+ LimitedString.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testLimitedStringParse6() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "LimitedString"));
+ element.setText("ab34");
+ try {
+ LimitedString.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testRatingParse1() throws Exception {
+ Rating rating = new Rating();
+ rating.setString("ab");
+ OMElement omElement = rating.getOMElement(LimitedStringE.MY_QNAME,
+ OMAbstractFactory.getOMFactory());
+ LimitedString.Factory.parse(omElement.getXMLStreamReader());
+ }
+
+ public void testRatingParse2() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "Rating"));
+ element.setText("a");
+ try {
+ Rating.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testRatingParse3() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "Rating"));
+ element.setText("abcde$");
+ try {
+ Rating.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testRatingParse4() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "Rating"));
+ element.setText("ab45");
+ try {
+ Rating.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testRatingParse5() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "Rating"));
+ element.setText("");
+ try {
+ Rating.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ public void testRatingParse6() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName(
+ "http://apache.org/axis2/schema/restriction", "Rating"));
+ element.setText("ab34");
+ try {
+ Rating.Factory.parse(element.getXMLStreamReader());
+ fail("This should throw RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(toString(e), ERROR_MSG, e.getMessage());
+
+ }
+ }
+
+ private String toString(RuntimeException e) {
+ StringWriter stringWriter = new StringWriter();
+ e.printStackTrace(new PrintWriter(stringWriter));
+ return stringWriter.toString();
+ }
+
+}
Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java
------------------------------------------------------------------------------
svn:eol-style = native