ReferenceError: module is not defined

This is a line that I do not want to see anymore. It happened to me when I tried to set up testing an angular application with some directives, using karma. I thought that I had followed all the steps to set it all up correctly, but I kept on getting this line, indicating that something was indeed wrong. I finally got it all to work, and to prevent others (and myself) the hassle again of finding out what you have to do to get karma working correctly (especially when you already have some js files that you would like to test), I will outline here shortly what I did. Continue reading “ReferenceError: module is not defined”

Spock, for tedious database conditions testing

As I mentioned earlier in my previous post, spock is a very nice groovy based testing framework, that helps us to write better readable test code. This is done through the use of groovy and by the use of behaviour driven development. In behaviour driven development you define what the system is supposed to do and express yourself in clear, hopefully, non programming terms. Groovy and spock helps you do just that. For instance, if I would like to test a valid login based on certain conditions, I could express that as follows:
Continue reading “Spock, for tedious database conditions testing”

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.”

Continuous integration with Git, Jenkins and Maven

Git is an excellent version control system, maven and jenkins are excellent ways for continuous integration and deployment, but how can you set them all up, so they will all work happily and content next to each other?

Requirements
To start it all of, you are going to need :

  • a maven project
  • a central git repository,
  • and jenkins.

Continue reading “Continuous integration with Git, Jenkins and Maven”

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”

Twitter 406 error code

Integrating with social sites, such as twitter, seems to be so easy, and it actually can be, once you get the configuration set up correctly. Last day however, I spend most of my time trying to hunt down a 406 error code when trying to login using a twitter account. According to the twitter site I have to :

  • Think of a name for my application that wants to use the twitter login, well that was not too hard
  • Enter a description
  • Tell on which domain your twitter application will be hosted, but you can enter a placeholder for this if you don’t know that yet, or want to test

And then you should be set and ready to go.

Twitter will then provide you with 2 keys that you need to use to communicate with twitter. Since there are already many libraries available that will take care of the communications for you with twitter, it looks like that was all that I needed to do. Started a webapp, using the playframework and the SecureSocial module and logged in using twitter. Or at least, I tried to login with twitter. Unfortunately, I was not allowed to login, since twitter returned me a 406 error:

WARNING: POST request for "https://api.twitter.com/oauth/request_token" resulted in 406 (Not Acceptable); invoking error handle

Checked it at the twitter error codes and it says :

406 Not Acceptable: Returned by the Search API when an invalid format is specified in the request.

Which is weird since I did not try to use the search api, I was trying to signin with the given keys. Googling around this error I ran into a number of solutions, none of them really worked for me, but after trying out a combination of solutions I finally got it working. This is what I had to do:

  • Allthough it is not required, you have to give a callback url. This url should be back to localhost but that is not a valid domain according to twitter. So I set the callback url to http://localhost.com
  • Changed my /etc/hosts file where localhost.com will now return the ip address of localhost

and now it was working. I could finally login. I think the 406 code explanation should be altered a bit to indicate that it might also be a configuration issue.

I found out later today that I could also have solved this by setting the callback url to http://127.0.0.1

Hope this helps someone sometime

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”

Playframework: handling of validated objects

In my previous blog (see validations for the play framework) I showed you how easy it can be to handle validations with the play framework. This time I will try to explain how this can be combined with the controllers in the playframework to handle these errors.

The controllers in the playframework are the central entry point from the web to your domain. Each controller should extend playframework’s Controller and have a static void method for each action that can be done on the controllers. These actions are static since they are supposed to be a binding point between the stateless aspect of http towards the statefull objects of your models. The actions are bound to urls and type of request (POST or GET) through the routes configuration file. Using the routes configuration file you can create nice looking rest-like url’s that are bound to the controllers. Also this routes file will be used to generate the urls for you if you add them to your view template files. For instance, given that your routes file contains the following route: Continue reading “Playframework: handling of validated objects”

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”