Exemplo n.º 1
0
        public virtual void testValidateExtensionschema()
        {
            JDFDoc       doc      = new JDFDoc("JDF");
            JDFValidator checkJDF = new JDFValidator();

            checkJDF.setPrint(false);
            checkJDF.bQuiet = true;
            checkJDF.level  = EnumValidationLevel.Incomplete;
            DirectoryInfo foo = new DirectoryInfo(sm_dirTestSchema);

            Assert.IsTrue(foo.Exists, "please mount the svn schema parallel to JDFLibNet");
            FileInfo jdfxsd = new FileInfo(sm_dirTestSchema + "JDF.xsd");

            checkJDF.setJDFSchemaLocation(jdfxsd);
            JDFNode n = doc.getJDFRoot();

            n.setType(EnumType.ConventionalPrinting);
            JDFMedia med = (JDFMedia)n.addResource("Media", null, EnumUsage.Input, null, null, null, null);

            checkJDF.setIgnorePrivate(false);
            doc.write2File(sm_dirTestDataTemp + "extension.jdf", 0, true);
            XMLDoc @out = checkJDF.processSingleFile(sm_dirTestDataTemp + "extension.jdf");

            Assert.AreEqual(@out.getRoot().getXPathAttribute("TestFile/SchemaValidationOutput/@ValidationResult", null), "Valid");

            checkJDF.schemaLocation += " http://www.extension.com " + sm_dirTestData + "extension.xsd";
            med.setAttribute("ext:ExtensionAtt", "a", "http://www.extension.com");
            KElement fooBar = med.appendElement("ext:FooBar", "http://www.extension.com");

            fooBar.setAttribute("ID", "f1");
            fooBar.setAttribute("Fnarf", "4");

            doc.write2File(sm_dirTestDataTemp + "extension.jdf", 0, true);
            @out = checkJDF.processSingleFile(sm_dirTestDataTemp + "extension.jdf");
            Assert.AreEqual(@out.getRoot().getXPathAttribute("TestFile[2]/SchemaValidationOutput/@ValidationResult", null), "Error");

            med.setAttribute("ext:ExtensionAtt", "3", "http://www.extension.com");
            doc.write2File(sm_dirTestDataTemp + "extension.jdf", 0, true);
            @out = checkJDF.processSingleFile(sm_dirTestDataTemp + "extension.jdf");
            Assert.AreEqual(@out.getRoot().getXPathAttribute("TestFile[3]/SchemaValidationOutput/@ValidationResult", null), "Valid");

            fooBar.setAttribute("Fnarf", "bad");
            doc.write2File(sm_dirTestDataTemp + "extension.jdf", 0, true);
            @out = checkJDF.processSingleFile(sm_dirTestDataTemp + "extension.jdf");
            Assert.AreEqual(@out.getRoot().getXPathAttribute("TestFile[4]/SchemaValidationOutput/@ValidationResult", null), "Error");
        }
Exemplo n.º 2
0
        private void processSingleFile(string fileName, bool bShouldValidate, EnumValidationLevel level)
        {
            JDFValidator checkJDF = new JDFValidator();

            checkJDF.setPrint(false);
            checkJDF.bQuiet = true;
            checkJDF.level  = level != null ? level : EnumValidationLevel.Complete;
            XMLDoc   schemaValidationResult = checkJDF.processSingleFile(fileName);
            KElement root = schemaValidationResult.getRoot();

            Assert.IsNotNull(root.getXPathElement("TestFile/SchemaValidationOutput"));
            Assert.IsNotNull(root.getXPathElement("TestFile/CheckJDFOutput"));

            checkJDF = new JDFValidator();
            checkJDF.setPrint(false);
            checkJDF.bQuiet = true;
            checkJDF.level  = EnumValidationLevel.Complete;
            checkJDF.processSingleFile(fileName);
            Assert.IsNotNull(root);

            if (bShouldValidate)
            {
                Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", ""), "true", fileName + " should validate");
            }
            else
            {
                Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", ""), "false", fileName + " should not validate");
            }

            // now repeat including schema
            checkJDF.setJDFSchemaLocation(new FileInfo(sm_dirTestSchema + "JDF.xsd"));
            checkJDF.processSingleDocument(null);
            Assert.IsNotNull(root);

            if (bShouldValidate)
            {
                Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", ""), "true");
            }
            else
            {
                Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", ""), "false");
            }
        }