@Test public void testFireTransitionUnmappedEvent() throws Exception { OrderStateManagerImpl orderStateManager = new OrderStateManagerImpl(handlersOk, beforeListenersMapOk, afterListenersMapOk); final OrderEvent event = new OrderEventImpl("some.unhandled.cart.event", null); assertFalse(orderStateManager.fireTransition(event)); assertFalse(afterTransitionListenerWasFired); assertFalse(beforeTransitionListenerWasFired); assertFalse(event.getRuntimeParams().containsKey("handled")); }
@Override public boolean fireTransition(final OrderEvent orderEvent) throws OrderException { final OrderEventHandler handler = handlers.get(orderEvent.getEventId()); if (handler == null) { LOG.warn("No handler registered for event {}", orderEvent); } else { fireEventListeners(beforeListenersMap, orderEvent); boolean result; try { LOG.info("{} ... handling", orderEvent); result = handler.handle(orderEvent); orderEvent.getRuntimeParams().put("handled", result); LOG.info("{} ... handled={}", orderEvent, result); fireEventListeners(afterListenersMap, orderEvent); return result; } catch (OrderException e) { if (e instanceof org.yes.cart.service.order.OrderItemAllocationException) { LOG.warn(Markers.alert(), e.getMessage()); } else { LOG.error(Markers.alert(), "Order state transition failed for event " + orderEvent + ", cause: " + e.getMessage(), e); } orderEvent.getRuntimeParams().put("handledException", e); fireEventListeners(afterListenersMap, orderEvent); throw e; } } return false; }
OrderStateManagerImpl implements OrderStateManager { @Override public boolean fireTransition(final OrderEvent orderEvent) throws OrderException { final OrderEventHandler handler = handlers.get(orderEvent.getEventId()); if (handler == null) { LOG.warn("No handler registered for event {}", orderEvent); } else { fireEventListeners(beforeListenersMap, orderEvent); boolean result; try { LOG.info("{} ... handling", orderEvent); result = handler.handle(orderEvent); orderEvent.getRuntimeParams().put("handled", result); LOG.info("{} ... handled={}", orderEvent, result); fireEventListeners(afterListenersMap, orderEvent); return result; } catch (OrderException e) { if (e instanceof org.yes.cart.service.order.OrderItemAllocationException) { LOG.warn(Markers.alert(), e.getMessage()); } else { LOG.error(Markers.alert(), "Order state transition failed for event " + orderEvent + ", cause: " + e.getMessage(), e); } orderEvent.getRuntimeParams().put("handledException", e); fireEventListeners(afterListenersMap, orderEvent); throw e; } } return false; } }
OrderStateManagerImpl implements OrderStateManager { @Override public boolean fireTransition(final OrderEvent orderEvent) throws OrderException { final OrderEventHandler handler = handlers.get(orderEvent.getEventId()); if (handler == null) { LOG.warn("No handler registered for event {}", orderEvent); } else { fireEventListeners(beforeListenersMap, orderEvent); boolean result; try { LOG.info("{} ... handling", orderEvent); result = handler.handle(orderEvent); orderEvent.getRuntimeParams().put("handled", result); LOG.info("{} ... handled={}", orderEvent, result); fireEventListeners(afterListenersMap, orderEvent); return result; } catch (OrderException e) { if (e instanceof org.yes.cart.service.order.OrderItemAllocationException) { LOG.warn(Markers.alert(), e.getMessage()); } else { LOG.error(Markers.alert(), "Order state transition failed for event " + orderEvent + ", cause: " + e.getMessage(), e); } orderEvent.getRuntimeParams().put("handledException", e); fireEventListeners(afterListenersMap, orderEvent); throw e; } } return false; } OrderStateManagerImpl(
            final Map<String, OrderEventHandler> handlers,
            final Map<String, List<? extends OrderStateTransitionListener>> beforeListenersMap,
            final Map<String, List<? extends OrderStateTransitionListener>> afterListenersMap); }
OrderStateManagerImpl implements OrderStateManager { @Override public boolean fireTransition(final OrderEvent orderEvent) throws OrderException { final OrderEventHandler handler = handlers.get(orderEvent.getEventId()); if (handler == null) { LOG.warn("No handler registered for event {}", orderEvent); } else { fireEventListeners(beforeListenersMap, orderEvent); boolean result; try { LOG.info("{} ... handling", orderEvent); result = handler.handle(orderEvent); orderEvent.getRuntimeParams().put("handled", result); LOG.info("{} ... handled={}", orderEvent, result); fireEventListeners(afterListenersMap, orderEvent); return result; } catch (OrderException e) { if (e instanceof org.yes.cart.service.order.OrderItemAllocationException) { LOG.warn(Markers.alert(), e.getMessage()); } else { LOG.error(Markers.alert(), "Order state transition failed for event " + orderEvent + ", cause: " + e.getMessage(), e); } orderEvent.getRuntimeParams().put("handledException", e); fireEventListeners(afterListenersMap, orderEvent); throw e; } } return false; } OrderStateManagerImpl(
            final Map<String, OrderEventHandler> handlers,
            final Map<String, List<? extends OrderStateTransitionListener>> beforeListenersMap,
            final Map<String, List<? extends OrderStateTransitionListener>> afterListenersMap); @Override boolean fireTransition(final OrderEvent orderEvent); @Override Map<String, List<? extends OrderStateTransitionListener>> getBeforeListenersMap(); @Override Map<String, OrderEventHandler> getHandlers(); @Override Map<String, List<? extends OrderStateTransitionListener>> getAfterListenersMap(); }
OrderStateManagerImpl implements OrderStateManager { @Override public boolean fireTransition(final OrderEvent orderEvent) throws OrderException { final OrderEventHandler handler = handlers.get(orderEvent.getEventId()); if (handler == null) { LOG.warn("No handler registered for event {}", orderEvent); } else { fireEventListeners(beforeListenersMap, orderEvent); boolean result; try { LOG.info("{} ... handling", orderEvent); result = handler.handle(orderEvent); orderEvent.getRuntimeParams().put("handled", result); LOG.info("{} ... handled={}", orderEvent, result); fireEventListeners(afterListenersMap, orderEvent); return result; } catch (OrderException e) { if (e instanceof org.yes.cart.service.order.OrderItemAllocationException) { LOG.warn(Markers.alert(), e.getMessage()); } else { LOG.error(Markers.alert(), "Order state transition failed for event " + orderEvent + ", cause: " + e.getMessage(), e); } orderEvent.getRuntimeParams().put("handledException", e); fireEventListeners(afterListenersMap, orderEvent); throw e; } } return false; } OrderStateManagerImpl(
            final Map<String, OrderEventHandler> handlers,
            final Map<String, List<? extends OrderStateTransitionListener>> beforeListenersMap,
            final Map<String, List<? extends OrderStateTransitionListener>> afterListenersMap); @Override boolean fireTransition(final OrderEvent orderEvent); @Override Map<String, List<? extends OrderStateTransitionListener>> getBeforeListenersMap(); @Override Map<String, OrderEventHandler> getHandlers(); @Override Map<String, List<? extends OrderStateTransitionListener>> getAfterListenersMap();  }