Browse Source

Polish XsdDocumentedTests

- NicerNoce->XmlNode
- NicerXmlSupport->XmlSupport
- NicerXmlParser->XmlParser

Issue: gh-4939
Rob Winch 7 years ago
parent
commit
234c20eb30

+ 13 - 13
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<String> attrElmts = new LinkedHashSet<>();
 	private Map<String, Element> 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<String, Element> elements(NicerNode node) {
+	private Map<String, Element> elements(XmlNode node) {
 		Map<String, Element> 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<Attribute> attrs(NicerNode element) {
+	private Collection<Attribute> attrs(XmlNode element) {
 		Collection<Attribute> attrs = new ArrayList<>();
 		element.children().forEach(c -> {
 			String name = c.simpleName();
@@ -94,7 +94,7 @@ public class SpringSecurityXsdParser {
 	 * @param element
 	 * @return
 	 */
-	private Collection<Attribute> attrgrps(NicerNode element) {
+	private Collection<Attribute> attrgrps(XmlNode element) {
 		Collection<Attribute> 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<NicerNode> expand(NicerNode root) {
+	private Stream<XmlNode> 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<Attribute> attrgrp(NicerNode e) {
+	private Collection<Attribute> attrgrp(XmlNode e) {
 		Collection<Attribute> 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");

+ 7 - 7
config/src/test/java/org/springframework/security/config/doc/NicerNode.java → 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<NicerNode> children() {
+	public Stream<XmlNode> children() {
 		NodeList children = this.node.getChildNodes();
 
 		return IntStream.range(0, children.getLength())
 				.mapToObj(children::item)
-				.map(NicerNode::new);
+				.map(XmlNode::new);
 	}
 
-	public Optional<NicerNode> child(String name) {
+	public Optional<XmlNode> child(String name) {
 		return this.children()
 				.filter(child -> name.equals(child.simpleName()))
 				.findFirst();
 	}
 
-	public Optional<NicerNode> parent() {
+	public Optional<XmlNode> parent() {
 		return Optional.ofNullable(this.node.getParentNode())
-				.map(parent -> new NicerNode(parent));
+				.map(parent -> new XmlNode(parent));
 	}
 
 	public String attribute(String name) {

+ 4 - 4
config/src/test/java/org/springframework/security/config/doc/NicerXmlParser.java → 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);
 		}

+ 5 - 5
config/src/test/java/org/springframework/security/config/doc/NicerXmlSupport.java → 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<String, Element> elementsByElementName(String location) throws IOException {
-		NicerNode node = parse(location);
+		XmlNode node = parse(location);
 		return new SpringSecurityXsdParser(node).parse();
 	}
 

+ 9 - 9
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<String> 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<String> 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());