java - Rebind an stateless ejb -
the stateless bean works fine when deployed app server,
@stateless(name = "utilitiespersonclient") @loggable public class utilitiespersonclient {
and output of log shows created correctly :
java:global/my-app/utilitiespersonclient java:app/my-app/utilitiespersonclient java:module/utilitiespersonclient
however in tests when try rebind bean mock, doesn't rebound , no error thrown :
ejbcontainer = ejbcontainer.createejbcontainer(p); @override @before public void setup() throws exception { super.setup(); utilitiespersonclient mockservice = mock(utilitiespersonclient.class); when(mockservice.getmymap(anycollection())).thenreturn(mockedmap()); ejbcontainer .getcontext() .rebind("java:module/utilitiespersonclient", mockservice); }
how rebind stateless bean using ejbcontainer ?
the rebind doesn't alter existing instances. alters binding yet occur.
so, overcome injected calling class, , altered calling class have setter. used setter directly alter instance.
@ejb private myservice myservice; @before public void setup() throws exception { super.setup(); utilitiespersonclient mockservice = mock(utilitiespersonclient.class); when(mockservice.getmymap(anycollection())).thenreturn(mockedmap()); myservice.setutilitiespersonclient(mockservice); }
Comments
Post a Comment