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++; } }
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"); } }
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); }