コード例 #1
0
        public virtual void testValidatePrivateDoc()
        {
            JDFDoc       doc      = new JDFDoc("JDF");
            JDFValidator checkJDF = new JDFValidator();

            checkJDF.setPrint(false);
            checkJDF.bQuiet = true;
            checkJDF.level  = EnumValidationLevel.Incomplete;
            JDFNode n = doc.getJDFRoot();

            checkJDF.setIgnorePrivate(true);

            n.setAttribute("foo:bar", "foobar", "www.foo.cpm");
            XMLDoc   schemaValidationResult = checkJDF.processSingleDocument(doc);
            KElement root = schemaValidationResult.getRoot();

            Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", "booboo"), "true");

            n.removeAttribute("bar", "www.foo.cpm");
            n.appendElement("foo:bar", "www.foo.cpm");
            schemaValidationResult = checkJDF.processSingleDocument(doc);
            root = schemaValidationResult.getRoot();
            Assert.AreEqual(root.getXPathAttribute("TestFile[2]/CheckJDFOutput/@IsValid", "booboo"), "true");

            n.setAttribute("jdfbar", "thisbebad");
            schemaValidationResult = checkJDF.processSingleDocument(doc);
            root = schemaValidationResult.getRoot();
            Assert.AreEqual(root.getXPathAttribute("TestFile[3]/CheckJDFOutput/@IsValid", "booboo"), "false");

            n.removeAttribute("jdfbar", null);
            n.appendElement("jdfbar", null);
            schemaValidationResult = checkJDF.processSingleDocument(doc);
            root = schemaValidationResult.getRoot();
            Assert.AreEqual(root.getXPathAttribute("TestFile[4]/CheckJDFOutput/@IsValid", "booboo"), "false");
        }
コード例 #2
0
        public virtual void testValidateCombined()
        {
            JDFDoc       doc      = new JDFDoc("JDF");
            JDFValidator checkJDF = new JDFValidator();

            checkJDF.setPrint(false);
            checkJDF.bQuiet = true;
            JDFNode n = doc.getJDFRoot();

            n.setType(EnumType.Combined);
            int v = 0;

            while (true)
            {
                checkJDF.level = EnumValidationLevel.getEnum(v);
                if (checkJDF.level == null)
                {
                    break;
                }
                for (int i = 0; i < 3; i++)
                {
                    if (i >= 1)
                    {
                        doc = null;
                    }
                    XMLDoc   schemaValidationResult = checkJDF.processSingleDocument(doc);
                    KElement root = schemaValidationResult.getRoot();
                    Assert.IsNotNull(root.getXPathElement("TestFile/SchemaValidationOutput"));
                    Assert.IsNotNull(root.getXPathElement("TestFile/CheckJDFOutput"));
                    Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", "booboo"), "true");
                }
                v++;
            }
        }
コード例 #3
0
        public virtual void testValidateJMF()
        {
            // Write temp JMF
            string   jmf     = "<?xml version='1.0' encoding='UTF-8'?><JMF xmlns='http://www.CIP4.org/JDFSchema_1_1' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'  SenderID='Alces' TimeStamp='2004-08-30T17:23:00+01:00' Version='1.2'><Query ID='M001' Type='KnownDevices' xsi:type='QueryKnownDevices'><DeviceFilter DeviceDetails='None'/></Query></JMF>";
            FileInfo jmfFile = new FileInfo(Path.Combine(Path.GetTempPath(), "Query-KnownDevices.jmf"));

            SupportClass.FileSupport.CreateNewFile(jmfFile);
            // jmfFile.deleteOnExit();
            StreamWriter @out = new StreamWriter(new FileStream(jmfFile.FullName, FileMode.Open));

            @out.Write(jmf);
            @out.Close();
            jmfFile.Refresh();
            Assert.IsTrue(jmfFile.Exists);

            FileInfo reportFile = new FileInfo(Path.Combine(Path.GetTempPath(), "Queue-KnownDevices-report.xml"));

            SupportClass.FileSupport.CreateNewFile(reportFile);
            // reportFile.deleteOnExit();

            // Run JDFValidator
            string[] args    = { jmfFile.FullName, "-cq", "-x " + reportFile.FullName };
            CheckJDF checker = new CheckJDF();
            XMLDoc   d       = checker.validate(args, null);
            KElement dRoot   = d.getRoot();

            Assert.AreEqual("true", dRoot.getXPathAttribute("/CheckOutput/TestFile/CheckJDFOutput/@IsValid", null));

            // Check that report exists
            reportFile.Refresh();
            Assert.IsTrue(reportFile.Exists);
            jmfFile.Delete();
            reportFile.Delete();
        }
コード例 #4
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");
            }
        }
コード例 #5
0
ファイル: JDFEvaluation.cs プロジェクト: cip4/JDFLibNet
        private bool fitsPath(KElement e, string xPath, KElement reportRoot)
        {
            bool     b       = false;
            KElement attr    = null;
            string   newPath = null;

            int posAt  = xPath.LastIndexOf("@");
            int posAtI = posAt > 0 ? xPath.LastIndexOf("[@") : -1;

            if (posAt < 0 || posAt == posAtI + 1) // element
            {
                KElement pathElement = e.getXPathElement(xPath);
                b = fitsValue(pathElement);
                if (b)
                {
                    if (reportRoot != null)
                    {
                        if (pathElement != null)
                        {
                            newPath = pathElement.buildXPath(null, 1);
                        }
                        attr = reportRoot.appendElement("TestedElement");
                        attr.setAttribute("Name", StringUtil.token(xPath, -1, "/"));
                    }
                }
            }
            else
            // attribute
            {
                string attrVal = e.getXPathAttribute(xPath, null);
                b = fitsValue(attrVal);
                string   attName     = xPath.Substring(posAt + 1);
                KElement pathElement = e.getXPathElement(xPath.Substring(0, posAt));

                if (pathElement is JDFResource)
                {
                    JDFResource r    = (JDFResource)pathElement;
                    JDFResource root = r.getResourceRoot();
                    while (r != root)
                    {
                        if (!r.hasAttribute_KElement(attName, null, false))
                        {
                            r = (JDFResource)r.getParentNode_KElement();
                        }
                        else
                        {
                            break;
                        }
                    }
                    pathElement = r;
                    newPath     = pathElement.buildXPath(null, 1) + "/@" + attName;
                }
                if (newPath != null)
                {
                    attrVal = e.getXPathAttribute(newPath, null);
                }
                b = fitsValue(attrVal);
                if (reportRoot != null)
                {
                    attr = reportRoot.appendElement("TestedAttribute");
                    attr.setAttribute("Name", attName);
                    attr.setAttribute("Value", attrVal);
                }
            }

            if (attr != null)
            {
                attr.setAttribute("XPath", newPath);
            }
            return(b);
        }