Thomas Hjorth Hansen
Thomas Hjorth Hansen

Reputation: 31

Run code before arquillian deployment

I am writing integration tests for a Java EE Servlet using Arquillian + JUnit. I need to be able to execute code before the server launches.

So is it possible to execute code before @Deployment? I tried @BeforeClass with no luck.

The reason I need to do this, is because trust and keystores for ssl needs to exists before the server starts. I am creating the stores problematically and is saving them to files afterwards.

I know a possible workaround would be to have static trust and keystores, but I prefer to create them programmatically before the test starts for full flexibility when writing tests.

Upvotes: 3

Views: 1763

Answers (2)

bartosz.majsak
bartosz.majsak

Reputation: 1064

There is not really a need to have your own specialization of Arquillian JUnit runner. This solution would be only for JUnit 4.x in that case which you are using for writing your tests.

Arquillian let you hook through extensions mechanism to its runtime and this way you can have some custom logic executed before server startup to provide your keystores. I believe this is more elegant and portable solution.

Please have a look at sample extensions on Github (especially lifecycle would be a good starting point). If you feel like implementing it this way I'm more than happy to help you. The event you might want to observe on is either BeforeSetup or BeforeStart.

Upvotes: 2

Gerald Mücke
Gerald Mücke

Reputation: 11132

You have two other options for executing code before and after your test:

  • Rules or ClassRules are executed around and before/after
  • Using a custom Testrunner (extending the default 'Arquillian' runner)

But as the static deployment method is not invoked by a rule, I assume you have to go for the testrunner.

Upvotes: 0

Related Questions