1

I am writing tests for my Hibernate DAO implementations as I explained here and they run well when I execute them with Maven or on Eclipse with Run as -> Maven test. The application uses Oracle so I had to define the TimeZone, and I did it adding Duser.timezone to the pom file as is described here.

The problem is when I want to execute only one test method, because each method has its own running configuration on Eclipse, and it is disappointing to add the timezone to the VM arguments of each configuration.

I have tried adding System.setProperty("user.timezone", "UTC") and also TimeZone.setDefault(new SimpleTimeZone(...)) to the @beforeClass method but it doesn't work. It shows the error ORA-01882: timezone region not found. I think that the cause is that @ContextConfiguration connects to the database before the @beforeClass method.

I have found a workaround that is adding it as a default argument to the VM. I have done it at Windows -> Preferences -> Installed JREs.

Do you know a better way of doing it?

Community
  • 1
  • 1
rafaborrego
  • 610
  • 1
  • 8
  • 19

1 Answers1

0

Well, If you are right about the @Configuration class meddling with the DB, an option would be to do the System.setProperty in a static block in the @Configuration class.

Maarten Winkels
  • 2,407
  • 16
  • 15
  • 1
    Thanks for your answer, it fixed the problem. For those who have never used a static block (like me), here is the code that I had to add at the beginning of the class: `static { System.setProperty("user.timezone", "..."); }` – rafaborrego Aug 08 '14 at 07:52
  • 1
    @rafaborrego - did you have to reset your timezone? i.e. the `System.setProperty` is a permanent JVM wide level setting AFAIK. Right now the problem I am having is that in `@BeforeClass`, `System.getProperty("user.timezone")` returns null. I was wanting to get the current value in `@BeforeClass` and then reset it in `@AfterClass`. – Collin Peters Jan 27 '15 at 00:29