AbstractOrderEventHandlerImpl extends AbstractEventHandlerImpl implements OrderEventHandler { protected void handleInternal(final OrderEvent orderEvent) { transition(orderEvent, orderEvent.getCustomerOrder(), getTransitionTarget(orderEvent)); }    }
@Test public void testHandleInternalNoAuditMessage() throws Exception { final OrderEvent event = this.context.mock(OrderEvent.class, "event"); final CustomerOrder order = this.context.mock(CustomerOrder.class, "order"); this.context.checking(new Expectations() {{ allowing(event).getCustomerOrder(); will(returnValue(order)); allowing(order).getOrderStatus(); will(returnValue(CustomerOrder.ORDER_STATUS_IN_PROGRESS)); allowing(order).getOrdernum(); will(returnValue("100000000000-1")); allowing(event).getParams(); will(returnValue(Collections.emptyMap())); oneOf(order).putValue(with(any(String.class)), with(equal("os.in.progress -> os.completed")), with(I18NModels.AUDITEXPORT)); oneOf(order).setOrderStatus(CustomerOrder.ORDER_STATUS_COMPLETED); }}); final AbstractOrderEventHandlerImpl handler = new AbstractOrderEventHandlerImpl() { @Override protected String getTransitionTarget(final OrderEvent orderEvent) { return CustomerOrder.ORDER_STATUS_COMPLETED; } @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { return false; } }; handler.handleInternal(event); }
@Test public void testHandleInternalWithAuditMessage() throws Exception { final OrderEvent event = this.context.mock(OrderEvent.class, "event"); final CustomerOrder order = this.context.mock(CustomerOrder.class, "order"); this.context.checking(new Expectations() {{ allowing(event).getCustomerOrder(); will(returnValue(order)); allowing(order).getOrderStatus(); will(returnValue(CustomerOrder.ORDER_STATUS_IN_PROGRESS)); allowing(order).getOrdernum(); will(returnValue("100000000000-1")); allowing(event).getParams(); will(returnValue( Collections.singletonMap(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_AUDIT_MESSAGE, "audit trail")) ); oneOf(order).putValue(with(any(String.class)), with(equal("os.in.progress -> os.completed, audit trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).setOrderStatus(CustomerOrder.ORDER_STATUS_COMPLETED); }}); final AbstractOrderEventHandlerImpl handler = new AbstractOrderEventHandlerImpl() { @Override protected String getTransitionTarget(final OrderEvent orderEvent) { return CustomerOrder.ORDER_STATUS_COMPLETED; } @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { return false; } }; handler.handleInternal(event); }
@Test public void testHandleInternalWithClientMessage() throws Exception { final OrderEvent event = this.context.mock(OrderEvent.class, "event"); final CustomerOrder order = this.context.mock(CustomerOrder.class, "order"); this.context.checking(new Expectations() {{ allowing(event).getCustomerOrder(); will(returnValue(order)); allowing(order).getOrderStatus(); will(returnValue(CustomerOrder.ORDER_STATUS_IN_PROGRESS)); allowing(order).getOrdernum(); will(returnValue("100000000000-1")); allowing(event).getParams(); will(returnValue( Collections.singletonMap(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_CLIENT_MESSAGE, "client trail")) ); oneOf(order).putValue(with(any(String.class)), with(equal("os.in.progress -> os.completed, client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).putValue(with(equal("OS_COMPLETED")), with(equal("client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).setOrderStatus(CustomerOrder.ORDER_STATUS_COMPLETED); }}); final AbstractOrderEventHandlerImpl handler = new AbstractOrderEventHandlerImpl() { @Override protected String getTransitionTarget(final OrderEvent orderEvent) { return CustomerOrder.ORDER_STATUS_COMPLETED; } @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { return false; } }; handler.handleInternal(event); }
@Test public void testHandleInternalWithAuditAndClientMessage() throws Exception { final OrderEvent event = this.context.mock(OrderEvent.class, "event"); final CustomerOrder order = this.context.mock(CustomerOrder.class, "order"); final Map<String, String> params = new HashMap<>(); params.put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_AUDIT_MESSAGE, "audit trail"); params.put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_CLIENT_MESSAGE, "client trail"); this.context.checking(new Expectations() {{ allowing(event).getCustomerOrder(); will(returnValue(order)); allowing(order).getOrderStatus(); will(returnValue(CustomerOrder.ORDER_STATUS_IN_PROGRESS)); allowing(order).getOrdernum(); will(returnValue("100000000000-1")); allowing(event).getParams(); will(returnValue(params)); oneOf(order).putValue(with(any(String.class)), with(equal("os.in.progress -> os.completed, audit trail, client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).putValue(with(equal("OS_COMPLETED")), with(equal("client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).setOrderStatus(CustomerOrder.ORDER_STATUS_COMPLETED); }}); final AbstractOrderEventHandlerImpl handler = new AbstractOrderEventHandlerImpl() { @Override protected String getTransitionTarget(final OrderEvent orderEvent) { return CustomerOrder.ORDER_STATUS_COMPLETED; } @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { return false; } }; handler.handleInternal(event); }
@Test public void testHandleInternalWithAuditAndClientMessageAndUser() throws Exception { final OrderEvent event = this.context.mock(OrderEvent.class, "event"); final CustomerOrder order = this.context.mock(CustomerOrder.class, "order"); final Map<String, String> params = new HashMap<>(); params.put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_AUDIT_MESSAGE, "audit trail"); params.put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_CLIENT_MESSAGE, "client trail"); params.put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_USER, "user@test.com"); this.context.checking(new Expectations() {{ allowing(event).getCustomerOrder(); will(returnValue(order)); allowing(order).getOrderStatus(); will(returnValue(CustomerOrder.ORDER_STATUS_IN_PROGRESS)); allowing(order).getOrdernum(); will(returnValue("100000000000-1")); allowing(event).getParams(); will(returnValue(params)); oneOf(order).putValue(with(any(String.class)), with(equal("os.in.progress -> os.completed, user@test.com, audit trail, client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).putValue(with(equal("OS_COMPLETED")), with(equal("client trail")), with(I18NModels.AUDITEXPORT)); oneOf(order).setOrderStatus(CustomerOrder.ORDER_STATUS_COMPLETED); }}); final AbstractOrderEventHandlerImpl handler = new AbstractOrderEventHandlerImpl() { @Override protected String getTransitionTarget(final OrderEvent orderEvent) { return CustomerOrder.ORDER_STATUS_COMPLETED; } @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { return false; } }; handler.handleInternal(event); }