Advanced spock testing.

Spock is a nice groovy based testing framework and all though it can be very easy to get you started with spock, this blog will show some non-standard things that you can do as well with spock. For more information about the spock framework (and you should definitely check this out if you are not familiar yet with this great framework), see the Spock framework link
Continue reading “Advanced spock testing.”

Test driven development, my way

We all do it, or at least some of us do it, trying to write test cases for a good code coverage of all the possible solutions for a complex problem. Some of us even try to drive the design for programs through a test driven approach. That is something that I am not a fan of because I think that once you start
programming for a while and start doing test driven development, you are capable enough of overseeing a problem and knowing the general direction for a solution, so the test driven design in my opinion can lead to waste. Waste as in test cases that are not needed anymore and if those test cases are not cleaned out might even lead to misunderstandings. Mind you, most of the time that won’t happen of course, because good test driven developers will clean away the waste. Continue reading “Test driven development, my way”

Playframework artikel van java magazine

Het playframework is een action based web applicatie framework waarbij snelheid van ontwikkeling voorop staat. DIt wordt gerealiseerd door een eigen classloader systeem die elke aanpassing aan java sources en resources meteen oppikt en opnieuw inlaadt zonder enige tussenkomst van de ontwikkelaar. Dit betekent dat er bijna geen re-starts van de server meer nodig zijn. Het playframework zal zelf geen data op de server vasthouden zodat applicaties in principe onbeperkt schaalbaar zijn. Elke actie die op de applicatie uitgevoerd kan worden, kan aan dynamische urls verbonden worden, zodat er nette REST urls gevormd kunnen worden. Het playframework kan complexe data structuren opbouwen aan de hand van http parameters door middel van data binding zonder dat je daar zelf veel voor hoeft te doen. Kortom het playframework maakt het bouwen van webapplicaties weer een stuk leuker. Continue reading “Playframework artikel van java magazine”

Validations for the Play Framework

It can be very easy to add validations to the play framework. Just adding annotations to the objects will usually do the trick, but these are for the values of one field only, like @Required or @Email. If you want to check if some combined properties are valid, then you can use the @CheckWith annotation. With this annotation you have to define a class that will be used for the validation and optionally a message if this fails. For instance, a check on multiple fields for uniqueness in the database can be handled this way. The checkwith class must extend Check. An example will make it more clear
Continue reading “Validations for the Play Framework”

Playframework: Comparing flash parameters for lookup tables

After working with play a bit more I ran into an issue with the flash parameters. If you validate some input form, and there are errors, you can store the previously filled parameters in the flash scope. After that you can re-populate the content of the form again with the flash parameters. However if you have a selection with a lookup table, this will most of the times fail.

Here is a bit of code to explain this situation in more detail. In the html there is a list of entities available:

<select name="orderline.id" id="orderline_id">
  <option value="">Select one
  #{list items: orderlines, as: 'orderline'}
    <option value='${orderline.id}' #{if flash['orderline.id'] != null && flash['orderline.id'] == orderline.id}selected="selected">${orderline.name}
  #{/list}
</select>

Continue reading “Playframework: Comparing flash parameters for lookup tables”

Access control for dwr with spring

With dwr it is possible to define methods on a bean that can be invoked from dwr-ajax calls. That much is easily to achieve following all the default tutorials on dwr on the web. However I wanted to restrict access to certain methods based on the roles that the users have. Otherwise it would be possible for certain users to call ajax methods that are not allowed for that user. But how can I change that behaviour. Looking at the documentation it is not obvious how that can be done, so I started the debugger to see how the integration really works. After some researching I came upon the DwrController that has a method call to ContainerUtil.setupDefaults. In here you can change the default behaviour classes, like the DefaultAccessControl class. So after having changed my own AccessControl implementation all I had to do is add it as parameter to the dwrController tag like so:
Continue reading “Access control for dwr with spring”

Defensive programming as anti-pattern

If you want a solid system, then null pointers can be your friend. This may seem like a contradiction since solid systems should not have null pointer exceptions but it can be a way to make your system fail fast on code that is not correct instead of covering it up. To make this more clear, take a look at the following code:<code>
if (optimizer.getStatus().equals("done") {
// do your thing, not interesting for this blog
else {
// do something else
}

Continue reading “Defensive programming as anti-pattern”

spring configurations

In larger projects you often end up with some settings which should be stored in configuration files. These are mostly settings that won’t change much during the development lifecycle but can change based on which machine the application is running on. A good example for this is the database connect string that the application should connect on. A developer machine can connect to a mysql instance where as the production machine can connect to a large scale oracle database. When deploying the application to production, the deployers should then always check to see if these settings are still corrrect. This can cause a lot of errors in a real time envrionment.
Continue reading “spring configurations”

JRebel for fast development

JRebel, also known in the past as java-rebel, is a class reloading tool, that will automatically reload your classes when you change anything in it. And with anything, I mean anything (well almost anything, but the exceptions will follow shortly).

Normal hot-swapping containers can also reload classes in some occasions, but those occasions are limited to the content of existing methods (and for a number of times. After a couple of times of reloading classes in tomcat, you might or might not start to see different results then you are expecting). JRebel however can reload many more situations, for instance when methods are added or removed, or when the signature of the method is changed. In all of these situations JRebel can reload your classes without requiring a restart of the container. And that is a huge time safer.
Continue reading “JRebel for fast development”