/** * Tests that a invocation on a SFSB method annotated with @Remove results in the removal of the * bean instance */ @Test public void testSimpleRemoveOnSFSB() { // remove the SFSB sfsbWithRemoveMethods.remove(); // try invoking again. we should expect a NoSuchEJBException try { sfsbWithRemoveMethods.remove(); Assert.fail("SFSB was expected to be removed after a call to the @Remove method"); } catch (NoSuchEJBException nsee) { // expected log.info("Got the expected NoSuchEJBException after invoking remove on the SFSB"); } }
/** * Tests that a invocation on SFSB method annotated with @Remove and with "retainIfException = * true" *doesn't* result in removal of the bean when a application exception is thrown. */ @Test public void testRemoveWithRetainIfExceptionOnSFSB() { // invoke the remove method which throws a app exception try { sfsbWithRemoveMethods.retainIfAppException(); Assert.fail("Did not get the expected app exception"); } catch (SimpleAppException sae) { // expected } // invoke again and it should *not* throw NoSuchEJBException try { sfsbWithRemoveMethods.retainIfAppException(); Assert.fail("Did not get the expected app exception on second invocation on SFSB"); } catch (SimpleAppException sae) { // expected } }
/** * Tests that a invocation on SFSB method annotated with @Remove (and without the * retainIfException set to true) results in removal of the bean even in case of application * exception. */ @Test public void testRemoveEvenIfAppExceptionOnSFSB() throws Exception { // invoke the remove method which throws a app exception try { sfsbWithRemoveMethods.removeEvenIfAppException(); Assert.fail("Did not get the expected app exception"); } catch (SimpleAppException sae) { // expected } // invoke again and it *must* throw NoSuchEJBException try { sfsbWithRemoveMethods.removeEvenIfAppException(); Assert.fail("Did not get the expected NoSuchEJBException on second invocation on SFSB"); } catch (NoSuchEJBException nsee) { // expected log.info("Got the expected NoSuchEJBException on second invocation on SFSB"); } }
/** * Tests that an invocation on a simple SFSB method which doesn't have the @Remove on it, * *doesn't* result in the bean instance removal. */ @Test public void testSimpleNonRemoveMethodOnSFSB() { sfsbWithRemoveMethods.doNothing(); sfsbWithRemoveMethods.doNothing(); sfsbWithRemoveMethods.doNothing(); }