If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!
Showing posts with label XQJ. Show all posts
Showing posts with label XQJ. Show all posts

Tuesday, July 5, 2011

Unit testing XQJGenerator

My first unit tests would only work if I had an xmldb up and running. That was not really convenient. So I looked around for a XQJ implementation that I could use from my unit tests. Saxon9-HE came to the rescue.

I added following dependency to my pom.xml after installing the jar in my local maven repo




test-application-context.xml:


xquery for unit-test: splitting a sentence into words



xquery for unit-test: retrieving all ASF members from pom.xml


unit-test: transform a plain string of words into xml output


unit-test: return the names of all ASF-members of pom.xml

Using XQJ API with Cocoon3

As my research pointed out XMLDB was a bit painfull to use as most xmldb implementations had quite specific API's to accomplish the same result. I instead turned my focus to the newer XQJ API which offers a JDBC alike approach to using XQuery.

Today I wrote a first draft version of an XQJGenerator accompanied from 2 basic unit tests. Although you have to be carefull that not all XQueries can be ported from XMLDB API to XQJ i managed to get the results extracted the way I wanted to.

XQJGenerator.java


XQJGeneratorTest.java


xquery1.xquery


demoboards1.xquery


test-application-context.xml


xquery1.xquery output


demoboards1.xquery output