diff --git a/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java b/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java index 0e3dd667de..06ae1b28af 100644 --- a/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java +++ b/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java @@ -27,12 +27,12 @@ import java.util.stream.Stream; * @author Josh Cummings */ public class SpringSecurityXsdParser { - private NicerNode rootElement; + private XmlNode rootElement; private Set attrElmts = new LinkedHashSet<>(); private Map elementNameToElement = new HashMap<>(); - public SpringSecurityXsdParser(NicerNode rootElement) { + public SpringSecurityXsdParser(XmlNode rootElement) { this.rootElement = rootElement; } @@ -52,7 +52,7 @@ public class SpringSecurityXsdParser { * @param node * @return */ - private Map elements(NicerNode node) { + private Map elements(XmlNode node) { Map elementNameToElement = new HashMap<>(); node.children().forEach(child -> { @@ -73,7 +73,7 @@ public class SpringSecurityXsdParser { * @param element * @return a collection of Attribute objects that are children of element. */ - private Collection attrs(NicerNode element) { + private Collection attrs(XmlNode element) { Collection attrs = new ArrayList<>(); element.children().forEach(c -> { String name = c.simpleName(); @@ -94,7 +94,7 @@ public class SpringSecurityXsdParser { * @param element * @return */ - private Collection attrgrps(NicerNode element) { + private Collection attrgrps(XmlNode element) { Collection attrgrp = new ArrayList<>(); element.children().forEach(c -> { @@ -105,7 +105,7 @@ public class SpringSecurityXsdParser { attrgrp.addAll(attrgrp(c)); } else { String name = c.attribute("ref").split(":")[1]; - NicerNode attrGrp = findNode(element, name); + XmlNode attrGrp = findNode(element, name); attrgrp.addAll(attrgrp(attrGrp)); } } else { @@ -116,8 +116,8 @@ public class SpringSecurityXsdParser { return attrgrp; } - private NicerNode findNode(NicerNode c, String name) { - NicerNode root = c; + private XmlNode findNode(XmlNode c, String name) { + XmlNode root = c; while (!"schema".equals(root.simpleName())) { root = root.parent().get(); } @@ -127,7 +127,7 @@ public class SpringSecurityXsdParser { .findFirst().orElseThrow(IllegalArgumentException::new); } - private Stream expand(NicerNode root) { + private Stream expand(XmlNode root) { return Stream.concat( Stream.of(root), root.children().flatMap(this::expand)); @@ -139,7 +139,7 @@ public class SpringSecurityXsdParser { * @param e * @return all the attributes for a specific attributeGroup and any child attributeGroups */ - private Collection attrgrp(NicerNode e) { + private Collection attrgrp(XmlNode e) { Collection attrs = attrs(e); attrs.addAll(attrgrps(e)); return attrs; @@ -151,7 +151,7 @@ public class SpringSecurityXsdParser { * @param element * @return */ - private String desc(NicerNode element) { + private String desc(XmlNode element) { return element.child("annotation") .flatMap(annotation -> annotation.child("documentation")) .map(documentation -> documentation.text()) @@ -164,7 +164,7 @@ public class SpringSecurityXsdParser { * @param n * @return */ - private Attribute attr(NicerNode n) { + private Attribute attr(XmlNode n) { return new Attribute(desc(n), n.attribute("name")); } @@ -174,7 +174,7 @@ public class SpringSecurityXsdParser { * @param n * @return */ - private Element elmt(NicerNode n) { + private Element elmt(XmlNode n) { String name = n.attribute("ref"); if (StringUtils.isEmpty(name)) { name = n.attribute("name"); diff --git a/config/src/test/java/org/springframework/security/config/doc/NicerNode.java b/config/src/test/java/org/springframework/security/config/doc/XmlNode.java similarity index 86% rename from config/src/test/java/org/springframework/security/config/doc/NicerNode.java rename to config/src/test/java/org/springframework/security/config/doc/XmlNode.java index da6883e95d..7a87652c46 100644 --- a/config/src/test/java/org/springframework/security/config/doc/NicerNode.java +++ b/config/src/test/java/org/springframework/security/config/doc/XmlNode.java @@ -25,10 +25,10 @@ import java.util.stream.Stream; /** * @author Josh Cummings */ -public class NicerNode { +public class XmlNode { private final Node node; - public NicerNode(Node node) { + public XmlNode(Node node) { this.node = node; } @@ -41,23 +41,23 @@ public class NicerNode { return this.node.getTextContent(); } - public Stream children() { + public Stream children() { NodeList children = this.node.getChildNodes(); return IntStream.range(0, children.getLength()) .mapToObj(children::item) - .map(NicerNode::new); + .map(XmlNode::new); } - public Optional child(String name) { + public Optional child(String name) { return this.children() .filter(child -> name.equals(child.simpleName())) .findFirst(); } - public Optional parent() { + public Optional parent() { return Optional.ofNullable(this.node.getParentNode()) - .map(parent -> new NicerNode(parent)); + .map(parent -> new XmlNode(parent)); } public String attribute(String name) { diff --git a/config/src/test/java/org/springframework/security/config/doc/NicerXmlParser.java b/config/src/test/java/org/springframework/security/config/doc/XmlParser.java similarity index 88% rename from config/src/test/java/org/springframework/security/config/doc/NicerXmlParser.java rename to config/src/test/java/org/springframework/security/config/doc/XmlParser.java index eece67afc9..8ac735b1e1 100644 --- a/config/src/test/java/org/springframework/security/config/doc/NicerXmlParser.java +++ b/config/src/test/java/org/springframework/security/config/doc/XmlParser.java @@ -26,19 +26,19 @@ import java.io.InputStream; /** * @author Josh Cummings */ -public class NicerXmlParser implements AutoCloseable { +public class XmlParser implements AutoCloseable { private InputStream xml; - public NicerXmlParser(InputStream xml) { + public XmlParser(InputStream xml) { this.xml = xml; } - public NicerNode parse() { + public XmlNode parse() { try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - return new NicerNode(dBuilder.parse(this.xml)); + return new XmlNode(dBuilder.parse(this.xml)); } catch ( IOException | ParserConfigurationException | SAXException e ) { throw new IllegalStateException(e); } diff --git a/config/src/test/java/org/springframework/security/config/doc/NicerXmlSupport.java b/config/src/test/java/org/springframework/security/config/doc/XmlSupport.java similarity index 84% rename from config/src/test/java/org/springframework/security/config/doc/NicerXmlSupport.java rename to config/src/test/java/org/springframework/security/config/doc/XmlSupport.java index af05fe188c..c31c0399c4 100644 --- a/config/src/test/java/org/springframework/security/config/doc/NicerXmlSupport.java +++ b/config/src/test/java/org/springframework/security/config/doc/XmlSupport.java @@ -25,18 +25,18 @@ import java.util.Map; * * @author Josh Cummings */ -public class NicerXmlSupport { - private NicerXmlParser parser; +public class XmlSupport { + private XmlParser parser; - public NicerNode parse(String location) throws IOException { + public XmlNode parse(String location) throws IOException { ClassPathResource resource = new ClassPathResource(location); - this.parser = new NicerXmlParser(resource.getInputStream()); + this.parser = new XmlParser(resource.getInputStream()); return this.parser.parse(); } public Map elementsByElementName(String location) throws IOException { - NicerNode node = parse(location); + XmlNode node = parse(location); return new SpringSecurityXsdParser(node).parse(); } diff --git a/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java b/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java index 8f711c94f8..11a36966e6 100644 --- a/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java +++ b/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java @@ -52,7 +52,7 @@ public class XsdDocumentedTests { String schema31xDocumentLocation = "org/springframework/security/config/spring-security-3.1.xsd"; String schemaDocumentLocation = "org/springframework/security/config/spring-security-5.0.xsd"; - NicerXmlSupport xml = new NicerXmlSupport(); + XmlSupport xml = new XmlSupport(); @After public void close() throws IOException { @@ -62,17 +62,17 @@ public class XsdDocumentedTests { @Test public void parseWhenLatestXsdThenAllNamedSecurityFiltersAreDefinedAndOrderedProperly() throws IOException { - NicerNode root = this.xml.parse(this.schemaDocumentLocation); + XmlNode root = this.xml.parse(this.schemaDocumentLocation); List nodes = root.child("schema") - .map(NicerNode::children) + .map(XmlNode::children) .orElse(Stream.empty()) .filter(node -> "simpleType".equals(node.simpleName()) && "named-security-filter".equals(node.attribute("name"))) - .flatMap(NicerNode::children) - .flatMap(NicerNode::children) + .flatMap(XmlNode::children) + .flatMap(XmlNode::children) .map(node -> node.attribute("value")) .filter(StringUtils::isNotEmpty) .collect(Collectors.toList()); @@ -110,17 +110,17 @@ public class XsdDocumentedTests { "LAST" ); - NicerNode root = this.xml.parse(this.schema31xDocumentLocation); + XmlNode root = this.xml.parse(this.schema31xDocumentLocation); List nodes = root.child("schema") - .map(NicerNode::children) + .map(XmlNode::children) .orElse(Stream.empty()) .filter(node -> "simpleType".equals(node.simpleName()) && "named-security-filter".equals(node.attribute("name"))) - .flatMap(NicerNode::children) - .flatMap(NicerNode::children) + .flatMap(XmlNode::children) + .flatMap(XmlNode::children) .map(node -> node.attribute("value")) .filter(StringUtils::isNotEmpty) .collect(Collectors.toList());