Hi,
I am looking for best practices to test EJBs that act as a kind of filter and pass the filtered input to another EJB. To give you an idea how my EJB works, I've provided some simplified sample code.
@Stateless
public class HandlerBean implements IHandler {
@EJB
private IProcessor proc;
@Override
public void handleItems(List<Item> inputItems) {
for (Item i: inputItems) {
// do some filtering, logging
// checking here...
if (itemIsOkay)
proc.furtherProcessItem(i);
}
}
}
Depending on the list of input items the business logic in the EJB will cause single input items to be passed to another EJB's method. So now I am interesting in testing the filter code. The code is quite complex
and also makes use to check the input against a persistence layer. My first attempt was to generate a mock for the IProcessor interface using a singleton bean. Internally this singleton maintains a list of Item objects
and the implementation of furtherProcessItem stores the parameters in the list. After testing the handleItems method with a defined input stimuli I compare this list with the expected list of further processed items.
However, the whole handling of this additional mocked bean is very cumbersome. I am looking for a more declarative way of expressing the expected behaviour. For the first step it would even be sufficient for me to just
count how often the furtherProcessItem method is called.
Any suggestions? Thank you in advance,
Ingo