What to do after Fortinet VPNClient Crash in Ubuntu

At work they are using ForitGate VPN. To be able to work from home I have to use the FortiNetSSLVpnClient. It seems FortiGate is not compatible with any existing other VPN Clients. The forticlient some times crashes and this seem to result in routes not being cleaned up as it should be.

When I am in the office my Ubuntu 12.10 thinks I’m still using VPN and tries to tunnel the connections through the forticlient, which is not running of course. The result is that I get failures for connecting to certain internal domains and servers.

Ping to the servers doens’t work. That gives DNS Lookup failures but performing dnslookup works.

The fix! Flush the dns’s using

sudo /etc/init.d/dns-clean

Update:
Also check that the DNS entries in /etc/resolve.conf are correct. It is possible that the fortinet client did not clean it up as it should be.

Unit testing the database layer

Testing the database layer. Usually an important part of many applications and thus everyone should test it.

But how do you do that?
(if you know how it’s done, this post is not for you, go read something more interesting then!)

You don’t want to setup an Oracle, MySQL, PostgreSQL and such just for running unit tests. Your option? Use an in memory database!

There are a couple of tools available on the opensource market to test your dao layer. I’ve put together an example for a database layer that is using Spring 3.1.2 with JPA2/Hibernate 4.x. For testing I choose the combination of Unitils, H2 in memory database and JUnit.

Unitils is the thing that creates the database using your entities or if you want it can also create your database using an sql script. I usually let hibernate create the database. And add some <dataset> xmls with data.

You can find the example code at github.

Take a look at the tests in src/test/java to see how it is done. There is one test that uses an xml file to populate the database and another test without an xml file. I’ve added Javadoc to the tests to explain what is happening.

This way of testing also allows you to test your service layer with a predefined dataset. Personally I prefer to mock stuff in the service layers. But for doing integration tests it can be useful to have an in memory database.

Happy Testing!

Stop copying that TestSuccessException

Finally you can stop copying that TestSuccessException you write when writing tests with mocking.

I’ve put it in a jar and uploaded it to Maven Central.


    be.redlab.testhelpers
    testhelpers
    1.0.0
    test

The code is on GitHub there is also an EmptyHttpServletRequest, can be useful when calling methods that need a HttpServletRequest as parameter. ( e.g. in Mockito you can’t mock interfaces, so you can mock with the EmptyHttpServletRequest )

At the time being those where the one I needed, want to add more? Just leave an issue on GitHub and/or send a pull request for interesting stuff.