@Test
  public void testCreateOrder() throws InterruptedException {
    OrderId orderId = new OrderId();
    commandGateway.send(new CreateOrderCommand(orderId, "TestOrder"));

    UnitOfWork unitOfWork = unitOfWorkProvider.get();
    Assert.assertEquals(
        "Order is not created", orderRepository.load(orderId).getIdentifier(), orderId);
    unitOfWork.commit();

    ItemId itemId1 = new ItemId();
    commandGateway.send(new AddOrderItemCommand(orderId, itemId1, 10));

    final AtomicBoolean injectionSuccessful = new AtomicBoolean();
    commandGateway.send(
        new RemoveOrderItemCommand(orderId, itemId1),
        new CommandCallback<Boolean>() {
          @Override
          public void onSuccess(Boolean result) {
            injectionSuccessful.set(true);
          }

          @Override
          public void onFailure(Throwable cause) {
            logger.error("Error", cause);
          }
        });

    Assert.assertTrue(
        "Injection into @CommandHandler method is not successful", injectionSuccessful.get());
  }
 @SuppressWarnings("unchecked")
 @Override
 public void run() {
   EventMessage<?> eventMessage = createMessage();
   if (logger.isInfoEnabled()) {
     logger.info(
         "Triggered the publication of event [{}]",
         eventMessage.getPayloadType().getSimpleName());
   }
   UnitOfWork unitOfWork = unitOfWorkFactory.createUnitOfWork();
   try {
     unitOfWork.publishEvent(eventMessage, eventBus);
     unitOfWork.commit();
   } finally {
     tokens.remove(tokenId);
   }
 }