Wicket continues to impress me

11 12 2008

So I wanted to put in a conditional css thing to fix a IE problem, todo this thing in wicket I just though up a way. And wrote the code, it just worked:)

Heres how:
Markup (in head):

<style wicket:id="ieStyle" type="text/css">


A simple webmarkupcontainer, to put in the hack (with a resource reference)::

add(new WebMarkupContainer("ieStyle"){

protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
super.onComponentTagBody(markupStream, openTag);
String csshoverurl=urlFor(new ResourceReference(BasePage.class,"csshover2.htc")).toString();
getResponse().write("" +
"body {" +
"behavior: url("+csshoverurl+");" +



And to finish it up make it conditional so only IE picks it up, by adding a behavior:

public class IECheckBehaviorBehavior extends  AbstractBehavior {
public IECheckBehaviorBehavior() {
public void beforeRender(Component component) {
Response response = component.getResponse();
response.write("*!--[if lt IE 7]&gt;--*");
public void onRendered(Component component) {
Response response = component.getResponse();

The result:

<!--[if lt IE 7]&gt;-->
body {behavior: url(resources/zeuzgroup.web.page.BasePage/csshover2.htc;jsessionid=1pjzdpc4j8asn);}

Simple and and almost clean 🙂

Ps updated the post to show correct source

testalicious testing

3 11 2008

Test Mashup, TDD / BDD

So these days test driven or behavior driven development are hot around my coordinates. Im going to write a bit about pratical usage of BDD using selenium & jBehave. With backup tools such as maven, cobertura and selenium.

We all hate to maintain large code bases of tests, tests are nice ( and necessary ) but sometimes you just get cluttered by them.

Introducing jBehave

So what if you could have a minimal amount of code and write something like this:

When user goes to homepage
homepage are rendered

Taking it a bit further:

Given a user nino with password dummy
When user goes to homepage and does a login
Then user are logged in and shown profilepage

That would be nice right? In jBehave you archive this by a blend of things, i’ll only cover a subset.

In your steps class you something like the below code, notice that I put in selenium. So the steps are sort of a mini test framework which the scenarios can utilize.

@When("a user visits $page")
public void visits(String page) {
selenium.open("http://localhost:8080/" + page);
@Then("$page are rendered")
public void seesPage(String page) {
"http://localhost:8080/" + page) == 0);
Ensure.ensureThat(!selenium.isTextPresent("HTTP ERROR: 404"));

The scenario are a plain text test, which utilizes the steps above. Something like this:

When a user visits homepage
Then home are rendered
When a user visits errorpage
Then errorpage are rendered

As you can see you could actually put in use cases, and things suddenly got a lot easier to discuss with customers, your tests are readable by non technical eyes and of course it’s not limited to web development. And your maintenance code base got smaller since what you need to write in java have shrunken, you are only building a small framework for the scenarios to utilize. Really really cool!

As you can see jBehave fit’s both for unit testing and the more obvious integration testing.

Introducing Cobertura

While you test it’s still nice to know your code coverage, cobertura’s nice for this as it gives you simple readable reports and it’s transparent to use. Just include a small mojo in your parent pom:

In your parent pom


And in the project pom using it





You will then get reports looking like this:

Cobertura report

Cobertura report

And you can even see which lines are touched in your code:

See what lines are touched by tests

See what lines are touched by tests

Introducing Selenium

Automatic independent browser tests, if your doing web development this is almost a must have, unless you like to do manual tests a lot. However if you are using code coverage which are using byte code instrumentation, you could loose track of what’s tested and what not. A way around this are perhaps to start a embedded jetty server as part of your test, then in theory you should be back on track. Since byte code instrumentation should be able to track again…

Generation of test data!

31 03 2008

I really need some tools to do this in a structured way. More will come once I’ve read into this.

Okay, I discovered something called dbmonster, it ran okay out of the box but failed in foreign key generation for tables..