@Test @SpecAssertion(section = Sections.TRANSACTIONAL_OBSERVER_METHODS, id = "aa") public void afterSuccessObserverIsNotNotifiedAfterTxRollBack() throws SystemException { ActionSequence.reset(); ejbTestBean.initTransaction(); ActionSequence.assertSequenceDataContainsAll( Arrays.asList(TransactionPhase.IN_PROGRESS.toString(), TransactionPhase.BEFORE_COMPLETION.toString(), TransactionPhase.AFTER_COMPLETION.toString(), TransactionPhase.AFTER_FAILURE.toString())); Assert.assertFalse(ActionSequence.getSequenceData().contains(TransactionPhase.AFTER_SUCCESS.toString())); } }
public void notify(EventContext<Giraffe> event) { ActionSequence.addAction(TransactionPhase.AFTER_SUCCESS.toString()); receivedPayload = event; }
public void observesAfterFailure(@Observes(during = TransactionPhase.AFTER_FAILURE) Foo foo) { ActionSequence.addAction(TransactionPhase.AFTER_FAILURE.toString()); }
public void observesProgress(@Observes(during = TransactionPhase.IN_PROGRESS) Foo foo) { ActionSequence.addAction(TransactionPhase.IN_PROGRESS.toString()); }
public void observesBeforeCompletion(@Observes(during = TransactionPhase.BEFORE_COMPLETION) Foo foo) { ActionSequence.addAction(TransactionPhase.BEFORE_COMPLETION.toString()); }
public void observesAfterCompletion(@Observes(during = TransactionPhase.AFTER_COMPLETION) Foo foo) { ActionSequence.addAction(TransactionPhase.AFTER_COMPLETION.toString()); }
public void observesAfterSuccess(@Observes(during = TransactionPhase.AFTER_SUCCESS) Foo foo) { ActionSequence.addAction(TransactionPhase.AFTER_SUCCESS.toString()); }
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = { PERSISTENCE, JAVAEE_FULL }) @SpecAssertions({ @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "a"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "b"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "c") }) public void testTransactionalObserverMethod(Student student) throws Exception { ActionSequence.reset(); student.printSuccess(); student.printFailure(); // Checking transaction and client security context is done in FooObserver ActionSequence.assertSequenceDataContainsAll(TransactionPhase.IN_PROGRESS.toString(), TransactionPhase.BEFORE_COMPLETION.toString(), TransactionPhase.AFTER_COMPLETION.toString(), TransactionPhase.AFTER_SUCCESS.toString(), TransactionPhase.AFTER_FAILURE.toString()); } }
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = { PERSISTENCE, JAVAEE_FULL }) @SpecAssertions({ @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "a"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "b"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "c") }) public void testTransactionalObserverMethod(Student student) throws Exception { ActionSequence.reset(); student.printSuccess(); student.printFailure(); // Checking transaction and client security context is done in FooObserver ActionSequence.assertSequenceDataContainsAll(TransactionPhase.IN_PROGRESS.toString(), TransactionPhase.BEFORE_COMPLETION.toString(), TransactionPhase.AFTER_COMPLETION.toString(), TransactionPhase.AFTER_SUCCESS.toString(), TransactionPhase.AFTER_FAILURE.toString()); } }
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER, groups = { PERSISTENCE, JAVAEE_FULL }) @SpecAssertions({ @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "a"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "b"), @SpecAssertion(section = OBSERVER_METHOD_INVOCATION_CONTEXT, id = "c") }) public void testTransactionalObserverMethod(Student student) throws Exception { ActionSequence.reset(); student.printSuccess(); student.printFailure(); // Checking transaction and client security context is done in FooObserver ActionSequence.assertSequenceDataContainsAll(TransactionPhase.IN_PROGRESS.toString(), TransactionPhase.BEFORE_COMPLETION.toString(), TransactionPhase.AFTER_COMPLETION.toString(), TransactionPhase.AFTER_SUCCESS.toString(), TransactionPhase.AFTER_FAILURE.toString()); } }
private void assertClientSecurityContext(TransactionPhase phase) { toner.spill(); try { printer.tryAccess(); fail("Transactional observer method was NOT called within the same client security context."); } catch (javax.ejb.EJBAccessException expected) { // OK } ActionSequence.addAction(phase.toString()); } }
private void assertClientSecurityContext(TransactionPhase phase) { assertTrue(sc.isCallerInRole("printer")); toner.spill(); try { printer.tryAccess(); fail("Transactional observer method was NOT called within the same client security context."); } catch (javax.ejb.EJBAccessException expected) { // OK } ActionSequence.addAction(phase.toString()); } }
private static void assertClientSecurityContext(TransactionPhase phase) { assertTrue(ejbContext.isCallerInRole("student")); assertTrue(!ejbContext.isCallerInRole("printer")); toner.spill(); try { printer.tryAccess(); fail("Transactional observer method was NOT called within the same client security context."); } catch (javax.ejb.EJBAccessException expected) { // OK } ActionSequence.addAction(phase.toString()); } }
@Test(groups = { INTEGRATION, PERSISTENCE }) @SpecAssertions({ @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "fa"), @SpecAssertion(section = OBSERVER_NOTIFICATION, id = "fb") }) public void testCustomTransactionalObserver() throws Exception { ActionSequence.reset(); // GiraffeObserver 2x, GiraffeCustomObserver 1x assertEquals(getCurrentManager().resolveObserverMethods(new Giraffe()).size(), 3); // Transactional invocation giraffeService.feed(); // Test ObserverMethod.notify() was called assertNotNull(extension.getAnyGiraffeObserver().getReceivedPayload()); assertEquals(Giraffe.class, extension.getAnyGiraffeObserver().getReceivedPayload().getEvent().getClass()); assertNotNull(extension.getAnyGiraffeObserver().getReceivedPayload().getMetadata()); // Test ObserverMethod.getTransactionPhase() was called assertTrue(extension.getAnyGiraffeObserver().isTransactionPhaseCalled()); // Test custom observer received notification during the after completion phase (after succesfull commit) // BEFORE_COMPLETION must be fired at the beginning of the commit (after checkpoint) // AFTER_SUCCESS and AFTER_COMPLETION must be fired after BEFORE_COMPLETION // AFTER_FAILURE is not fired ActionSequence.getSequence().beginsWith("checkpoint", TransactionPhase.BEFORE_COMPLETION.toString()); ActionSequence.getSequence().assertDataContainsAll(TransactionPhase.AFTER_SUCCESS.toString(), TransactionPhase.AFTER_COMPLETION.toString()); }
static JsonObjectBuilder createBasicObserverJson(ObserverMethod<?> observerMethod, Probe probe) { JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethod, probe); observerBuilder.add(RECEPTION, observerMethod.getReception().toString()); observerBuilder.add(TX_PHASE, observerMethod.getTransactionPhase().toString()); if (!observerMethod.getObservedQualifiers().isEmpty()) { JsonArrayBuilder qualifiersBuilder = Json.arrayBuilder(); for (Annotation qualifier : observerMethod.getObservedQualifiers()) { qualifiersBuilder.add(annotationToString(qualifier)); } observerBuilder.add(QUALIFIERS, qualifiersBuilder); } if (observerMethod instanceof ObserverMethodImpl) { ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod; observerBuilder.add(DECLARING_BEAN, createSimpleBeanJson(observerMethodImpl.getDeclaringBean(), probe)); } if (isUnrestrictedProcessAnnotatedTypeObserver(observerMethod)) { observerBuilder.add(DESCRIPTION, WARNING_UNRESTRICTED_PAT_OBSERVER); } // Every OM is now instance of Prioritized final int priority = Prioritized.class.cast(observerMethod).getPriority(); observerBuilder.add(PRIORITY, priority); observerBuilder.add(PRIORITY_RANGE, Components.PriorityRange.of(priority).toString()); return observerBuilder; }
static JsonObjectBuilder createBasicObserverJson(ObserverMethod<?> observerMethod, Probe probe) { JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethod, probe); observerBuilder.add(RECEPTION, observerMethod.getReception().toString()); observerBuilder.add(TX_PHASE, observerMethod.getTransactionPhase().toString()); if (!observerMethod.getObservedQualifiers().isEmpty()) { JsonArrayBuilder qualifiersBuilder = Json.arrayBuilder(); for (Annotation qualifier : observerMethod.getObservedQualifiers()) { qualifiersBuilder.add(qualifier.toString()); } observerBuilder.add(QUALIFIERS, qualifiersBuilder); } if (observerMethod instanceof ObserverMethodImpl) { ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod; observerBuilder.add(DECLARING_BEAN, createSimpleBeanJson(observerMethodImpl.getDeclaringBean(), probe)); if (isUnrestrictedProcessAnnotatedTypeObserver(observerMethodImpl)) { observerBuilder.add(DESCRIPTION, WARNING_UNRESTRICTED_PAT_OBSERVER); } } return observerBuilder; }