Monthly Archives: October 2008

Java Café

A few weeks ago I went to Belgium, for an European Union project revision. While I was there, I saw this:

Java Café

Java Café

This may not be new to European people, but certainly is to me! Nice, Java Café!

And at lunch, when adding sugar to my coffee:

Java Sugar

Java Sugar

So, it IS true! Java IS everywhere!


Getting the data out of the tests

Hello everybody!

A few days ago, while I was searching for ways to improve the tests in our projects, I found an interesting article with some ideas. The main concept was to make the tests behavior, data and actual implementation separated. The original article can be found here. In this post, I’ll talk about the first of those things we decided to implement here: getting the data separated from the tests implementations.

First, if the data is not to be inside the test implementation, it ought to be somewhere. Where should it be? The answer is anywhere you decide it is easy to change. Better yet if it can be changed by non-programmers as well. In our case (and in the mentioned article’s example) we are using Excel spreadsheets.

Here is an example of how this looks like:

Data in an excel spreadsheet

Data in an excel spreadsheet

It is most likely that almost anyone can edit this file. So if you have someone that is not involved in programming (like a client), this person should be able to edit this spreadsheet pretty easily.

After having the data ready, you need to access it somehow. To do this, we are using the Apache POI project, which makes accessing and reading this file (and any other MS Office files) pretty easy. The code bellow would read all cells in the spreadsheet and print them out.

HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(fileName));
HSSFSheet sheet = wb.getSheet(sheetName);

for (Iterator<HSSFRow> rit = sheet.rowIterator(); rit.hasNext(); ) {
  HSSFRow row = rit.next();
  for (Iterator<HSSFCell> cit = row.cellIterator(); cit.hasNext(); ) {
    HSSFCell cell = cit.next();
    System.out.println(cell.toString() + " ");
  }
  System.out.println();
}

Now, if you want to know if the correct user listing is being returned from some business logic implementation, you would only need to change that code to compare the results read from the files with the ones returned from your business class. The business rules changed? Change the file and the new expectation will be in place, without even having to touch the test code, unless of course it is a change in the structure of the information.

The next problem that my arise is that you probably have a LOT of tests. Or at least you should have… Anyway, having a spreadsheet for each one would be suicide. Tons of files to handle! So what we can do is to create one spreadsheet per test class. Inside the file, we create one sheet per test. The footer of the spreadsheet then looks like this:

Multiple sheets in a spreadsheet

Multiple sheets in a spreadsheet

And that’s it! What do you think? Any ideas on how to improve this even more? Don’t be shy and post a comment!


Lichcast

Hello everybody!

This time, I will go a little bit off-topic.

A few days ago, I started a podcast. The reason this is off-topic is that the podcast is not related to Java or Agile; it is about a game: World of Warcraft. I really love this game, and it happens that there is no podcast about it in Portuguese, so I decided to start one. Let’s see how it goes!

tauren

tauren

If you are interested, take a look at Lichcast! But be warned that it is recorded in Portuguese…

Bye!


Podcasts!

Do you know what podcasts are? If not, shame on you!

Podcasts are one of the best things invented in the last few years. And I really mean it. Podcasts are like radio shows, but you can download them, put in your mp3 player (it doesn’t have to be an iPod), and listen anytime you want. Actually, I use my mobile phone as a mp3 player to listen to podcasts.

Stuck on traffic? You can be learning something from a podcast while wainting to get home (or work). Or you can liston to something nice while doing the dishes… Or whanever you can think of.

So, bellow are a few ones I listen to all the time. But this is only the tip of the iceberg.

Java Posse – The best java podcast. Ever. Four great java developers discuss java related stuff and makes you laugh in the process.

Java Mobility Podcast – Get up to date in mobility related topics.

Agile Toolkit – So you are into Agile development? Then this podcast is a must. It features a lot of invaluable information.

Talking Metal – Relax a little bit and get some heavy-metal music news ;)

If you listen to any good podcast you think I should also listen to, please leave a comment! :)


Quick Jxta Introduction

According to the classical definition of a peer-to-peer network, peers that are part of this network should be able to run both as a client and as a server. This is what Jxta allows you to do.

Jxta is a platform for developing peer-to-peer applications. It supports the definition stated above, plus a lot of infrastructure features that most peer-to-peer applications might need. One example of such a feature is firewall traversal, which is done transparently for us. Also, it has some other very important qualities:

  • It is open source and thus publicly available;
  • It is programming language agnostic – there is at least a Java, a C++, a Ruby and a mobile implementation;
  • It is communication protocol agnostic: it can run on top of TCP, HTTP, Bluetooth etc.

It is important to note that Jxta is not an API – that’s why it can be independent of the programming language. Jxta defines a set of protocols, that can be implemented in a variety of different platforms. Currently, these are the protocols specified by Jxta:

  • Peer Resolver Protocol (PRP): provides the foundation for sending and responding generic queries between peers
  • Rendezvous Protocol (RVP): used to help propagating queries between peers
  • Peer Discovery Protocol (PDP): used to allow peers to publish and find resources (like other peers, services etc)
  • Endpoint Routing Protocol (ERP): provides the mechanism that a peer can use to find routes to other peers, hiding low level details
  • Pipe Binding Protocol (PBP): provides the means to make a connection between two peers
  • Peer Information Protocol (PIP): used to get information from a peer, like its status or provided services for example

Those are of course very basic definitions of the protocols, but should be enough for now.

Jxta is not difficult to learn but it is extensive. If you are to fully use it, you have a lot to learn. You can find a lot of resources on the internet. There is the official site, which is the best starting point. And the community is active in the mailing lists. Also, I’m currently reading this book, which you can download for free.


Sun Tech Days 2008

This last Monday and Tuesday hold the Sun Tech Days 2008, in São Paulo, Brazil. It was a nice and interesting event, although the last edition was better. The event happened in a good but small venue, Amcham. I had the chance to keep in touch with some people and I ate some good food as well.

Maybe the reason I didn’t like it as must as the last one was the lack of really new and unexpected things… The speeches and tech talks were basically the same as in few other events I attended not too long ago. A little bit more up-to-date, but not that exciting nonetheless.

The only thing I really loved was a demo presented by Simon Ritter, where he used a Nintendo Wii controller and a projector. With the projector he painted a card in a piece of wood he was holding, of the size of an open magazine. He had put infra-red sensors on three of the wood piece corners. The Wii controller was standing on the table, and it was detecting the position of the piece of wood as Simon moved it. With this information, the projector updated the image of the card in the correct location, keeping it always inside the wooden piece.

Then he flipped the wood. And what happens? The back of the card is shown! And all of this written in Java! Amazing =)

To end this post, two pictures:

Fábio and Claudio

Fábio and Claudio at the Conference

People having fun at the Conference

People having fun at the Conference

I took these pictures at the reception party at the end of the first day. More food and drinks!


Follow

Get every new post delivered to your Inbox.