diff --git a/clearing-parent/backend-api/pom.xml b/clearing-parent/backend-api/pom.xml
index add972c06..6120a417b 100644
--- a/clearing-parent/backend-api/pom.xml
+++ b/clearing-parent/backend-api/pom.xml
@@ -111,10 +111,6 @@
org.mockito
mockito-core
-
-
- com.fasterxml.jackson.dataformat
- jackson-dataformat-xml
test
diff --git a/clearing-parent/backend-api/src/test/java/ru/spcex/clearing/backendapi/meta/DataXmlTest.java b/clearing-parent/backend-api/src/test/java/ru/spcex/clearing/backendapi/meta/DataXmlTest.java
index bb299c3de..93bfd5325 100644
--- a/clearing-parent/backend-api/src/test/java/ru/spcex/clearing/backendapi/meta/DataXmlTest.java
+++ b/clearing-parent/backend-api/src/test/java/ru/spcex/clearing/backendapi/meta/DataXmlTest.java
@@ -1,15 +1,20 @@
package ru.spcex.clearing.backendapi.meta;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.*;
-import java.io.File;
-import java.io.IOException;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.*;
import java.util.*;
/**
@@ -22,7 +27,7 @@ public class DataXmlTest {
private Logger log = LoggerFactory.getLogger(getClass());
@Test
- public void testMetaXml() throws IOException {
+ public void testMetaXml() throws Exception {
verifyXML(new File("src/main/resources/meta/meta.xml"));
}
@@ -46,12 +51,73 @@ public class DataXmlTest {
verifyXML(new File("src/main/resources/meta/data_register_code.xml"));
}
- protected void verifyXML(File xmlFile) throws IOException {
- XmlMapper xmlObjectMapper = new XmlMapper();
- xmlObjectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
- xmlObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ Map parseXml(File xmlFile) throws ParserConfigurationException, IOException, SAXException {
// Это юнит-тест с внутренними данными, парсинг DTD выключать не обязательно.
- Map root = xmlObjectMapper.readValue(xmlFile, Map.class);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
+ factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Map out = new HashMap<>();
+ try (FileInputStream is = new FileInputStream(xmlFile)) {
+ Document doc = builder.parse(new InputSource(is));
+ out.put(doc.getNodeName(), xmlNodeToMap(doc));
+ }
+ return out;
+ }
+
+ /**
+ * Аналог TransformerFactory.newInstance().newTransformer() to Map
+ *
+ * @param node w3c.Node для разбора
+ * @return Map или String
+ */
+ private Object xmlNodeToMap(Node node) {
+ if (node == null)
+ return null;
+ Map out = new LinkedHashMap<>();
+ int n = 0;
+ if (node.hasAttributes()) {
+ NamedNodeMap attributes = node.getAttributes();
+ int attrCount = attributes.getLength();
+ for (int i = 0; i < attrCount; i++) {
+ Node attribute = attributes.item(i);
+ String value = attribute.getNodeValue();
+ if (value != null)
+ out.put((n++) + "attr " + attribute.getNodeName(), value);
+ }
+ }
+ String value = node.getNodeValue();
+ if (node.hasChildNodes()) {
+ NodeList childs = node.getChildNodes();
+ for (int i = 0; i < childs.getLength(); i++) {
+ Node child = childs.item(i);
+ if (child != null && child.getNodeType() != Node.COMMENT_NODE) {
+ out.put((n++) + " " + child.getNodeName(), xmlNodeToMap(child));
+ }
+ }
+ }
+ if (out.isEmpty()) {
+ return value;
+ } else {
+ if (value != null) {
+ out.put("value ", value);
+ }
+ }
+
+ return out;
+ }
+
+ protected void verifyXML(File xmlFile) throws IOException {
+ Map root = null;
+ try {
+ root = parseXml(xmlFile);
+ } catch (ParserConfigurationException | SAXException e) {
+ throw new IOException("Can not parse XML " + xmlFile, e);
+ }
Assertions.assertNotNull(root, "Empty XML in file " + xmlFile);
String errors = verifyNode(xmlFile.getName(), root);
@@ -119,7 +185,7 @@ public class DataXmlTest {
if (text != null) {
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
- boolean isWhitespace = Character.isWhitespace(c);
+ boolean isWhitespace = Character.isWhitespace(c) || c == '=' || c == '='; // || c=='_'
boolean isCyrillic = Arrays.binarySearch(CYRILLICS, c) >= 0;
boolean isLatin = Arrays.binarySearch(LATINS, c) >= 0;
assert !(isCyrillic && isLatin);
@@ -155,6 +221,7 @@ public class DataXmlTest {
Assertions.assertTrue(verifyText("XML"));
Assertions.assertTrue(verifyText("Same sample apple"));
Assertions.assertTrue(verifyText("По tExT кРАям"));
+ Assertions.assertTrue(verifyText("company id=\"5\" fullName=\"Центральный Банк Российской Федерации\" "));
Assertions.assertFalse(verifyText("Пользоватьель userтекст обычный."));
Assertions.assertFalse(verifyText("ХML"));