Skip to content

Commit

Permalink
multi-thread tests for XSLDocument and XSDDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Jan 6, 2014
1 parent e7262b4 commit 2f8d874
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/com/jcabi/xml/XSDDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package com.jcabi.xml;

import com.jcabi.aspects.Parallel;
import com.jcabi.aspects.Tv;
import java.util.Collection;
import javax.xml.transform.dom.DOMSource;
Expand Down Expand Up @@ -135,4 +136,32 @@ public void validatesComplexXml() throws Exception {
}
}

/**
* XSDDocument can validate XML in multiple threads.
* @throws Exception If something goes wrong inside
*/
@Test
public void validatesXmlInThreads() throws Exception {
final XSD xsd = new XSDDocument(
IOUtils.toInputStream(
StringUtils.join(
"<xs:schema xmlns:xs ='http://www.w3.org/2001/XMLSchema' >",
"<xs:element name='foo-5'/>",
" </xs:schema> "
)
)
);
new Runnable() {
@Override
@Parallel(threads = Tv.TEN)
public void run() {
MatcherAssert.assertThat(
xsd.validate(
new DOMSource(new XMLDocument("<foo-5/>").node())
),
Matchers.empty()
);
}
}.run();
}
}
29 changes: 29 additions & 0 deletions src/test/java/com/jcabi/xml/XSLDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
package com.jcabi.xml;

import com.jcabi.aspects.Parallel;
import com.jcabi.aspects.Tv;
import com.rexsl.test.XhtmlMatchers;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -66,4 +68,31 @@ public void makesXslTransformations() throws Exception {
);
}

/**
* XSLDocument can make XSL transformations in multiple threads.
* @throws Exception If something goes wrong inside
*/
@Test
public void makesXslTransformationsInThreads() throws Exception {
final XSL xsl = new XSLDocument(
StringUtils.join(
"<xsl:stylesheet",
" xmlns:xsl='http://www.w3.org/1999/XSL/Transform' ",
" version='2.0' >",
"<xsl:template match='/'><works/>",
"</xsl:template> </xsl:stylesheet>"
)
);
new Runnable() {
@Override
@Parallel(threads = Tv.TEN)
public void run() {
MatcherAssert.assertThat(
xsl.transform(new XMLDocument("<test/>")),
XhtmlMatchers.hasXPath("/works")
);
}
}.run();
}

}

0 comments on commit 2f8d874

Please sign in to comment.