If you did not attend and you don’t have good excuse – you should regret it. I have never seen such professionals in giving lectures like those two guys. No matter what was the reason of your absence in this post I will try to shortly summarize what this event was all about.
Beauty and curse same time of Java ecosystem is the variety of available frameworks and solutions. There are plenty of ready to use solutions for most of problems that we meet on our daily basis and the tricky part is only to choose the right one. It also applies to testing frameworks. Times when the only tool you use is JUnit are hopefully gone – now there are plenty of very high quality frameworks that help to write any kind of automated tests not only faster but what is more important tests reliability and maintainability factor increases a lot.
Today I would like to share with you 3 testing frameworks/tools that I find very useful and handy.
Behavior Driven Development becomes more and more popular. In my opinion it is a great way not only writing acceptance tests but developing software in general. There are couple of BDD frameworks for Java and since march 2012 we can find real Java port of one of the most important Ruby frameworks – Cucumber – Cucumber JVM.
Cucumber supports Gherkin language to define steps which makes it easy and natural to create specification. Another advantage of Gherkin is that there are cucumber-like frameworks for many languages and platforms which makes it grate to use in organization when team members need to learn only one way of defining steps.
Complete example of usage Cucumber-JVM can be found in version 1.0.0 official announcement. As you can see there – it does not look hard. Hard part begins when it comes to write testable step definitions – it is something for another post. That’s how example feature can look like:
Feature: As a player I want to be able to send mail invitation to my friends
Scenario: player sends successful invitation
Given player "John Doe"
When "John Doe" invites "firstname.lastname@example.org"
Then 1 mail is sent
And invitation from "John Doe" to "email@example.com" is saved
REST, sessions .. wait. There are no sessions in REST application, right? Well, thats true. If we can avoid sessions we should do that. REST is stateless. The main concern about statelessness is authentication. In usual web applications we were used to store user data in session after authentication. How to solve that if we don’t want to use sessions? We should authenticate every request.
Thanks to that we can scale our application, add new nodes, remove nodes without care about session replication and also about consumed Java heap memory.
Recently I’ve been working on high load REST application. Actually we didn’t expect to have high traffic there but surprisingly we had much much higher that we have been prepared for (it’s so called “happy problem”). Application is based on Spring Framework and its secured with Spring Security deployed on Apache Tomcat 7. All resources are totally stateless – HttpSession is not touched by any piece of my code. Unfortunately used Java heap space was increasing all the time until:
java.lang.OutOfMemoryError: Java heap space
was thrown. In order to analyze Java heap dump and runtime usage of heap I used VisualVM.
In this article I will show you how to generate code with JAnnocessor framework created by Nikolche Mihajlovski. First time I met JAnnocessor on GeeCON 2012 conference during Nikolche’s speech: “Innovative and Pragmatic Java Source Code Generation”(slides). Afterwards I used it successfully in one of my projects. There are almost no resources about this framework so I hope my article will be useful for those who are interested in using it or just are looking for brand new toy for their project.
Every Java developer uses some sort of code generation tool on a daily basis. Setters, getters, trivial constructors, toString – all of these is just a boilerplate code. Usually we generate it with our favorite IDE’s help. I can’t really imagine coding it manually and because Java is a static language we will never be able to skip this process.
Those trivial examples of code generation provided by all modern IDEs are not the only situations when code generation is useful. There are many modern frameworks generate some code to help us to write more reliable code and do it faster. I think the most well known examples are QueryDSL and JPA2 Metamodel Generator that creates objects used to perform type-safe database queries.
There are also other situations – not so well supported by IDE – where we could use code generation. Usually it might be helpful in generating:
DTOs and mappers from domain objects to DTOs
These are only examples. For some projects there might be something project specific where we can’t use any existing code generation tool and we have to write our own. How to do that? With Java APT – Annotation Processing Tool.
In the middle of May one of the biggest Java conferences in Poland took place – GeeCON 2012. Although I think it is almost always worth to technical conferences even if lectures not necessarily fit your needs – it was my first time on GeeCON and first visit to technical conference since DevCrowd in April 2011. I went to GeeCON with hurray optimism and very high expectations. I was interested in lots of lectures and I hoped that I will be able to use some of knowledge shared there immediately when I am back to work (some people would call it conference driven development ).
Few facts about GeeCON
3 days – one so called University Day and 2 main days
5 paths – at most 5 lectures at same time
Variety of topics from Java EE by testing, tools like Vaadin, OSGI into Agile methodologies
No speech about Spring Framework or any related product