From cfe20a5c1c6f19e884d6c68a76759e080d87b83d Mon Sep 17 00:00:00 2001 From: AlexJitianu Date: Thu, 11 Jun 2020 12:32:11 +0300 Subject: [PATCH] #41 Add a wrapper for the case when the select matches attributes. --- .../unit-report-oxygen.xsl | 12 ++- .../oxygenxml/xspec/jfx/XSpecMeta2Test.java | 79 +++++++++++++++++++ .../xspec/jfx/XSpecViewTestBase.java | 25 ++++++ src/test/resources/#41/to-test.xsl | 27 +++++++ src/test/resources/#41/to-test.xspec | 20 +++++ 5 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/oxygenxml/xspec/jfx/XSpecMeta2Test.java create mode 100644 src/test/resources/#41/to-test.xsl create mode 100644 src/test/resources/#41/to-test.xspec diff --git a/frameworks/xspec/oxygen-results-view/unit-report-oxygen.xsl b/frameworks/xspec/oxygen-results-view/unit-report-oxygen.xsl index 482463d..0a1f3e2 100644 --- a/frameworks/xspec/oxygen-results-view/unit-report-oxygen.xsl +++ b/frameworks/xspec/oxygen-results-view/unit-report-oxygen.xsl @@ -188,11 +188,17 @@ - - + + + + + + + + - + diff --git a/src/test/java/com/oxygenxml/xspec/jfx/XSpecMeta2Test.java b/src/test/java/com/oxygenxml/xspec/jfx/XSpecMeta2Test.java new file mode 100644 index 0000000..ec186b6 --- /dev/null +++ b/src/test/java/com/oxygenxml/xspec/jfx/XSpecMeta2Test.java @@ -0,0 +1,79 @@ +package com.oxygenxml.xspec.jfx; + +import java.io.File; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.oxygenxml.xspec.XSpecUtil; + +import ro.sync.util.URLUtil; + +/** + * Asserts the XSpec transformation meta data and the special report. + * + * @author alex_jitianu + */ +public class XSpecMeta2Test extends XSpecViewTestBase { + + /** + * An assert with match on attributes. + * + * https://github.com/xspec/oXygen-XML-editor-xspec-support/issues/41 + * + * @throws Exception If it fails. + */ + public void testRunXSpec() throws Exception { + URL xspecURL = getClass().getClassLoader().getResource("#41/to-test.xspec"); + URL xslURL = getClass().getClassLoader().getResource("#41/to-test.xsl"); + File xspecFile = URLUtil.getCanonicalFileFromFileUrl(xspecURL); + File outputFile = new File(xspecFile.getParentFile(), "to-test.html"); + + executeANT(xspecFile, outputFile); + + String firstID = XSpecUtil.generateId("template name code-to-code"); + + File xmlFormatOutput = new File(xspecFile.getParentFile(), "xspec/to-test-result.xml"); + + assertEquals("\n" + + " \n" + + " \n" + + " \n" + + " ", executeXPath(xmlFormatOutput, "//*:result")); + + assertEquals("\n" + + " \n" + + " \n" + + " \n" + + " ", executeXPath(xmlFormatOutput, "//*:expect")); + + + + assertTrue(outputFile.exists()); + + File css = new File("frameworks/xspec/oxygen-results-view/test-report.css"); + File js = new File("frameworks/xspec/oxygen-results-view/test-report.js"); + + + String htmlContent = simplify(read(outputFile.toURI().toURL()).toString()); + Pattern compile = Pattern.compile("
.*
"); + Matcher matcher = compile.matcher(htmlContent); + matcher.find(); + String actual = matcher.group(); + + assertEquals("
<wrapper code=\"F\" codeSystem=\"null\" displayName=\"Vrouw\"/>
<wrapper code=\"false\" codeSystem=\"2.16.840.1.113883.5.1\" displayName=\"Vrouw\"/>
", actual); + } + + private String simplify(String string) { + return string.replaceAll("", "") .replaceAll("x:test id=\"[^\"]*\"", "x:test"); } + + /** + * Executes XPath. + * + * @param resource Input. + * @param xpath XPath expression. + * + * @return Result. + * + * @throws Exception if it fails. + */ + protected String executeXPath(File resource, String xpath) throws Exception { + Processor processor = new Processor(false); + XdmNode build = processor.newDocumentBuilder().build(resource); + XPathCompiler newXPathCompiler = processor.newXPathCompiler(); + + XdmItem evaluateSingle = newXPathCompiler.evaluateSingle(xpath, build); + + return evaluateSingle.toString(); + } } diff --git a/src/test/resources/#41/to-test.xsl b/src/test/resources/#41/to-test.xsl new file mode 100644 index 0000000..549bf75 --- /dev/null +++ b/src/test/resources/#41/to-test.xsl @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/#41/to-test.xspec b/src/test/resources/#41/to-test.xspec new file mode 100644 index 0000000..9b0508f --- /dev/null +++ b/src/test/resources/#41/to-test.xspec @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + +