1

I'm trying to write some tests to check whether the GUI is behaving correctly. What I have EAR project divided into jar with EJBs (business logic) and WAR (generally GUI). So far I've already written several tests and the business logic works as desired. However I'm struggling with Arquillian tests for functional testing.

For example: I have a login form, with Session Scoped bean responsible for sending a call to EJB with given username and password. The EJB does entire logic - validation, database access etc and then returns the User object. The EJB is injected using CDI.

What I would like to do, is to mock the the injected EJB, so I can simply return null or new User without the database calling and processing. I know I could simply write a new mock ejb class and add it to ShrinkWrap deployment instead of the real implementation, but I find working with Mockito being much nicer solution.

I tried to mock it through @Mock annotation and then use @InjectMocks on the managed bean, but that didn't do any good. I indeed had the reference to the managed bean with the mock being injected but this was not an object that the website made a call to. I believe it's because for the functional testing I am running the test as a client, while the mocking should be done on the server...

What is the proper way to do it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vers
  • 29
  • 5
  • Check out this github repo. It's got all kinds of java-ee tests which use arquillian (including EJB ones). I'm sure you can find examples there. https://github.com/javaee-samples/javaee7-samples – Andy Guibert Dec 10 '15 at 01:32
  • Can't see anything similar to what I want to do. – vers Dec 11 '15 at 21:02

0 Answers0