-
Notifications
You must be signed in to change notification settings - Fork 0
/
sectionize.groovy
79 lines (67 loc) · 2.52 KB
/
sectionize.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import groovy.xml.XmlUtil
/**
* Sectionize test definitions
*/
def testkit = '/Users/bill/git/iheos-toolkit2/xdstools2/src/main/webapp/toolkitx/testkit'
def areas = ['testdata', 'tests', 'testdata-registry', 'testdata-repository', 'testdata-xdr', 'examples']
def tests = new File(testkit, 'tests')
def testdata = new File(testkit, 'testdata')
processTestKit(testkit)
//processTestPlan(new File(testdata, '12345'))
def processTestKit(String testkit) {
def area = 'examples'
File areaDir = new File(new File(testkit), area)
areaDir.eachFile { File testDir ->
if (testDir.isDirectory() && new File(testDir, "testplan.xml").exists()) {
println "Test ${testDir}.name"
processTestPlan(testDir)
}
}
}
def processTestPlan(File testplanDir) {
def testPlanFile = new File(testplanDir, 'testplan.xml')
def testplan = new XmlParser().parse(testPlanFile)
def testId = testplan.Test.text()
println "Test ID is $testId"
def sections = []
testplan.each { node ->
if (node.name() == 'TestStep') {
def testStepNode = node
def stepId = node.attribute('id')
println "Step ID is $stepId"
def sectionName = stepId
def sectionTestId = "$testId/$sectionName"
def sectionDir = new File("$testplanDir/$sectionName")
sectionDir.mkdirs()
def wrapper = """
<TestPlan>
<Test>$sectionTestId</Test>
${XmlUtil.serialize(testStepNode)}
</TestPlan>
"""
new File("$sectionDir/testplan.xml").write(wrapper)
sections << sectionName
def documents = testStepNode.depthFirst().findAll { it.name() == 'Document' }
documents.each {
def filename = it.text()
println "Copying $filename"
def buffer = new File(testplanDir, filename).text
new File(sectionDir, filename).write(buffer)
}
def metadata = testStepNode.depthFirst().findAll { it.name() == 'MetadataFile' }
metadata.each {
def filename = it.text()
println "Copying $filename"
try {
def buffer = new File(testplanDir, filename).text
new File(sectionDir, filename).write(buffer)
} catch (FileNotFoundException e) {
//ignore
}
}
}
}
def index_idx = new File(testplanDir, 'index.idx')
sections.each { index_idx << "$it\n" }
testPlanFile.delete()
}