change line endings
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1886772 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/compile/scomp/detailed/DetailedCompTests.java b/src/test/java/compile/scomp/detailed/DetailedCompTests.java
index 438aef7..82eea9a 100644
--- a/src/test/java/compile/scomp/detailed/DetailedCompTests.java
+++ b/src/test/java/compile/scomp/detailed/DetailedCompTests.java
@@ -1,282 +1,282 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 compile.scomp.detailed;
-
-import compile.scomp.common.CompileCommon;
-import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
-import org.junit.Test;
-
-import javax.xml.namespace.QName;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import static org.junit.Assert.*;
-
-
-public class DetailedCompTests {
- /**
- * This test requires laxDoc.xsd to be compiled and
- * on the classpath ahead of time, otherwise documentation
- * element processing would not occur
- * @throws Exception
- */
- @Test
- public void testLaxDocProcessing() throws Exception {
- QName q = new QName("urn:lax.Doc.Compilation", "ItemRequest");
- ArrayList err = new ArrayList();
- XmlOptions xm_opt = new XmlOptions().setErrorListener(err);
- xm_opt.setSavePrettyPrint();
-
- XmlObject xObj = XmlObject.Factory.parse(
- new File(CompileCommon.fileLocation+"/detailed/laxDoc.xsd"));
- XmlObject[] schemas = new XmlObject[]{xObj};
-
-
- // ensure exception is thrown when
- // xmloptions flag is not set
- boolean valDocEx = false;
- try{
- SchemaTypeSystem sts = XmlBeans.compileXmlBeans(null, null,
- schemas, null, XmlBeans.getBuiltinTypeSystem(), null, xm_opt);
- assertNotNull("STS was null", sts);
- }catch(XmlException xmlEx){
- valDocEx = true;
- System.err.println("Expected Error: "+xmlEx.getMessage());
- } catch(Exception e){
- throw e;
- }
-
- //check exception was thrown
- if(!valDocEx)
- throw new Exception("Documentation processing " +
- "should have thrown and error");
- // validate error code
- valDocEx = false;
- for (Iterator iterator = err.iterator(); iterator.hasNext();) {
- XmlError xErr = (XmlError)iterator.next();
- //System.out.println("ERROR: '"+ xErr+"'");
- //any one of these are possible
- if(xErr.getErrorCode().compareTo("cvc-complex-type.4") == 0 ||
- xErr.getErrorCode().compareTo("cvc-complex-type.2.3") == 0 ||
- xErr.getErrorCode().compareTo("cvc-complex-type.2.4c") == 0)
- valDocEx = true;
- }
-
- if (!valDocEx)
- throw new Exception("Expected Error code did not validate");
-
- //reset errors
- err.clear();
-
- //ensure no exception when error
- xm_opt = xm_opt.setCompileNoValidation();
- try {
- SchemaTypeSystem sts = XmlBeans.compileXmlBeans(null, null,
- schemas, null, XmlBeans.getBuiltinTypeSystem(), null,
- xm_opt);
-
- if(!err.isEmpty())
- throw new Exception("Error listener should be empty");
-
- for (Iterator iterator = err.iterator(); iterator.hasNext();) {
- System.out.println(iterator.next());
- }
-
- SchemaGlobalElement sge = sts.findElement(q);
- System.out.println("QName: " + sge.getName());
- System.out.println("Type: " + sge.getType());
-
-
- } catch (Exception e) {
- throw e;
- }
-
- }
-
- private static final String schema_begin = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n";
- private static final String root_decl = "<xs:element name=\"root\">\n <xs:complexType>\n";
- private static final String att_decl = " <xs:attribute name=\"att\" type=\"simpleNotType\"/>\n";
- private static final String root_end = " </xs:complexType>\n</xs:element>\n";
- private static final String schema_end = "</xs:schema>\n";
-
- private static final String notation1 = " <xs:attribute name=\"att\" type=\"xs:NOTATION\"/>\n";
- private static final String notation2 = "<xs:simpleType name=\"simpleNotType\">\n" +
- " <xs:restriction base=\"xs:NOTATION\">\n" +
- " <xs:pattern value=\"ns:.*\"/>\n" +
- " </xs:restriction>\n</xs:simpleType>\n";
- private static final String notation3 = " <xs:sequence>\n " +
- "<xs:element name=\"elem\" type=\"xs:ID\"/>\n" +
- " </xs:sequence>\n";
- private static final String notation4 = " targetNamespace=\"scomp.detailed.CompilationTests\" " +
- "xmlns=\"scomp.detailed.CompilationTests\">\n";
- private static final String simpleTypeDef= "<xs:simpleType name=\"simpleNotType\">\n" +
- " <xs:restriction base=\"enumDef\">\n";
- private static final String notation6 = " <xs:pattern value=\"ns:.*\"/>\n";
- private static final String notation5 = " <xs:length value=\"6\"/>\n";
- private static final String enumDef = " </xs:restriction>\n</xs:simpleType>\n" +
- "<xs:simpleType name=\"enumDef\">\n" +
- " <xs:restriction base=\"xs:NOTATION\" xmlns:ns=\"namespace.notation\">\n" +
- " <xs:enumeration value=\"ns:app1\"/>\n" +
- " <xs:enumeration value=\"ns:app2\"/>\n" +
- " </xs:restriction>\n</xs:simpleType>\n";
-
- private static final String doc_begin = "<root xmlns:ns=\"namespace.notation\" " +
- "xmlns:app=\"namespace.notation\" att=\"";
- private static final String doc_end = "\"/>";
- private static final String notation7 = "ns1:app1";
- private static final String notation8 = "ns:app";
- private static final String notation9 = "app:app1";
- private static final String notation10 = "ns:app1";
-
- /**
- * This tests usage of the xs:NOTATION type
- */
- @Test
- public void testNotation() throws Exception
- {
- String schema;
- String xml;
- SchemaTypeSystem typeSystem;
- XmlObject[] parsedSchema = new XmlObject[1];
- XmlObject parsedDoc;
- XmlOptions opts = new XmlOptions();
- ArrayList errors = new ArrayList();
- opts.setErrorListener(errors);
- opts.setCompilePartialTypesystem();
-
- // 1. Negative test - Error if xs:NOTATION used directly
- schema = schema_begin + root_decl + notation1 + root_end + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected error: NOTATION type cannot be used directly", errors.size() == 1);
- assertEquals("Expected error: NOTATION type cannot be used directly",
- XmlErrorCodes.ATTR_NOTATION_TYPE_FORBIDDEN, ((XmlError)errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
-
- // 2. Negative test - Error if xs:NOTATION restricted without enumeration
- schema = schema_begin + root_decl + att_decl + root_end + notation2 + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected error: restriction of NOTATION must use enumeration facet", errors.size() == 1);
- assertEquals("Expected error: restriction of NOTATION must use enumeration facet",
- XmlErrorCodes.DATATYPE_ENUM_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
-
- // 3. Warning if xs:NOTATION used as type of an element
- final String correctTypes = simpleTypeDef + notation6 + enumDef;
- schema = schema_begin + root_decl + notation3 + root_end + correctTypes + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected warning: NOTATION-derived type should not be used on elements", errors.size() == 1);
- assertEquals("Expected warning: NOTATION-derived type should not be used on elements",
- XmlErrorCodes.ELEM_COMPATIBILITY_TYPE, ((XmlError)errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
-
- // 4. Warning if xs:NOTATION is used in a Schema with target namespace
- schema = schema_begin.substring(0, schema_begin.length() - 2) + notation4 + root_decl +
- att_decl + root_end + correctTypes + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace", errors.size() == 1);
- assertEquals("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace",
- XmlErrorCodes.ATTR_COMPATIBILITY_TARGETNS, ((XmlError)errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
-
- // 5. Warning - Deprecation of minLength, maxLength and length facets
- schema = schema_begin + root_decl + att_decl + root_end + simpleTypeDef + notation5 +
- enumDef + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected warning: length facet cannot be used on a type derived from NOTATION", errors.size() == 1);
- assertEquals("Expected warning: length facet cannot be used on a type derived from NOTATION",
- XmlErrorCodes.FACETS_DEPRECATED_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
-
- // 6. Positive test - Test restriction via enumeration, then same as 2
- schema = schema_begin + root_decl + att_decl + root_end + correctTypes + schema_end;
-// System.out.println(schema);
- parsedSchema[0] = SchemaDocument.Factory.parse(schema);
- errors.clear();
- typeSystem = XmlBeans.compileXsd(parsedSchema, null, opts);
- assertTrue("Expected no errors or warnings", errors.size() == 0);
- SchemaType docType = typeSystem.findDocumentType(new QName("", "root"));
- SchemaType type = docType.getElementProperty(new QName("", "root")).getType().
- getAttributeProperty(new QName("", "att")).getType();
- assertEquals(type.getPrimitiveType().getBuiltinTypeCode(), SchemaType.BTC_NOTATION);
-
- SchemaTypeLoader loader = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] {typeSystem,
- XmlBeans.getBuiltinTypeSystem()});
-
- // 7. Validation negative - Test error if QName has bad prefix
- xml = doc_begin + notation7 + doc_end;
- parsedDoc = loader.parse(xml, null, opts);
- assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
- errors.clear();
- parsedDoc.validate(opts);
- // Both "prefix not found" and "pattern doesn't match" errors
- assertTrue("Expected validation errors", errors.size() == 2);
- // Unfortunately, can't get the error code because it is logged via an intermediate exception
- assertTrue("Expected prefix not found error", ((XmlError) errors.get(0)).getMessage().
- indexOf("Invalid QName") >= 0);
- assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
-// System.out.println(xml);
-
- // 8. Validation negative - Test error if QName has correct prefix but not in enumeration
- xml = doc_begin + notation8 + doc_end;
- parsedDoc = loader.parse(xml, null, opts);
- assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
- errors.clear();
- parsedDoc.validate(opts);
- assertTrue("Expected validation errors", errors.size() == 1);
- assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_ENUM_VALID,
- ((XmlError) errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
-// System.out.println(xml);
-
- // 9. Validation negative - Test error if QName doesn't match the extra facet
- xml = doc_begin + notation9 + doc_end;
- parsedDoc = loader.parse(xml, null, opts);
- assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
- errors.clear();
- parsedDoc.validate(opts);
- assertTrue("Expected validation errors", errors.size() == 1);
- assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
- ((XmlError) errors.get(0)).getErrorCode());
- assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
-// System.out.println(xml);
-
- // 10. Validation positive - Test that validation can be performed correctly
- xml = doc_begin + notation10 + doc_end;
- parsedDoc = loader.parse(xml, null, opts);
- assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
- errors.clear();
- parsedDoc.validate(opts);
- assertTrue("Expected no validation errors", errors.size() == 0);
-// System.out.println(xml);
- }
-}
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 compile.scomp.detailed;
+
+import compile.scomp.common.CompileCommon;
+import org.apache.xmlbeans.*;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import static org.junit.Assert.*;
+
+
+public class DetailedCompTests {
+ /**
+ * This test requires laxDoc.xsd to be compiled and
+ * on the classpath ahead of time, otherwise documentation
+ * element processing would not occur
+ * @throws Exception
+ */
+ @Test
+ public void testLaxDocProcessing() throws Exception {
+ QName q = new QName("urn:lax.Doc.Compilation", "ItemRequest");
+ ArrayList err = new ArrayList();
+ XmlOptions xm_opt = new XmlOptions().setErrorListener(err);
+ xm_opt.setSavePrettyPrint();
+
+ XmlObject xObj = XmlObject.Factory.parse(
+ new File(CompileCommon.fileLocation+"/detailed/laxDoc.xsd"));
+ XmlObject[] schemas = new XmlObject[]{xObj};
+
+
+ // ensure exception is thrown when
+ // xmloptions flag is not set
+ boolean valDocEx = false;
+ try{
+ SchemaTypeSystem sts = XmlBeans.compileXmlBeans(null, null,
+ schemas, null, XmlBeans.getBuiltinTypeSystem(), null, xm_opt);
+ assertNotNull("STS was null", sts);
+ }catch(XmlException xmlEx){
+ valDocEx = true;
+ System.err.println("Expected Error: "+xmlEx.getMessage());
+ } catch(Exception e){
+ throw e;
+ }
+
+ //check exception was thrown
+ if(!valDocEx)
+ throw new Exception("Documentation processing " +
+ "should have thrown and error");
+ // validate error code
+ valDocEx = false;
+ for (Iterator iterator = err.iterator(); iterator.hasNext();) {
+ XmlError xErr = (XmlError)iterator.next();
+ //System.out.println("ERROR: '"+ xErr+"'");
+ //any one of these are possible
+ if(xErr.getErrorCode().compareTo("cvc-complex-type.4") == 0 ||
+ xErr.getErrorCode().compareTo("cvc-complex-type.2.3") == 0 ||
+ xErr.getErrorCode().compareTo("cvc-complex-type.2.4c") == 0)
+ valDocEx = true;
+ }
+
+ if (!valDocEx)
+ throw new Exception("Expected Error code did not validate");
+
+ //reset errors
+ err.clear();
+
+ //ensure no exception when error
+ xm_opt = xm_opt.setCompileNoValidation();
+ try {
+ SchemaTypeSystem sts = XmlBeans.compileXmlBeans(null, null,
+ schemas, null, XmlBeans.getBuiltinTypeSystem(), null,
+ xm_opt);
+
+ if(!err.isEmpty())
+ throw new Exception("Error listener should be empty");
+
+ for (Iterator iterator = err.iterator(); iterator.hasNext();) {
+ System.out.println(iterator.next());
+ }
+
+ SchemaGlobalElement sge = sts.findElement(q);
+ System.out.println("QName: " + sge.getName());
+ System.out.println("Type: " + sge.getType());
+
+
+ } catch (Exception e) {
+ throw e;
+ }
+
+ }
+
+ private static final String schema_begin = "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n";
+ private static final String root_decl = "<xs:element name=\"root\">\n <xs:complexType>\n";
+ private static final String att_decl = " <xs:attribute name=\"att\" type=\"simpleNotType\"/>\n";
+ private static final String root_end = " </xs:complexType>\n</xs:element>\n";
+ private static final String schema_end = "</xs:schema>\n";
+
+ private static final String notation1 = " <xs:attribute name=\"att\" type=\"xs:NOTATION\"/>\n";
+ private static final String notation2 = "<xs:simpleType name=\"simpleNotType\">\n" +
+ " <xs:restriction base=\"xs:NOTATION\">\n" +
+ " <xs:pattern value=\"ns:.*\"/>\n" +
+ " </xs:restriction>\n</xs:simpleType>\n";
+ private static final String notation3 = " <xs:sequence>\n " +
+ "<xs:element name=\"elem\" type=\"xs:ID\"/>\n" +
+ " </xs:sequence>\n";
+ private static final String notation4 = " targetNamespace=\"scomp.detailed.CompilationTests\" " +
+ "xmlns=\"scomp.detailed.CompilationTests\">\n";
+ private static final String simpleTypeDef= "<xs:simpleType name=\"simpleNotType\">\n" +
+ " <xs:restriction base=\"enumDef\">\n";
+ private static final String notation6 = " <xs:pattern value=\"ns:.*\"/>\n";
+ private static final String notation5 = " <xs:length value=\"6\"/>\n";
+ private static final String enumDef = " </xs:restriction>\n</xs:simpleType>\n" +
+ "<xs:simpleType name=\"enumDef\">\n" +
+ " <xs:restriction base=\"xs:NOTATION\" xmlns:ns=\"namespace.notation\">\n" +
+ " <xs:enumeration value=\"ns:app1\"/>\n" +
+ " <xs:enumeration value=\"ns:app2\"/>\n" +
+ " </xs:restriction>\n</xs:simpleType>\n";
+
+ private static final String doc_begin = "<root xmlns:ns=\"namespace.notation\" " +
+ "xmlns:app=\"namespace.notation\" att=\"";
+ private static final String doc_end = "\"/>";
+ private static final String notation7 = "ns1:app1";
+ private static final String notation8 = "ns:app";
+ private static final String notation9 = "app:app1";
+ private static final String notation10 = "ns:app1";
+
+ /**
+ * This tests usage of the xs:NOTATION type
+ */
+ @Test
+ public void testNotation() throws Exception
+ {
+ String schema;
+ String xml;
+ SchemaTypeSystem typeSystem;
+ XmlObject[] parsedSchema = new XmlObject[1];
+ XmlObject parsedDoc;
+ XmlOptions opts = new XmlOptions();
+ ArrayList errors = new ArrayList();
+ opts.setErrorListener(errors);
+ opts.setCompilePartialTypesystem();
+
+ // 1. Negative test - Error if xs:NOTATION used directly
+ schema = schema_begin + root_decl + notation1 + root_end + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected error: NOTATION type cannot be used directly", errors.size() == 1);
+ assertEquals("Expected error: NOTATION type cannot be used directly",
+ XmlErrorCodes.ATTR_NOTATION_TYPE_FORBIDDEN, ((XmlError)errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
+
+ // 2. Negative test - Error if xs:NOTATION restricted without enumeration
+ schema = schema_begin + root_decl + att_decl + root_end + notation2 + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected error: restriction of NOTATION must use enumeration facet", errors.size() == 1);
+ assertEquals("Expected error: restriction of NOTATION must use enumeration facet",
+ XmlErrorCodes.DATATYPE_ENUM_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_ERROR, ((XmlError)errors.get(0)).getSeverity());
+
+ // 3. Warning if xs:NOTATION used as type of an element
+ final String correctTypes = simpleTypeDef + notation6 + enumDef;
+ schema = schema_begin + root_decl + notation3 + root_end + correctTypes + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected warning: NOTATION-derived type should not be used on elements", errors.size() == 1);
+ assertEquals("Expected warning: NOTATION-derived type should not be used on elements",
+ XmlErrorCodes.ELEM_COMPATIBILITY_TYPE, ((XmlError)errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+ // 4. Warning if xs:NOTATION is used in a Schema with target namespace
+ schema = schema_begin.substring(0, schema_begin.length() - 2) + notation4 + root_decl +
+ att_decl + root_end + correctTypes + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace", errors.size() == 1);
+ assertEquals("Expected warning: NOTATION-derived type should not be used in a Schema with target namespace",
+ XmlErrorCodes.ATTR_COMPATIBILITY_TARGETNS, ((XmlError)errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+ // 5. Warning - Deprecation of minLength, maxLength and length facets
+ schema = schema_begin + root_decl + att_decl + root_end + simpleTypeDef + notation5 +
+ enumDef + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected warning: length facet cannot be used on a type derived from NOTATION", errors.size() == 1);
+ assertEquals("Expected warning: length facet cannot be used on a type derived from NOTATION",
+ XmlErrorCodes.FACETS_DEPRECATED_NOTATION, ((XmlError)errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_WARNING, ((XmlError)errors.get(0)).getSeverity());
+
+ // 6. Positive test - Test restriction via enumeration, then same as 2
+ schema = schema_begin + root_decl + att_decl + root_end + correctTypes + schema_end;
+// System.out.println(schema);
+ parsedSchema[0] = SchemaDocument.Factory.parse(schema);
+ errors.clear();
+ typeSystem = XmlBeans.compileXsd(parsedSchema, null, opts);
+ assertTrue("Expected no errors or warnings", errors.size() == 0);
+ SchemaType docType = typeSystem.findDocumentType(new QName("", "root"));
+ SchemaType type = docType.getElementProperty(new QName("", "root")).getType().
+ getAttributeProperty(new QName("", "att")).getType();
+ assertEquals(type.getPrimitiveType().getBuiltinTypeCode(), SchemaType.BTC_NOTATION);
+
+ SchemaTypeLoader loader = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] {typeSystem,
+ XmlBeans.getBuiltinTypeSystem()});
+
+ // 7. Validation negative - Test error if QName has bad prefix
+ xml = doc_begin + notation7 + doc_end;
+ parsedDoc = loader.parse(xml, null, opts);
+ assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+ errors.clear();
+ parsedDoc.validate(opts);
+ // Both "prefix not found" and "pattern doesn't match" errors
+ assertTrue("Expected validation errors", errors.size() == 2);
+ // Unfortunately, can't get the error code because it is logged via an intermediate exception
+ assertTrue("Expected prefix not found error", ((XmlError) errors.get(0)).getMessage().
+ indexOf("Invalid QName") >= 0);
+ assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+// System.out.println(xml);
+
+ // 8. Validation negative - Test error if QName has correct prefix but not in enumeration
+ xml = doc_begin + notation8 + doc_end;
+ parsedDoc = loader.parse(xml, null, opts);
+ assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+ errors.clear();
+ parsedDoc.validate(opts);
+ assertTrue("Expected validation errors", errors.size() == 1);
+ assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_ENUM_VALID,
+ ((XmlError) errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+// System.out.println(xml);
+
+ // 9. Validation negative - Test error if QName doesn't match the extra facet
+ xml = doc_begin + notation9 + doc_end;
+ parsedDoc = loader.parse(xml, null, opts);
+ assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+ errors.clear();
+ parsedDoc.validate(opts);
+ assertTrue("Expected validation errors", errors.size() == 1);
+ assertEquals("Expected prefix not found error", XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
+ ((XmlError) errors.get(0)).getErrorCode());
+ assertEquals(XmlError.SEVERITY_ERROR, ((XmlError) errors.get(0)).getSeverity());
+// System.out.println(xml);
+
+ // 10. Validation positive - Test that validation can be performed correctly
+ xml = doc_begin + notation10 + doc_end;
+ parsedDoc = loader.parse(xml, null, opts);
+ assertEquals("Did not find the root element in the Schema", docType, parsedDoc.schemaType());
+ errors.clear();
+ parsedDoc.validate(opts);
+ assertTrue("Expected no validation errors", errors.size() == 0);
+// System.out.println(xml);
+ }
+}
diff --git a/src/test/java/compile/scomp/detailed/SchemaCompilerTests.java b/src/test/java/compile/scomp/detailed/SchemaCompilerTests.java
index b39a389..a20fe75 100644
--- a/src/test/java/compile/scomp/detailed/SchemaCompilerTests.java
+++ b/src/test/java/compile/scomp/detailed/SchemaCompilerTests.java
@@ -1,176 +1,176 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 compile.scomp.detailed;
-
-import common.Common;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.fail;
-
-/**
- * This class contains tests that need to invoke the SchemaCompiler class which is
- * equivalent to using scomp from the command line and capture errors
- *
- * The tests need to be run with cmd line param that points to the test case root directory and xmlbeans root
- * ex: -Dcases.location=D:\svnnew\xmlbeans\trunk\test\cases -Dxbean.rootdir=D:\svnnew\xmlbeans\trunk
- */
-public class SchemaCompilerTests extends Common
-{
- public static String scompTestFilesRoot = XBEAN_CASE_ROOT + P + "compile" + P + "scomp" + P + "schemacompiler" + P;
- public static String schemaCompOutputDirPath = OUTPUTROOT + P + "compile" + P + "scomp" + P;
-
- private void _testCompile(File[] xsdFiles,
- String outputDirName,
- String testName)
- {
- List errors = new ArrayList();
- Parameters params = new Parameters();
- params.setXsdFiles(xsdFiles);
- params.setErrorListener(errors);
- params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
- params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors))
- {
- fail(testName + "(): failure when executing scomp");
- }
- }
-
- @Test
- public void testUnionRedefine()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "union_initial.xsd"),
- new File(scompTestFilesRoot + "union_redefine.xsd") };
- String outputDirName = "unionred";
- String testname = "testUnionRedefine";
- _testCompile(xsdFiles, outputDirName, testname);
- }
-
- /** This tests a bug where compilation of a schema redefining a type
- involving an enumeration fails.
- */
- @Test
- public void testEnumerationRedefine1()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "enum1.xsd_"),
- new File(scompTestFilesRoot + "enum1_redefine.xsd_") };
- String outputDirName = "enumRedef1";
- String testname = "testEnumerationRedefine1";
- _testCompile(xsdFiles, outputDirName, testname);
- }
-
- /** This tests a bug where compilation of a schema redefining a type
- involving an enumeration fails.
- */
- @Test
- public void testEnumerationRedefine2()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "enum2.xsd_"),
- new File(scompTestFilesRoot + "enum2_redefine.xsd_") };
- String outputDirName = "enumRedef2";
- String testname = "testEnumerationRedefine2";
- _testCompile(xsdFiles, outputDirName, testname);
- }
-
- /** This tests a bug where compilation of a schema redefining a type
- involving an enumeration fails.
- */
- @Test
- public void testEnumerationRedefine3()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "enum1.xsd_"),
- new File(scompTestFilesRoot + "enum3.xsd_"),
- new File(scompTestFilesRoot + "enum3_redefine.xsd_") };
- String outputDirName = "enumRedef3";
- String testname = "testEnumerationRedefine3";
- _testCompile(xsdFiles, outputDirName, testname);
- }
-
- /**
- * [XMLBEANS-205]:
- * using static handlers for extension interfaces with same method names
- */
- @Test
- public void testExtensionHandlerMethodNameCollision()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsd_") };
- File[] configFiles =
- new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsdconfig_") };
- File[] javaFiles =
- new File[] { new File(scompTestFilesRoot + "ext" + P + "I1.java"),
- new File(scompTestFilesRoot + "ext" + P + "H1.java"),
- new File(scompTestFilesRoot + "ext" + P + "I2.java"),
- new File(scompTestFilesRoot + "ext" + P + "H2.java")};
- String outputDirName = "methodsColide_jira205";
-
- List errors = new ArrayList();
- Parameters params = new Parameters();
- params.setXsdFiles(xsdFiles);
- params.setConfigFiles(configFiles);
- params.setJavaFiles(javaFiles);
- params.setErrorListener(errors);
- params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
- params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors))
- {
- fail("testExtensionHandlerMethodNameCollision(): failure when executing scomp");
- }
- }
-
- /**
- * [XMLBEANS-278]:
- * -noext flag for compilation
- */
- @Test
- public void testNoExt()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsd_") };
- File[] configFiles =
- new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsdconfig_") };
- String outputDirName = "noExt";
-
- List errors = new ArrayList();
- Parameters params = new Parameters();
- params.setXsdFiles(xsdFiles);
- params.setConfigFiles(configFiles);
- // no java files, if noExt flag doesn't work should fail for not finding the java files params.setJavaFiles(javaFiles);
- params.setErrorListener(errors);
- params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
- params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
-
- // no extensions
- params.setNoExt(true);
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors))
- {
- fail("testNoExt(): failure when executing scomp");
- }
- }
-}
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 compile.scomp.detailed;
+
+import common.Common;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.fail;
+
+/**
+ * This class contains tests that need to invoke the SchemaCompiler class which is
+ * equivalent to using scomp from the command line and capture errors
+ *
+ * The tests need to be run with cmd line param that points to the test case root directory and xmlbeans root
+ * ex: -Dcases.location=D:\svnnew\xmlbeans\trunk\test\cases -Dxbean.rootdir=D:\svnnew\xmlbeans\trunk
+ */
+public class SchemaCompilerTests extends Common
+{
+ public static String scompTestFilesRoot = XBEAN_CASE_ROOT + P + "compile" + P + "scomp" + P + "schemacompiler" + P;
+ public static String schemaCompOutputDirPath = OUTPUTROOT + P + "compile" + P + "scomp" + P;
+
+ private void _testCompile(File[] xsdFiles,
+ String outputDirName,
+ String testName)
+ {
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+ params.setXsdFiles(xsdFiles);
+ params.setErrorListener(errors);
+ params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
+ params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors))
+ {
+ fail(testName + "(): failure when executing scomp");
+ }
+ }
+
+ @Test
+ public void testUnionRedefine()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "union_initial.xsd"),
+ new File(scompTestFilesRoot + "union_redefine.xsd") };
+ String outputDirName = "unionred";
+ String testname = "testUnionRedefine";
+ _testCompile(xsdFiles, outputDirName, testname);
+ }
+
+ /** This tests a bug where compilation of a schema redefining a type
+ involving an enumeration fails.
+ */
+ @Test
+ public void testEnumerationRedefine1()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "enum1.xsd_"),
+ new File(scompTestFilesRoot + "enum1_redefine.xsd_") };
+ String outputDirName = "enumRedef1";
+ String testname = "testEnumerationRedefine1";
+ _testCompile(xsdFiles, outputDirName, testname);
+ }
+
+ /** This tests a bug where compilation of a schema redefining a type
+ involving an enumeration fails.
+ */
+ @Test
+ public void testEnumerationRedefine2()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "enum2.xsd_"),
+ new File(scompTestFilesRoot + "enum2_redefine.xsd_") };
+ String outputDirName = "enumRedef2";
+ String testname = "testEnumerationRedefine2";
+ _testCompile(xsdFiles, outputDirName, testname);
+ }
+
+ /** This tests a bug where compilation of a schema redefining a type
+ involving an enumeration fails.
+ */
+ @Test
+ public void testEnumerationRedefine3()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "enum1.xsd_"),
+ new File(scompTestFilesRoot + "enum3.xsd_"),
+ new File(scompTestFilesRoot + "enum3_redefine.xsd_") };
+ String outputDirName = "enumRedef3";
+ String testname = "testEnumerationRedefine3";
+ _testCompile(xsdFiles, outputDirName, testname);
+ }
+
+ /**
+ * [XMLBEANS-205]:
+ * using static handlers for extension interfaces with same method names
+ */
+ @Test
+ public void testExtensionHandlerMethodNameCollision()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsd_") };
+ File[] configFiles =
+ new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsdconfig_") };
+ File[] javaFiles =
+ new File[] { new File(scompTestFilesRoot + "ext" + P + "I1.java"),
+ new File(scompTestFilesRoot + "ext" + P + "H1.java"),
+ new File(scompTestFilesRoot + "ext" + P + "I2.java"),
+ new File(scompTestFilesRoot + "ext" + P + "H2.java")};
+ String outputDirName = "methodsColide_jira205";
+
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+ params.setXsdFiles(xsdFiles);
+ params.setConfigFiles(configFiles);
+ params.setJavaFiles(javaFiles);
+ params.setErrorListener(errors);
+ params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
+ params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors))
+ {
+ fail("testExtensionHandlerMethodNameCollision(): failure when executing scomp");
+ }
+ }
+
+ /**
+ * [XMLBEANS-278]:
+ * -noext flag for compilation
+ */
+ @Test
+ public void testNoExt()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsd_") };
+ File[] configFiles =
+ new File[] { new File(scompTestFilesRoot + "methodsColide_jira205_278.xsdconfig_") };
+ String outputDirName = "noExt";
+
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+ params.setXsdFiles(xsdFiles);
+ params.setConfigFiles(configFiles);
+ // no java files, if noExt flag doesn't work should fail for not finding the java files params.setJavaFiles(javaFiles);
+ params.setErrorListener(errors);
+ params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
+ params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
+
+ // no extensions
+ params.setNoExt(true);
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors))
+ {
+ fail("testNoExt(): failure when executing scomp");
+ }
+ }
+}
diff --git a/src/test/java/compile/scomp/detailed/XmlBeanCompilationTests.java b/src/test/java/compile/scomp/detailed/XmlBeanCompilationTests.java
index 48ab1f8..14c33f5 100644
--- a/src/test/java/compile/scomp/detailed/XmlBeanCompilationTests.java
+++ b/src/test/java/compile/scomp/detailed/XmlBeanCompilationTests.java
@@ -1,310 +1,310 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 compile.scomp.detailed;
-
-import compile.scomp.common.CompileTestBase;
-import compile.scomp.common.mockobj.TestBindingConfig;
-import compile.scomp.common.mockobj.TestFiler;
-import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
-import org.junit.After;
-import org.junit.Test;
-
-import javax.xml.namespace.QName;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * Ensure that several compilation mechanisms all generate
- * the same schematypesystem
- */
-public class XmlBeanCompilationTests extends CompileTestBase {
- private final List<XmlError> xm_errors = new ArrayList<>();
- private final XmlOptions xm_opts = new XmlOptions();
-
- public XmlBeanCompilationTests() {
- xm_opts.setErrorListener(xm_errors);
- xm_opts.setSavePrettyPrint();
- }
-
- @After
- public void tearDown() throws Exception {
- if (xm_errors.size() > 0) {
- xm_errors.clear();
- }
- }
-
- /**
- * Filer != null for BindingConfig to be used
- */
- @Test
- public void test_bindingconfig_extension_compilation() throws Exception {
- TestFiler f = new TestFiler();
- //initialize all of the values
- String extCaseDir = XBEAN_CASE_ROOT + P + "extensions" + P;
- String extSrcDir = getRootFile() + P +
- "src" + P + "test" + P + "java" + P + "xmlobject" + P + "extensions" + P;
- File[] cPath = CompileTestBase.getClassPath();
- String dir = extCaseDir + P + "interfaceFeature" + P + "averageCase";
- String dir2 = extCaseDir + P + "prePostFeature" + P +
- "ValueRestriction";
-
- ConfigDocument.Config bConf = ConfigDocument.Factory.parse(
- new File(dir + P + "po.xsdconfig"))
- .getConfig();
- ConfigDocument.Config cConf = ConfigDocument.Factory.parse(
- new File(dir2 + P + "company.xsdconfig"))
- .getConfig();
-
- String simpleConfig = "<xb:config " +
- "xmlns:xb=\"http://xml.apache.org/xmlbeans/2004/02/xbean/config\"\n" +
- " xmlns:ep=\"http://xbean.interface_feature/averageCase/PurchaseOrder\">\n" +
- "<xb:namespace uri=\"http://xbean.interface_feature/averageCase/PurchaseOrder\">\n" +
- "<xb:package>com.easypo</xb:package>\n" +
- "</xb:namespace></xb:config>";
- ConfigDocument.Config confDoc = ConfigDocument.Factory.parse(simpleConfig).getConfig();
- ConfigDocument.Config[] confs = new ConfigDocument.Config[]{bConf, confDoc, cConf};
-
- String fooHandlerPath = extSrcDir + P + "interfaceFeature" + P +
- "averageCase" + P + "existing" + P + "FooHandler.java";
- String iFooPath = extSrcDir + P + "interfaceFeature" + P +
- "averageCase" + P + "existing" + P + "IFoo.java";
- String iSetterPath = extSrcDir + P + "prePostFeature" + P +
- "ValueRestriction" + P + "existing" + P + "ISetter.java";
- String setterHandlerPath = extSrcDir + P + "prePostFeature" + P +
- "ValueRestriction" + P + "existing" + P + "SetterHandler.java";
-
-
- File[] fList = new File[]{new File(fooHandlerPath), new File(iFooPath),
- new File(iSetterPath),
- new File(setterHandlerPath)};
-
- //use created BindingConfig
- TestBindingConfig bind = new TestBindingConfig(confs, fList, cPath);
-
- //set XSDs
- XmlObject obj1 = XmlObject.Factory.parse(new File(dir + P + "po.xsd"));
- XmlObject obj2 = XmlObject.Factory.parse(
- new File(dir2 + P + "company.xsd"));
- XmlObject[] schemas = new XmlObject[]{obj1, obj2};
-
- //filer must be present on this method
- SchemaTypeSystem apiSts = XmlBeans.compileXmlBeans("apiCompile", null,
- schemas, bind, XmlBeans.getBuiltinTypeSystem(), f, xm_opts);
-
- if (!bind.isIslookupPrefixForNamespace()) {
- throw new Exception("isIslookupPrefixForNamespace not invoked");
- }
- if (!bind.isIslookupPackageForNamespace()) {
- throw new Exception("isIslookupPackageForNamespace not invoked");
- }
- if (!bind.isIslookupSuffixForNamespace()) {
- throw new Exception("isIslookupSuffixForNamespace not invoked");
- }
- if (!bind.isIslookupJavanameForQName()) {
- throw new Exception("isIslookupJavanameForQName not invoked");
- }
- if (!bind.isIsgetInterfaceExtensionsString()) {
- throw new Exception("isIsgetInterfaceExtensionsString not invoked");
- }
- if (!bind.isIsgetInterfaceExtensions()) {
- throw new Exception("isIsgetInterfaceExtensions not invoked");
- }
- if (!bind.isIsgetPrePostExtensions()) {
- throw new Exception("isIsgetPrePostExtensions not invoked");
- }
- if (!bind.isIsgetPrePostExtensionsString()) {
- throw new Exception("isIsgetPrePostExtensionsString not invoked");
- }
- }
-
- /**
- * Verify basic incremental compilation
- * and compilation with partial SOM usages
- */
- @Test
- public void test_incrCompile() throws Exception {
- XmlObject obj1 = XmlObject.Factory.parse(forXsd);
- obj1.documentProperties().setSourceName("OBJ1");
- XmlObject[] schemas = new XmlObject[]{obj1};
- QName sts1 = new QName("http://baz", "elName");
-
- XmlObject obj2 = XmlObject.Factory.parse(incrXsd);
- obj2.documentProperties().setSourceName("OBJ2");
- XmlObject[] schemas2 = new XmlObject[]{obj2};
- QName sts2 = new QName("http://bar", "elName");
-
- XmlObject obj3 = XmlObject.Factory.parse(errXsd);
- obj3.documentProperties().setSourceName("OBJ3");
- XmlObject[] schemas3 = new XmlObject[]{obj3};
- QName sts3 = new QName("http://bar", "elErrName");
-
- SchemaTypeSystem sts;
- ArrayList err = new ArrayList();
- XmlOptions opt = new XmlOptions().setErrorListener(err);
- opt.setCompilePartialTypesystem();
-
- //BASIC COMPILATION
- sts = XmlBeans.compileXmlBeans(null,
- null, schemas, null,
- XmlBeans.getBuiltinTypeSystem(), null, opt);
-
- assertTrue("Errors should have been empty", err.isEmpty());
- // find element in the type System
- if (!findGlobalElement(sts.globalElements(), sts1)) {
- throw new Exception(
- "Could Not find Type from first Type System: " + sts1);
- }
-
- //SIMPLE INCR COMPILATION
- sts = XmlBeans.compileXmlBeans(null,
- sts, schemas2, null,
- XmlBeans.getBuiltinTypeSystem(), null, opt);
- assertTrue("Errors should have been empty", err.isEmpty());
- // find element in the type System
-
- if (!findGlobalElement(sts.globalElements(), sts1)) {
- throw new Exception("Could Not find Type from first Type System: " +
- sts1);
- }
-
- if (!findGlobalElement(sts.globalElements(), sts2)) {
- throw new Exception("Could Not find Type from 2nd Type System: " +
- sts2);
- }
-
- System.out.println("Building over Existing");
- //BUILDING OFF BASE SIMPLE INCR COMPILATION
- sts = XmlBeans.compileXmlBeans(null,
- sts, schemas2, null,
- sts, null, opt);
- assertTrue("Errors should have been empty", err.isEmpty());
- // find element in the type System
-
- if (!findGlobalElement(sts.globalElements(), sts1)) {
- throw new Exception("Could Not find Type from first Type System: " +
- sts1);
- }
-
- if (!findGlobalElement(sts.globalElements(), sts2)) {
- throw new Exception("Could Not find Type from 2nd Type System: " +
- sts2);
- }
-
- //INCR COMPILATION WITH RECOVERABLE ERROR
- err.clear();
- SchemaTypeSystem b = XmlBeans.compileXmlBeans(null,
- sts, schemas3, null,
- XmlBeans.getBuiltinTypeSystem(), null, opt);
- // find element in the type System
- if (!findGlobalElement(b.globalElements(), sts1)) {
- throw new Exception("Could Not find Type from first Type System: " +
- sts1);
- }
-
- if (!findGlobalElement(b.globalElements(), sts2)) {
- throw new Exception("Could Not find Type from 2nd Type System: " +
- sts2);
- }
-
- if (!findGlobalElement(b.globalElements(), sts3)) {
- throw new Exception("Could Not find Type from 3rd Type System: " +
- sts3);
- }
-
- printSTS(b);
-
- //INSPECT ERRORS
- boolean psom_expError = false;
- // print out the recovered xm_errors
- if (!err.isEmpty()) {
- System.out.println(
- "Schema invalid: partial schema type system recovered");
- for (Iterator i = err.iterator(); i.hasNext(); ) {
- XmlError xErr = (XmlError) i.next();
- System.out.println(xErr);
- //compare to the expected xm_errors
- if ((xErr.getErrorCode().compareTo("src-resolve") == 0) &&
- (xErr.getMessage().compareTo(
- "type 'bType@http://baz' not found.") ==
- 0)) {
- psom_expError = true;
- }
- }
- }
- if (!psom_expError) {
- throw new Exception("Error Code was not as Expected");
- }
-
-
- }
-
-/*
- @Test
- public void test_diff_compilationMethods() throws IOException,
- XmlException, Exception {
-
-
- //initialize the schema compiler
- SchemaCompiler.Parameters params = new SchemaCompiler.Parameters();
- params.setXsdFiles(new File[]{scompFile});
- params.setSrcDir(scompDirFile);
- params.setClassesDir(scompDirFile);
-
- //save out schema for use in scomp later
- XmlObject obj1 = XmlObject.Factory.parse(forXsd);
- obj1.save(scompFile);
-
- //scomp saved out schema
- SchemaCompiler.compile(params);
-
- //use new api to get typesystem
- XmlObject[] schemas = new XmlObject[]{obj1};
- SchemaTypeSystem apiSts = XmlBeans.compileXmlBeans("apiCompile", null,
- schemas, null, XmlBeans.getBuiltinTypeSystem(), null, xm_opts);
-
- //use alternative api to get typesystem
- SchemaTypeSystem altSts = XmlBeans.compileXsd(schemas,
- XmlBeans.getBuiltinTypeSystem(), null);
-
- //save out sts for diff later
- SchemaCodeGenerator.saveTypeSystem(apiSts, apiDirFile, null, null,
- null);
- SchemaCodeGenerator.saveTypeSystem(altSts, baseDirFile, null, null,
- null);
-
- //diff new api to old api
- xm_errors = null;
- xm_errors = new ArrayList();
- Diff.dirsAsTypeSystems(apiDirFile, baseDirFile, xm_errors);
- if (xm_errors.size() >= 1)
- throw new Exception("API STS ERRORS: " + xm_errors.toString());
-
- //diff scomp sts to new api
- xm_errors = null;
- xm_errors = new ArrayList();
- Diff.dirsAsTypeSystems(apiDirFile, scompDirFile, xm_errors);
- if (xm_errors.size() >= 1)
- throw new Exception("API SCOMP ERRORS: " + xm_errors.toString());
- }
-*/
-
-}
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 compile.scomp.detailed;
+
+import compile.scomp.common.CompileTestBase;
+import compile.scomp.common.mockobj.TestBindingConfig;
+import compile.scomp.common.mockobj.TestFiler;
+import org.apache.xmlbeans.*;
+import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
+import org.junit.After;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Ensure that several compilation mechanisms all generate
+ * the same schematypesystem
+ */
+public class XmlBeanCompilationTests extends CompileTestBase {
+ private final List<XmlError> xm_errors = new ArrayList<>();
+ private final XmlOptions xm_opts = new XmlOptions();
+
+ public XmlBeanCompilationTests() {
+ xm_opts.setErrorListener(xm_errors);
+ xm_opts.setSavePrettyPrint();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (xm_errors.size() > 0) {
+ xm_errors.clear();
+ }
+ }
+
+ /**
+ * Filer != null for BindingConfig to be used
+ */
+ @Test
+ public void test_bindingconfig_extension_compilation() throws Exception {
+ TestFiler f = new TestFiler();
+ //initialize all of the values
+ String extCaseDir = XBEAN_CASE_ROOT + P + "extensions" + P;
+ String extSrcDir = getRootFile() + P +
+ "src" + P + "test" + P + "java" + P + "xmlobject" + P + "extensions" + P;
+ File[] cPath = CompileTestBase.getClassPath();
+ String dir = extCaseDir + P + "interfaceFeature" + P + "averageCase";
+ String dir2 = extCaseDir + P + "prePostFeature" + P +
+ "ValueRestriction";
+
+ ConfigDocument.Config bConf = ConfigDocument.Factory.parse(
+ new File(dir + P + "po.xsdconfig"))
+ .getConfig();
+ ConfigDocument.Config cConf = ConfigDocument.Factory.parse(
+ new File(dir2 + P + "company.xsdconfig"))
+ .getConfig();
+
+ String simpleConfig = "<xb:config " +
+ "xmlns:xb=\"http://xml.apache.org/xmlbeans/2004/02/xbean/config\"\n" +
+ " xmlns:ep=\"http://xbean.interface_feature/averageCase/PurchaseOrder\">\n" +
+ "<xb:namespace uri=\"http://xbean.interface_feature/averageCase/PurchaseOrder\">\n" +
+ "<xb:package>com.easypo</xb:package>\n" +
+ "</xb:namespace></xb:config>";
+ ConfigDocument.Config confDoc = ConfigDocument.Factory.parse(simpleConfig).getConfig();
+ ConfigDocument.Config[] confs = new ConfigDocument.Config[]{bConf, confDoc, cConf};
+
+ String fooHandlerPath = extSrcDir + P + "interfaceFeature" + P +
+ "averageCase" + P + "existing" + P + "FooHandler.java";
+ String iFooPath = extSrcDir + P + "interfaceFeature" + P +
+ "averageCase" + P + "existing" + P + "IFoo.java";
+ String iSetterPath = extSrcDir + P + "prePostFeature" + P +
+ "ValueRestriction" + P + "existing" + P + "ISetter.java";
+ String setterHandlerPath = extSrcDir + P + "prePostFeature" + P +
+ "ValueRestriction" + P + "existing" + P + "SetterHandler.java";
+
+
+ File[] fList = new File[]{new File(fooHandlerPath), new File(iFooPath),
+ new File(iSetterPath),
+ new File(setterHandlerPath)};
+
+ //use created BindingConfig
+ TestBindingConfig bind = new TestBindingConfig(confs, fList, cPath);
+
+ //set XSDs
+ XmlObject obj1 = XmlObject.Factory.parse(new File(dir + P + "po.xsd"));
+ XmlObject obj2 = XmlObject.Factory.parse(
+ new File(dir2 + P + "company.xsd"));
+ XmlObject[] schemas = new XmlObject[]{obj1, obj2};
+
+ //filer must be present on this method
+ SchemaTypeSystem apiSts = XmlBeans.compileXmlBeans("apiCompile", null,
+ schemas, bind, XmlBeans.getBuiltinTypeSystem(), f, xm_opts);
+
+ if (!bind.isIslookupPrefixForNamespace()) {
+ throw new Exception("isIslookupPrefixForNamespace not invoked");
+ }
+ if (!bind.isIslookupPackageForNamespace()) {
+ throw new Exception("isIslookupPackageForNamespace not invoked");
+ }
+ if (!bind.isIslookupSuffixForNamespace()) {
+ throw new Exception("isIslookupSuffixForNamespace not invoked");
+ }
+ if (!bind.isIslookupJavanameForQName()) {
+ throw new Exception("isIslookupJavanameForQName not invoked");
+ }
+ if (!bind.isIsgetInterfaceExtensionsString()) {
+ throw new Exception("isIsgetInterfaceExtensionsString not invoked");
+ }
+ if (!bind.isIsgetInterfaceExtensions()) {
+ throw new Exception("isIsgetInterfaceExtensions not invoked");
+ }
+ if (!bind.isIsgetPrePostExtensions()) {
+ throw new Exception("isIsgetPrePostExtensions not invoked");
+ }
+ if (!bind.isIsgetPrePostExtensionsString()) {
+ throw new Exception("isIsgetPrePostExtensionsString not invoked");
+ }
+ }
+
+ /**
+ * Verify basic incremental compilation
+ * and compilation with partial SOM usages
+ */
+ @Test
+ public void test_incrCompile() throws Exception {
+ XmlObject obj1 = XmlObject.Factory.parse(forXsd);
+ obj1.documentProperties().setSourceName("OBJ1");
+ XmlObject[] schemas = new XmlObject[]{obj1};
+ QName sts1 = new QName("http://baz", "elName");
+
+ XmlObject obj2 = XmlObject.Factory.parse(incrXsd);
+ obj2.documentProperties().setSourceName("OBJ2");
+ XmlObject[] schemas2 = new XmlObject[]{obj2};
+ QName sts2 = new QName("http://bar", "elName");
+
+ XmlObject obj3 = XmlObject.Factory.parse(errXsd);
+ obj3.documentProperties().setSourceName("OBJ3");
+ XmlObject[] schemas3 = new XmlObject[]{obj3};
+ QName sts3 = new QName("http://bar", "elErrName");
+
+ SchemaTypeSystem sts;
+ ArrayList err = new ArrayList();
+ XmlOptions opt = new XmlOptions().setErrorListener(err);
+ opt.setCompilePartialTypesystem();
+
+ //BASIC COMPILATION
+ sts = XmlBeans.compileXmlBeans(null,
+ null, schemas, null,
+ XmlBeans.getBuiltinTypeSystem(), null, opt);
+
+ assertTrue("Errors should have been empty", err.isEmpty());
+ // find element in the type System
+ if (!findGlobalElement(sts.globalElements(), sts1)) {
+ throw new Exception(
+ "Could Not find Type from first Type System: " + sts1);
+ }
+
+ //SIMPLE INCR COMPILATION
+ sts = XmlBeans.compileXmlBeans(null,
+ sts, schemas2, null,
+ XmlBeans.getBuiltinTypeSystem(), null, opt);
+ assertTrue("Errors should have been empty", err.isEmpty());
+ // find element in the type System
+
+ if (!findGlobalElement(sts.globalElements(), sts1)) {
+ throw new Exception("Could Not find Type from first Type System: " +
+ sts1);
+ }
+
+ if (!findGlobalElement(sts.globalElements(), sts2)) {
+ throw new Exception("Could Not find Type from 2nd Type System: " +
+ sts2);
+ }
+
+ System.out.println("Building over Existing");
+ //BUILDING OFF BASE SIMPLE INCR COMPILATION
+ sts = XmlBeans.compileXmlBeans(null,
+ sts, schemas2, null,
+ sts, null, opt);
+ assertTrue("Errors should have been empty", err.isEmpty());
+ // find element in the type System
+
+ if (!findGlobalElement(sts.globalElements(), sts1)) {
+ throw new Exception("Could Not find Type from first Type System: " +
+ sts1);
+ }
+
+ if (!findGlobalElement(sts.globalElements(), sts2)) {
+ throw new Exception("Could Not find Type from 2nd Type System: " +
+ sts2);
+ }
+
+ //INCR COMPILATION WITH RECOVERABLE ERROR
+ err.clear();
+ SchemaTypeSystem b = XmlBeans.compileXmlBeans(null,
+ sts, schemas3, null,
+ XmlBeans.getBuiltinTypeSystem(), null, opt);
+ // find element in the type System
+ if (!findGlobalElement(b.globalElements(), sts1)) {
+ throw new Exception("Could Not find Type from first Type System: " +
+ sts1);
+ }
+
+ if (!findGlobalElement(b.globalElements(), sts2)) {
+ throw new Exception("Could Not find Type from 2nd Type System: " +
+ sts2);
+ }
+
+ if (!findGlobalElement(b.globalElements(), sts3)) {
+ throw new Exception("Could Not find Type from 3rd Type System: " +
+ sts3);
+ }
+
+ printSTS(b);
+
+ //INSPECT ERRORS
+ boolean psom_expError = false;
+ // print out the recovered xm_errors
+ if (!err.isEmpty()) {
+ System.out.println(
+ "Schema invalid: partial schema type system recovered");
+ for (Iterator i = err.iterator(); i.hasNext(); ) {
+ XmlError xErr = (XmlError) i.next();
+ System.out.println(xErr);
+ //compare to the expected xm_errors
+ if ((xErr.getErrorCode().compareTo("src-resolve") == 0) &&
+ (xErr.getMessage().compareTo(
+ "type 'bType@http://baz' not found.") ==
+ 0)) {
+ psom_expError = true;
+ }
+ }
+ }
+ if (!psom_expError) {
+ throw new Exception("Error Code was not as Expected");
+ }
+
+
+ }
+
+/*
+ @Test
+ public void test_diff_compilationMethods() throws IOException,
+ XmlException, Exception {
+
+
+ //initialize the schema compiler
+ SchemaCompiler.Parameters params = new SchemaCompiler.Parameters();
+ params.setXsdFiles(new File[]{scompFile});
+ params.setSrcDir(scompDirFile);
+ params.setClassesDir(scompDirFile);
+
+ //save out schema for use in scomp later
+ XmlObject obj1 = XmlObject.Factory.parse(forXsd);
+ obj1.save(scompFile);
+
+ //scomp saved out schema
+ SchemaCompiler.compile(params);
+
+ //use new api to get typesystem
+ XmlObject[] schemas = new XmlObject[]{obj1};
+ SchemaTypeSystem apiSts = XmlBeans.compileXmlBeans("apiCompile", null,
+ schemas, null, XmlBeans.getBuiltinTypeSystem(), null, xm_opts);
+
+ //use alternative api to get typesystem
+ SchemaTypeSystem altSts = XmlBeans.compileXsd(schemas,
+ XmlBeans.getBuiltinTypeSystem(), null);
+
+ //save out sts for diff later
+ SchemaCodeGenerator.saveTypeSystem(apiSts, apiDirFile, null, null,
+ null);
+ SchemaCodeGenerator.saveTypeSystem(altSts, baseDirFile, null, null,
+ null);
+
+ //diff new api to old api
+ xm_errors = null;
+ xm_errors = new ArrayList();
+ Diff.dirsAsTypeSystems(apiDirFile, baseDirFile, xm_errors);
+ if (xm_errors.size() >= 1)
+ throw new Exception("API STS ERRORS: " + xm_errors.toString());
+
+ //diff scomp sts to new api
+ xm_errors = null;
+ xm_errors = new ArrayList();
+ Diff.dirsAsTypeSystems(apiDirFile, scompDirFile, xm_errors);
+ if (xm_errors.size() >= 1)
+ throw new Exception("API SCOMP ERRORS: " + xm_errors.toString());
+ }
+*/
+
+}
diff --git a/src/test/java/misc/detailed/JiraRegression151_200Test.java b/src/test/java/misc/detailed/JiraRegression151_200Test.java
index fe546fc..4d673d8 100644
--- a/src/test/java/misc/detailed/JiraRegression151_200Test.java
+++ b/src/test/java/misc/detailed/JiraRegression151_200Test.java
@@ -1,129 +1,129 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import misc.common.JiraTestBase;
-import net.eads.space.scoexml.test.TestExponentDocument;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.junit.Test;
-
-import java.io.File;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class JiraRegression151_200Test extends JiraTestBase
-{
-
- /**
- * [XMLBEANS-175] Validation of decimal in exponential representation fails
- * @throws Exception
- */
- @Test
- public void test_jira_xmlbeans175() throws Exception{
-
- TestExponentDocument.TestExponent exponent = TestExponentDocument.TestExponent.Factory.newInstance();
- exponent.setDecimal(new BigDecimal("1E1"));
-
- ArrayList errors = new ArrayList();
- XmlOptions validationOptions = new XmlOptions();
- validationOptions.setErrorListener(errors);
- exponent.validate(validationOptions);
-
- for (Iterator iterator = errors.iterator(); iterator.hasNext();) {
- System.out.println("Validation Error:" + iterator.next());
- }
-
- // fails, IMHO should not!
- assertEquals(0, errors.size());
- /* note: the following uses JDK 1.5 API, not supported in 1.4
- // workaround
- exponent.setDecimal(new BigDecimal(new BigDecimal("1E1").toPlainString()));
- errors.removeAll(errors);
- exponent.validate(validationOptions);
- assertEquals(0, errors.size());
- */
- }
-
- /**
- * [XMLBEANS-179] Saving xml with '&' and '<' characters in attribute values throws an ArrayIndexOutOfBoundsException
- */
- @Test
- public void test_jira_xmlbeans179() throws Exception{
- String xmlWithIssues = "<Net id=\"dbid:66754220\" name=\"3<.3V\" type=\"POWER\"/>";
-
- XmlObject xobj = XmlObject.Factory.parse(xmlWithIssues);
- File outFile = new File(schemaCompOutputDirPath + P + "jira_xmlbeans179.xml");
- assertNotNull(outFile);
-
- if(outFile.exists())
- outFile.delete();
-
- xobj.save(outFile);
- }
-
- /*
- * [XMLBEANS-184]: NPE when running scomp without nopvr option
- */
- @Test
- public void test_jira_xmlbeans184() throws Exception {
- List errors = new ArrayList();
-
- // compile with nopvr, goes thro fine
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_184_vdx_data_V1.04.xsd_")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
- params.setNoPvr(true);
-
- try {
- SchemaCompiler.compile(params);
- } catch (NullPointerException npe) {
- npe.printStackTrace();
- fail("NPE when executing scomp");
- }
-
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans184() : Errors found when executing scomp");
- }
-
- // now compile without the pvr option and NPE is thrown
- params.setNoPvr(false);
- try {
- SchemaCompiler.compile(params);
- } catch (NullPointerException npe) {
- npe.printStackTrace();
- fail("NPE when executing scomp");
- }
-
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans184() : Errors found when executing scomp ");
- }
-
- }
-
-
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import misc.common.JiraTestBase;
+import net.eads.space.scoexml.test.TestExponentDocument;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.junit.Test;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class JiraRegression151_200Test extends JiraTestBase
+{
+
+ /**
+ * [XMLBEANS-175] Validation of decimal in exponential representation fails
+ * @throws Exception
+ */
+ @Test
+ public void test_jira_xmlbeans175() throws Exception{
+
+ TestExponentDocument.TestExponent exponent = TestExponentDocument.TestExponent.Factory.newInstance();
+ exponent.setDecimal(new BigDecimal("1E1"));
+
+ ArrayList errors = new ArrayList();
+ XmlOptions validationOptions = new XmlOptions();
+ validationOptions.setErrorListener(errors);
+ exponent.validate(validationOptions);
+
+ for (Iterator iterator = errors.iterator(); iterator.hasNext();) {
+ System.out.println("Validation Error:" + iterator.next());
+ }
+
+ // fails, IMHO should not!
+ assertEquals(0, errors.size());
+ /* note: the following uses JDK 1.5 API, not supported in 1.4
+ // workaround
+ exponent.setDecimal(new BigDecimal(new BigDecimal("1E1").toPlainString()));
+ errors.removeAll(errors);
+ exponent.validate(validationOptions);
+ assertEquals(0, errors.size());
+ */
+ }
+
+ /**
+ * [XMLBEANS-179] Saving xml with '&' and '<' characters in attribute values throws an ArrayIndexOutOfBoundsException
+ */
+ @Test
+ public void test_jira_xmlbeans179() throws Exception{
+ String xmlWithIssues = "<Net id=\"dbid:66754220\" name=\"3<.3V\" type=\"POWER\"/>";
+
+ XmlObject xobj = XmlObject.Factory.parse(xmlWithIssues);
+ File outFile = new File(schemaCompOutputDirPath + P + "jira_xmlbeans179.xml");
+ assertNotNull(outFile);
+
+ if(outFile.exists())
+ outFile.delete();
+
+ xobj.save(outFile);
+ }
+
+ /*
+ * [XMLBEANS-184]: NPE when running scomp without nopvr option
+ */
+ @Test
+ public void test_jira_xmlbeans184() throws Exception {
+ List errors = new ArrayList();
+
+ // compile with nopvr, goes thro fine
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_184_vdx_data_V1.04.xsd_")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+ params.setNoPvr(true);
+
+ try {
+ SchemaCompiler.compile(params);
+ } catch (NullPointerException npe) {
+ npe.printStackTrace();
+ fail("NPE when executing scomp");
+ }
+
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans184() : Errors found when executing scomp");
+ }
+
+ // now compile without the pvr option and NPE is thrown
+ params.setNoPvr(false);
+ try {
+ SchemaCompiler.compile(params);
+ } catch (NullPointerException npe) {
+ npe.printStackTrace();
+ fail("NPE when executing scomp");
+ }
+
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans184() : Errors found when executing scomp ");
+ }
+
+ }
+
+
+}
diff --git a/src/test/java/misc/detailed/JiraRegression1_50Test.java b/src/test/java/misc/detailed/JiraRegression1_50Test.java
index 2e16997..2df896a 100644
--- a/src/test/java/misc/detailed/JiraRegression1_50Test.java
+++ b/src/test/java/misc/detailed/JiraRegression1_50Test.java
@@ -1,549 +1,549 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import misc.common.JiraTestBase;
-import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import xmlbeans48.FeedInfoType;
-
-import javax.xml.namespace.QName;
-import java.io.*;
-import java.util.*;
-
-import static org.junit.Assert.*;
-
-public class JiraRegression1_50Test extends JiraTestBase {
-
- /*
- * [XMLBEANS-2] Problem with XmlError.forObject(String,int,XmlObject)
- */
- @Test
- public void test_jira_xmlbeans02() throws Exception {
- StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
- xmlstringbuf.append("<test>");
- xmlstringbuf.append("<testchild attr=\"abcd\"> Jira02 </testchild>");
- xmlstringbuf.append("</test>");
-
- XmlObject myxmlobj = null;
- List errors = new ArrayList();
- XmlOptions options = new XmlOptions().setErrorListener(errors);
- try {
- myxmlobj = XmlObject.Factory.parse(xmlstringbuf.toString(), options);
- XmlCursor cur = myxmlobj.newCursor();
- XmlError xmlerr = XmlError.forObject("This is my custom error message", XmlError.SEVERITY_ERROR, myxmlobj);
-
- // call an API on the cursor : verification of cursor not being disposed
- System.out.println("Cursor Text Value: " + cur.getTextValue());
-
- } catch (XmlException xme) {
- if (!xme.getErrors().isEmpty()) {
- for (Iterator itr = xme.getErrors().iterator(); itr.hasNext();) {
- System.out.println("Parse Errors :" + itr.next());
- }
- }
-
- } catch (NullPointerException npe) {
- fail("test_jira_xmlbeans02() : Null Pointer Exception thrown !");
- }
-
- printOptionErrMsgs(errors);
- }
-
- /*
- * [XMLBEANS-4] xs:decimal size greater than 18 results in uncompilable java code
- */
- @Test
- public void test_jira_xmlbeans04() {
- List errors = new ArrayList();
-
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_04.xsd_")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans04() : Errors found when executing scomp");
- }
- }
-
-
-
- /*
- * [XMLBEANS-9] Null Pointer Exception when running validate from cmd line
- */
- @Test
- @Ignore("no shell tests on junit")
- public void test_jira_xmlbeans09() throws Exception {
- // Exec validate script from cmd line - Refer xmlbeans_09.xsd, xmlbeans_09.xml
-
- StringBuilder sb = new StringBuilder(" ");
- sb.append(System.getProperty("xbean.rootdir") + P + "bin" + P + "validate.cmd ");
- sb.append(scompTestFilesRoot + "xmlbeans_09.xsd_" + " " + scompTestFilesRoot + "xmlbeans_09.xml");
- Process validator_proc = null;
- try {
- validator_proc = Runtime.getRuntime().exec(sb.toString());
- } catch (NullPointerException npe) {
- fail("test_jira_xmlbeans09() : Null Pointer Exception when running validate for schema");
- }
-
- System.out.println("cmd:" + sb);
- BufferedInputStream inbuf = new BufferedInputStream(validator_proc.getInputStream());
- BufferedReader reader = new BufferedReader(new InputStreamReader(inbuf));
- String eachline = reader.readLine();
- try {
-
- while (reader.readLine() != null) {
- System.out.println("output: " + eachline);
- }
- } catch (IOException ioe) {
- ioe.getMessage();
- ioe.printStackTrace();
- }
-
- }
-
- /*
- * [XMLBEANS-11]: Calling getUnionMemberTypes() on SchemaType for non-union types results in NullPointerException
- * status : fixed
- */
- @Test
- public void test_jira_xmlbeans11() throws Exception {
-
- StringBuilder xsdAsString = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
- xsdAsString.append(" <!-- W3C Schema generated by XML Spy v4.3 U (http://www.xmlspy.com)\n");
- xsdAsString.append(" --> \n");
- xsdAsString.append(" <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">\n");
- xsdAsString.append(" <xs:simpleType name=\"restrictsString\">\n");
- xsdAsString.append(" <xs:restriction base=\"xs:string\">\n");
- xsdAsString.append(" <xs:length value=\"10\" /> \n");
- xsdAsString.append(" </xs:restriction>\n");
- xsdAsString.append(" </xs:simpleType>\n");
- xsdAsString.append(" </xs:schema>");
-
- // load schema file as SchemaDocument XmlObject
- SchemaDocument sd = SchemaDocument.Factory.parse(xsdAsString.toString());
-
- // compile loaded XmlObject
- SchemaTypeSystem sts = XmlBeans.compileXsd((XmlObject[]) Collections.singletonList(sd).toArray(new XmlObject[]{}),
- XmlBeans.getContextTypeLoader(),
- new XmlOptions());
- sts.resolve();
-
- SchemaType[] st = sts.globalTypes();
-
- System.out.println("NUMBER OF GLOBAL TYPES: " + st.length);
-
- try {
- for (int i = 0; i < st.length; i++)
- // check if it is union type
- {
- System.out.println("IS UNION TYPE: " + (st[i].getUnionMemberTypes() != null));
- }
- } catch (NullPointerException npe) {
- fail("test_jira_xmlbeans11(): Null Pointer Exception thrown !");
- }
-
- }
-
- /*
- * [XMLBEANS-14]: newDomNode() throws NullPointerException
- */
- @Test
- public void test_jira_xmlbeans14() throws Exception {
- XmlObject xObj = XmlObject.Factory.parse("<Baz/>");
- // add element
- XmlCursor xCursor = xObj.newCursor();
- xCursor.toFirstContentToken();
- xCursor.insertElementWithText(new QName("Some uri", "SomeName"), "SomeValue");
- xCursor.insertElementWithText(new QName("Some uri", "SomeName1"), "SomeValue1");
- xCursor.dispose();
-
- // debug
- xObj.save(System.out);
-
- // throws npe in v1
- try {
- xObj.newDomNode();
- } catch (NullPointerException npe) {
- fail("test_jira_xmlbeans14() : Null Pointer Exception when create Dom Node");
- }
-
- }
-
-
- /*
- * [XMLBEANS-16]: newDomNode creates a DOM with empty strings for namespace URIs for unprefixed
- * attributes (rather than null)
- * status : fails with crimson and not with Xerces
- */
- @Test
- @Ignore("still happens with current xerces 2.11")
- public void test_jira_xmlbeans16() throws Exception {
- StringBuilder sb = new StringBuilder(100);
- sb.append("<?xml version='1.0'?>\n");
- sb.append("<test noprefix='nonamespace' \n");
- sb.append(" ns:prefix='namespace' \n");
- sb.append(" xmlns:ns='http://xml.apache.org/xmlbeans'>value</test>");
-
- // Parse it using XMLBeans
- XmlObject xdoc = XmlObject.Factory.parse(sb.toString());
-
- // Convert to a DOM Element
- Element firstChild = (Element) xdoc.newDomNode().getFirstChild();
-
- // We expect to find a null namespace for the first attribute and 'ns' for the second
- NamedNodeMap attributes = firstChild.getAttributes();
- System.out.println("Prefix for attr noprefix is:" + attributes.getNamedItem("noprefix").getPrefix() + ":");
- assertNull("Expected null namespace for attribute noprefix", attributes.getNamedItem("noprefix").getPrefix());
- assertEquals("Wrong namespace for attribute prefix", "ns", attributes.getNamedItem("ns:prefix").getPrefix());
-
- // We should be able to lookup 'prefix' by specifying the appropriate URI
- String prefix = firstChild.getAttributeNS("http://xml.apache.org/xmlbeans", "prefix");
- assertEquals("Wrong value for prefixed attribute", "namespace", prefix);
-
- // And 'noprefix' by specifying a null namespace URI
- String noprefix = firstChild.getAttributeNS(null, "noprefix");
- assertEquals("Wrong value for unprefixed attribute", "nonamespace", noprefix); // This assertion fails under Crimson
-
- }
-
- /*
- * [XMLBEANS-33]: insertions occur in improper order when subclassing schema types
- */
- @Test
- public void test_jira_xmlbeans33() throws Exception {
-
- xbeansJira33B.SubjectType subject =
- xbeansJira33B.SubjectType.Factory.newInstance();
- subject.addNewIDPProvidedNameIdentifier();
- subject.addNewSubjectConfirmation().addConfirmationMethod("foo");
- subject.addNewNameIdentifier();
- XmlOptions options = new XmlOptions();
- ArrayList list = new ArrayList();
- options.setErrorListener(list);
-
- boolean bResult = subject.validate(options);
- System.out.println(bResult ? "valid" : "invalid");
-
- // print out errors
- for (int i = 0; i < list.size(); i++) {
- System.out.println("Validation Error : " + list.get(i));
- }
- assertTrue("Validation Failed, should pass", bResult);
-
- }
-
- /*
- * [XMLBEANS-34]: error compiling classes when using a schema with a redefined subelement
- */
- @Test
- public void test_jira_xmlbeans34() throws Exception {
- List errors = new ArrayList();
-
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_34b.xsd_")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
- params.setDownload(true);
- params.setNoPvr(true);
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans34() : Errors found when executing scomp");
- }
-
- }
-
-
- /**
- * BUGBUG: [XMLBEANS-38]
- * [XMLBEANS-38] Does not support xs:key (keyRef NoIllegalEntries)
- */
- public void test_jira_xmlbeans38() throws Exception {
- String keyrefXSD = "<?xml version=\"1.0\"?>" +
- "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
- "<xsd:element name=\"supermarket\">" +
- "<xsd:complexType>" +
- "<xsd:sequence> " +
- "<xsd:element name=\"aisle\" maxOccurs=\"unbounded\"> \n" +
- "<xsd:complexType> " +
- "<xsd:sequence>" +
- "<xsd:element name=\"item\" maxOccurs=\"unbounded\"> \n" +
- "<xsd:complexType> " +
- "<xsd:simpleContent>" +
- "<xsd:extension base=\"xsd:string\"> \n" +
- "<xsd:attribute name=\"code\" type=\"xsd:positiveInteger\"/> \n" +
- "<xsd:attribute name=\"quantity\" type=\"xsd:positiveInteger\"/> \n" +
- "<xsd:attribute name=\"price\" type=\"xsd:decimal\"/> \n" +
- "</xsd:extension> \n" +
- "</xsd:simpleContent> \n" +
- "</xsd:complexType> \n" +
- "</xsd:element> \n" +
- "</xsd:sequence> \n" + //"<!-- Attribute Of Aisle --> \n" +
- "<xsd:attribute name=\"name\" type=\"xsd:string\"/> \n" +
- "<xsd:attribute name=\"number\" type=\"xsd:positiveInteger\"/> \n" + //"<!-- Of Aisle --> \n" +
- "</xsd:complexType> \n" +
- "<xsd:keyref name=\"NoIllegalEntries\" refer=\"itemKey\"> \n" +
- "<xsd:selector xpath=\"item\"/> \n" +
- "<xsd:field xpath=\"@code\"/> \n" +
- "</xsd:keyref> \n" +
- "</xsd:element> \n" +
- "<xsd:element name=\"items\"> \n" +
- "<xsd:complexType> \n" +
- "<xsd:sequence> \n" +
- "<xsd:element name=\"item\" maxOccurs=\"unbounded\"> \n" +
- "<xsd:complexType> \n" +
- "<xsd:simpleContent> \n" +
- "<xsd:extension base=\"xsd:string\"> \n" +
- "<xsd:attribute name=\"code\" type=\"xsd:positiveInteger\"/> \n" +
- "</xsd:extension> \n" +
- "</xsd:simpleContent> \n" +
- "</xsd:complexType> \n" +
- "</xsd:element> \n" +
- "</xsd:sequence> \n" +
- "</xsd:complexType> \n" +
- "</xsd:element> \n" +
- "</xsd:sequence> \n" +
- "<xsd:attribute name=\"name\" type=\"xsd:string\"/> \n" +
- "</xsd:complexType> \n" +
- "<xsd:key name=\"itemKey\"> \n" +
- "<xsd:selector xpath=\"items/item\"/> \n" +
- "<xsd:field xpath=\"@code\"/> \n" +
- "</xsd:key> \n" +
- "</xsd:element> \n" +
- "</xsd:schema>";
-
-
- String keyRefInstance = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
- "<supermarket xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"C:\\tmp\\Supermarket.xsd\" name=\"String\"> \n" +
- "<aisle name=\"String\" number=\"2\"> \n" +
- "<item code=\"1234\" quantity=\"2\" price=\"3.1415926535897932384626433832795\">String</item> \n" +
- "</aisle> \n" +
- "<items> \n" +
- "<item code=\"1234\">Java</item> \n" +
- "</items> \n" +
- "</supermarket>";
-
- validateInstance(new String[]{keyrefXSD}, new String[]{keyRefInstance}, null);
- }
-
-
- /**
- * Loads the class at runtime and inspects for appropriate methods
- * Statically using methods (class.getGeneration()) would stop build
- * if the bug resurfaced.
- * <p/>
- * [XMLBEANS-45] <xsd:redefine> tag is not supported
- */
- public void test_jira_XmlBeans45() throws Exception {
- //this class is built during the build.schemas target
- Class cls = Class.forName("xmlbeans45.PersonName");
- //check for methods in class
- //getGeneration()
- if (cls.getMethod("getGeneration") == null)
- throw new Exception("getGeneration() was not found in class");
- //getTitle()
- if (cls.getMethod("getTitle") == null)
- throw new Exception("getTitle() was not found in class");
- //getForenameArray()
- if (cls.getMethod("getForenameArray") == null)
- throw new Exception("getForenameArray() was not found in class");
-
- }
-
- /**
- * Could not Repro this
- * [XMLBEANS-46] Regex validation fails in multi-threaded, multi-processor environment
- */
- public void test_jira_XmlBeans46() throws Exception {
- RegexThread[] threads = new RegexThread[45];
-
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new RegexThread();
- System.out.println("Thread[" + i + "]-starting ");
- threads[i].start();
- }
-
- Thread.sleep(6000);
- System.out.println("Done with RegEx Threading Test...");
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < threads.length; i++) {
- if (threads[i].getException() != null)
- sb.append(threads[i].getException().getMessage() + "\n");
- }
-
- if (sb.length() > 0)
- throw new Exception("Threaded Regex Validation Failed\n" + sb.toString());
- }
-
-
- /**
- * Incorrect XML
- * [XMLBEANS-48] Bug with Root.fetch ( Splay parent, QName name, QNameSet set, int n )
- */
- public void test_jira_XmlBeans48() throws Exception {
- String incorrectXml = "<sch:Feed xmlns:sch=\"http://xmlbeans_48\">" +
- "<sch:Feed>" +
- "<sch:Location>http://xmlbeans.apache.org</sch:Location>" +
- "<sch:TimeEntered>2004-08-11T15:50:23.064-04:00</sch:TimeEntered>" +
- "</sch:Feed>" +
- "</sch:Feed>";
-
- xmlbeans48.FeedDocument feedDoc = (xmlbeans48.FeedDocument) XmlObject.Factory.parse(incorrectXml);
- FeedInfoType feedInfoType = feedDoc.getFeed();
- String location = feedInfoType.getLocation();
- System.out.println("Location: " + location);
- if (location != null)
- throw new Exception("Location value should not have been populated");
-
- String correctXml = "<sch:Feed xmlns:sch=\"http://xmlbeans_48\">" +
- "<sch:Location>http://xmlbeans.apache.org</sch:Location>" +
- "<sch:TimeEntered>2004-08-11T15:50:23.064-04:00</sch:TimeEntered>" +
- "</sch:Feed>";
-
- feedDoc = (xmlbeans48.FeedDocument) XmlObject.Factory.parse(correctXml);
- feedInfoType = feedDoc.getFeed();
- location = feedInfoType.getLocation();
- System.out.println("Location: " + location);
- if (location == null)
- throw new Exception("Location value should have been populated");
- }
-
- /*
- * [XMLBEANS-49]: Schema compiler won't compile portlet.xsd from jsr168/pluto
- *
- */
- public void test_jira_xmlbeans49() {
- List errors = new ArrayList();
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_49.xsd_")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
-
- // needs network downloads enabled
- params.setDownload(true);
-
- try {
- SchemaCompiler.compile(params);
- } catch (Exception ex) {
- if (!errors.isEmpty()) {
- for (Iterator itr = errors.iterator(); itr.hasNext();) {
- System.out.println("scomp errors: ");
- }
- }
-
- fail("test_jira_xmlbeans49() :Exception thrown with above errors!");
- }
-
- // view errors
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans49() : Errors found when executing scomp");
- }
- }
-
- /**
- * For Testing jira issue 46
- */
- public static class RegexThread extends TestThread
- {
- private xmlbeans46.UsPhoneNumberDocument phone;
- Random rand;
-
- public RegexThread()
- {
- super();
- phone = xmlbeans46.UsPhoneNumberDocument.Factory.newInstance();
- rand = new Random();
- }
-
- /**
- * Validates a type that uses the following pattern
- * <xs:restriction base="xs:string">
- * <xs:pattern value="\d{3}\-\d{3}\-\d{4}"/>
- * </xs:restriction>
- */
- public void run()
- {
- try {
-
- for (int i = 0; i < 9; i++) {
- int pre = rand.nextInt(999);
- int mid = rand.nextInt(999);
- int post = rand.nextInt(9999);
- String testVal = ((pre > 100) ? String.valueOf(pre) : "128") + "-" +
- ((mid > 100) ? String.valueOf(mid) : "256") + "-" +
- ((post > 1000) ? String.valueOf(post) : "1024");
-
- String xmlData = "<xb:usPhoneNumber xmlns:xb=\"http://xmlbeans_46\">" +
- testVal +
- "</xb:usPhoneNumber>";
- //cannot repro using this method
- //phone.setUsPhoneNumber(testVal);
- //if (!phone.validate(xm)) {
- // _throwable = new Throwable("Multi Threaded Regular " +
- // "Expression did not validate - " + testVal);
- // if (errors != null && errors.size() > 0)
- // System.err.println("ERROR: " + errors);
- //}
-
- boolean validated = parseAndValidate(xmlData);
- if (!validated) {
- System.out.println("Not Valid!!!");
- }
- System.out.println("Validated " + testVal + " successfully ");
- }
- _result = true;
-
- } catch (Throwable t) {
- _throwable = t;
- t.printStackTrace();
- }
- }
-
- private boolean parseAndValidate(String val) throws XmlException
- {
- xmlbeans46.UsPhoneNumberDocument xml = xmlbeans46.UsPhoneNumberDocument.Factory.parse(val);
- return validate(xml);
- }
-
- private boolean validate(xmlbeans46.UsPhoneNumberDocument rdd)
- {
- Collection errors = new ArrayList();
- XmlOptions validateOptions = new XmlOptions();
- validateOptions.setErrorListener(errors);
- boolean valid = rdd.validate(validateOptions);
- if (!valid) {
- for (Iterator iterator = errors.iterator(); iterator.hasNext();) {
- XmlError xmlError = (XmlError) iterator.next();
- System.out.println("XML Error - " + xmlError.getMessage() + " at\n" + xmlError.getCursorLocation().xmlText());
- }
-
- }
- return valid;
- }
- }
-}
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import misc.common.JiraTestBase;
+import org.apache.xmlbeans.*;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import xmlbeans48.FeedInfoType;
+
+import javax.xml.namespace.QName;
+import java.io.*;
+import java.util.*;
+
+import static org.junit.Assert.*;
+
+public class JiraRegression1_50Test extends JiraTestBase {
+
+ /*
+ * [XMLBEANS-2] Problem with XmlError.forObject(String,int,XmlObject)
+ */
+ @Test
+ public void test_jira_xmlbeans02() throws Exception {
+ StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
+ xmlstringbuf.append("<test>");
+ xmlstringbuf.append("<testchild attr=\"abcd\"> Jira02 </testchild>");
+ xmlstringbuf.append("</test>");
+
+ XmlObject myxmlobj = null;
+ List errors = new ArrayList();
+ XmlOptions options = new XmlOptions().setErrorListener(errors);
+ try {
+ myxmlobj = XmlObject.Factory.parse(xmlstringbuf.toString(), options);
+ XmlCursor cur = myxmlobj.newCursor();
+ XmlError xmlerr = XmlError.forObject("This is my custom error message", XmlError.SEVERITY_ERROR, myxmlobj);
+
+ // call an API on the cursor : verification of cursor not being disposed
+ System.out.println("Cursor Text Value: " + cur.getTextValue());
+
+ } catch (XmlException xme) {
+ if (!xme.getErrors().isEmpty()) {
+ for (Iterator itr = xme.getErrors().iterator(); itr.hasNext();) {
+ System.out.println("Parse Errors :" + itr.next());
+ }
+ }
+
+ } catch (NullPointerException npe) {
+ fail("test_jira_xmlbeans02() : Null Pointer Exception thrown !");
+ }
+
+ printOptionErrMsgs(errors);
+ }
+
+ /*
+ * [XMLBEANS-4] xs:decimal size greater than 18 results in uncompilable java code
+ */
+ @Test
+ public void test_jira_xmlbeans04() {
+ List errors = new ArrayList();
+
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_04.xsd_")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans04() : Errors found when executing scomp");
+ }
+ }
+
+
+
+ /*
+ * [XMLBEANS-9] Null Pointer Exception when running validate from cmd line
+ */
+ @Test
+ @Ignore("no shell tests on junit")
+ public void test_jira_xmlbeans09() throws Exception {
+ // Exec validate script from cmd line - Refer xmlbeans_09.xsd, xmlbeans_09.xml
+
+ StringBuilder sb = new StringBuilder(" ");
+ sb.append(System.getProperty("xbean.rootdir") + P + "bin" + P + "validate.cmd ");
+ sb.append(scompTestFilesRoot + "xmlbeans_09.xsd_" + " " + scompTestFilesRoot + "xmlbeans_09.xml");
+ Process validator_proc = null;
+ try {
+ validator_proc = Runtime.getRuntime().exec(sb.toString());
+ } catch (NullPointerException npe) {
+ fail("test_jira_xmlbeans09() : Null Pointer Exception when running validate for schema");
+ }
+
+ System.out.println("cmd:" + sb);
+ BufferedInputStream inbuf = new BufferedInputStream(validator_proc.getInputStream());
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inbuf));
+ String eachline = reader.readLine();
+ try {
+
+ while (reader.readLine() != null) {
+ System.out.println("output: " + eachline);
+ }
+ } catch (IOException ioe) {
+ ioe.getMessage();
+ ioe.printStackTrace();
+ }
+
+ }
+
+ /*
+ * [XMLBEANS-11]: Calling getUnionMemberTypes() on SchemaType for non-union types results in NullPointerException
+ * status : fixed
+ */
+ @Test
+ public void test_jira_xmlbeans11() throws Exception {
+
+ StringBuilder xsdAsString = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
+ xsdAsString.append(" <!-- W3C Schema generated by XML Spy v4.3 U (http://www.xmlspy.com)\n");
+ xsdAsString.append(" --> \n");
+ xsdAsString.append(" <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">\n");
+ xsdAsString.append(" <xs:simpleType name=\"restrictsString\">\n");
+ xsdAsString.append(" <xs:restriction base=\"xs:string\">\n");
+ xsdAsString.append(" <xs:length value=\"10\" /> \n");
+ xsdAsString.append(" </xs:restriction>\n");
+ xsdAsString.append(" </xs:simpleType>\n");
+ xsdAsString.append(" </xs:schema>");
+
+ // load schema file as SchemaDocument XmlObject
+ SchemaDocument sd = SchemaDocument.Factory.parse(xsdAsString.toString());
+
+ // compile loaded XmlObject
+ SchemaTypeSystem sts = XmlBeans.compileXsd((XmlObject[]) Collections.singletonList(sd).toArray(new XmlObject[]{}),
+ XmlBeans.getContextTypeLoader(),
+ new XmlOptions());
+ sts.resolve();
+
+ SchemaType[] st = sts.globalTypes();
+
+ System.out.println("NUMBER OF GLOBAL TYPES: " + st.length);
+
+ try {
+ for (int i = 0; i < st.length; i++)
+ // check if it is union type
+ {
+ System.out.println("IS UNION TYPE: " + (st[i].getUnionMemberTypes() != null));
+ }
+ } catch (NullPointerException npe) {
+ fail("test_jira_xmlbeans11(): Null Pointer Exception thrown !");
+ }
+
+ }
+
+ /*
+ * [XMLBEANS-14]: newDomNode() throws NullPointerException
+ */
+ @Test
+ public void test_jira_xmlbeans14() throws Exception {
+ XmlObject xObj = XmlObject.Factory.parse("<Baz/>");
+ // add element
+ XmlCursor xCursor = xObj.newCursor();
+ xCursor.toFirstContentToken();
+ xCursor.insertElementWithText(new QName("Some uri", "SomeName"), "SomeValue");
+ xCursor.insertElementWithText(new QName("Some uri", "SomeName1"), "SomeValue1");
+ xCursor.dispose();
+
+ // debug
+ xObj.save(System.out);
+
+ // throws npe in v1
+ try {
+ xObj.newDomNode();
+ } catch (NullPointerException npe) {
+ fail("test_jira_xmlbeans14() : Null Pointer Exception when create Dom Node");
+ }
+
+ }
+
+
+ /*
+ * [XMLBEANS-16]: newDomNode creates a DOM with empty strings for namespace URIs for unprefixed
+ * attributes (rather than null)
+ * status : fails with crimson and not with Xerces
+ */
+ @Test
+ @Ignore("still happens with current xerces 2.11")
+ public void test_jira_xmlbeans16() throws Exception {
+ StringBuilder sb = new StringBuilder(100);
+ sb.append("<?xml version='1.0'?>\n");
+ sb.append("<test noprefix='nonamespace' \n");
+ sb.append(" ns:prefix='namespace' \n");
+ sb.append(" xmlns:ns='http://xml.apache.org/xmlbeans'>value</test>");
+
+ // Parse it using XMLBeans
+ XmlObject xdoc = XmlObject.Factory.parse(sb.toString());
+
+ // Convert to a DOM Element
+ Element firstChild = (Element) xdoc.newDomNode().getFirstChild();
+
+ // We expect to find a null namespace for the first attribute and 'ns' for the second
+ NamedNodeMap attributes = firstChild.getAttributes();
+ System.out.println("Prefix for attr noprefix is:" + attributes.getNamedItem("noprefix").getPrefix() + ":");
+ assertNull("Expected null namespace for attribute noprefix", attributes.getNamedItem("noprefix").getPrefix());
+ assertEquals("Wrong namespace for attribute prefix", "ns", attributes.getNamedItem("ns:prefix").getPrefix());
+
+ // We should be able to lookup 'prefix' by specifying the appropriate URI
+ String prefix = firstChild.getAttributeNS("http://xml.apache.org/xmlbeans", "prefix");
+ assertEquals("Wrong value for prefixed attribute", "namespace", prefix);
+
+ // And 'noprefix' by specifying a null namespace URI
+ String noprefix = firstChild.getAttributeNS(null, "noprefix");
+ assertEquals("Wrong value for unprefixed attribute", "nonamespace", noprefix); // This assertion fails under Crimson
+
+ }
+
+ /*
+ * [XMLBEANS-33]: insertions occur in improper order when subclassing schema types
+ */
+ @Test
+ public void test_jira_xmlbeans33() throws Exception {
+
+ xbeansJira33B.SubjectType subject =
+ xbeansJira33B.SubjectType.Factory.newInstance();
+ subject.addNewIDPProvidedNameIdentifier();
+ subject.addNewSubjectConfirmation().addConfirmationMethod("foo");
+ subject.addNewNameIdentifier();
+ XmlOptions options = new XmlOptions();
+ ArrayList list = new ArrayList();
+ options.setErrorListener(list);
+
+ boolean bResult = subject.validate(options);
+ System.out.println(bResult ? "valid" : "invalid");
+
+ // print out errors
+ for (int i = 0; i < list.size(); i++) {
+ System.out.println("Validation Error : " + list.get(i));
+ }
+ assertTrue("Validation Failed, should pass", bResult);
+
+ }
+
+ /*
+ * [XMLBEANS-34]: error compiling classes when using a schema with a redefined subelement
+ */
+ @Test
+ public void test_jira_xmlbeans34() throws Exception {
+ List errors = new ArrayList();
+
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_34b.xsd_")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+ params.setDownload(true);
+ params.setNoPvr(true);
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans34() : Errors found when executing scomp");
+ }
+
+ }
+
+
+ /**
+ * BUGBUG: [XMLBEANS-38]
+ * [XMLBEANS-38] Does not support xs:key (keyRef NoIllegalEntries)
+ */
+ public void test_jira_xmlbeans38() throws Exception {
+ String keyrefXSD = "<?xml version=\"1.0\"?>" +
+ "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
+ "<xsd:element name=\"supermarket\">" +
+ "<xsd:complexType>" +
+ "<xsd:sequence> " +
+ "<xsd:element name=\"aisle\" maxOccurs=\"unbounded\"> \n" +
+ "<xsd:complexType> " +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"item\" maxOccurs=\"unbounded\"> \n" +
+ "<xsd:complexType> " +
+ "<xsd:simpleContent>" +
+ "<xsd:extension base=\"xsd:string\"> \n" +
+ "<xsd:attribute name=\"code\" type=\"xsd:positiveInteger\"/> \n" +
+ "<xsd:attribute name=\"quantity\" type=\"xsd:positiveInteger\"/> \n" +
+ "<xsd:attribute name=\"price\" type=\"xsd:decimal\"/> \n" +
+ "</xsd:extension> \n" +
+ "</xsd:simpleContent> \n" +
+ "</xsd:complexType> \n" +
+ "</xsd:element> \n" +
+ "</xsd:sequence> \n" + //"<!-- Attribute Of Aisle --> \n" +
+ "<xsd:attribute name=\"name\" type=\"xsd:string\"/> \n" +
+ "<xsd:attribute name=\"number\" type=\"xsd:positiveInteger\"/> \n" + //"<!-- Of Aisle --> \n" +
+ "</xsd:complexType> \n" +
+ "<xsd:keyref name=\"NoIllegalEntries\" refer=\"itemKey\"> \n" +
+ "<xsd:selector xpath=\"item\"/> \n" +
+ "<xsd:field xpath=\"@code\"/> \n" +
+ "</xsd:keyref> \n" +
+ "</xsd:element> \n" +
+ "<xsd:element name=\"items\"> \n" +
+ "<xsd:complexType> \n" +
+ "<xsd:sequence> \n" +
+ "<xsd:element name=\"item\" maxOccurs=\"unbounded\"> \n" +
+ "<xsd:complexType> \n" +
+ "<xsd:simpleContent> \n" +
+ "<xsd:extension base=\"xsd:string\"> \n" +
+ "<xsd:attribute name=\"code\" type=\"xsd:positiveInteger\"/> \n" +
+ "</xsd:extension> \n" +
+ "</xsd:simpleContent> \n" +
+ "</xsd:complexType> \n" +
+ "</xsd:element> \n" +
+ "</xsd:sequence> \n" +
+ "</xsd:complexType> \n" +
+ "</xsd:element> \n" +
+ "</xsd:sequence> \n" +
+ "<xsd:attribute name=\"name\" type=\"xsd:string\"/> \n" +
+ "</xsd:complexType> \n" +
+ "<xsd:key name=\"itemKey\"> \n" +
+ "<xsd:selector xpath=\"items/item\"/> \n" +
+ "<xsd:field xpath=\"@code\"/> \n" +
+ "</xsd:key> \n" +
+ "</xsd:element> \n" +
+ "</xsd:schema>";
+
+
+ String keyRefInstance = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
+ "<supermarket xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"C:\\tmp\\Supermarket.xsd\" name=\"String\"> \n" +
+ "<aisle name=\"String\" number=\"2\"> \n" +
+ "<item code=\"1234\" quantity=\"2\" price=\"3.1415926535897932384626433832795\">String</item> \n" +
+ "</aisle> \n" +
+ "<items> \n" +
+ "<item code=\"1234\">Java</item> \n" +
+ "</items> \n" +
+ "</supermarket>";
+
+ validateInstance(new String[]{keyrefXSD}, new String[]{keyRefInstance}, null);
+ }
+
+
+ /**
+ * Loads the class at runtime and inspects for appropriate methods
+ * Statically using methods (class.getGeneration()) would stop build
+ * if the bug resurfaced.
+ * <p/>
+ * [XMLBEANS-45] <xsd:redefine> tag is not supported
+ */
+ public void test_jira_XmlBeans45() throws Exception {
+ //this class is built during the build.schemas target
+ Class cls = Class.forName("xmlbeans45.PersonName");
+ //check for methods in class
+ //getGeneration()
+ if (cls.getMethod("getGeneration") == null)
+ throw new Exception("getGeneration() was not found in class");
+ //getTitle()
+ if (cls.getMethod("getTitle") == null)
+ throw new Exception("getTitle() was not found in class");
+ //getForenameArray()
+ if (cls.getMethod("getForenameArray") == null)
+ throw new Exception("getForenameArray() was not found in class");
+
+ }
+
+ /**
+ * Could not Repro this
+ * [XMLBEANS-46] Regex validation fails in multi-threaded, multi-processor environment
+ */
+ public void test_jira_XmlBeans46() throws Exception {
+ RegexThread[] threads = new RegexThread[45];
+
+ for (int i = 0; i < threads.length; i++) {
+ threads[i] = new RegexThread();
+ System.out.println("Thread[" + i + "]-starting ");
+ threads[i].start();
+ }
+
+ Thread.sleep(6000);
+ System.out.println("Done with RegEx Threading Test...");
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < threads.length; i++) {
+ if (threads[i].getException() != null)
+ sb.append(threads[i].getException().getMessage() + "\n");
+ }
+
+ if (sb.length() > 0)
+ throw new Exception("Threaded Regex Validation Failed\n" + sb.toString());
+ }
+
+
+ /**
+ * Incorrect XML
+ * [XMLBEANS-48] Bug with Root.fetch ( Splay parent, QName name, QNameSet set, int n )
+ */
+ public void test_jira_XmlBeans48() throws Exception {
+ String incorrectXml = "<sch:Feed xmlns:sch=\"http://xmlbeans_48\">" +
+ "<sch:Feed>" +
+ "<sch:Location>http://xmlbeans.apache.org</sch:Location>" +
+ "<sch:TimeEntered>2004-08-11T15:50:23.064-04:00</sch:TimeEntered>" +
+ "</sch:Feed>" +
+ "</sch:Feed>";
+
+ xmlbeans48.FeedDocument feedDoc = (xmlbeans48.FeedDocument) XmlObject.Factory.parse(incorrectXml);
+ FeedInfoType feedInfoType = feedDoc.getFeed();
+ String location = feedInfoType.getLocation();
+ System.out.println("Location: " + location);
+ if (location != null)
+ throw new Exception("Location value should not have been populated");
+
+ String correctXml = "<sch:Feed xmlns:sch=\"http://xmlbeans_48\">" +
+ "<sch:Location>http://xmlbeans.apache.org</sch:Location>" +
+ "<sch:TimeEntered>2004-08-11T15:50:23.064-04:00</sch:TimeEntered>" +
+ "</sch:Feed>";
+
+ feedDoc = (xmlbeans48.FeedDocument) XmlObject.Factory.parse(correctXml);
+ feedInfoType = feedDoc.getFeed();
+ location = feedInfoType.getLocation();
+ System.out.println("Location: " + location);
+ if (location == null)
+ throw new Exception("Location value should have been populated");
+ }
+
+ /*
+ * [XMLBEANS-49]: Schema compiler won't compile portlet.xsd from jsr168/pluto
+ *
+ */
+ public void test_jira_xmlbeans49() {
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_49.xsd_")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+
+ // needs network downloads enabled
+ params.setDownload(true);
+
+ try {
+ SchemaCompiler.compile(params);
+ } catch (Exception ex) {
+ if (!errors.isEmpty()) {
+ for (Iterator itr = errors.iterator(); itr.hasNext();) {
+ System.out.println("scomp errors: ");
+ }
+ }
+
+ fail("test_jira_xmlbeans49() :Exception thrown with above errors!");
+ }
+
+ // view errors
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans49() : Errors found when executing scomp");
+ }
+ }
+
+ /**
+ * For Testing jira issue 46
+ */
+ public static class RegexThread extends TestThread
+ {
+ private xmlbeans46.UsPhoneNumberDocument phone;
+ Random rand;
+
+ public RegexThread()
+ {
+ super();
+ phone = xmlbeans46.UsPhoneNumberDocument.Factory.newInstance();
+ rand = new Random();
+ }
+
+ /**
+ * Validates a type that uses the following pattern
+ * <xs:restriction base="xs:string">
+ * <xs:pattern value="\d{3}\-\d{3}\-\d{4}"/>
+ * </xs:restriction>
+ */
+ public void run()
+ {
+ try {
+
+ for (int i = 0; i < 9; i++) {
+ int pre = rand.nextInt(999);
+ int mid = rand.nextInt(999);
+ int post = rand.nextInt(9999);
+ String testVal = ((pre > 100) ? String.valueOf(pre) : "128") + "-" +
+ ((mid > 100) ? String.valueOf(mid) : "256") + "-" +
+ ((post > 1000) ? String.valueOf(post) : "1024");
+
+ String xmlData = "<xb:usPhoneNumber xmlns:xb=\"http://xmlbeans_46\">" +
+ testVal +
+ "</xb:usPhoneNumber>";
+ //cannot repro using this method
+ //phone.setUsPhoneNumber(testVal);
+ //if (!phone.validate(xm)) {
+ // _throwable = new Throwable("Multi Threaded Regular " +
+ // "Expression did not validate - " + testVal);
+ // if (errors != null && errors.size() > 0)
+ // System.err.println("ERROR: " + errors);
+ //}
+
+ boolean validated = parseAndValidate(xmlData);
+ if (!validated) {
+ System.out.println("Not Valid!!!");
+ }
+ System.out.println("Validated " + testVal + " successfully ");
+ }
+ _result = true;
+
+ } catch (Throwable t) {
+ _throwable = t;
+ t.printStackTrace();
+ }
+ }
+
+ private boolean parseAndValidate(String val) throws XmlException
+ {
+ xmlbeans46.UsPhoneNumberDocument xml = xmlbeans46.UsPhoneNumberDocument.Factory.parse(val);
+ return validate(xml);
+ }
+
+ private boolean validate(xmlbeans46.UsPhoneNumberDocument rdd)
+ {
+ Collection errors = new ArrayList();
+ XmlOptions validateOptions = new XmlOptions();
+ validateOptions.setErrorListener(errors);
+ boolean valid = rdd.validate(validateOptions);
+ if (!valid) {
+ for (Iterator iterator = errors.iterator(); iterator.hasNext();) {
+ XmlError xmlError = (XmlError) iterator.next();
+ System.out.println("XML Error - " + xmlError.getMessage() + " at\n" + xmlError.getCursorLocation().xmlText());
+ }
+
+ }
+ return valid;
+ }
+ }
+}
diff --git a/src/test/java/misc/detailed/JiraRegression201_250Test.java b/src/test/java/misc/detailed/JiraRegression201_250Test.java
index 7252dc6..c17a2a4 100644
--- a/src/test/java/misc/detailed/JiraRegression201_250Test.java
+++ b/src/test/java/misc/detailed/JiraRegression201_250Test.java
@@ -1,117 +1,117 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import jira.xmlbeans228.substitution.CommentType;
-import jira.xmlbeans228.substitution.FirstCommentType;
-import jira.xmlbeans228.substitution.PersonDocument;
-import misc.common.JiraTestBase;
-import misc.detailed.jira208.FrogBreathDocument;
-import org.apache.xmlbeans.XmlOptions;
-import org.junit.Test;
-
-import javax.xml.namespace.QName;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-public class JiraRegression201_250Test extends JiraTestBase {
-
- /*
- * [XMLBEANS-206]: Wrong method finding in getMethod() of InterfaceExtensionImpl
- *
- */
- // Refer test case xmlobject.extensions.interfaceFeature.averageCase.checkin.testJiraXMLBEANS_206
-
- /*
- * [XMLBEANS-208]: validation of decimal with fractionDigits -- special case, additional zero digits
- *
- */
- @Test
- public void test_jira_xmlbeans208() throws Exception {
-
- XmlOptions options = new XmlOptions();
- List err = new ArrayList();
- options.setErrorListener(err);
-
- // decimal value invalid
- FrogBreathDocument invalidDoc = FrogBreathDocument.Factory.parse("<dec:frog_breath xmlns:dec=\"http://misc/detailed/jira208\">1000.000001</dec:frog_breath>");
- boolean valid = invalidDoc.validate(options);
- if(!valid)
- {
- for (Iterator iterator = err.iterator(); iterator.hasNext();) {
- System.out.println("Validation Error (invalid doc):" + iterator.next());
- }
- }
- // expected to fail
- assertFalse(valid);
-
- // decimal value with trailing zeros tagged as invalid
- FrogBreathDocument validDoc = FrogBreathDocument.Factory.parse("<dec:frog_breath xmlns:dec=\"http://misc/detailed/jira208\">1000.000000</dec:frog_breath>");
-
- err.clear();
- boolean valid2 = validDoc.validate(options);
- if(!valid2)
- {
- for (Iterator iterator = err.iterator(); iterator.hasNext();) {
- System.out.println("Validation Error (valid doc):" + iterator.next());
- }
- }
-
- assertTrue(valid2);
- }
-
- /*
- * [XMLBEANS-228]:
- * element order in sequence incorrect after calling substitute()
- */
- @Test
- public void test_jira_xmlbeans228() throws Exception
- {
- PersonDocument personDocument = PersonDocument.Factory.newInstance();
- PersonDocument.Person person = personDocument.addNewPerson();
- CommentType commentType = person.addNewComment();
- String ns = "http://jira/xmlbeans_228/substitution";
- QName qName = new QName(ns, "FirstCommentElement");
- Object resultObject = commentType.substitute(qName, FirstCommentType.type);
- FirstCommentType firstCommentType = (FirstCommentType)resultObject;
- firstCommentType.setStringValue("ThirdElement");
- person.setComment(firstCommentType);
-
- person.setFirstName("FirstElement");
- person.setLastName("SecondElement");
-
- XmlOptions opts = new XmlOptions().setSavePrettyPrint().setUseDefaultNamespace();
- StringWriter out = new StringWriter();
- personDocument.save(out, opts);
-
- String exp =
- "<Person xmlns=\"http://jira/xmlbeans_228/substitution\">" + NEWLINE +
- " <FirstName>FirstElement</FirstName>" + NEWLINE +
- " <LastName>SecondElement</LastName>" + NEWLINE +
- " <FirstCommentElement>ThirdElement</FirstCommentElement>" + NEWLINE +
- "</Person>";
-
- assertEquals(exp, out.toString());
- if (!personDocument.validate())
- {
- fail("Wrong element order!");
- }
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import jira.xmlbeans228.substitution.CommentType;
+import jira.xmlbeans228.substitution.FirstCommentType;
+import jira.xmlbeans228.substitution.PersonDocument;
+import misc.common.JiraTestBase;
+import misc.detailed.jira208.FrogBreathDocument;
+import org.apache.xmlbeans.XmlOptions;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class JiraRegression201_250Test extends JiraTestBase {
+
+ /*
+ * [XMLBEANS-206]: Wrong method finding in getMethod() of InterfaceExtensionImpl
+ *
+ */
+ // Refer test case xmlobject.extensions.interfaceFeature.averageCase.checkin.testJiraXMLBEANS_206
+
+ /*
+ * [XMLBEANS-208]: validation of decimal with fractionDigits -- special case, additional zero digits
+ *
+ */
+ @Test
+ public void test_jira_xmlbeans208() throws Exception {
+
+ XmlOptions options = new XmlOptions();
+ List err = new ArrayList();
+ options.setErrorListener(err);
+
+ // decimal value invalid
+ FrogBreathDocument invalidDoc = FrogBreathDocument.Factory.parse("<dec:frog_breath xmlns:dec=\"http://misc/detailed/jira208\">1000.000001</dec:frog_breath>");
+ boolean valid = invalidDoc.validate(options);
+ if(!valid)
+ {
+ for (Iterator iterator = err.iterator(); iterator.hasNext();) {
+ System.out.println("Validation Error (invalid doc):" + iterator.next());
+ }
+ }
+ // expected to fail
+ assertFalse(valid);
+
+ // decimal value with trailing zeros tagged as invalid
+ FrogBreathDocument validDoc = FrogBreathDocument.Factory.parse("<dec:frog_breath xmlns:dec=\"http://misc/detailed/jira208\">1000.000000</dec:frog_breath>");
+
+ err.clear();
+ boolean valid2 = validDoc.validate(options);
+ if(!valid2)
+ {
+ for (Iterator iterator = err.iterator(); iterator.hasNext();) {
+ System.out.println("Validation Error (valid doc):" + iterator.next());
+ }
+ }
+
+ assertTrue(valid2);
+ }
+
+ /*
+ * [XMLBEANS-228]:
+ * element order in sequence incorrect after calling substitute()
+ */
+ @Test
+ public void test_jira_xmlbeans228() throws Exception
+ {
+ PersonDocument personDocument = PersonDocument.Factory.newInstance();
+ PersonDocument.Person person = personDocument.addNewPerson();
+ CommentType commentType = person.addNewComment();
+ String ns = "http://jira/xmlbeans_228/substitution";
+ QName qName = new QName(ns, "FirstCommentElement");
+ Object resultObject = commentType.substitute(qName, FirstCommentType.type);
+ FirstCommentType firstCommentType = (FirstCommentType)resultObject;
+ firstCommentType.setStringValue("ThirdElement");
+ person.setComment(firstCommentType);
+
+ person.setFirstName("FirstElement");
+ person.setLastName("SecondElement");
+
+ XmlOptions opts = new XmlOptions().setSavePrettyPrint().setUseDefaultNamespace();
+ StringWriter out = new StringWriter();
+ personDocument.save(out, opts);
+
+ String exp =
+ "<Person xmlns=\"http://jira/xmlbeans_228/substitution\">" + NEWLINE +
+ " <FirstName>FirstElement</FirstName>" + NEWLINE +
+ " <LastName>SecondElement</LastName>" + NEWLINE +
+ " <FirstCommentElement>ThirdElement</FirstCommentElement>" + NEWLINE +
+ "</Person>";
+
+ assertEquals(exp, out.toString());
+ if (!personDocument.validate())
+ {
+ fail("Wrong element order!");
+ }
+ }
+}
diff --git a/src/test/java/misc/detailed/JiraRegression251_300Test.java b/src/test/java/misc/detailed/JiraRegression251_300Test.java
index 67dbbfa..47994a0 100644
--- a/src/test/java/misc/detailed/JiraRegression251_300Test.java
+++ b/src/test/java/misc/detailed/JiraRegression251_300Test.java
@@ -1,40 +1,40 @@
-/*
- * Copyright 2009 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import com.easypo.XmlShipperBean;
-import misc.common.JiraTestBase;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-
-public class JiraRegression251_300Test extends JiraTestBase
-{
- /*
- * [XMLBEANS-260]: SchemaType#isSkippedAnonymousType() throws an NPE
- * if _outerSchemaTypeRef is not set
- */
- @Test
- public void test_jira_xmlbeans260()
- {
- // construct an instance of a non-anonymous type
- XmlShipperBean xbean = XmlShipperBean.Factory.newInstance();
- // the following call should not throw an NPE;
- // it should return false instead
- boolean isSkipped = xbean.schemaType().isSkippedAnonymousType();
- assertFalse(isSkipped);
- }
-}
+/*
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import com.easypo.XmlShipperBean;
+import misc.common.JiraTestBase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+
+public class JiraRegression251_300Test extends JiraTestBase
+{
+ /*
+ * [XMLBEANS-260]: SchemaType#isSkippedAnonymousType() throws an NPE
+ * if _outerSchemaTypeRef is not set
+ */
+ @Test
+ public void test_jira_xmlbeans260()
+ {
+ // construct an instance of a non-anonymous type
+ XmlShipperBean xbean = XmlShipperBean.Factory.newInstance();
+ // the following call should not throw an NPE;
+ // it should return false instead
+ boolean isSkipped = xbean.schemaType().isSkippedAnonymousType();
+ assertFalse(isSkipped);
+ }
+}
diff --git a/src/test/java/misc/detailed/JiraRegression50_100Test.java b/src/test/java/misc/detailed/JiraRegression50_100Test.java
index 7a490e3..89ee310 100644
--- a/src/test/java/misc/detailed/JiraRegression50_100Test.java
+++ b/src/test/java/misc/detailed/JiraRegression50_100Test.java
@@ -1,849 +1,849 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import dufourrault.DummyDocument;
-import dufourrault.Father;
-import misc.common.JiraTestBase;
-import net.orthogony.xml.sample.structure.ARootDocument;
-import net.orthogony.xml.sample.structure.ChildType;
-import org.apache.beehive.netui.tools.testrecorder.x2004.session.RecorderSessionDocument;
-import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Node;
-import test.xbean.xmlcursor.purchaseOrder.PurchaseOrderDocument;
-import testDateAttribute.TestDatewTZone;
-import testDateAttribute.TestElementWithDateAttributeDocument;
-import tools.util.JarUtil;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.*;
-
-import static org.junit.Assert.*;
-
-
-public class JiraRegression50_100Test extends JiraTestBase
-{
-
-
- ///**
- // * [XMLBEANS-##] <BUG TITLE>
- // */
- //public void test_jira_XmlBeans45() throws Exception
- //{
- //
- //}
-
-
-
-
- /**
- * [XMLBEANS-52] Validator loops when schema has certain conditions
- */
- @Test
- public void test_jira_XmlBeans52() throws Exception{
- //reusing code from method test_jira_XmlBeans48()
- String correctXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
- "<!--Sample XML file generated by XMLSPY v5 rel. 4 U (http://www.xmlspy.com)--/> \n" +
- "<aList xmlns=\"http://pfa.dk/dummy/errorInXmlBeansValidation.xsd\" " +
- "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
- "xsi:schemaLocation=\"http://pfa.dk/dummy/errorInXmlBeansValidation.xsd \n" +
- "C:\\pfa\\techr3\\TransformationWorkbench\\schema\\errorInXmlBeansValidation.xsd\"> \n" +
- "<myListEntry> \n" +
- "<HelloWorld>Hello World</HelloWorld> \n" +
- "</myListEntry> \n" +
- "</aList> ";
-
-
- }
-
- /*
- * [XMLBEANS-54]: problem with default value
- */
- @Test
- public void test_jira_xmlbeans54() throws Exception {
- List errors = new ArrayList();
-
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_54.xsd_")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
- params.setDownload(true);
- params.setNoPvr(true);
-
- // Runs out of Heap Memory
- params.setMemoryMaximumSize("1024m");
- params.setMemoryInitialSize("512m");
-
- try {
- SchemaCompiler.compile(params);
- } catch (OutOfMemoryError ome) {
- System.out.println(ome.getStackTrace());
- System.out.println("test_jira_xmlbeans54() - out of Heap Memory");
- }
-
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans54() : Errors found when executing scomp");
- }
- }
-
- /**
- * [XMLBEANS-56] samples issue with easypo schema and config file
- */
- @Test
- public void test_jira_XmlBeans56() throws Exception {
- String xsdConfig = "<xb:config " +
- " xmlns:xb=\"http://xml.apache.org/xmlbeans/2004/02/xbean/config\"\n" +
- " xmlns:ep=\"http://openuri.org/easypo\">\n" +
- " <xb:namespace uri=\"http://openuri.org/easypo\">\n" +
- " <xb:package>com.easypo</xb:package>\n" +
- " </xb:namespace>\n" +
- " <xb:namespace uri=\"##any\">\n" +
- " <xb:prefix>Xml</xb:prefix>\n" +
- " <xb:suffix>Bean</xb:suffix>\n" +
- " </xb:namespace>\n" +
- " <xb:extension for=\"com.easypo.XmlCustomerBean\">\n" +
- " <xb:interface name=\"myPackage.Foo\">\n" +
- " <xb:staticHandler>myPackage.FooHandler</xb:staticHandler>\n" +
- " </xb:interface>\n" +
- " </xb:extension>\n" +
- " <xb:qname name=\"ep:purchase-order\" javaname=\"purchaseOrderXXX\"/>\n" +
- "</xb:config> ";
- ConfigDocument config =
- ConfigDocument.Factory.parse(xsdConfig);
- xmOpts.setErrorListener(errorList);
- if (config.validate(xmOpts)) {
- System.out.println("Config Validated");
- return;
- } else {
- System.err.println("Config File did not validate");
- for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
- System.out.println("Error: " + iterator.next());
- }
- throw new Exception("Config File did not validate");
- }
-
- }
-
- /**
- * [XMLBEANS-57] scomp failure for XSD namespace "DAV:"
- */
- @Test
- public void test_jira_XmlBeans57() throws Exception {
- String P = File.separator;
- String outputDir = OUTPUTROOT + P + "dav";
-
- File srcDir = new File(outputDir + P + "src");
- srcDir.mkdirs();
- File classDir = new File(outputDir + P + "classes");
- classDir.mkdirs();
-
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(JIRA_CASES + "xmlbeans_57.xml")});
- params.setErrorListener(errorList);
- params.setSrcDir(srcDir);
- params.setClassesDir(classDir);
- SchemaCompiler.compile(params);
- Collection errs = params.getErrorListener();
- boolean outTextPresent = true;
-
- if (errs.size() != 0) {
- for (Iterator iterator = errs.iterator(); iterator.hasNext();) {
- Object o = iterator.next();
- String out = o.toString();
- System.out.println("Dav: " + out);
- if (out.startsWith("Compiled types to"))
- outTextPresent = false;
- }
- }
-
- //cleanup gen'd dirs
- srcDir.deleteOnExit();
- classDir.deleteOnExit();
-
- if (outTextPresent)
- System.out.println("No errors when running schemacompiler with DAV namespace");
- else
- throw new Exception("There were errors while compiling XSD with DAV " +
- "namespace. See sys.out for more info");
- }
-
- /*
- * [XMLBEANS-58]:resolving transitive <redefine>'d types...
- * This is realted to xmlbeans36 - its the same case but the schemas seem to have been updated at the w3c site.
- * Hence adding a new testcase with the new schemas
- */
- @Test
- @Ignore("the url doesn't exist anymore ...")
- public void test_jira_xmlbeans58() throws Exception {
- List errors = new ArrayList();
- Parameters params = new Parameters();
-
- // old url has been retired
- //params.setUrlFiles(new URL[]{new URL("http://devresource.hp.com/drc/specifications/wsrf/interfaces/WS-BrokeredNotification-1-0.wsdl")});
- // this seems to be a url for a WS-BrokeredNotification 1.0 wsdl
- params.setUrlFiles(new URL[]{new URL("http://www.ibm.com/developerworks/library/specification/ws-notification/WS-BrokeredN.wsdl")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
- params.setDownload(true);
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans55() : Errors found when executing scomp");
- }
-
- }
-
-
- /**
- * [XMLBEANS-62] Avoid class cast exception when compiling older schema namespace
- */
- @Test
- public void test_jira_XmlBeans62() throws Exception {
- String P = File.separator;
- String outputDir = System.getProperty("xbean.rootdir") + P + "build" +
- P + "test" + P + "output" + P + "x1999";
-
- File srcDir = new File(outputDir + P + "src");
- srcDir.mkdirs();
- File classDir = new File(outputDir + P + "classes");
- classDir.mkdirs();
-
- Parameters params = new Parameters();
- params.setWsdlFiles(new File[]{new File(JIRA_CASES + "xmlbeans_62.xml")});
- params.setErrorListener(errorList);
- params.setSrcDir(srcDir);
- params.setClassesDir(classDir);
- SchemaCompiler.compile(params);
- Collection errs = params.getErrorListener();
- boolean warningPresent = false;
- for (Iterator iterator = errs.iterator(); iterator.hasNext();) {
- Object o = iterator.next();
- String out = o.toString();
- if (out.endsWith("did not have any schema documents in namespace 'http://www.w3.org/2001/XMLSchema'")) ;
- warningPresent = true;
- }
-
- //cleanup gen'd dirs
- srcDir.deleteOnExit();
- classDir.deleteOnExit();
-
- //validate error present
- if (!warningPresent)
- throw new Exception("Warning for 1999 schema was not found when compiling srcs");
- else
- System.out.println("Warning Present, test Passed");
- }
-
- /**
- * [XMLBEANS-64] ArrayIndexOutOfBoundsException during validation
- */
- @Test
- public void test_jira_XmlBeans64() throws Exception {
- // load the document
- File inst = new File(JIRA_CASES + "xmlbeans_64.xml");
- XmlObject doc = RecorderSessionDocument.Factory.parse(inst);
- // validate
- XmlOptions validateOptions = new XmlOptions();
- validateOptions.setLoadLineNumbers();
- ArrayList errorList = new ArrayList();
- validateOptions.setErrorListener(errorList);
- boolean isValid = doc.validate(validateOptions);
-
- if (!isValid)
- throw new Exception("Errors: " + errorList);
- }
-
- /**
- * [XMLBEANS-66] NullPointerException when restricting a union with one of the union members
- */
- @Test
- public void test_jira_XmlBeans66() throws Exception {
- String reproXsd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
- "<xsd:schema targetNamespace=\"http://www.w3.org/2003/12/XQueryX\" \n" +
- " xmlns=\"http://www.w3.org/2003/12/XQueryX\" \n" +
- " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" +
- " elementFormDefault=\"qualified\" \n" +
- " attributeFormDefault=\"qualified\"> \n" +
- " <!-- Kludge for anySimpleType --> \n" +
- " <xsd:simpleType name=\"constantValueType\"> \n" +
- " <xsd:union memberTypes=\"xsd:integer xsd:decimal xsd:string xsd:double\"/> \n" +
- " </xsd:simpleType> \n" +
- " <!-- constant expressions. We have 4 different subclasses for this --> \n" +
- " <xsd:complexType name=\"constantExpr\"> \n" +
- " <xsd:sequence> \n" +
- " <xsd:element name=\"value\" type=\"constantValueType\"/> \n" +
- " </xsd:sequence> \n" +
- " </xsd:complexType> \n" +
- " <xsd:complexType name=\"integerConstantExpr\"> \n" +
- " <xsd:complexContent> \n" +
- " <xsd:restriction base=\"constantExpr\"> \n" +
- " <xsd:sequence> \n" +
- " <xsd:element name=\"value\" type=\"xsd:integer\"/> \n" +
- " </xsd:sequence> \n" +
- " </xsd:restriction> \n" +
- " </xsd:complexContent> \n" +
- " </xsd:complexType>" +
- "<!-- added for element validation -->" +
- "<xsd:element name=\"Kludge\" type=\"integerConstantExpr\" />\n" +
- "</xsd:schema> ";
-
- SchemaTypeLoader stl = makeSchemaTypeLoader(new String[]{reproXsd});
- QName reproQName = new QName("http://www.w3.org/2003/12/XQueryX", "Kludge");
- SchemaGlobalElement elVal = stl.findElement(reproQName);
- assertTrue("Element is null or not found", (elVal != null));
-
- String reproInst = "<Kludge xmlns=\"http://www.w3.org/2003/12/XQueryX\"><value>12</value></Kludge>";
- validateInstance(new String[]{reproXsd}, new String[]{reproInst}, null);
- }
-
- /**
- * [XMLBEANS-68] GDateBuilder outputs empty string when used without time or timezone
- */
- @Test
- public void test_jira_XmlBeans68() throws Exception {
- Calendar cal = Calendar.getInstance();
- GDateBuilder gdateBuilder = new GDateBuilder(cal);
- gdateBuilder.clearTime();
- gdateBuilder.clearTimeZone();
- GDate gdate = gdateBuilder.toGDate();
- TestDatewTZone xdate = TestDatewTZone.Factory.newInstance();
- xdate.setGDateValue(gdate);
- TestElementWithDateAttributeDocument doc =
- TestElementWithDateAttributeDocument.Factory.newInstance();
- TestElementWithDateAttributeDocument.TestElementWithDateAttribute root =
- doc.addNewTestElementWithDateAttribute();
-
- root.xsetSomeDate(xdate);
- System.out.println("Doc: " + doc);
- System.out.println("Date: " + xdate.getStringValue());
-
- if (xdate.getStringValue().compareTo("") == 0 ||
- xdate.getStringValue().length() <= 1)
- throw new Exception("Date without TimeZone should not be empty");
- if (root.getSomeDate().getTimeInMillis() != gdate.getCalendar().getTimeInMillis())
- throw new Exception("Set Dates were not equal");
- }
-
- /**
- * This issue needed an elementFormDefault=qualified added to the schema
- * [XMLBEANS-71] when trying to retrieve data from a XMLBean with Input from a XML Document, we cannot get any data from the Bean.
- */
- @Test
- public void test_jira_XmlBeans71() throws Exception {
- //schema src lives in cases/xbean/xmlobject/xmlbeans_71.xsd
- abc.BazResponseDocument doc = abc.BazResponseDocument.Factory.parse(JarUtil.getResourceFromJarasFile("xbean/misc/jira/xmlbeans_71.xml"), xmOpts);
- xmOpts.setErrorListener(errorList);
- abc.BazResponseDocument.BazResponse baz = doc.getBazResponse();
-
- if (!doc.validate(xmOpts))
- System.out.println("DOC-ERRORS: " + errorList + "\n" + doc.xmlText());
- else
- System.out.println("DOC-XML:\n" + doc.xmlText());
-
- errorList.removeAll(errorList);
- xmOpts.setErrorListener(errorList);
-
- if (!baz.validate(xmOpts))
- System.out.println("BAZ-ERRORS: " + errorList + "\n" + baz.xmlText());
- //throw new Exception("Response Document did not validate\n"+errorList);
- else
- System.out.println("BAZ-XML:\n" + baz.xmlText());
-
- if (baz.getStatus().compareTo("SUCCESS") != 0)
- throw new Exception("Status was not loaded properly");
- else
- System.out.println("Sucess was received correctly");
- }
-
-
- /**
- * [XMLBEANS-72] Document properties are lost
- */
- @Test
- @Ignore
- public void test_jira_XmlBeans72() throws Exception {
- String docTypeName = "struts-config";
- String docTypePublicID = "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN";
- String docTypeSystemID = "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";
- String fileName = "xmlbeans72.xml";
-
- //create instance and set doc properties
- PurchaseOrderDocument po = PurchaseOrderDocument.Factory.newInstance();
- org.apache.xmlbeans.XmlDocumentProperties docProps = po.documentProperties();
- docProps.setDoctypeName(docTypeName);
- docProps.setDoctypePublicId(docTypePublicID);
- docProps.setDoctypeSystemId(docTypeSystemID);
- po.addNewPurchaseOrder();
- po.save(new File(fileName));
-
- //parse saved out file and verify values set above are present
- PurchaseOrderDocument po2 = PurchaseOrderDocument.Factory.parse(new File(fileName));
- //XmlObject po2 = XmlObject.Factory.parse(new File(fileName));
-
- org.apache.xmlbeans.XmlDocumentProperties doc2Props = po2.documentProperties();
-
- //verify information using DOM
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document = builder.parse(new File(fileName));
-
- DocumentType docType = document.getDoctype();
-
- //System.out.println("Name: "+ doc2Props.getDoctypeName() +" = " + docType.getName());
- //System.out.println("System: "+ doc2Props.getDoctypeSystemId() + " = " + docType.getSystemId());
- //System.out.println("Public: "+ doc2Props.getDoctypePublicId()+ " = " + docType.getPublicId());
-
- StringBuilder compareText = new StringBuilder();
- //check values - compare to expected and DOM
- if (doc2Props != null) {
- if (doc2Props.getDoctypeName() == null ||
- doc2Props.getDoctypeName().compareTo(docTypeName) != 0 ||
- doc2Props.getDoctypeName().compareTo(docType.getName()) != 0)
- compareText.append("docTypeName was not as " +
- "expected in the document properties " +
- doc2Props.getDoctypeName()+"\n");
-
- if (doc2Props.getDoctypePublicId() == null ||
- doc2Props.getDoctypePublicId().compareTo(docTypePublicID) != 0 ||
- doc2Props.getDoctypePublicId().compareTo(docType.getPublicId()) != 0)
- compareText.append("docTypePublicID was not as " +
- "expected in the document properties " +
- doc2Props.getDoctypePublicId()+"\n");
-
- if (doc2Props.getDoctypeSystemId() == null ||
- doc2Props.getDoctypeSystemId().compareTo(docTypeSystemID) != 0 ||
- doc2Props.getDoctypeSystemId().compareTo(docType.getSystemId()) != 0)
- compareText.append("docTypeSystemID was not as " +
- "expected in the document properties "+
- doc2Props.getDoctypeSystemId()+"\n" );
- } else {
- compareText.append("Document Properties were null, should have been set");
- }
-
- //cleanup
- po2 = null;
- po = null;
- new File(fileName).deleteOnExit();
-
- if (compareText.toString().length() > 1)
- throw new Exception("Doc properties were not saved or read correctly\n" + compareText.toString());
- }
-
- /**
- * BUGBUG: XMLBEANS-78 - NPE when processing XMLStreamReader Midstream
- * XMLBEANS-78 - NPE when processing XMLStreamReader Midstream
- */
- @Test
- public void test_jira_xmlbeans78() throws Exception {
- XMLInputFactory factory = XMLInputFactory.newInstance();
- FileInputStream fis = new FileInputStream(new File(JIRA_CASES+ "xmlbeans_78.xml"));
- XMLStreamReader reader = factory.createXMLStreamReader(fis);
- skipToBody(reader);
- XmlObject o = XmlObject.Factory.parse(reader);
- }
-
- /**
- * Move reader to element of SOAP Body
- *
- * @param reader
- * @throws javax.xml.stream.XMLStreamException
- *
- */
- private void skipToBody(XMLStreamReader reader) throws javax.xml.stream.XMLStreamException {
- while (true) {
- int event = reader.next();
- switch (event) {
- case XMLStreamReader.END_DOCUMENT:
- return;
- case XMLStreamReader.START_ELEMENT:
- if (reader.getLocalName().equals("Body")) {
- return;
- }
- break;
- default:
- break;
- }
- }
- }
-
- /**
- * Repro case for jira issue
- * XMLBEANS-80 problems in XPath selecting with namespaces and Predicates.
- */
- @Test
- public void test_jira_xmlbeans80() throws Exception {
- String xpathDoc = "<?xml version=\"1.0\"?> \n" +
- "<doc xmlns:ext=\"http://somebody.elses.extension\"> \n" +
- " <ext:a test=\"test\" /> \n" +
- " <b attr1=\"a1\" attr2=\"a2\" \n" +
- " xmlns:java=\"http://xml.apache.org/xslt/java\"> \n" +
- " <a> \n" +
- " </a> \n" +
- " </b> \n" +
- "</doc> ";
- XmlObject xb80 = XmlObject.Factory.parse(xpathDoc);
- // change $this to '.' to avoid XQuery syntax error for $this not being declared
- //XmlObject[] resSet = xb80.selectPath("declare namespace " +
- // "ext='http://somebody.elses.extension'; $this//ext:a[@test='test']");
-
- XmlObject[] resSet = xb80.selectPath("declare namespace " +
- "ext='http://somebody.elses.extension'; .//ext:a[@test='test']");
-
-
- assertEquals(1, resSet.length);
- System.out.println("Result was: " + resSet[0].xmlText());
- }
-
- /**
- * Repro case for jira issue
- * XMLBEANS-81 Cursor selectPath() method not working with predicates
- */
- @Test
- public void test_jira_xmlbeans81() throws Exception {
- String xpathDoc = "<MatchedRecords>" +
- " <MatchedRecord>" +
- " <TableName>" +
- "ABC" +
- "</TableName>" +
- " </MatchedRecord>" +
- " <MatchedRecord>" +
- " <TableName>\n" +
- " BCD \n" +
- " </TableName> \n" +
- " </MatchedRecord> \n" +
- "</MatchedRecords> ";
- XmlObject xb81 = XmlObject.Factory.parse(xpathDoc);
- // change $this to '.' to avoid XQuery syntax error for $this not being declared
- //XmlObject[] resSet = xb81.selectPath("$this//MatchedRecord[TableName=\"ABC\"]/TableName");
- XmlObject[] resSet = xb81.selectPath(".//MatchedRecord[TableName=\"ABC\"]/TableName");
- assertEquals(resSet.length , 1);
- XmlCursor cursor = xb81.newCursor();
- //cursor.selectPath("$this//MatchedRecord[TableName=\"ABC\"]/TableName");
- cursor.selectPath(".//MatchedRecord[TableName=\"ABC\"]/TableName");
- }
-
- /**
- * XMLBeans-84 Cannot run XmlObject.selectPath using Jaxen in multi threaded environment
- */
- @Test
- public void test_jira_XmlBeans84() throws Exception {
- XPathThread[] threads = new XPathThread[15];
-
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new XPathThread();
- System.out.println("Thread[" + i + "]-starting ");
- threads[i].start();
- }
-
- Thread.sleep(6000);
- System.out.println("Done with XPaths?...");
-
- for (int i = 0; i < threads.length; i++) {
- Assert.assertNull(threads[i].getException());
- }
-
- }
-
- /*
- * [XMLBEANS-88]:Cannot compile eBay schema
- */
- @Ignore
- @Test
- public void test_jira_xmlbeans88() throws Exception {
- List errors = new ArrayList();
- Parameters params = new Parameters();
-
- params.setUrlFiles(new URL[]{new URL("http://developer.ebay.com/webservices/latest/eBaySvc.wsdl")});
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
- params.setDownload(true);
-
- // ignore unique particle rule in order to compile this schema
- params.setNoUpa(true);
-
- // runs out of memory..
- params.setMemoryMaximumSize("512m");
-
- try {
- SchemaCompiler.compile(params);
- } catch (java.lang.OutOfMemoryError ome) {
- System.out.println(ome.getCause());
- System.out.println(ome.getMessage());
- System.out.println(ome.getStackTrace());
- fail("test_jira_xmlbeans88(): Out Of Memory Error");
- } catch (Throwable t) {
- t.getMessage();
- System.out.println("Ok Some Exception is caught here");
- }
-
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans88() : Errors found when executing scomp");
- }
- }
-
- /**
- * [XMLBEANS-96]:XmlDocumentProperties missing version and encoding
- */
- @Test
- @Ignore
- public void test_jira_xmlbeans96() throws Exception {
- StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
- xmlstringbuf.append("<test>");
- xmlstringbuf.append("<testchild attr=\"abcd\"> Jira02 </testchild>");
- xmlstringbuf.append("</test>");
-
- XmlObject doc = XmlObject.Factory.parse(xmlstringbuf.toString());
- XmlDocumentProperties props = doc.documentProperties();
- assertEquals("test_jira_xmlbeans96() : Xml Version is not picked up", "1.0", props.getVersion());
- assertEquals("test_jira_xmlbeans96() : Xml Encoding is not picked up", "UTF-8", props.getEncoding());
-
- }
-
- /**
- * [XMLBEANS-98] setSaveSuggestedPrefixes doesn't
- * work for QName attribute values
- */
- @Test
- @Ignore
- public void test_jira_xmlbeans98() throws Exception {
- String outfn = outputroot + "xmlbeans_98.xml";
- String structnamespace = "http://www.orthogony.net/xml/sample/structure";
- String datanamespace = "http://www.orthogony.net/xml/sample/data";
- String schemaloc = "xmlbeans_98.xsd";
- String xsinamespace = "http://www.w3.org/2001/XMLSchema-instance";
-
- File out = new File(outfn);
- XmlOptions options = new XmlOptions();
-
- // associate namespaces with prefixes
- Map prefixes = new HashMap();
- prefixes.put(structnamespace, "s");
- prefixes.put(datanamespace, "d");
- prefixes.put(xsinamespace, "v");
- options.setSaveSuggestedPrefixes(prefixes);
- options.setSavePrettyPrint();
-
- // create a sample document
- ARootDocument doc = ARootDocument.Factory.newInstance();
- ARootDocument.ARoot root = doc.addNewARoot();
- ChildType child = root.addNewAChild();
- // This is where the prefix map should take effect
- child.setQualifiedData(new QName(datanamespace, "IAmQualified"));
-
- // Add a schema location attribute to the doc element
- XmlCursor c = root.newCursor();
- c.toNextToken();
- c.insertAttributeWithValue("schemaLocation", xsinamespace,
- structnamespace + " " + schemaloc);
-
- //String expXML = doc.xmlText(options.setSavePrettyPrint())
- // save as XML text using the options
- //System.out.println("OUT: \n"+doc.xmlText());
- //doc.save(out, options);
- doc.save(out, options);
- XmlObject xObj = XmlObject.Factory.parse(out);
-
- String expXText = "<s:a-root v:schemaLocation=\"http://www.orthogony.net/xml/sample/structure xmlbeans_98.xsd\" xmlns:s=\"http://www.orthogony.net/xml/sample/structure\" xmlns:v=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
- " <s:a-child qualified-data=\"data:IAmQualified\" xmlns:data=\"http://www.orthogony.net/xml/sample/data\"/>\n" +
- "</s:a-root>";
- XmlObject txtXObj = XmlObject.Factory.parse(doc.xmlText());
- System.out.println("xObj: " + xObj.xmlText());
- //NamedNodeMap n = xObj.getDomNode().getAttributes();
- //Assert.assertTrue("Length was not as expected", n.getLength() == 3);
- Node no = xObj.getDomNode();//n.getNamedItem("a-root");
- Assert.assertTrue("Expected Prefix was not present: " + no.getPrefix(), no.getPrefix().compareTo("s") == 0);
- //Assert.assertTrue("s prefix was not found " + no.lookupPrefix(structnamespace), no.lookupPrefix(structnamespace).compareTo("s") == 0);
- //Assert.assertTrue("d prefix was not found " + no.lookupPrefix(datanamespace), no.lookupPrefix(datanamespace).compareTo("s") == 0);
- //Assert.assertTrue("v prefix was not found " + no.lookupPrefix(xsinamespace), no.lookupPrefix(xsinamespace).compareTo("s") == 0);
-
-
- // throw new Exception(out.getCanonicalPath());
-
- }
-
- /**
- * [XMLBEANS-99] NPE/AssertionFailure in newDomNode()
- */
- @Test
- public void test_jira_xmlbeans99_a() throws Exception {
- //typed verification
- DummyDocument doc = DummyDocument.Factory.parse(new File(JIRA_CASES + "xmlbeans_99.xml"));
- org.w3c.dom.Node node = doc.newDomNode();
- System.out.println("node = " + node);
- //UnTyped Verification
- XmlObject xObj = XmlObject.Factory.parse(new File(JIRA_CASES +
- "xmlbeans_99.xml"));
- org.w3c.dom.Node xNode = xObj.newDomNode();
- System.out.println("xNode: " + xNode);
- }
-
- /*
- * [XMLBEANS-99]: NPE/AssertionFailure in newDomNode()
- * refer to [XMLBEANS-14]
- */
- @Test
- public void test_jira_xmlbeans99_b() throws Exception {
- StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?> \n");
- xmlstringbuf.append(" <x:dummy xmlns:x=\"http://dufourrault\" xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" xsi:SchemaLocation=\"dummy.xsd\">\n");
- xmlstringbuf.append(" <x:father>\n");
- xmlstringbuf.append(" <x:son>toto</x:son> \n");
- xmlstringbuf.append(" </x:father>\n");
- xmlstringbuf.append(" </x:dummy>");
-
- try {
- //From empty instance
- DummyDocument newDoc = DummyDocument.Factory.newInstance();
- DummyDocument.Dummy newDummy = newDoc.addNewDummy();
- Node newNode = newDummy.newDomNode();
- System.out.println("New Node = " + newNode);
-
- //set Item
- DummyDocument new2Doc = DummyDocument.Factory.newInstance();
- DummyDocument.Dummy new2Dummy = new2Doc.addNewDummy();
- Father newFather= Father.Factory.newInstance();
- newFather.setSon("son");
- new2Dummy.setFather(newFather);
- Node new2Node = new2Dummy.newDomNode();
- System.out.println("SetFather Node = " + new2Node);
-
- //With Loaded instance Document
- DummyDocument doc = DummyDocument.Factory.parse(xmlstringbuf.toString());
- Node node = doc.newDomNode();
- System.out.println("node = " + node);
- //Just Element Type Node
- dufourrault.DummyDocument.Dummy dummy = doc.addNewDummy();
- Node typeNode = dummy.newDomNode();
- System.out.println("TypeNode = "+typeNode);
-
- dufourrault.Father fatherType = Father.Factory.newInstance();
- fatherType.setSon("son");
- Node fatherTypeNode = fatherType.newDomNode();
- System.out.println("New Father Type Node: "+ fatherTypeNode);
-
- } catch (NullPointerException npe) {
- fail("test_jira_xmlbeans99() : Null Pointer Exception when create Dom Node");
- } catch (Exception e) {
- fail("test_jira_xmlbeans99() : Exception when create Dom Node");
- }
- }
-
-
-
- /**
- * For Testing jira issue 84
- */
- public static class XPathThread extends TestThread
- {
- public XPathThread()
- {
- super();
- }
-
- public void run()
- {
-
- try {
- for (int i = 0; i < ITERATION_COUNT; i++) {
- switch (i % 2) {
- case 0:
- runStatusXPath();
- break;
- case 1:
- runDocXPath();
- break;
- default:
- System.out.println("Val: " + i);
- break;
- }
-
- }
- _result = true;
-
- } catch (Throwable t) {
- _throwable = t;
- t.printStackTrace();
- }
- }
-
- public void runStatusXPath()
- {
- try {
- System.out.println("Testing Status");
- String statusDoc = "<statusreport xmlns=\"http://openuri.org/enumtest\">\n" +
- " <status name=\"first\" target=\"all\">all</status>\n" +
- " <status name=\"second\" target=\"all\">few</status>\n" +
- " <status name=\"third\" target=\"none\">most</status>\n" +
- " <status name=\"first\" target=\"none\">none</status>\n" +
- "</statusreport>";
- XmlObject path = XmlObject.Factory.parse(statusDoc, xm);
- XmlObject[] resSet = path.selectPath("//*:status");
- Assert.assertTrue(resSet.length + "", resSet.length == 4);
- resSet = path.selectPath("//*:status[@name='first']");
- Assert.assertTrue(resSet.length == 2);
-
- } catch (Throwable t) {
- _throwable = t;
- t.printStackTrace();
- }
- }
-
- public void runDocXPath()
- {
- try {
- System.out.println("Testing Doc");
- String docDoc = "<?xml version=\"1.0\"?>\n" +
- "<doc xmlns:ext=\"http://somebody.elses.extension\">\n" +
- " <a test=\"test\" />\n" +
- " <b attr1=\"a1\" attr2=\"a2\" \n" +
- " xmlns:java=\"http://xml.apache.org/xslt/java\">\n" +
- " <a>\n" +
- " </a> \n" +
- " </b>\n" +
- "</doc><!-- --> ";
- XmlObject path = XmlObject.Factory.parse(docDoc, xm);
- XmlObject[] resSet = path.selectPath("//a");
- Assert.assertTrue(resSet.length == 2);
- resSet = path.selectPath("//b[@attr2]");
- Assert.assertTrue(resSet.length == 1);
-
- } catch (Throwable t) {
- _throwable = t;
- t.printStackTrace();
- }
- }
- }
-}
-
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import dufourrault.DummyDocument;
+import dufourrault.Father;
+import misc.common.JiraTestBase;
+import net.orthogony.xml.sample.structure.ARootDocument;
+import net.orthogony.xml.sample.structure.ChildType;
+import org.apache.beehive.netui.tools.testrecorder.x2004.session.RecorderSessionDocument;
+import org.apache.xmlbeans.*;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Node;
+import test.xbean.xmlcursor.purchaseOrder.PurchaseOrderDocument;
+import testDateAttribute.TestDatewTZone;
+import testDateAttribute.TestElementWithDateAttributeDocument;
+import tools.util.JarUtil;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.*;
+
+import static org.junit.Assert.*;
+
+
+public class JiraRegression50_100Test extends JiraTestBase
+{
+
+
+ ///**
+ // * [XMLBEANS-##] <BUG TITLE>
+ // */
+ //public void test_jira_XmlBeans45() throws Exception
+ //{
+ //
+ //}
+
+
+
+
+ /**
+ * [XMLBEANS-52] Validator loops when schema has certain conditions
+ */
+ @Test
+ public void test_jira_XmlBeans52() throws Exception{
+ //reusing code from method test_jira_XmlBeans48()
+ String correctXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
+ "<!--Sample XML file generated by XMLSPY v5 rel. 4 U (http://www.xmlspy.com)--/> \n" +
+ "<aList xmlns=\"http://pfa.dk/dummy/errorInXmlBeansValidation.xsd\" " +
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
+ "xsi:schemaLocation=\"http://pfa.dk/dummy/errorInXmlBeansValidation.xsd \n" +
+ "C:\\pfa\\techr3\\TransformationWorkbench\\schema\\errorInXmlBeansValidation.xsd\"> \n" +
+ "<myListEntry> \n" +
+ "<HelloWorld>Hello World</HelloWorld> \n" +
+ "</myListEntry> \n" +
+ "</aList> ";
+
+
+ }
+
+ /*
+ * [XMLBEANS-54]: problem with default value
+ */
+ @Test
+ public void test_jira_xmlbeans54() throws Exception {
+ List errors = new ArrayList();
+
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_54.xsd_")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+ params.setDownload(true);
+ params.setNoPvr(true);
+
+ // Runs out of Heap Memory
+ params.setMemoryMaximumSize("1024m");
+ params.setMemoryInitialSize("512m");
+
+ try {
+ SchemaCompiler.compile(params);
+ } catch (OutOfMemoryError ome) {
+ System.out.println(ome.getStackTrace());
+ System.out.println("test_jira_xmlbeans54() - out of Heap Memory");
+ }
+
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans54() : Errors found when executing scomp");
+ }
+ }
+
+ /**
+ * [XMLBEANS-56] samples issue with easypo schema and config file
+ */
+ @Test
+ public void test_jira_XmlBeans56() throws Exception {
+ String xsdConfig = "<xb:config " +
+ " xmlns:xb=\"http://xml.apache.org/xmlbeans/2004/02/xbean/config\"\n" +
+ " xmlns:ep=\"http://openuri.org/easypo\">\n" +
+ " <xb:namespace uri=\"http://openuri.org/easypo\">\n" +
+ " <xb:package>com.easypo</xb:package>\n" +
+ " </xb:namespace>\n" +
+ " <xb:namespace uri=\"##any\">\n" +
+ " <xb:prefix>Xml</xb:prefix>\n" +
+ " <xb:suffix>Bean</xb:suffix>\n" +
+ " </xb:namespace>\n" +
+ " <xb:extension for=\"com.easypo.XmlCustomerBean\">\n" +
+ " <xb:interface name=\"myPackage.Foo\">\n" +
+ " <xb:staticHandler>myPackage.FooHandler</xb:staticHandler>\n" +
+ " </xb:interface>\n" +
+ " </xb:extension>\n" +
+ " <xb:qname name=\"ep:purchase-order\" javaname=\"purchaseOrderXXX\"/>\n" +
+ "</xb:config> ";
+ ConfigDocument config =
+ ConfigDocument.Factory.parse(xsdConfig);
+ xmOpts.setErrorListener(errorList);
+ if (config.validate(xmOpts)) {
+ System.out.println("Config Validated");
+ return;
+ } else {
+ System.err.println("Config File did not validate");
+ for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
+ System.out.println("Error: " + iterator.next());
+ }
+ throw new Exception("Config File did not validate");
+ }
+
+ }
+
+ /**
+ * [XMLBEANS-57] scomp failure for XSD namespace "DAV:"
+ */
+ @Test
+ public void test_jira_XmlBeans57() throws Exception {
+ String P = File.separator;
+ String outputDir = OUTPUTROOT + P + "dav";
+
+ File srcDir = new File(outputDir + P + "src");
+ srcDir.mkdirs();
+ File classDir = new File(outputDir + P + "classes");
+ classDir.mkdirs();
+
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(JIRA_CASES + "xmlbeans_57.xml")});
+ params.setErrorListener(errorList);
+ params.setSrcDir(srcDir);
+ params.setClassesDir(classDir);
+ SchemaCompiler.compile(params);
+ Collection errs = params.getErrorListener();
+ boolean outTextPresent = true;
+
+ if (errs.size() != 0) {
+ for (Iterator iterator = errs.iterator(); iterator.hasNext();) {
+ Object o = iterator.next();
+ String out = o.toString();
+ System.out.println("Dav: " + out);
+ if (out.startsWith("Compiled types to"))
+ outTextPresent = false;
+ }
+ }
+
+ //cleanup gen'd dirs
+ srcDir.deleteOnExit();
+ classDir.deleteOnExit();
+
+ if (outTextPresent)
+ System.out.println("No errors when running schemacompiler with DAV namespace");
+ else
+ throw new Exception("There were errors while compiling XSD with DAV " +
+ "namespace. See sys.out for more info");
+ }
+
+ /*
+ * [XMLBEANS-58]:resolving transitive <redefine>'d types...
+ * This is realted to xmlbeans36 - its the same case but the schemas seem to have been updated at the w3c site.
+ * Hence adding a new testcase with the new schemas
+ */
+ @Test
+ @Ignore("the url doesn't exist anymore ...")
+ public void test_jira_xmlbeans58() throws Exception {
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+
+ // old url has been retired
+ //params.setUrlFiles(new URL[]{new URL("http://devresource.hp.com/drc/specifications/wsrf/interfaces/WS-BrokeredNotification-1-0.wsdl")});
+ // this seems to be a url for a WS-BrokeredNotification 1.0 wsdl
+ params.setUrlFiles(new URL[]{new URL("http://www.ibm.com/developerworks/library/specification/ws-notification/WS-BrokeredN.wsdl")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+ params.setDownload(true);
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans55() : Errors found when executing scomp");
+ }
+
+ }
+
+
+ /**
+ * [XMLBEANS-62] Avoid class cast exception when compiling older schema namespace
+ */
+ @Test
+ public void test_jira_XmlBeans62() throws Exception {
+ String P = File.separator;
+ String outputDir = System.getProperty("xbean.rootdir") + P + "build" +
+ P + "test" + P + "output" + P + "x1999";
+
+ File srcDir = new File(outputDir + P + "src");
+ srcDir.mkdirs();
+ File classDir = new File(outputDir + P + "classes");
+ classDir.mkdirs();
+
+ Parameters params = new Parameters();
+ params.setWsdlFiles(new File[]{new File(JIRA_CASES + "xmlbeans_62.xml")});
+ params.setErrorListener(errorList);
+ params.setSrcDir(srcDir);
+ params.setClassesDir(classDir);
+ SchemaCompiler.compile(params);
+ Collection errs = params.getErrorListener();
+ boolean warningPresent = false;
+ for (Iterator iterator = errs.iterator(); iterator.hasNext();) {
+ Object o = iterator.next();
+ String out = o.toString();
+ if (out.endsWith("did not have any schema documents in namespace 'http://www.w3.org/2001/XMLSchema'")) ;
+ warningPresent = true;
+ }
+
+ //cleanup gen'd dirs
+ srcDir.deleteOnExit();
+ classDir.deleteOnExit();
+
+ //validate error present
+ if (!warningPresent)
+ throw new Exception("Warning for 1999 schema was not found when compiling srcs");
+ else
+ System.out.println("Warning Present, test Passed");
+ }
+
+ /**
+ * [XMLBEANS-64] ArrayIndexOutOfBoundsException during validation
+ */
+ @Test
+ public void test_jira_XmlBeans64() throws Exception {
+ // load the document
+ File inst = new File(JIRA_CASES + "xmlbeans_64.xml");
+ XmlObject doc = RecorderSessionDocument.Factory.parse(inst);
+ // validate
+ XmlOptions validateOptions = new XmlOptions();
+ validateOptions.setLoadLineNumbers();
+ ArrayList errorList = new ArrayList();
+ validateOptions.setErrorListener(errorList);
+ boolean isValid = doc.validate(validateOptions);
+
+ if (!isValid)
+ throw new Exception("Errors: " + errorList);
+ }
+
+ /**
+ * [XMLBEANS-66] NullPointerException when restricting a union with one of the union members
+ */
+ @Test
+ public void test_jira_XmlBeans66() throws Exception {
+ String reproXsd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
+ "<xsd:schema targetNamespace=\"http://www.w3.org/2003/12/XQueryX\" \n" +
+ " xmlns=\"http://www.w3.org/2003/12/XQueryX\" \n" +
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" +
+ " elementFormDefault=\"qualified\" \n" +
+ " attributeFormDefault=\"qualified\"> \n" +
+ " <!-- Kludge for anySimpleType --> \n" +
+ " <xsd:simpleType name=\"constantValueType\"> \n" +
+ " <xsd:union memberTypes=\"xsd:integer xsd:decimal xsd:string xsd:double\"/> \n" +
+ " </xsd:simpleType> \n" +
+ " <!-- constant expressions. We have 4 different subclasses for this --> \n" +
+ " <xsd:complexType name=\"constantExpr\"> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name=\"value\" type=\"constantValueType\"/> \n" +
+ " </xsd:sequence> \n" +
+ " </xsd:complexType> \n" +
+ " <xsd:complexType name=\"integerConstantExpr\"> \n" +
+ " <xsd:complexContent> \n" +
+ " <xsd:restriction base=\"constantExpr\"> \n" +
+ " <xsd:sequence> \n" +
+ " <xsd:element name=\"value\" type=\"xsd:integer\"/> \n" +
+ " </xsd:sequence> \n" +
+ " </xsd:restriction> \n" +
+ " </xsd:complexContent> \n" +
+ " </xsd:complexType>" +
+ "<!-- added for element validation -->" +
+ "<xsd:element name=\"Kludge\" type=\"integerConstantExpr\" />\n" +
+ "</xsd:schema> ";
+
+ SchemaTypeLoader stl = makeSchemaTypeLoader(new String[]{reproXsd});
+ QName reproQName = new QName("http://www.w3.org/2003/12/XQueryX", "Kludge");
+ SchemaGlobalElement elVal = stl.findElement(reproQName);
+ assertTrue("Element is null or not found", (elVal != null));
+
+ String reproInst = "<Kludge xmlns=\"http://www.w3.org/2003/12/XQueryX\"><value>12</value></Kludge>";
+ validateInstance(new String[]{reproXsd}, new String[]{reproInst}, null);
+ }
+
+ /**
+ * [XMLBEANS-68] GDateBuilder outputs empty string when used without time or timezone
+ */
+ @Test
+ public void test_jira_XmlBeans68() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ GDateBuilder gdateBuilder = new GDateBuilder(cal);
+ gdateBuilder.clearTime();
+ gdateBuilder.clearTimeZone();
+ GDate gdate = gdateBuilder.toGDate();
+ TestDatewTZone xdate = TestDatewTZone.Factory.newInstance();
+ xdate.setGDateValue(gdate);
+ TestElementWithDateAttributeDocument doc =
+ TestElementWithDateAttributeDocument.Factory.newInstance();
+ TestElementWithDateAttributeDocument.TestElementWithDateAttribute root =
+ doc.addNewTestElementWithDateAttribute();
+
+ root.xsetSomeDate(xdate);
+ System.out.println("Doc: " + doc);
+ System.out.println("Date: " + xdate.getStringValue());
+
+ if (xdate.getStringValue().compareTo("") == 0 ||
+ xdate.getStringValue().length() <= 1)
+ throw new Exception("Date without TimeZone should not be empty");
+ if (root.getSomeDate().getTimeInMillis() != gdate.getCalendar().getTimeInMillis())
+ throw new Exception("Set Dates were not equal");
+ }
+
+ /**
+ * This issue needed an elementFormDefault=qualified added to the schema
+ * [XMLBEANS-71] when trying to retrieve data from a XMLBean with Input from a XML Document, we cannot get any data from the Bean.
+ */
+ @Test
+ public void test_jira_XmlBeans71() throws Exception {
+ //schema src lives in cases/xbean/xmlobject/xmlbeans_71.xsd
+ abc.BazResponseDocument doc = abc.BazResponseDocument.Factory.parse(JarUtil.getResourceFromJarasFile("xbean/misc/jira/xmlbeans_71.xml"), xmOpts);
+ xmOpts.setErrorListener(errorList);
+ abc.BazResponseDocument.BazResponse baz = doc.getBazResponse();
+
+ if (!doc.validate(xmOpts))
+ System.out.println("DOC-ERRORS: " + errorList + "\n" + doc.xmlText());
+ else
+ System.out.println("DOC-XML:\n" + doc.xmlText());
+
+ errorList.removeAll(errorList);
+ xmOpts.setErrorListener(errorList);
+
+ if (!baz.validate(xmOpts))
+ System.out.println("BAZ-ERRORS: " + errorList + "\n" + baz.xmlText());
+ //throw new Exception("Response Document did not validate\n"+errorList);
+ else
+ System.out.println("BAZ-XML:\n" + baz.xmlText());
+
+ if (baz.getStatus().compareTo("SUCCESS") != 0)
+ throw new Exception("Status was not loaded properly");
+ else
+ System.out.println("Sucess was received correctly");
+ }
+
+
+ /**
+ * [XMLBEANS-72] Document properties are lost
+ */
+ @Test
+ @Ignore
+ public void test_jira_XmlBeans72() throws Exception {
+ String docTypeName = "struts-config";
+ String docTypePublicID = "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN";
+ String docTypeSystemID = "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";
+ String fileName = "xmlbeans72.xml";
+
+ //create instance and set doc properties
+ PurchaseOrderDocument po = PurchaseOrderDocument.Factory.newInstance();
+ org.apache.xmlbeans.XmlDocumentProperties docProps = po.documentProperties();
+ docProps.setDoctypeName(docTypeName);
+ docProps.setDoctypePublicId(docTypePublicID);
+ docProps.setDoctypeSystemId(docTypeSystemID);
+ po.addNewPurchaseOrder();
+ po.save(new File(fileName));
+
+ //parse saved out file and verify values set above are present
+ PurchaseOrderDocument po2 = PurchaseOrderDocument.Factory.parse(new File(fileName));
+ //XmlObject po2 = XmlObject.Factory.parse(new File(fileName));
+
+ org.apache.xmlbeans.XmlDocumentProperties doc2Props = po2.documentProperties();
+
+ //verify information using DOM
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(new File(fileName));
+
+ DocumentType docType = document.getDoctype();
+
+ //System.out.println("Name: "+ doc2Props.getDoctypeName() +" = " + docType.getName());
+ //System.out.println("System: "+ doc2Props.getDoctypeSystemId() + " = " + docType.getSystemId());
+ //System.out.println("Public: "+ doc2Props.getDoctypePublicId()+ " = " + docType.getPublicId());
+
+ StringBuilder compareText = new StringBuilder();
+ //check values - compare to expected and DOM
+ if (doc2Props != null) {
+ if (doc2Props.getDoctypeName() == null ||
+ doc2Props.getDoctypeName().compareTo(docTypeName) != 0 ||
+ doc2Props.getDoctypeName().compareTo(docType.getName()) != 0)
+ compareText.append("docTypeName was not as " +
+ "expected in the document properties " +
+ doc2Props.getDoctypeName()+"\n");
+
+ if (doc2Props.getDoctypePublicId() == null ||
+ doc2Props.getDoctypePublicId().compareTo(docTypePublicID) != 0 ||
+ doc2Props.getDoctypePublicId().compareTo(docType.getPublicId()) != 0)
+ compareText.append("docTypePublicID was not as " +
+ "expected in the document properties " +
+ doc2Props.getDoctypePublicId()+"\n");
+
+ if (doc2Props.getDoctypeSystemId() == null ||
+ doc2Props.getDoctypeSystemId().compareTo(docTypeSystemID) != 0 ||
+ doc2Props.getDoctypeSystemId().compareTo(docType.getSystemId()) != 0)
+ compareText.append("docTypeSystemID was not as " +
+ "expected in the document properties "+
+ doc2Props.getDoctypeSystemId()+"\n" );
+ } else {
+ compareText.append("Document Properties were null, should have been set");
+ }
+
+ //cleanup
+ po2 = null;
+ po = null;
+ new File(fileName).deleteOnExit();
+
+ if (compareText.toString().length() > 1)
+ throw new Exception("Doc properties were not saved or read correctly\n" + compareText.toString());
+ }
+
+ /**
+ * BUGBUG: XMLBEANS-78 - NPE when processing XMLStreamReader Midstream
+ * XMLBEANS-78 - NPE when processing XMLStreamReader Midstream
+ */
+ @Test
+ public void test_jira_xmlbeans78() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ FileInputStream fis = new FileInputStream(new File(JIRA_CASES+ "xmlbeans_78.xml"));
+ XMLStreamReader reader = factory.createXMLStreamReader(fis);
+ skipToBody(reader);
+ XmlObject o = XmlObject.Factory.parse(reader);
+ }
+
+ /**
+ * Move reader to element of SOAP Body
+ *
+ * @param reader
+ * @throws javax.xml.stream.XMLStreamException
+ *
+ */
+ private void skipToBody(XMLStreamReader reader) throws javax.xml.stream.XMLStreamException {
+ while (true) {
+ int event = reader.next();
+ switch (event) {
+ case XMLStreamReader.END_DOCUMENT:
+ return;
+ case XMLStreamReader.START_ELEMENT:
+ if (reader.getLocalName().equals("Body")) {
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /**
+ * Repro case for jira issue
+ * XMLBEANS-80 problems in XPath selecting with namespaces and Predicates.
+ */
+ @Test
+ public void test_jira_xmlbeans80() throws Exception {
+ String xpathDoc = "<?xml version=\"1.0\"?> \n" +
+ "<doc xmlns:ext=\"http://somebody.elses.extension\"> \n" +
+ " <ext:a test=\"test\" /> \n" +
+ " <b attr1=\"a1\" attr2=\"a2\" \n" +
+ " xmlns:java=\"http://xml.apache.org/xslt/java\"> \n" +
+ " <a> \n" +
+ " </a> \n" +
+ " </b> \n" +
+ "</doc> ";
+ XmlObject xb80 = XmlObject.Factory.parse(xpathDoc);
+ // change $this to '.' to avoid XQuery syntax error for $this not being declared
+ //XmlObject[] resSet = xb80.selectPath("declare namespace " +
+ // "ext='http://somebody.elses.extension'; $this//ext:a[@test='test']");
+
+ XmlObject[] resSet = xb80.selectPath("declare namespace " +
+ "ext='http://somebody.elses.extension'; .//ext:a[@test='test']");
+
+
+ assertEquals(1, resSet.length);
+ System.out.println("Result was: " + resSet[0].xmlText());
+ }
+
+ /**
+ * Repro case for jira issue
+ * XMLBEANS-81 Cursor selectPath() method not working with predicates
+ */
+ @Test
+ public void test_jira_xmlbeans81() throws Exception {
+ String xpathDoc = "<MatchedRecords>" +
+ " <MatchedRecord>" +
+ " <TableName>" +
+ "ABC" +
+ "</TableName>" +
+ " </MatchedRecord>" +
+ " <MatchedRecord>" +
+ " <TableName>\n" +
+ " BCD \n" +
+ " </TableName> \n" +
+ " </MatchedRecord> \n" +
+ "</MatchedRecords> ";
+ XmlObject xb81 = XmlObject.Factory.parse(xpathDoc);
+ // change $this to '.' to avoid XQuery syntax error for $this not being declared
+ //XmlObject[] resSet = xb81.selectPath("$this//MatchedRecord[TableName=\"ABC\"]/TableName");
+ XmlObject[] resSet = xb81.selectPath(".//MatchedRecord[TableName=\"ABC\"]/TableName");
+ assertEquals(resSet.length , 1);
+ XmlCursor cursor = xb81.newCursor();
+ //cursor.selectPath("$this//MatchedRecord[TableName=\"ABC\"]/TableName");
+ cursor.selectPath(".//MatchedRecord[TableName=\"ABC\"]/TableName");
+ }
+
+ /**
+ * XMLBeans-84 Cannot run XmlObject.selectPath using Jaxen in multi threaded environment
+ */
+ @Test
+ public void test_jira_XmlBeans84() throws Exception {
+ XPathThread[] threads = new XPathThread[15];
+
+ for (int i = 0; i < threads.length; i++) {
+ threads[i] = new XPathThread();
+ System.out.println("Thread[" + i + "]-starting ");
+ threads[i].start();
+ }
+
+ Thread.sleep(6000);
+ System.out.println("Done with XPaths?...");
+
+ for (int i = 0; i < threads.length; i++) {
+ Assert.assertNull(threads[i].getException());
+ }
+
+ }
+
+ /*
+ * [XMLBEANS-88]:Cannot compile eBay schema
+ */
+ @Ignore
+ @Test
+ public void test_jira_xmlbeans88() throws Exception {
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+
+ params.setUrlFiles(new URL[]{new URL("http://developer.ebay.com/webservices/latest/eBaySvc.wsdl")});
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+ params.setDownload(true);
+
+ // ignore unique particle rule in order to compile this schema
+ params.setNoUpa(true);
+
+ // runs out of memory..
+ params.setMemoryMaximumSize("512m");
+
+ try {
+ SchemaCompiler.compile(params);
+ } catch (java.lang.OutOfMemoryError ome) {
+ System.out.println(ome.getCause());
+ System.out.println(ome.getMessage());
+ System.out.println(ome.getStackTrace());
+ fail("test_jira_xmlbeans88(): Out Of Memory Error");
+ } catch (Throwable t) {
+ t.getMessage();
+ System.out.println("Ok Some Exception is caught here");
+ }
+
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans88() : Errors found when executing scomp");
+ }
+ }
+
+ /**
+ * [XMLBEANS-96]:XmlDocumentProperties missing version and encoding
+ */
+ @Test
+ @Ignore
+ public void test_jira_xmlbeans96() throws Exception {
+ StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ xmlstringbuf.append("<test>");
+ xmlstringbuf.append("<testchild attr=\"abcd\"> Jira02 </testchild>");
+ xmlstringbuf.append("</test>");
+
+ XmlObject doc = XmlObject.Factory.parse(xmlstringbuf.toString());
+ XmlDocumentProperties props = doc.documentProperties();
+ assertEquals("test_jira_xmlbeans96() : Xml Version is not picked up", "1.0", props.getVersion());
+ assertEquals("test_jira_xmlbeans96() : Xml Encoding is not picked up", "UTF-8", props.getEncoding());
+
+ }
+
+ /**
+ * [XMLBEANS-98] setSaveSuggestedPrefixes doesn't
+ * work for QName attribute values
+ */
+ @Test
+ @Ignore
+ public void test_jira_xmlbeans98() throws Exception {
+ String outfn = outputroot + "xmlbeans_98.xml";
+ String structnamespace = "http://www.orthogony.net/xml/sample/structure";
+ String datanamespace = "http://www.orthogony.net/xml/sample/data";
+ String schemaloc = "xmlbeans_98.xsd";
+ String xsinamespace = "http://www.w3.org/2001/XMLSchema-instance";
+
+ File out = new File(outfn);
+ XmlOptions options = new XmlOptions();
+
+ // associate namespaces with prefixes
+ Map prefixes = new HashMap();
+ prefixes.put(structnamespace, "s");
+ prefixes.put(datanamespace, "d");
+ prefixes.put(xsinamespace, "v");
+ options.setSaveSuggestedPrefixes(prefixes);
+ options.setSavePrettyPrint();
+
+ // create a sample document
+ ARootDocument doc = ARootDocument.Factory.newInstance();
+ ARootDocument.ARoot root = doc.addNewARoot();
+ ChildType child = root.addNewAChild();
+ // This is where the prefix map should take effect
+ child.setQualifiedData(new QName(datanamespace, "IAmQualified"));
+
+ // Add a schema location attribute to the doc element
+ XmlCursor c = root.newCursor();
+ c.toNextToken();
+ c.insertAttributeWithValue("schemaLocation", xsinamespace,
+ structnamespace + " " + schemaloc);
+
+ //String expXML = doc.xmlText(options.setSavePrettyPrint())
+ // save as XML text using the options
+ //System.out.println("OUT: \n"+doc.xmlText());
+ //doc.save(out, options);
+ doc.save(out, options);
+ XmlObject xObj = XmlObject.Factory.parse(out);
+
+ String expXText = "<s:a-root v:schemaLocation=\"http://www.orthogony.net/xml/sample/structure xmlbeans_98.xsd\" xmlns:s=\"http://www.orthogony.net/xml/sample/structure\" xmlns:v=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
+ " <s:a-child qualified-data=\"data:IAmQualified\" xmlns:data=\"http://www.orthogony.net/xml/sample/data\"/>\n" +
+ "</s:a-root>";
+ XmlObject txtXObj = XmlObject.Factory.parse(doc.xmlText());
+ System.out.println("xObj: " + xObj.xmlText());
+ //NamedNodeMap n = xObj.getDomNode().getAttributes();
+ //Assert.assertTrue("Length was not as expected", n.getLength() == 3);
+ Node no = xObj.getDomNode();//n.getNamedItem("a-root");
+ Assert.assertTrue("Expected Prefix was not present: " + no.getPrefix(), no.getPrefix().compareTo("s") == 0);
+ //Assert.assertTrue("s prefix was not found " + no.lookupPrefix(structnamespace), no.lookupPrefix(structnamespace).compareTo("s") == 0);
+ //Assert.assertTrue("d prefix was not found " + no.lookupPrefix(datanamespace), no.lookupPrefix(datanamespace).compareTo("s") == 0);
+ //Assert.assertTrue("v prefix was not found " + no.lookupPrefix(xsinamespace), no.lookupPrefix(xsinamespace).compareTo("s") == 0);
+
+
+ // throw new Exception(out.getCanonicalPath());
+
+ }
+
+ /**
+ * [XMLBEANS-99] NPE/AssertionFailure in newDomNode()
+ */
+ @Test
+ public void test_jira_xmlbeans99_a() throws Exception {
+ //typed verification
+ DummyDocument doc = DummyDocument.Factory.parse(new File(JIRA_CASES + "xmlbeans_99.xml"));
+ org.w3c.dom.Node node = doc.newDomNode();
+ System.out.println("node = " + node);
+ //UnTyped Verification
+ XmlObject xObj = XmlObject.Factory.parse(new File(JIRA_CASES +
+ "xmlbeans_99.xml"));
+ org.w3c.dom.Node xNode = xObj.newDomNode();
+ System.out.println("xNode: " + xNode);
+ }
+
+ /*
+ * [XMLBEANS-99]: NPE/AssertionFailure in newDomNode()
+ * refer to [XMLBEANS-14]
+ */
+ @Test
+ public void test_jira_xmlbeans99_b() throws Exception {
+ StringBuilder xmlstringbuf = new StringBuilder("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?> \n");
+ xmlstringbuf.append(" <x:dummy xmlns:x=\"http://dufourrault\" xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" xsi:SchemaLocation=\"dummy.xsd\">\n");
+ xmlstringbuf.append(" <x:father>\n");
+ xmlstringbuf.append(" <x:son>toto</x:son> \n");
+ xmlstringbuf.append(" </x:father>\n");
+ xmlstringbuf.append(" </x:dummy>");
+
+ try {
+ //From empty instance
+ DummyDocument newDoc = DummyDocument.Factory.newInstance();
+ DummyDocument.Dummy newDummy = newDoc.addNewDummy();
+ Node newNode = newDummy.newDomNode();
+ System.out.println("New Node = " + newNode);
+
+ //set Item
+ DummyDocument new2Doc = DummyDocument.Factory.newInstance();
+ DummyDocument.Dummy new2Dummy = new2Doc.addNewDummy();
+ Father newFather= Father.Factory.newInstance();
+ newFather.setSon("son");
+ new2Dummy.setFather(newFather);
+ Node new2Node = new2Dummy.newDomNode();
+ System.out.println("SetFather Node = " + new2Node);
+
+ //With Loaded instance Document
+ DummyDocument doc = DummyDocument.Factory.parse(xmlstringbuf.toString());
+ Node node = doc.newDomNode();
+ System.out.println("node = " + node);
+ //Just Element Type Node
+ dufourrault.DummyDocument.Dummy dummy = doc.addNewDummy();
+ Node typeNode = dummy.newDomNode();
+ System.out.println("TypeNode = "+typeNode);
+
+ dufourrault.Father fatherType = Father.Factory.newInstance();
+ fatherType.setSon("son");
+ Node fatherTypeNode = fatherType.newDomNode();
+ System.out.println("New Father Type Node: "+ fatherTypeNode);
+
+ } catch (NullPointerException npe) {
+ fail("test_jira_xmlbeans99() : Null Pointer Exception when create Dom Node");
+ } catch (Exception e) {
+ fail("test_jira_xmlbeans99() : Exception when create Dom Node");
+ }
+ }
+
+
+
+ /**
+ * For Testing jira issue 84
+ */
+ public static class XPathThread extends TestThread
+ {
+ public XPathThread()
+ {
+ super();
+ }
+
+ public void run()
+ {
+
+ try {
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ switch (i % 2) {
+ case 0:
+ runStatusXPath();
+ break;
+ case 1:
+ runDocXPath();
+ break;
+ default:
+ System.out.println("Val: " + i);
+ break;
+ }
+
+ }
+ _result = true;
+
+ } catch (Throwable t) {
+ _throwable = t;
+ t.printStackTrace();
+ }
+ }
+
+ public void runStatusXPath()
+ {
+ try {
+ System.out.println("Testing Status");
+ String statusDoc = "<statusreport xmlns=\"http://openuri.org/enumtest\">\n" +
+ " <status name=\"first\" target=\"all\">all</status>\n" +
+ " <status name=\"second\" target=\"all\">few</status>\n" +
+ " <status name=\"third\" target=\"none\">most</status>\n" +
+ " <status name=\"first\" target=\"none\">none</status>\n" +
+ "</statusreport>";
+ XmlObject path = XmlObject.Factory.parse(statusDoc, xm);
+ XmlObject[] resSet = path.selectPath("//*:status");
+ Assert.assertTrue(resSet.length + "", resSet.length == 4);
+ resSet = path.selectPath("//*:status[@name='first']");
+ Assert.assertTrue(resSet.length == 2);
+
+ } catch (Throwable t) {
+ _throwable = t;
+ t.printStackTrace();
+ }
+ }
+
+ public void runDocXPath()
+ {
+ try {
+ System.out.println("Testing Doc");
+ String docDoc = "<?xml version=\"1.0\"?>\n" +
+ "<doc xmlns:ext=\"http://somebody.elses.extension\">\n" +
+ " <a test=\"test\" />\n" +
+ " <b attr1=\"a1\" attr2=\"a2\" \n" +
+ " xmlns:java=\"http://xml.apache.org/xslt/java\">\n" +
+ " <a>\n" +
+ " </a> \n" +
+ " </b>\n" +
+ "</doc><!-- --> ";
+ XmlObject path = XmlObject.Factory.parse(docDoc, xm);
+ XmlObject[] resSet = path.selectPath("//a");
+ Assert.assertTrue(resSet.length == 2);
+ resSet = path.selectPath("//b[@attr2]");
+ Assert.assertTrue(resSet.length == 1);
+
+ } catch (Throwable t) {
+ _throwable = t;
+ t.printStackTrace();
+ }
+ }
+ }
+}
+
diff --git a/src/test/java/misc/detailed/JiraRegressionSchemaCompilerTest.java b/src/test/java/misc/detailed/JiraRegressionSchemaCompilerTest.java
index 772902d..dfea55f 100644
--- a/src/test/java/misc/detailed/JiraRegressionSchemaCompilerTest.java
+++ b/src/test/java/misc/detailed/JiraRegressionSchemaCompilerTest.java
@@ -1,123 +1,123 @@
-/* Copyright 2006 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import misc.common.JiraTestBase;
-import org.apache.xmlbeans.XmlError;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class JiraRegressionSchemaCompilerTest extends JiraTestBase {
- private List _testCompile(File[] xsdFiles,
- String outputDirName)
- {
- System.out.println(xsdFiles[0].getAbsolutePath());
- List errors = new ArrayList();
- Parameters params = new Parameters();
- params.setXsdFiles(xsdFiles);
- params.setErrorListener(errors);
- params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
- params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
- params.setQuiet(true);
- SchemaCompiler.compile(params);
- return errors;
- }
-
- private boolean findErrMsg(Collection errors, String msg)
- {
- boolean errFound = false;
- if (!errors.isEmpty())
- {
- for (Iterator i = errors.iterator(); i.hasNext();)
- {
- XmlError err = (XmlError) i.next();
- int errSeverity = err.getSeverity();
- if (errSeverity == XmlError.SEVERITY_ERROR)
- {
- if (msg.equals(err.getMessage()))
- errFound = true;
- }
- }
- }
- errors.clear();
- return errFound;
- }
-
- @Test
- public void test_jira_xmlbeans236()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "xmlbeans_236.xsd_") };
- String outputDirName = "xmlbeans_236";
- List errors = _testCompile(xsdFiles, outputDirName);
- if (printOptionErrMsgs(errors))
- {
- fail("test_jira_xmlbeans236(): failure when executing scomp");
- }
- }
-
- @Test
- public void test_jira_xmlbeans239()
- {
- /* complexType with complexContent extending base type with
- simpleContent is valid */
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "xmlbeans_239a.xsd_") };
- String outputDirName = "xmlbeans_239";
- List errors = _testCompile(xsdFiles, outputDirName);
- if (printOptionErrMsgs(errors))
- {
- fail("test_jira_xmlbeans239(): failure when executing scomp");
- }
-
- /* complexType with complexContent extending simpleType is not valid */
- xsdFiles =
- new File[] { new File(scompTestFilesRoot + "xmlbeans_239b.xsd_") };
- errors = _testCompile(xsdFiles, outputDirName);
- String msg = "Type 'dtSTRING@http://www.test.bmecat.org' is being used as the base type for a complexContent definition. To do this the base type must be a complex type.";
- assertTrue(findErrMsg(errors, msg));
-
- /* complexType with complexContent extending base type with
- simpleContent cannot add particles */
- xsdFiles =
- new File[] { new File(scompTestFilesRoot + "xmlbeans_239c.xsd_") };
- errors = _testCompile(xsdFiles, outputDirName);
- msg = "This type extends a base type 'dtMLSTRING@http://www.test.bmecat.org' which has simpleContent. In that case this type cannot add particles.";
- assertTrue(findErrMsg(errors, msg));
- }
-
- @Test
- public void test_jira_xmlbeans251()
- {
- File[] xsdFiles =
- new File[] { new File(scompTestFilesRoot + "xmlbeans_251.xsd_") };
- String outputDirName = "xmlbeans_251";
- List errors = _testCompile(xsdFiles, outputDirName);
- if (printOptionErrMsgs(errors))
- {
- fail("test_jira_xmlbeans251(): failure when executing scomp");
- }
- }
-}
+/* Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import misc.common.JiraTestBase;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class JiraRegressionSchemaCompilerTest extends JiraTestBase {
+ private List _testCompile(File[] xsdFiles,
+ String outputDirName)
+ {
+ System.out.println(xsdFiles[0].getAbsolutePath());
+ List errors = new ArrayList();
+ Parameters params = new Parameters();
+ params.setXsdFiles(xsdFiles);
+ params.setErrorListener(errors);
+ params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
+ params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
+ params.setQuiet(true);
+ SchemaCompiler.compile(params);
+ return errors;
+ }
+
+ private boolean findErrMsg(Collection errors, String msg)
+ {
+ boolean errFound = false;
+ if (!errors.isEmpty())
+ {
+ for (Iterator i = errors.iterator(); i.hasNext();)
+ {
+ XmlError err = (XmlError) i.next();
+ int errSeverity = err.getSeverity();
+ if (errSeverity == XmlError.SEVERITY_ERROR)
+ {
+ if (msg.equals(err.getMessage()))
+ errFound = true;
+ }
+ }
+ }
+ errors.clear();
+ return errFound;
+ }
+
+ @Test
+ public void test_jira_xmlbeans236()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "xmlbeans_236.xsd_") };
+ String outputDirName = "xmlbeans_236";
+ List errors = _testCompile(xsdFiles, outputDirName);
+ if (printOptionErrMsgs(errors))
+ {
+ fail("test_jira_xmlbeans236(): failure when executing scomp");
+ }
+ }
+
+ @Test
+ public void test_jira_xmlbeans239()
+ {
+ /* complexType with complexContent extending base type with
+ simpleContent is valid */
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "xmlbeans_239a.xsd_") };
+ String outputDirName = "xmlbeans_239";
+ List errors = _testCompile(xsdFiles, outputDirName);
+ if (printOptionErrMsgs(errors))
+ {
+ fail("test_jira_xmlbeans239(): failure when executing scomp");
+ }
+
+ /* complexType with complexContent extending simpleType is not valid */
+ xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "xmlbeans_239b.xsd_") };
+ errors = _testCompile(xsdFiles, outputDirName);
+ String msg = "Type 'dtSTRING@http://www.test.bmecat.org' is being used as the base type for a complexContent definition. To do this the base type must be a complex type.";
+ assertTrue(findErrMsg(errors, msg));
+
+ /* complexType with complexContent extending base type with
+ simpleContent cannot add particles */
+ xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "xmlbeans_239c.xsd_") };
+ errors = _testCompile(xsdFiles, outputDirName);
+ msg = "This type extends a base type 'dtMLSTRING@http://www.test.bmecat.org' which has simpleContent. In that case this type cannot add particles.";
+ assertTrue(findErrMsg(errors, msg));
+ }
+
+ @Test
+ public void test_jira_xmlbeans251()
+ {
+ File[] xsdFiles =
+ new File[] { new File(scompTestFilesRoot + "xmlbeans_251.xsd_") };
+ String outputDirName = "xmlbeans_251";
+ List errors = _testCompile(xsdFiles, outputDirName);
+ if (printOptionErrMsgs(errors))
+ {
+ fail("test_jira_xmlbeans251(): failure when executing scomp");
+ }
+ }
+}
diff --git a/src/test/java/misc/detailed/JiraRegressionTest101_150.java b/src/test/java/misc/detailed/JiraRegressionTest101_150.java
index 7d26fae..ad90b1a 100644
--- a/src/test/java/misc/detailed/JiraRegressionTest101_150.java
+++ b/src/test/java/misc/detailed/JiraRegressionTest101_150.java
@@ -1,103 +1,103 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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 misc.detailed;
-
-import misc.common.JiraTestBase;
-import org.apache.xmlbeans.XmlError;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.impl.tool.Parameters;
-import org.apache.xmlbeans.impl.tool.SchemaCompiler;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- *
- */
-public class JiraRegressionTest101_150 extends JiraTestBase
-{
- /**
- * [XMLBEANS-103] XMLBeans - QName thread cache, cause memory leaks
- */
- @Test
- public void test_jira_xmlbeans102a() throws Exception{
- // set the parameters similar to those in the bug
- Parameters params = new Parameters();
- params.setXsdFiles(new File[]{new File(JIRA_CASES + "xmlbeans_102.xsd")});
- params.setOutputJar(new File(outputroot+P+"xmlbeans_102.jar"));
- File outputDir = new File(outputroot + P + "xmlbeans_102");
- outputDir.mkdirs();
- params.setClassesDir(outputDir);
- params.setSrcDir(outputDir);
- // compile schema
- SchemaCompiler.compile(params);
- // check for jar - compilation success
- if(!(new File(outputroot + P + "xmlbeans_102.jar").exists()) )
- throw new Exception("Jar File was not found");
- //cleanup
- deltree(outputroot);
- }
-
- /*
- * [XMLBEANS-102]: scomp - infinite loop during jar for specific xsd and params for netui_config.xsd
- */
- @Test
- public void test_jira_xmlbeans102b() {
- //Assert.fail("test_jira_xmlbeans102: Infinite loop after completion of parsing" );
-
- Parameters params = new Parameters();
- params.setOutputJar(new File(schemaCompOutputDirPath + "jira102.jar"));
- params.setClassesDir(schemaCompClassesDir);
-
- params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_102_netui-config.xsd_")});
- List errors = new ArrayList();
- params.setErrorListener(errors);
- params.setSrcDir(schemaCompSrcDir);
- params.setClassesDir(schemaCompClassesDir);
-
- SchemaCompiler.compile(params);
- if (printOptionErrMsgs(errors)) {
- fail("test_jira_xmlbeans102() : Errors found when executing scomp");
- }
-
- }
-
- /**
- * NPE while initializing a type system w/ a type that extends
- * an a complex type from a different type system
- */
- @Test
- public void test_jira_xmlbeans105() throws Exception {
- //run untyped parse
- XmlObject obj = XmlObject.Factory.parse(new File(JIRA_CASES + "xmlbeans_105.xml"));
-
- //run Typed Parse
- jira.xmlbeans105.ResourceUnknownFaultDocument rud =
- jira.xmlbeans105.ResourceUnknownFaultDocument.Factory.parse(new File(JIRA_CASES + "xmlbeans_105.xml"));
-
- // / we know the instance is invalid
- // make sure the error message is what is expected
- rud.validate(xmOpts);
- assertEquals("More Errors than expected", 1, errorList.size());
- assertEquals("Did not receive the expected error code: " + ((XmlError) errorList.get(0)).getErrorCode(), 0, ((XmlError) errorList.get(0)).getErrorCode().compareToIgnoreCase("cvc-complex-type.2.4a"));
-
- }
-}
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 misc.detailed;
+
+import misc.common.JiraTestBase;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.impl.tool.Parameters;
+import org.apache.xmlbeans.impl.tool.SchemaCompiler;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ *
+ */
+public class JiraRegressionTest101_150 extends JiraTestBase
+{
+ /**
+ * [XMLBEANS-103] XMLBeans - QName thread cache, cause memory leaks
+ */
+ @Test
+ public void test_jira_xmlbeans102a() throws Exception{
+ // set the parameters similar to those in the bug
+ Parameters params = new Parameters();
+ params.setXsdFiles(new File[]{new File(JIRA_CASES + "xmlbeans_102.xsd")});
+ params.setOutputJar(new File(outputroot+P+"xmlbeans_102.jar"));
+ File outputDir = new File(outputroot + P + "xmlbeans_102");
+ outputDir.mkdirs();
+ params.setClassesDir(outputDir);
+ params.setSrcDir(outputDir);
+ // compile schema
+ SchemaCompiler.compile(params);
+ // check for jar - compilation success
+ if(!(new File(outputroot + P + "xmlbeans_102.jar").exists()) )
+ throw new Exception("Jar File was not found");
+ //cleanup
+ deltree(outputroot);
+ }
+
+ /*
+ * [XMLBEANS-102]: scomp - infinite loop during jar for specific xsd and params for netui_config.xsd
+ */
+ @Test
+ public void test_jira_xmlbeans102b() {
+ //Assert.fail("test_jira_xmlbeans102: Infinite loop after completion of parsing" );
+
+ Parameters params = new Parameters();
+ params.setOutputJar(new File(schemaCompOutputDirPath + "jira102.jar"));
+ params.setClassesDir(schemaCompClassesDir);
+
+ params.setXsdFiles(new File[]{new File(scompTestFilesRoot + "xmlbeans_102_netui-config.xsd_")});
+ List errors = new ArrayList();
+ params.setErrorListener(errors);
+ params.setSrcDir(schemaCompSrcDir);
+ params.setClassesDir(schemaCompClassesDir);
+
+ SchemaCompiler.compile(params);
+ if (printOptionErrMsgs(errors)) {
+ fail("test_jira_xmlbeans102() : Errors found when executing scomp");
+ }
+
+ }
+
+ /**
+ * NPE while initializing a type system w/ a type that extends
+ * an a complex type from a different type system
+ */
+ @Test
+ public void test_jira_xmlbeans105() throws Exception {
+ //run untyped parse
+ XmlObject obj = XmlObject.Factory.parse(new File(JIRA_CASES + "xmlbeans_105.xml"));
+
+ //run Typed Parse
+ jira.xmlbeans105.ResourceUnknownFaultDocument rud =
+ jira.xmlbeans105.ResourceUnknownFaultDocument.Factory.parse(new File(JIRA_CASES + "xmlbeans_105.xml"));
+
+ // / we know the instance is invalid
+ // make sure the error message is what is expected
+ rud.validate(xmOpts);
+ assertEquals("More Errors than expected", 1, errorList.size());
+ assertEquals("Did not receive the expected error code: " + ((XmlError) errorList.get(0)).getErrorCode(), 0, ((XmlError) errorList.get(0)).getErrorCode().compareToIgnoreCase("cvc-complex-type.2.4a"));
+
+ }
+}