SEC-2349: Fix documentation tests
This commit is contained in:
parent
4b43cf3f50
commit
dd1c2483b5
|
@ -30,8 +30,7 @@ import spock.lang.*
|
||||||
class XsdDocumentedTests extends Specification {
|
class XsdDocumentedTests extends Specification {
|
||||||
|
|
||||||
def ignoredIds = ['nsa-any-user-service','nsa-any-user-service-parents','nsa-authentication','nsa-ldap','nsa-method-security','nsa-web']
|
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 reference = new File('../docs/manual/src/asciidoctor/index.adoc')
|
||||||
@Shared def appendixRoot = new XmlSlurper().parse(appendix)
|
|
||||||
|
|
||||||
@Shared File schema31xDocument = new File('src/main/resources/org/springframework/security/config/spring-security-3.1.xsd')
|
@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')
|
@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() {
|
def setupSpec() {
|
||||||
schemaRootElement = new XmlSlurper().parse(schemaDocument)
|
schemaRootElement = new XmlSlurper().parse(schemaDocument)
|
||||||
elementNameToElement = new SpringSecurityXsdParser(rootElement: schemaRootElement).parse()
|
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() {
|
def cleanupSpec() {
|
||||||
appendix = null
|
reference = null
|
||||||
appendixRoot = null
|
|
||||||
schema31xDocument = null
|
schema31xDocument = null
|
||||||
schemaDocument = null
|
schemaDocument = null
|
||||||
elementNameToElement = null
|
elementNameToElement = null
|
||||||
|
@ -120,7 +100,12 @@ class XsdDocumentedTests extends Specification {
|
||||||
*/
|
*/
|
||||||
def 'the entire schema is included in the appendix documentation'() {
|
def 'the entire schema is included in the appendix documentation'() {
|
||||||
setup: 'get all the documented ids and the expected ids'
|
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'
|
when: 'the schema is compared to the appendix documentation'
|
||||||
def expectedIds = [] as Set
|
def expectedIds = [] as Set
|
||||||
elementNameToElement*.value*.ids*.each { expectedIds.addAll it }
|
elementNameToElement*.value*.ids*.each { expectedIds.addAll it }
|
||||||
|
@ -142,15 +127,34 @@ class XsdDocumentedTests extends Specification {
|
||||||
when: "get all the links for each element's children and parents"
|
when: "get all the links for each element's children and parents"
|
||||||
def docAttrNameToChildren = [:]
|
def docAttrNameToChildren = [:]
|
||||||
def docAttrNameToParents = [:]
|
def docAttrNameToParents = [:]
|
||||||
appendixRoot.sections().each { c->
|
|
||||||
def id = c.@id.text()
|
def currentDocAttrNameToElmt
|
||||||
if(id.endsWith('-parents')) {
|
def docAttrName
|
||||||
c.hrefs(docAttrNameToParents)
|
|
||||||
}
|
reference.eachLine { line ->
|
||||||
if(id.endsWith('-children')) {
|
if(line.matches('^\\[\\[.*\\]\\]$')) {
|
||||||
c.hrefs(docAttrNameToChildren)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def schemaAttrNameToParents = [:]
|
def schemaAttrNameToParents = [:]
|
||||||
def schemaAttrNameToChildren = [:]
|
def schemaAttrNameToChildren = [:]
|
||||||
elementNameToElement.each { entry ->
|
elementNameToElement.each { entry ->
|
||||||
|
|
Loading…
Reference in New Issue