Skip to content

Commit fa363f6

Browse files
committed
Move XML Validation out of Mocha and into build process
1 parent 7074042 commit fa363f6

3 files changed

Lines changed: 64 additions & 112 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ The Srophé Application depends on a unique identifier, for Syriaca.org uses `te
3535
It is also possible to use the document uri, changes would have to made in repo-config.xml and in controller.xql to enable use of the document uri rather then the tei:idno.
3636

3737
### Deploy data and application
38-
In the root directory of each of your new repositories run '`./mvnw`' (or `mvnw.cmd` if you are on Windows) to build the application.
38+
In the root directory of each of your new repositories run `./mvnw clean package` (or `mvnw.cmd` if you are on Windows) to build the application.
3939
A new `srophe-3.1.0-SNAPSHOT.xar` file will be built and saved in `target/`. You can install these applications via the Elemental (or eXist-db) dashboard [http://localhost:8080/exist/apps/dashboard/index.html] using the Package Manager.
4040

4141
Once deployed the application should show up as 'The Srophé web application' on your dashboard.
4242
Click on the icon to be taken to the app.
4343

44-
Learn how to customize the application.
44+
Learn how to customize the application.
45+
46+
### Developing this Code Base
47+
You can run the integration tests by executing `./mvnw clean package -Pintegration-test`.

pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,40 @@
153153
</execution>
154154
</executions>
155155
</plugin>
156+
<plugin>
157+
<groupId>org.codehaus.mojo</groupId>
158+
<artifactId>xml-maven-plugin</artifactId>
159+
<version>1.1.0</version>
160+
<executions>
161+
<execution>
162+
<id>validate-xml</id>
163+
<phase>process-resources</phase>
164+
<goals>
165+
<goal>validate</goal>
166+
</goals>
167+
<configuration>
168+
<validationSets>
169+
<validationSet>
170+
<dir>src/main/xar-resources</dir>
171+
<includes>
172+
<include>**/*.html</include>
173+
<include>**/*.xml</include>
174+
<include>**/*.xconf</include>
175+
<include>**/*.odd</include>
176+
</includes>
177+
</validationSet>
178+
</validationSets>
179+
</configuration>
180+
</execution>
181+
</executions>
182+
<configuration>
183+
<validationSets>
184+
<validationSet>
185+
<dir>src/main/xml</dir>
186+
</validationSet>
187+
</validationSets>
188+
</configuration>
189+
</plugin>
156190
<plugin>
157191
<groupId>org.apache.maven.plugins</groupId>
158192
<artifactId>maven-resources-plugin</artifactId>

src/test/mocha/app_spec.js

Lines changed: 25 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,13 @@ const assert = require('yeoman-assert')
1111

1212
// this is not equivalent to using a real xml parser
1313
describe('file system checks', function () {
14-
describe('markup files are well-formed', function () {
15-
chai.use(chaiXml)
16-
it('*.html is xhtml', function (done) {
17-
glob('**/*.html', { ignore: 'node_modules/**' }, function (err, files) {
18-
if (err) throw err
19-
// console.log(files)
20-
files.forEach(function (html) {
21-
const xhtml = fs.readFileSync(html, 'utf8')
22-
const hParsed = new xmldoc.XmlDocument(xhtml).toString()
23-
expect(hParsed).xml.to.be.valid()
24-
})
25-
})
26-
done()
27-
})
28-
29-
it('*.xml', function (done) {
30-
glob('**/*.xml', { ignore: 'node_modules/**' }, function (err, files) {
31-
if (err) throw err
32-
// console.log(files)
33-
files.forEach(function (xmls) {
34-
const xml = fs.readFileSync(xmls, 'utf8')
35-
const xParsed = new xmldoc.XmlDocument(xml).toString()
36-
expect(xParsed).xml.to.be.valid()
37-
})
38-
})
39-
done()
40-
})
41-
42-
it('*.xconf', function (done) {
43-
glob('**/*.xconf', { ignore: 'node_modules/**' }, function (err, files) {
44-
if (err) throw err
45-
// console.log(files)
46-
files.forEach(function (xconfs) {
47-
const xconf = fs.readFileSync(xconfs, 'utf8')
48-
const cParsed = new xmldoc.XmlDocument(xconf).toString()
49-
expect(cParsed).xml.to.be.valid()
50-
})
51-
})
52-
done()
53-
})
54-
it('*.odd', function (done) {
55-
this.slow(1000)
56-
glob('**/*.odd', { ignore: 'node_modules/**' }, function (err, files) {
57-
if (err) throw err
58-
// console.log(files)
59-
files.forEach(function (odds) {
60-
const odd = fs.readFileSync(odds, 'utf8')
61-
const xParsed = new xmldoc.XmlDocument(odd).toString()
62-
expect(xParsed).xml.to.be.valid()
63-
})
64-
})
65-
done()
66-
})
67-
})
6814

6915
describe('Consistent data in aux files', function () {
7016
it('should contain identical descriptions', function (done) {
71-
if (fs.existsSync('build.xml')) {
72-
const build = fs.readFileSync('build.xml', 'utf8')
17+
if (fs.existsSync('pom.xml')) {
18+
const build = fs.readFileSync('pom.xml', 'utf8')
7319
const parsed = new xmldoc.XmlDocument(build)
74-
var buildDesc = parsed.childNamed('description').val
20+
var pomDesc = parsed.childNamed('description').val
7521
}
7622

7723
if (fs.existsSync('package.json')) {
@@ -80,25 +26,8 @@ describe('file system checks', function () {
8026
var pkgDesc = parsed.description
8127
}
8228

83-
if (fs.existsSync('repo.xml')) {
84-
const repo = fs.readFileSync('repo.xml', 'utf8')
85-
const parsed = new xmldoc.XmlDocument(repo)
86-
var repoDesc = parsed.childNamed('description').val
87-
}
88-
89-
if (fs.existsSync('expath-pkg.xml')) {
90-
const exPkg = fs.readFileSync('expath-pkg.xml', 'utf8')
91-
const parsed = new xmldoc.XmlDocument(exPkg)
92-
var exPkgDesc = parsed.childNamed('title').val
93-
}
29+
expect(pkgDesc).to.equal(pomDesc)
9430

95-
const desc = [exPkgDesc, buildDesc, pkgDesc, repoDesc, buildDesc].filter(Boolean)
96-
let i = 0
97-
// console.log(desc)
98-
desc.forEach(function () {
99-
expect(desc[i]).to.equal(exPkgDesc)
100-
i++
101-
})
10231
done()
10332
})
10433

@@ -109,19 +38,14 @@ describe('file system checks', function () {
10938
var pkgVer = parsed.version
11039
}
11140

112-
if (fs.existsSync('expath-pkg.xml')) {
113-
const exPkg = fs.readFileSync('expath-pkg.xml', 'utf8')
114-
const parsed = new xmldoc.XmlDocument(exPkg)
115-
var exPkgVer = parsed.attr.version
41+
if (fs.existsSync('pom.xml')) {
42+
const pom = fs.readFileSync('pom.xml', 'utf8')
43+
const parsed = new xmldoc.XmlDocument(pom)
44+
var pomVer = parsed.childNamed('version').val
11645
}
11746

118-
const vers = [exPkgVer, pkgVer].filter(Boolean)
119-
let i = 0
120-
// console.log(vers)
121-
vers.forEach(function () {
122-
expect(vers[i]).to.equal(exPkgVer)
123-
i++
124-
})
47+
expect(pkgVer).to.equal(pomVer)
48+
12549
done()
12650
})
12751

@@ -132,27 +56,22 @@ describe('file system checks', function () {
13256
var pkgLic = parsed.license
13357
}
13458

135-
if (fs.existsSync('repo.xml')) {
136-
const exRepo = fs.readFileSync('repo.xml', 'utf8')
137-
const parsed = new xmldoc.XmlDocument(exRepo)
138-
var repoLic = parsed.childNamed('license').val
59+
if (fs.existsSync('pom.xml')) {
60+
const pom = fs.readFileSync('pom.xml', 'utf8')
61+
const parsed = new xmldoc.XmlDocument(pom)
62+
var pomLic = parsed.childNamed('licenses').childNamed('license').childNamed('name').val
13963
}
14064

141-
const lic = [repoLic, pkgLic].filter(Boolean)
142-
let i = 0
143-
// console.log(lic)
144-
lic.forEach(function () {
145-
expect(lic[i]).to.equal(pkgLic)
146-
i++
147-
})
65+
expect(pkgLic).to.equal(pomLic)
66+
14867
done()
14968
})
15069

15170
it('should contain identical titles', function (done) {
152-
if (fs.existsSync('build.xml')) {
153-
const build = fs.readFileSync('build.xml', 'utf8')
154-
const parsed = new xmldoc.XmlDocument(build)
155-
var buildTit = parsed.attr.name.toLowerCase()
71+
if (fs.existsSync('pom.xml')) {
72+
const pom = fs.readFileSync('pom.xml', 'utf8')
73+
const parsed = new xmldoc.XmlDocument(pom)
74+
var pomTitle = parsed.childNamed('name').val
15675
}
15776

15877
if (fs.existsSync('package.json')) {
@@ -161,20 +80,16 @@ describe('file system checks', function () {
16180
var pkgTitle = parsed.name
16281
}
16382

164-
if (fs.existsSync('templates/page.html')) {
165-
const page = fs.readFileSync('templates/page.html', 'utf8')
83+
expect(pkgTitle).to.equal(pomTitle)
84+
85+
if (fs.existsSync('target/classes/xar-resources/templates/page.html')) {
86+
const page = fs.readFileSync('target/classes/xar-resources/templates/page.html', 'utf8')
16687
const parsed = new xmldoc.XmlDocument(page)
16788
var pageTitle = parsed.descendantWithPath('head.title').val
16889
}
16990

170-
const titles = [buildTit, pkgTitle, pageTitle].filter(Boolean)
171-
let i = 0
91+
expect(pageTitle).to.equal(pomTitle)
17292

173-
// console.log(titles)
174-
titles.forEach(function () {
175-
expect(titles[i]).to.equal(pkgTitle)
176-
i++
177-
})
17893
done()
17994
})
18095

0 commit comments

Comments
 (0)