0

my Problem involves the following toolchain:

  1. javaee 7 application on a glassfish application Server.
  2. JSF with Primefaces as GUI Libraries.
  3. Selenium as GUI Testsuite.

Core Problem is, that i want to reset the Database (postgres/jpa/eclipselink) to a completely fresh state after each Selenium Testcase.

What i have until now is:

  1. Start of each Selenium Testcase initializes the Database with needed Data for this single test. Therefore it uses its own PersistenceUnit with "drop-and-create-tables".
  2. A HttpSessionListener that recognizes the testuser when he logs into the Application and then calls EntityManager.clear().

What I do not fully understand is, what happens with the data stored in my session beans? At the time the testuser logs in, each beans @PostConstruct is called and all Lists, Arrays etc. are reinitialized.

How can I be sure that all data stored in SessionBeans and even in the Primefaces caches (e.g. <p:tabview cache="true">) are discarded?

AlexEnde
  • 1
  • 4

1 Answers1

0

Invalidate your session should do the trick. Call it after each of your test.

you can do it via this piece of code:

FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
Milkmaid
  • 1,659
  • 4
  • 26
  • 39
  • Thank you, that is a good hint, but I fear i forgot to mention the following Problem: A user is not loggin out via a "logout" button so i dont have a a logout() function where i could put that piece of code. The session times out after 30 minutes so the SessionListener is also not a good spot. – AlexEnde Oct 15 '15 at 11:35