xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkro...@apache.org
Subject svn commit: r151245 [4/4] - in xmlbeans/trunk/test: cases/xbean/compile/som/ src/compile/scomp/som/ src/compile/scomp/som/checkin/ src/compile/scomp/som/common/ src/compile/scomp/som/detailed/
Date Thu, 03 Feb 2005 23:02:12 GMT
Added: xmlbeans/trunk/test/src/compile/scomp/som/common/SomTestBase.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/compile/scomp/som/common/SomTestBase.java?view=auto&rev=151245
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/som/common/SomTestBase.java (added)
+++ xmlbeans/trunk/test/src/compile/scomp/som/common/SomTestBase.java Thu Feb  3 15:02:05 2005
@@ -0,0 +1,508 @@
+/*   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.
+ */
+/*   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.som.common;
+
+import compile.scomp.common.CompileCommon;
+import compile.scomp.common.CompileTestBase;
+import junit.framework.Assert;
+import org.apache.xmlbeans.*;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author: rbalacha
+ *          January 29th, 2005
+ */
+public class SomTestBase extends CompileTestBase
+{
+    public static String P = File.separator;
+    public static String casesRootDir = CompileCommon.caseroot + P + "xbean" + P + "compile" + P + "som";
+    public static String somOutputRootDir = CompileCommon.outputroot + P + "som";
+    public static long runid;
+    public static PrintWriter outlog = null;
+
+    public SchemaTypeSystem builtin;
+    public List errors;
+    public XmlOptions options;
+
+    public static final String anySimpleType = "anySimpleType";
+    public static final String anyType = "anyType";
+
+    public SomTestBase(String name)
+    {
+        super(name);
+    }
+
+    public static void inspectSOM(SchemaTypeSystem schematypesys,
+                                  int expectedGlobalElems,
+                                  int expectedGlobalAttrs,
+                                  int expectedGlobalTypes,
+                                  int expectedAttrGroups)
+    {
+        // System.outs written to a log file in the build\test\output\som directory, one file per run
+        // ex. SOM_INSPECTION_RESULT_1107129259405.txt
+
+        File outDir = new File(somOutputRootDir);
+        if (!outDir.exists())
+        {
+            outDir.mkdir();
+        }
+
+        // check if file exists already
+        String logFileName = somOutputRootDir + P + "SOM_INSPECTION_RESULT_" + runid + ".txt";
+        File outfile = new File(logFileName);
+        PrintWriter out = null;
+
+        try
+        {
+            // if file exists for this run, append to it
+            if (outfile.exists())
+            {
+                out = new PrintWriter(new FileWriter(outfile, true));
+            }
+            else
+            {
+                if (outfile.createNewFile())
+                {
+                    out = new PrintWriter(new FileWriter(outfile));
+                }
+            }
+
+            out.println("\n Call to inspectPSOM .. .. .. ..");
+            out.println("\n\n =======================================================");
+            out.println("Now Inspecting SOM for STS : " + schematypesys.getName());
+            out.println("=======================================================");
+            out.println("Input Params : #elems (" + expectedGlobalElems + "), #attr (" + expectedGlobalAttrs
+                    + "), #types (" + expectedGlobalTypes + "), #attr groups (" + expectedAttrGroups + ")");
+            out.println("-------------------------------------------------------");
+
+            // walk thro the SOM here
+            out.println("----- Loader Name      :" + schematypesys.getName());
+
+            // # of global attributes
+            out.println("----- # Global Attributes :" + schematypesys.globalAttributes().length);
+            Assert.assertEquals("Incorrect Number of Global Attributes in STS " + schematypesys.getName(), expectedGlobalAttrs, schematypesys.globalAttributes().length);
+            for (int i = 0; i < schematypesys.globalAttributes().length; i++)
+            {
+                out.println("\t------> Attr Name  :" + schematypesys.globalAttributes()[i].getName());
+                out.println("\t------> Attr Type  :" + schematypesys.globalAttributes()[i].getType());
+            }
+
+            // # of global elements
+            out.println("----- # Global Elements :" + schematypesys.globalElements().length);
+            Assert.assertEquals("Incorrect Number of Global Elements in STS " + schematypesys.getName(), expectedGlobalElems, schematypesys.globalElements().length);
+            for (int i = 0; i < schematypesys.globalElements().length; i++)
+            {
+                out.println("\t------> Elem Name :" + schematypesys.globalElements()[i].getName());
+                out.println("\t------> Elem Type :" + schematypesys.globalElements()[i].getType());
+            }
+
+            // # of global Types
+            out.println("----- # Global Types :" + schematypesys.globalTypes().length);
+            Assert.assertEquals("Incorrect Number of Global Types in STS " + schematypesys.getName(), expectedGlobalTypes, schematypesys.globalTypes().length);
+            for (int i = 0; i < schematypesys.globalTypes().length; i++)
+            {
+                out.println("\t------> TypeName:" + schematypesys.globalTypes()[i].getName());
+            }
+
+            // # of attribute Groups
+            out.println("----- # of Attribute Groups :" + schematypesys.attributeGroups().length);
+            Assert.assertEquals("Incorrect Number of Attribute Groups in STS " + schematypesys.getName(), expectedAttrGroups, schematypesys.attributeGroups().length);
+            for (int i = 0; i < schematypesys.attributeGroups().length; i++)
+            {
+                out.println("\t------> Attr Group Name :" + schematypesys.attributeGroups()[i].getName());
+                out.println("\t------> Attr STS   :" + schematypesys.attributeGroups()[i].getTypeSystem());
+            }
+
+            out.println("----- # of Model Groups :" + schematypesys.modelGroups().length);
+            Assert.assertNotNull("Invalid Model Groups Collection returned in STS " + schematypesys.documentTypes());
+            for (int i = 0; i < schematypesys.modelGroups().length; i++)
+            {
+                out.println("\t------> Model Group Name:" + schematypesys.modelGroups()[i].getName());
+                out.println("\t------> Model Group STS :" + schematypesys.modelGroups()[i].getTypeSystem());
+            }
+
+            out.println("----- # of Schema Annotations :" + schematypesys.annotations().length);
+            Assert.assertNotNull("Invalid Annotations Collection returned in STS " + schematypesys.annotations());
+
+            out.println("----- # of Attribute Types :" + schematypesys.attributeTypes().length);
+            Assert.assertNotNull("Invalid Attribute Types Collection returned in STS " + schematypesys.attributeTypes());
+
+            for (int i = 0; i < schematypesys.attributeTypes().length; i++)
+            {
+                out.println("\t------> Attr Type Name :" + schematypesys.attributeTypes()[i].getName());
+                out.println("\t------> Attr STS :" + schematypesys.attributeTypes()[i].getTypeSystem());
+            }
+
+            out.println("----- # of Document Types :" + schematypesys.documentTypes().length);
+            Assert.assertNotNull("Invalid Document Types Collection returned in STS " + schematypesys.documentTypes());
+            for (int i = 0; i < schematypesys.documentTypes().length; i++)
+            {
+                out.println("\t------> Doc Type Name :" + schematypesys.documentTypes()[i].getName());
+                out.println("\t------> Doc Type STS  :" + schematypesys.documentTypes()[i].getTypeSystem());
+            }
+
+            // walk through the Schema Types of this STS in detail
+            out.println("\t=======================================================");
+            out.println("\tWalking thro Global Schema TYpes for STS : " + schematypesys.getName());
+            out.println("\t=======================================================");
+            SchemaType[] schematypes = schematypesys.globalTypes();
+            for (int i = 0; i < schematypes.length; i++)
+            {
+                SchemaType schema = schematypes[i];
+
+                out.println("\n\t Schema Type :" + schema.getName());
+                out.println("\t=======================================================");
+
+                out.println("\t----Acessing New Schema Type ......");
+                if (schema.isCompiled())
+                {
+                    out.println("\t----This Schema has been successfully compiled");
+                }
+                else
+                {
+                    out.println("\t----This Schema has NOT compiled successfully yet");
+                }
+
+                out.println("\t----Content Type: " + schema.getContentType());
+                out.println("\t----Name: " + schema.getName());
+                out.println("\t----Doc Elem Name : " + schema.getDocumentElementName());
+                out.println("\t----Annotation (class) : " + schema.getAnnotation());
+                out.println("\t----Java Name : " + schema.getFullJavaName());
+                out.println("\t----Java Imp Name : " + schema.getFullJavaImplName());
+                out.println("\t----Java Class Name : " + schema.getJavaClass());
+                out.println("\t----XSD src File Name : " + schema.getSourceName());
+
+
+                // get Elements and Attributes
+                out.println("\t Elements & Attributes for Schema Type :" + schema.getName());
+                out.println("\t=======================================================");
+                SchemaProperty[] spropsArr = schema.getProperties();
+                for (int j = 0; j < spropsArr.length; j++)
+                {
+                    SchemaProperty schemaProperty = spropsArr[j];
+                    out.println("\t:::-> Each prop name : " + schemaProperty.getName());
+                }
+                out.println("\t=======================================================");
+
+                // other api's to look for
+                SchemaProperty[] sderviedpropArr = schema.getDerivedProperties();
+                for (int j = 0; j < sderviedpropArr.length; j++)
+                {
+                    SchemaProperty schemaProperty = sderviedpropArr[j];
+                    out.println("\t+++-> Each derived prop name : " + schemaProperty.getName());
+                }
+
+                // TODO anonymus types - complete this
+                //schema.getAnonymousTypes();
+
+            }
+            out.println("-------------------------------------------------------");
+
+            out.println("Output for SchemaTypeSystem " + schematypesys.getName());
+            out.close();
+
+        } // end of try
+        catch (IOException ioe)
+        {
+            System.out.println(ioe.getMessage());
+            ioe.printStackTrace();
+        }
+
+
+    }
+
+    public boolean lookForAttributeInSTS(SchemaTypeSystem tgtSTS,
+                                         String sAttrLocalName)
+    {
+        // The QName for the find is constructed using the local name since the schemas have no namespace
+        SchemaGlobalAttribute sga = tgtSTS.findAttribute(new QName(sAttrLocalName));
+        if(sga == null)
+            return false;
+        else
+            return true;
+    }
+
+    public boolean lookForElemInSTS(SchemaTypeSystem tgtSTS,
+                                    String sElemLocalName)
+    {
+        // The QName for the find is constructed using the local name since the schemas have no namespace
+        SchemaGlobalElement sge = tgtSTS.findElement(new QName(sElemLocalName));
+
+        if(sge == null)
+            return false;
+        else
+            return true;
+    }
+
+    public boolean lookForIdentityConstraint(SchemaTypeSystem sts,
+                                             String ConstraintLocalName)
+    {
+
+        SchemaIdentityConstraint.Ref ref = sts.findIdentityConstraintRef(new QName(ConstraintLocalName));
+        Assert.assertNotNull(ref);
+
+        return false;
+    }
+
+    public boolean checkPSOMSave(SchemaTypeSystem tgtSTS)
+    {
+        String outDirName = tgtSTS.getName().split("schema.system.")[1];
+        String outDirNameWithPath = somOutputRootDir + P + runid + P + outDirName;
+
+        // call the save
+        try
+        {
+            tgtSTS.saveToDirectory(new File(outDirNameWithPath));
+        }
+        catch (IllegalStateException ise)
+        {
+            return false;
+        }
+        return true;
+
+    }
+
+    public boolean printRecoveredErrors()
+    {
+        // check list of errors and print them
+        if (!errors.isEmpty())
+        {
+            System.out.println("Schema invalid: partial schema type system recovered");
+            for (Iterator i = errors.iterator(); i.hasNext();)
+            {
+                System.out.println("Err Msg (s): " + i.next());
+            }
+            errors.clear();
+            return true;
+        }
+        return false;
+    }
+
+    public boolean validateInstance(File instancefile,
+                                    SchemaTypeSystem sts)
+    {
+        try
+        {
+            XmlObject instancedoc = sts.parse(instancefile, null, null);
+
+            XmlOptions instanceValOptions = new XmlOptions();
+            ArrayList errList = new ArrayList();
+            instanceValOptions.setErrorListener(errList);
+
+            if (!instancedoc.validate(instanceValOptions))
+            {
+                if (!errList.isEmpty())
+                {
+                    for (Iterator it = errList.iterator(); it.hasNext();)
+                    {
+                        System.out.println("Instance Validation Error(s) : " + it.next());
+                    }
+                }
+                //Assert.fail("Validation against instance failed");
+                return false;
+            }
+        }
+        catch (IOException ioe)
+        {
+            ioe.getMessage();
+            ioe.printStackTrace();
+            Assert.fail("IOException throw when accessing instance xml file " + instancefile.getAbsoluteFile());
+        }
+        catch (XmlException xme)
+        {
+            System.out.println("Instance Validation Errors .. .. ..");
+            if (xme.getErrors().isEmpty())
+            {
+                System.out.println(xme.getMessage());
+            }
+            else
+            {
+                for (Iterator itr = xme.getErrors().iterator(); itr.hasNext();)
+                {
+                    System.out.println(itr.next());
+                }
+            }
+            System.out.println("END Instance Validation Errors .. .. ..");
+            Assert.fail("Instance Validation - Xml Exception caught");
+        }
+
+        // validation successful
+        return true;
+
+    }
+
+    public File getTestCaseFile(String sFileName)
+    {
+        String sFileWithPath = casesRootDir + P + sFileName;
+        System.out.println("getTestCaseFile() Opening File : " + sFileWithPath);
+        File schemaFile = new File(sFileWithPath);
+        Assert.assertNotNull("Schema File " + sFileWithPath + " Loading failed", schemaFile);
+        return (schemaFile);
+    }
+
+    // returns the Local Part of the type QName for the specified Elem
+    public String getElementType(SchemaTypeSystem sts,
+                                 String sElementLocalName)
+    {
+
+        for (int i = 0; i < sts.globalElements().length; i++)
+        {
+            //System.out.println("comparing getname, input-> " + sts.globalElements()[i].getName().getLocalPart() + ":" + sElementLocalName);
+            if (sts.globalElements()[i].getName().getLocalPart().equals(sElementLocalName))
+            {
+                System.out.println("getElementType() returning " + sts.globalElements()[i].getType().getName().getLocalPart());
+                return sts.globalElements()[i].getType().getName().getLocalPart();
+            }
+        }
+        return "ElemNotFound";
+        //TODO : change this to findElement
+    }
+
+    public String getAttributeGroup(SchemaTypeSystem sts,
+                                    String sAttrGrpLocalName)
+    {
+        for (int i = 0; i < sts.attributeGroups().length; i++)
+        {
+            //System.out.println("comparing getname, input-> " + sts.attributeGroups()[i].getName().getLocalPart() + ":" + sAttrGrpLocalName);
+            if (sts.attributeGroups()[i].getName().getLocalPart().equals(sAttrGrpLocalName))
+            {
+                System.out.println("getElementType() returning " + sts.attributeGroups()[i].getName().getLocalPart());
+                return sts.attributeGroups()[i].getName().getLocalPart();
+            }
+        }
+        return "AttributeGrpNotFound";
+        //TODO : change this to findAttributeGroup
+    }
+
+
+    public SchemaTypeSystem createNewSTS(String xsdFileName,
+                                         SchemaTypeSystem baseSchema,
+                                         String sSTSName, String sBaseSourceName)
+    {
+        SchemaTypeSystem returnSTS = null;
+        try
+        {
+            File xsdModified = getTestCaseFile(xsdFileName);
+            XmlObject xsdModifiedObj = XmlObject.Factory.parse(xsdModified);
+            System.out.println("xsdModSRCName: "+xsdModifiedObj.documentProperties().getSourceName());
+            xsdModifiedObj.documentProperties().setSourceName(sBaseSourceName);
+            Assert.assertNotNull("Xml Object creation failed", xsdModifiedObj);
+            XmlObject[] xobjArr = new XmlObject[]{xsdModifiedObj};
+
+            returnSTS = XmlBeans.compileXmlBeans(sSTSName, baseSchema, xobjArr, null, builtin, null, options);
+            Assert.assertNotNull("Schema Type System created is Null.", returnSTS);
+
+            // validate the XmlObject created
+            Assert.assertTrue("Return Value for Validate()", xsdModifiedObj.validate());
+        }
+        catch (XmlException xme)
+        {
+            // even if using "COMPILE_PARTIAL_TYPESYSTEM", compilation will fail if
+            // there are any non-recoverable errors and an XmlException will be thrown
+            System.out.println("Schema invalid, XML Exception thrown : couldn't recover from errors");
+            if (errors.isEmpty())
+            {
+                System.out.println(xme.getMessage());
+            }
+            else
+            {
+                for (Iterator i = errors.iterator(); i.hasNext();)
+                {
+                    System.out.println(i.next());
+                }
+            }
+            fail("Schema invalid, XML Exception thrown : couldn't recover from errors");
+        }
+        catch (IOException ioe)
+        {
+            ioe.getMessage();
+            ioe.printStackTrace();
+        }
+        finally
+        {
+            //printRecoveredErrors();
+            return returnSTS;
+        }
+    }
+
+    // deletes contents of specified directory, does not delete the specified directory
+    public void deleteDirRecursive(File dirToClean)
+    {
+        if (dirToClean.exists() && dirToClean.isDirectory())
+        {
+            File filesFound [] = dirToClean.listFiles();
+            for (int i = 0; i < filesFound.length; i++)
+            {
+                if (filesFound[i].isDirectory())
+                {
+                    deleteDirRecursive(filesFound[i]);
+                    Assert.assertTrue("Output Directory " + filesFound[i] + " Deletion Failed ", filesFound[i].delete());
+                }
+                else if (filesFound[i].isFile())
+                {
+                    Assert.assertTrue("Output File " + filesFound[i] + " Deletion Failed ", filesFound[i].delete());
+                }
+            }
+        }
+
+    }
+
+    public void createRunLogFile()
+    {
+        File logfile = new File(somOutputRootDir + P + "PartialSOMCheckinTest_Run_" + runid + ".log");
+
+
+        try
+        {
+            // if file exists for this run, append to it
+            if (logfile.exists())
+            {
+                outlog = new PrintWriter(new FileWriter(logfile, true));
+            }
+            else
+            {
+                outlog = new PrintWriter(new FileWriter(logfile));
+            }
+        }
+        catch (IOException ioe)
+        {
+            ioe.printStackTrace();
+        }
+    }
+
+
+}

Added: xmlbeans/trunk/test/src/compile/scomp/som/detailed/PartialSOMDetailedTest.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/compile/scomp/som/detailed/PartialSOMDetailedTest.java?view=auto&rev=151245
==============================================================================
--- xmlbeans/trunk/test/src/compile/scomp/som/detailed/PartialSOMDetailedTest.java (added)
+++ xmlbeans/trunk/test/src/compile/scomp/som/detailed/PartialSOMDetailedTest.java Thu Feb  3 15:02:05 2005
@@ -0,0 +1,627 @@
+/*   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.som.detailed;
+
+import compile.scomp.som.common.SomTestBase;
+import junit.framework.Assert;
+import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlOptions;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Date;
+
+
+/**
+ * @author: rbalacha
+ *          January 29th, 2005
+ */
+public class PartialSOMDetailedTest extends SomTestBase
+{
+
+    public PartialSOMDetailedTest(String name)
+    {
+        super(name);
+    }
+
+    // inherited methods
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        // initialize the built in schema type
+        builtin = XmlBeans.getBuiltinTypeSystem();
+
+        // populate the XmlOptions
+        if (errors== null) {
+            errors = new ArrayList();
+        }
+        if (options == null) {
+            options = (new XmlOptions()).setErrorListener(errors);
+            options.setCompileDownloadUrls();
+            options.put("COMPILE_PARTIAL_TYPESYSTEM");
+            options.setLoadLineNumbers();
+        }
+
+        // initialize the runid to be used for generating output files for the PSOM walk thro's
+        runid = new Date().getTime();
+
+        // clean the output from the previous run
+        // delete directories created by checkPSOMSave() and output text file created by inspectPSOM()
+        deleteDirRecursive(new File(somOutputRootDir));
+    }
+
+    public void tearDown() throws Exception
+    {
+        errors.clear();
+        super.tearDown();
+    }
+
+    // TODO: all of add/del/modify
+    public void testAddDataTypesList() throws Exception
+    {
+        System.out.println("Inside test case testAddDataTypesList()");
+
+        // Step 1 : create a PSOM from an incomplete/invalid xsd (datatypes.xsd) with unresolved references to various types
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("datatypes.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // recovearble errors should exist
+        Assert.assertTrue("No Recovered Errors for Invalid Schema",
+                printRecoveredErrors());
+
+        // Walk thro the SOM (pass #Elems, #Attr, #Types, #AttrGroups)
+        inspectSOM(baseSTS, 12, 1, 4, 1);
+
+        // Test for saving of the PSOM - should not be able to save
+        Assert.assertFalse("Partial SOM " + baseSTS.getName() + "Save successful - should fail!",
+                checkPSOMSave(baseSTS));
+
+        // instance validation - should fail
+        Assert.assertFalse("Validation against instance Success - should fail ",
+                validateInstance(getTestCaseFile("instance_datatypes_valid.xml"), baseSTS));
+
+        // validate unresolved types - the ListType should resolve to 'anySimpleType'
+        Assert.assertEquals("Unresolved List Type should be 'anySimpleType'",
+                anySimpleType,
+                getElementType(baseSTS, "testListTypeElem"));
+    }
+
+    public void testDeleteReusableGroups() throws Exception
+    {
+        System.out.println("Inside test case testDeleteSubstitutionGroups()");
+
+        // Step 1: read in a clean XSD groups_added.xsd
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("groups_added.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 7, 0, 5, 2);
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertTrue("SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), baseSTS));
+
+        // verify named model groups
+        Assert.assertEquals("Elem Type  should be 'ModelGrpType'",
+                "ModelGrpType",
+                getElementType(baseSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'AttributeGroup'",
+                "AttributeGroup",
+                getAttributeGroup(baseSTS, "AttributeGroup"));
+
+        // step2: load an invalid PSOM by deleting the ModelGroup and AttributeGroup definitions commented
+        SchemaTypeSystem modifiedSTS = createNewSTS("reusable_grps.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // Recovered Errors, Test for saving of the SOM
+        Assert.assertFalse("SOM " + modifiedSTS.getName() + "Save Success - should fail!",
+                checkPSOMSave(modifiedSTS));
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(modifiedSTS, 7, 0, 4, 1);
+
+        // instance validation - should fail
+        Assert.assertFalse("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), modifiedSTS));
+
+        // named model groups
+        Assert.assertEquals("Elem Type  should be 'anyType'",
+                anyType,
+                getElementType(modifiedSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'anyType'",
+                anyType,
+                getAttributeGroup(modifiedSTS, "AttributeGroup"));
+
+        // step 3: create a PSOM with the original xsd
+        SchemaTypeSystem finalSTS = createNewSTS("groups_added.xsd",
+                modifiedSTS,
+                "FinalSchemaTS", sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", finalSTS);
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertTrue("SOM " + finalSTS.getName() + "Save failed!",
+                checkPSOMSave(finalSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), finalSTS));
+
+        // verify named model groups types
+        Assert.assertEquals("Elem Type  should be 'ModelGrpType'",
+                "ModelGrpType",
+                getElementType(baseSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'AttributeGroup'",
+                "AttributeGroup",
+                getAttributeGroup(baseSTS, "AttributeGroup"));
+
+        // TODO compare this to the original schema here
+    }
+
+    public void testModifyDataTypesList() throws Exception
+    {
+        System.out.println("Inside test case testModifyDataTypes()");
+
+        // 1. remove one of the constituent types for the union and test to see if union is anySimpleType
+
+        // Step 1: read in a clean XSD datatypes_added.xsd, to create a base schema with no unresolved components
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("datatypes_added.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 13, 1, 15, 1);
+
+        // Recovered Errors, Test for saving of the SOM - should go thro
+        Assert.assertTrue("SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_datatypes_valid.xml"), baseSTS));
+
+        // check types before modify
+        Assert.assertEquals("Unresolved Simple Type should be 'attachmentTypes'",
+                "attachmentTypes",
+                getElementType(baseSTS, "testAtomicTypeElem"));
+        Assert.assertEquals("Unresolved List Type should be 'attchmentExtensionListTypes'",
+                "attchmentExtensionListTypes",
+                getElementType(baseSTS, "testListTypeElem"));
+        Assert.assertEquals("Unresolved Simple Type should be 'union.attachmentUnionType",
+                "union.attachmentUnionType",
+                getElementType(baseSTS, "testUnionTypeElem"));
+
+
+        //Step 2 : modify types from the schema - should result in STS with unresolved refs
+        SchemaTypeSystem modifiedSTS = createNewSTS("datatypes_modified.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // test the PSOM created :walk thro the PSOM, look for # of elements,attributes,types & attribute groups
+        inspectSOM(modifiedSTS, 13, 1, 13, 1);
+
+        // Test for saving of the PSOM - should not be able to save
+        Assert.assertFalse("PSOM " + modifiedSTS.getName() + " Save should fail",
+                checkPSOMSave(modifiedSTS));
+
+        // validate unresolved types
+        Assert.assertEquals("Unresolved Simple Type - Atomic should be 'anyType'",
+                anyType,
+                getElementType(modifiedSTS, "testAtomicTypeElem"));
+        Assert.assertEquals("Unresolved List Type should be 'anySimpleType'",
+                anySimpleType,
+                getElementType(modifiedSTS, "testListTypeElem"));
+        Assert.assertEquals("Unresolved Simple Type - Union should be 'anySimpleType'",
+                anySimpleType,
+                getElementType(modifiedSTS, "testUnionTypeElem"));
+
+        // validate against an xml valid instance - should fail
+        Assert.assertFalse("Validation against instance should Failed ",
+                validateInstance(getTestCaseFile("instance_simple_types_valid.xml"), modifiedSTS));
+
+        // step 3: reload the original STS
+        SchemaTypeSystem finalSTS = createNewSTS("datatypes_added.xsd",
+                modifiedSTS,
+                "FinalSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", finalSTS);
+
+        // walk the SOM
+        inspectSOM(finalSTS, 13, 1, 15, 1);
+
+        // validate successful save
+        Assert.assertTrue("SOM " + finalSTS.getName() + "Save failed",
+                checkPSOMSave(finalSTS)); // should be able to save as its a valid SOM
+
+        // validate instance - should validate
+        Assert.assertTrue("Validation against instance Failed ",
+                validateInstance(getTestCaseFile("instance_simple_types_valid.xml"), finalSTS));
+
+        // check types after modify
+        Assert.assertEquals("Unresolved Simple Type should be 'attachmentTypes'",
+                "attachmentTypes",
+                getElementType(finalSTS, "testAtomicTypeElem"));
+        Assert.assertEquals("Unresolved List Type should be 'attchmentExtensionListTypes'",
+                "attchmentExtensionListTypes",
+                getElementType(finalSTS, "testListTypeElem"));
+        Assert.assertEquals("Unresolved Simple Type should be 'union.attachmentUnionType",
+                "union.attachmentUnionType",
+                getElementType(finalSTS, "testUnionTypeElem"));
+
+        // TODO compare this to the original schema here
+    }
+
+    public void testDeleteDerivedTypes() throws Exception
+    {
+        System.out.println("Inside test case testDeleteDerivedTypes()");
+
+        // Step 1: read in a clean XSD derived_types_added.xsd with base and derived types to create a base schema with no unresolved components
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("derived_types_added.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 13, 0, 14, 0);
+
+        // Recovered Errors, Test for saving of the SOM - should go thro
+        Assert.assertTrue("Valid SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_derived_types_valid.xml"), baseSTS));
+
+        // check types before deletion of base types
+        Assert.assertEquals("Elem Type  should be 'RestrictionSimpleContentBaseType'",
+                "RestrictionSimpleContentBaseType", getElementType(baseSTS, "RestrictionSimpleContentBaseTypeElem"));
+
+        // Step 2: create invalid PSOM with base type removed
+        SchemaTypeSystem modifiedSTS = createNewSTS("derived_types.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // recovearble errors
+        Assert.assertTrue("No Recovered Errors for Invalid PSOM",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(modifiedSTS, 13, 0, 9, 0);
+
+        // Recovered Errors, Test for saving of the SOM
+        Assert.assertEquals("SOM " + modifiedSTS.getName() + "Save Success - should fail!",
+                false, checkPSOMSave(modifiedSTS));
+
+        // instance validation - should fail
+        Assert.assertFalse("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_derived_types_valid.xml"), modifiedSTS));
+
+        // check types - base should be 'anyType'
+        // Restriction Simple Content Base type commented does not result in recoverable SOM
+        Assert.assertEquals("Elem Type  should be 'anyType'",
+                anyType,
+                getElementType(modifiedSTS, "RestrictionSimpleContentBaseTypeElem"));
+
+
+    }
+
+    public void testModifyReusableGroups() throws Exception
+    {
+        System.out.println("Inside test case testModifyReusableGroups()");
+
+        // Step 1: read in a clean XSD groups_added.xsd
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("groups_added.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 7, 0, 5, 2);
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertEquals("SOM " + baseSTS.getName() + "Save failed!", true, checkPSOMSave(baseSTS));
+
+        // instance validation - should be ok
+        Assert.assertEquals("Validation against instance failed", true, validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), baseSTS));
+
+        // verify named model groups
+        Assert.assertEquals("Elem Type  should be 'ModelGrpType'", "ModelGrpType",
+                getElementType(baseSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'AttributeGroup'", "AttributeGroup",
+                getAttributeGroup(baseSTS, "AttributeGroup"));
+
+        // step2: load a modified xsd with type of head elem in subs grp changed
+        SchemaTypeSystem modifiedSTS = createNewSTS("reusable_grps_modified.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // Recovered Errors, Test for saving of the SOM    - still a valid PSOM
+        Assert.assertTrue("SOM " + modifiedSTS.getName() + "Save Success - should fail!",
+                checkPSOMSave(modifiedSTS));
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(modifiedSTS, 7, 0, 5, 2);
+
+        // instance validation - should fail
+        Assert.assertFalse("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), modifiedSTS));
+
+        // verify named model groups
+        Assert.assertEquals("Elem Type  should be 'ModelGrpType'",
+                "ModelGrpType",
+                getElementType(modifiedSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'AttributeGroup'",
+                "AttributeGroup",
+                getAttributeGroup(modifiedSTS, "AttributeGroup"));
+
+        // step3 : reload the original xsd
+        SchemaTypeSystem finalSTS = createNewSTS("groups_added.xsd",
+                modifiedSTS,
+                "FinalSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", finalSTS);
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertTrue("SOM " + finalSTS.getName() + "Save failed!",
+                checkPSOMSave(finalSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_subst_grps_valid.xml"), finalSTS));
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(finalSTS, 7, 0, 5, 2);
+
+        // verify named model groups
+        Assert.assertEquals("Elem Type  should be 'ModelGrpType'",
+                "ModelGrpType",
+                getElementType(finalSTS, "ModelGrpTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'AttributeGroup'", "AttributeGroup",
+                getAttributeGroup(finalSTS, "AttributeGroup"));
+
+        // TODO compare this to the original schema here
+    }
+
+    public void testModifyDerivedTypes() throws Exception
+    {
+        System.out.println("Inside test case testModifyDerivedTypes()");
+
+        // Step 1: read in a clean XSD derived_types_added.xsd
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("derived_types_added.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 13, 0, 14, 0);
+
+        // Recovered Errors, Test for saving of the SOM - should go thro
+        Assert.assertTrue("Valid SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // instance validation - should be ok
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_derived_types_valid.xml"), baseSTS));
+
+        // check types before deletion of base types
+        Assert.assertEquals("Elem Type  should be 'ExtensionBaseType' (base)",
+                "ExtensionBaseType",
+                getElementType(baseSTS, "ExtensionBaseTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'ExtensionDerivedComplexContentType' (derived)",
+                "ExtensionDerivedComplexContentType",
+                getElementType(baseSTS, "ExtensionDerivedComplexContentTypeElem"));
+
+        Assert.assertEquals("Elem Type  should be 'ExtensionBaseMixedContentType' (base)",
+                "ExtensionBaseMixedContentType",
+                getElementType(baseSTS, "ExtensionBaseMixedContentTypElem"));
+        Assert.assertEquals("Elem Type  should be 'ExtensionDerivedMixedContentType' (derived)",
+                "ExtensionDerivedMixedContentType",
+                getElementType(baseSTS, "ExtensionDerivedMixedContentTypeElem"));
+
+        Assert.assertEquals("Elem Type  should be 'RestrictionSimpleContentBaseType'",
+                "RestrictionSimpleContentBaseType",
+                getElementType(baseSTS, "RestrictionSimpleContentBaseTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'RestrictionSimpleContentDerivedType'",
+                "RestrictionSimpleContentDerivedType",
+                getElementType(baseSTS, "RestrictionSimpleContentDerivedTypeElem"));
+
+        Assert.assertEquals("Elem Type  should be 'RestrictionBaseComplexContentType'",
+                "RestrictionBaseComplexContentType",
+                getElementType(baseSTS, "RestrictionBaseComplexContentTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'RestrictionDerivedComplexContentType'",
+                "RestrictionDerivedComplexContentType",
+                getElementType(baseSTS, "RestrictionDerivedComplexContentTypeElem"));
+
+        Assert.assertEquals("Elem Type  should be 'RestrictionBaseMixedContentType'",
+                "RestrictionBaseMixedContentType",
+                getElementType(baseSTS, "RestrictionBaseMixedContentTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'RestrictionDerivedMixedContentType'",
+                "RestrictionDerivedMixedContentType",
+                getElementType(baseSTS, "RestrictionDerivedMixedContentTypeElem"));
+
+        Assert.assertEquals("Elem Type  should be 'RestrictionBaseEmptyContentType'",
+                "RestrictionBaseEmptyContentType",
+                getElementType(baseSTS, "RestrictionBaseEmptyContentTypeElem"));
+        Assert.assertEquals("Elem Type  should be 'RestrictionDerivedEmptyContentType'",
+                "RestrictionDerivedEmptyContentType",
+                getElementType(baseSTS, "RestrictionDerivedEmptyContentTypeElem"));
+
+
+        // step 2 : change the base types now : derived_types_modified.xsd
+        SchemaTypeSystem modifiedSTS = createNewSTS("derived_types_modifed.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // no recovearble errors   just added another type
+        Assert.assertFalse("valid PSOM",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        //inspectSOM(modifiedSTS, 13, 0, 14, 0);
+        inspectSOM(modifiedSTS, 13, 0, 15, 0);
+
+        // instance validation - should fail
+        Assert.assertFalse("Validation against instance success - should fail",
+                validateInstance(getTestCaseFile("instance_derived_types_valid.xml"), modifiedSTS));
+
+        // now validate instance with new base type - this should go thro
+        // TODO resolve     this validation
+        Assert.assertTrue("Validation against instance failed",
+                validateInstance(getTestCaseFile("instance_derived_types_modify.xml"), modifiedSTS));
+
+    }
+    public void testNameSpacesImportFile() throws Exception
+    {
+        System.out.println("Inside test case testNameSpacesImportFile()");
+
+        // Step 1: read in an xsd that imports from another xsd file providing file name only
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("namespaces_import_fileonly.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors   this should not be a partial Schema
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+    }
+
+    public void testNameSpacesImportFileWithPath() throws Exception
+    {
+        System.out.println("Inside test case testNameSpacesImportFileWithPath()");
+
+        //Step 1: read in an xsd that does not have any imports
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("namespaces_noimports.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors - this should not be a partial Schema
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertTrue("Valid SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 1, 0, 0, 0);
+
+        // step 2 : read in an xsd that imports a namespace from another xsd file providing the complete file path for the imported xsd
+        SchemaTypeSystem modifiedSTS = createNewSTS("namespaces_import_filepath.xsd",
+                baseSTS,
+                "ModifiedSchemaTS",
+                sBaseSourceName);
+        Assert.assertNotNull("Schema Type System created is Null.", modifiedSTS);
+
+        // no recovearble errors   just added another type
+        Assert.assertFalse("valid PSOM",
+                printRecoveredErrors());
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(modifiedSTS, 2, 0, 1, 0);
+
+    }
+
+    public void testNameSpacesWithInclude() throws Exception
+    {
+        System.out.println("Inside test case testNameSpacesWithInclude()");
+
+        // Step 1: read in an xsd that includes another namespace in xsd file namespaces2.xsd
+        String sBaseSourceName = "testsourcename";
+        SchemaTypeSystem baseSTS = createNewSTS("namespaces_include.xsd",
+                null,
+                "BaseSchemaTS",
+                sBaseSourceName);
+
+        Assert.assertNotNull("Schema Type System created is Null.", baseSTS);
+
+        // there should be NO recovearble errors - this should not be a partial Schema
+        Assert.assertFalse("Recovered Errors for Valid Schema",
+                printRecoveredErrors());
+
+        // Test for saving of the SOM - should go thro
+        Assert.assertTrue("Valid SOM " + baseSTS.getName() + "Save failed!",
+                checkPSOMSave(baseSTS));
+
+        // the tests - Walk thro the valid SOM
+        inspectSOM(baseSTS, 2, 0, 1, 0);
+
+
+    }
+
+}
+
+
+
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message