diff --git a/config/src/test/groovy/org/springframework/security/config/doc/XsdDocumentedTests.groovy b/config/src/test/groovy/org/springframework/security/config/doc/XsdDocumentedTests.groovy index 945a85a3e4..540d071924 100644 --- a/config/src/test/groovy/org/springframework/security/config/doc/XsdDocumentedTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/doc/XsdDocumentedTests.groovy @@ -30,8 +30,7 @@ import spock.lang.* class XsdDocumentedTests extends Specification { def ignoredIds = ['nsa-any-user-service','nsa-any-user-service-parents','nsa-authentication','nsa-ldap','nsa-method-security','nsa-web'] - @Shared def appendix = new File('../docs/manual/src/docbook/appendix-namespace.xml') - @Shared def appendixRoot = new XmlSlurper().parse(appendix) + @Shared def reference = new File('../docs/manual/src/asciidoctor/index.adoc') @Shared File schema31xDocument = new File('src/main/resources/org/springframework/security/config/spring-security-3.1.xsd') @Shared File schemaDocument = new File('src/main/resources/org/springframework/security/config/spring-security-3.2.xsd') @@ -41,29 +40,10 @@ class XsdDocumentedTests extends Specification { def setupSpec() { schemaRootElement = new XmlSlurper().parse(schemaDocument) elementNameToElement = new SpringSecurityXsdParser(rootElement: schemaRootElement).parse() - appendixRoot.getMetaClass().sections = { - delegate.breadthFirst().inject([]) {result, c-> - if(c.name() == 'section' && c.@id) { - result.add(c) - } - result - } - } - NodeChild.metaClass.hrefs = { result -> - def id = delegate.@id.text().replace('-parents', '').replace('-children', '') - result.put(id,[]) - delegate.children().breadthFirst().each { sectionChild -> - def href = sectionChild.@linkend.text() - if(href) { - result.get(id).add(href) - } - } - } } def cleanupSpec() { - appendix = null - appendixRoot = null + reference = null schema31xDocument = null schemaDocument = null elementNameToElement = null @@ -120,17 +100,22 @@ class XsdDocumentedTests extends Specification { */ def 'the entire schema is included in the appendix documentation'() { setup: 'get all the documented ids and the expected ids' - def documentedIds = appendixRoot.sections().collect { it.@id.text() } + def documentedIds = [] + reference.eachLine { line -> + if(line.matches("\\[\\[(nsa-.*)\\]\\]")) { + documentedIds.add(line.substring(2,line.length() - 2)) + } + } when: 'the schema is compared to the appendix documentation' - def expectedIds = [] as Set - elementNameToElement*.value*.ids*.each { expectedIds.addAll it } - documentedIds.removeAll ignoredIds - expectedIds.removeAll ignoredIds - def undocumentedIds = (expectedIds - documentedIds) - def shouldNotBeDocumented = (documentedIds - expectedIds) + def expectedIds = [] as Set + elementNameToElement*.value*.ids*.each { expectedIds.addAll it } + documentedIds.removeAll ignoredIds + expectedIds.removeAll ignoredIds + def undocumentedIds = (expectedIds - documentedIds) + def shouldNotBeDocumented = (documentedIds - expectedIds) then: 'all the elements and attributes are documented' - shouldNotBeDocumented.empty - undocumentedIds.empty + shouldNotBeDocumented.empty + undocumentedIds.empty } /** @@ -140,36 +125,55 @@ class XsdDocumentedTests extends Specification { */ def 'validate parents and children are linked in the appendix documentation'() { when: "get all the links for each element's children and parents" - def docAttrNameToChildren = [:] - def docAttrNameToParents = [:] - appendixRoot.sections().each { c-> - def id = c.@id.text() - if(id.endsWith('-parents')) { - c.hrefs(docAttrNameToParents) + def docAttrNameToChildren = [:] + def docAttrNameToParents = [:] + + def currentDocAttrNameToElmt + def docAttrName + + reference.eachLine { line -> + if(line.matches('^\\[\\[.*\\]\\]$')) { + def id = line.substring(2,line.length() - 2) + if(id.endsWith("-children")) { + docAttrName = id.substring(0,id.length() - 9) + currentDocAttrNameToElmt = docAttrNameToChildren + } else if(id.endsWith("-parents")) { + docAttrName = id.substring(0,id.length() - 8) + currentDocAttrNameToElmt = docAttrNameToParents + } else if(docAttrName && !id.startsWith(docAttrName)) { + currentDocAttrNameToElmt = null + docAttrName = null + } + } + + if(docAttrName) { + def expression = '^\\* <<(nsa-.*),.*>>$' + if(line.matches(expression)) { + String elmtId = line.replaceAll(expression, '$1') + currentDocAttrNameToElmt.get(docAttrName, []).add(elmtId) + } + } } - if(id.endsWith('-children')) { - c.hrefs(docAttrNameToChildren) + + def schemaAttrNameToParents = [:] + def schemaAttrNameToChildren = [:] + elementNameToElement.each { entry -> + def key = 'nsa-'+entry.key + if(ignoredIds.contains(key)) { + return + } + def parentIds = entry.value.allParentElmts.values()*.id.findAll { !ignoredIds.contains(it) }.sort() + if(parentIds) { + schemaAttrNameToParents.put(key,parentIds) + } + def childIds = entry.value.allChildElmts.values()*.id.findAll { !ignoredIds.contains(it) }.sort() + if(childIds) { + schemaAttrNameToChildren.put(key,childIds) + } } - } - def schemaAttrNameToParents = [:] - def schemaAttrNameToChildren = [:] - elementNameToElement.each { entry -> - def key = 'nsa-'+entry.key - if(ignoredIds.contains(key)) { - return - } - def parentIds = entry.value.allParentElmts.values()*.id.findAll { !ignoredIds.contains(it) }.sort() - if(parentIds) { - schemaAttrNameToParents.put(key,parentIds) - } - def childIds = entry.value.allChildElmts.values()*.id.findAll { !ignoredIds.contains(it) }.sort() - if(childIds) { - schemaAttrNameToChildren.put(key,childIds) - } - } then: "the expected parents and children are all documented" - schemaAttrNameToChildren.sort() == docAttrNameToChildren.sort() - schemaAttrNameToParents.sort() == docAttrNameToParents.sort() + schemaAttrNameToChildren.sort() == docAttrNameToChildren.sort() + schemaAttrNameToParents.sort() == docAttrNameToParents.sort() } /**