Profile cover photo
Profile photo
Benson Margulies
154 followers
154 followers
About
Posts

Post has attachment

Post has attachment
Homage to Henry Moore
Photo
Add a comment...

Post has attachment
Birthday Girl.
Photo
Add a comment...

Post has attachment
Add a comment...

Post has attachment
Photo
Add a comment...

Post has attachment
Early Fall
Photo
Add a comment...

Post has attachment
painting from greece in 1982
Photo
Add a comment...

Post has attachment

Post has shared content
Add a comment...

Post has attachment
Sometimes you shave the yak, and sometimes the yak shaves you.

I was looking to improve the testing coverage of a system built of a collection of components with a user interface on the top. The UI gets what it needs by talking to some restful endpoints. In some cases, the UI code is using Ajax to talk to the services from the browser. There isn't a platoon of test developers, or any other developers, available. A small group of people has been slowly evolving this stuff.

So, I had a moment of apparent insight: "Why not write some tests cases in Javascript that talk to the services in an integration test? This will prove that the system is working end-to-end and that there isn't some subtle screwup in the services that causes browser problems.

A bit of looking around revealed Jasmine, and a 'jasmine-maven-plugin'. Now, stop with me a second and consider the stack here. You have a test in javascript. It's wrapped into an HTML page by the jasmine-maven-plugin, incorporating jasmine itself and any other 'javascript under test' you let it see. The plugin then stuffs the results into HtmlUnit, which then parses the HTML page and shoves the resulting Javascript into a slightly tweaked copy of Rhino. One of the tweaks of the Rhino is an implementation of XMLHttpRequest, which (in principle) allows for the Javascript to talk to the web service (which is running via the wonders of the Maven 'pre-integration-test' phase).

Do you sense wobbling? Is Yurtle sitting on the top of rather a lot of grumpy compatriots? If 'Turtles all the way down' converges on a stable universe, 'Turtles all the way up (according to Dr. Seuss) has quite a different stability profile.

Sure enough, 'look out below ...'

The XMLHttpRequest implementation in HTMLUnit carefully implements cross-scripting restrictions, but does not include implementation of CORS (http://www.w3.org/TR/cors/). Meanwhile, the constructed web page built in the plugin is, of course, sitting at a file: URL. Oops.

So, now what? Well, I considered making arrangements for the plugin to shove its web page inside the orbit of the container running the service. Not impossible, there's no other reason for this container to be service static anything, so that seemed a lot of code to exist just to facilitate a test.

I considered patching up HtmlUnit to handle CORS. This would not be a small job. CORS has a fundamental effect; a CORS-compatible XMLHttpRequest can't just check for a cross-script request at 'open' and throw. It has to go ahead and send the request, and then decide whether to fail it based on the headers that come back. That's just the 'simple' form. If there are any verbs other than GET or POST in the woodwork, it must (if I'm reading the spec right) save away the original request, and then push an OPTION instead, before deciding whether to send the original. Ugh, this is more work that I can justify to accomplish the original goal.

End of story? I just wrote tests in JUnit that use the CXF REST client API with Jackson to poke at the returned JSON.

Sufficient insomnia might lead me back to HtmlUnit, though testing the results would be a poser. I wonder if there are some open source components that could help me with that?
Add a comment...
Wait while more posts are being loaded