From 49ad312fc1e536a03e023cda81631a26b80147c7 Mon Sep 17 00:00:00 2001
From: Maxim <maxplusim@mail.ru>
Date: Sun, 1 Oct 2023 23:57:47 +0300
Subject: [PATCH] Update RegressionTestingHelper

---
 .../pdfa/qa/RegressionTestingHelper.java      | 26 ++++++-------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/veraPDF-integration/src/main/java/org/verapdf/pdfa/qa/RegressionTestingHelper.java b/veraPDF-integration/src/main/java/org/verapdf/pdfa/qa/RegressionTestingHelper.java
index 59a3205..371385a 100644
--- a/veraPDF-integration/src/main/java/org/verapdf/pdfa/qa/RegressionTestingHelper.java
+++ b/veraPDF-integration/src/main/java/org/verapdf/pdfa/qa/RegressionTestingHelper.java
@@ -111,7 +111,7 @@ public void getFailedPolicyComplianceFiles(Map<String, List<FailedPolicyCheck>>
                 applyPolicy(tempSchFile, tempMrrFile, tempResultFile);
                 int failedPolicyJobsCount = countFailedPolicyJobs(tempResultFile);
                 if (failedPolicyJobsCount > 0) {
-                    failedFiles.put(pdfName, getFailedChecks(tempResultFile));
+                    failedFiles.put(pdfName, getFailedChecks(tempResultFile, tempMrrFile));
                 }
             } catch (Exception e) {
                 failedFiles.put(pdfName, Collections.singletonList(new FailedPolicyCheck(e.getMessage())));
@@ -183,24 +183,22 @@ public static int countFailedPolicyJobs(File xmlReport)
             throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
         DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document document = documentBuilder.parse(xmlReport);
-        XPath path = XPathFactory.newInstance().newXPath();
-        return ((Number) path.evaluate("count(//policyReport[@failedChecks > 0])", document, XPathConstants.NUMBER))
-                .intValue();
+        return document.getElementsByTagName("svrl:failed-assert").getLength();
     }
 
-    public static List<FailedPolicyCheck> getFailedChecks(File xmlReport)
+    public static List<FailedPolicyCheck> getFailedChecks(File xmlReport, File tempMrrFile)
             throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
         DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document document = documentBuilder.parse(xmlReport);
+        Document mrrDocument = documentBuilder.parse(tempMrrFile);
         XPath path = XPathFactory.newInstance().newXPath();
         List<FailedPolicyCheck> failedChecks = new LinkedList<>();
-        NodeList list = ((NodeList) path.evaluate("//policyReport/failedChecks/check", document,
-                XPathConstants.NODESET));
+        NodeList list = document.getElementsByTagName("svrl:failed-assert");
         for (int i = 0; i < list.getLength(); i++) {
             Element check = (Element) list.item(i);
             String test = check.getAttribute("test");
-            String messageValue = getProperty(check, "message").getTextContent();
-            Element node = (Element) path.evaluate(check.getAttribute("location"), document, XPathConstants.NODE);
+            String messageValue = getProperty(check, "svrl:text").getTextContent();
+            Element node = (Element) path.evaluate(check.getAttribute("location"), mrrDocument, XPathConstants.NODE);
             failedChecks.add(new FailedPolicyCheck(node, messageValue, test));
         }
         return failedChecks;
@@ -208,18 +206,10 @@ public static List<FailedPolicyCheck> getFailedChecks(File xmlReport)
 
     public static void applyPolicy(File policyFile, File tempMrrFile, File tempResultFile)
             throws IOException, VeraPDFException {
-        File tempPolicyResult = File.createTempFile("policyResult", "veraPDF");
         try (InputStream mrrIs = new FileInputStream(tempMrrFile);
-                OutputStream policyResultOs = new FileOutputStream(tempPolicyResult)) {
+                OutputStream policyResultOs = new FileOutputStream(tempResultFile)) {
             PolicyChecker.applyPolicy(policyFile, mrrIs, policyResultOs);
         }
-        try (OutputStream mrrReport = new FileOutputStream(tempResultFile)) {
-            PolicyChecker.insertPolicyReport(tempPolicyResult, tempMrrFile, mrrReport);
-        }
-
-        if (!tempPolicyResult.delete()) {
-            tempPolicyResult.deleteOnExit();
-        }
     }
 
     private static Node getProperty(Node parent, String propertyName) {