@Test(expected = Exception.class) public void testExecuteInvalidRequest() throws Exception { ServiceDispatcher<?, ?> mockServiceDispatcher = new ServiceDispatcher<Request, Response>() { { this.userContext = Mockito.mock(UserContextApi.class); } @Override protected EntityManager getEntityManager() { return ServiceDispatcherTest.this.mockEM; } @Override protected TransactionControl getTransactionControl() throws InterruptedException, VmidcException { return ServiceDispatcherTest.this.mockedTxControl; } @Override public Response exec(Request request, EntityManager em) throws Exception { throw new Exception(""); } }; mockServiceDispatcher.dispatch(null); Mockito.verify(this.mockedTransaction).rollback(); }
@Override public O dispatch(I request) throws Exception { log.info("Service dispatch " + this.getClass().getSimpleName() + ". User: " + this.userContext.getCurrentUser() + ", Request: " + request); if (Server.isInMaintenance()) { log.warn("Incoming request (pid:" + ServerUtil.getCurrentPid() + ") while server is in maintenance mode."); throw new VmidcException(Server.PRODUCT_NAME + " server is in maintenance mode."); } if (this.em == null) { this.em = getEntityManager(); } TransactionControl txControl = getTransactionControl(); O response = null; try { response = txControl.required(() -> exec(request, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } ChainedDispatch<O> nextDispatch; while ((nextDispatch = popChain()) != null) { try { final O previousResponse = response; final ChainedDispatch<O> tempNext = nextDispatch; response = txControl.required(() -> tempNext.dispatch(previousResponse, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } } log.info("Service response: " + response); return response; }
ServiceDispatcher implements ServiceDispatcherApi<I, O> { @Override public O dispatch(I request) throws Exception { log.info("Service dispatch " + this.getClass().getSimpleName() + ". User: " + this.userContext.getCurrentUser() + ", Request: " + request); if (Server.isInMaintenance()) { log.warn("Incoming request (pid:" + ServerUtil.getCurrentPid() + ") while server is in maintenance mode."); throw new VmidcException(Server.PRODUCT_NAME + " server is in maintenance mode."); } if (this.em == null) { this.em = getEntityManager(); } TransactionControl txControl = getTransactionControl(); O response = null; try { response = txControl.required(() -> exec(request, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } ChainedDispatch<O> nextDispatch; while ((nextDispatch = popChain()) != null) { try { final O previousResponse = response; final ChainedDispatch<O> tempNext = nextDispatch; response = txControl.required(() -> tempNext.dispatch(previousResponse, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } } log.info("Service response: " + response); return response; } }
ServiceDispatcher implements ServiceDispatcherApi<I, O> { @Override public O dispatch(I request) throws Exception { log.info("Service dispatch " + this.getClass().getSimpleName() + ". User: " + this.userContext.getCurrentUser() + ", Request: " + request); if (Server.isInMaintenance()) { log.warn("Incoming request (pid:" + ServerUtil.getCurrentPid() + ") while server is in maintenance mode."); throw new VmidcException(Server.PRODUCT_NAME + " server is in maintenance mode."); } if (this.em == null) { this.em = getEntityManager(); } TransactionControl txControl = getTransactionControl(); O response = null; try { response = txControl.required(() -> exec(request, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } ChainedDispatch<O> nextDispatch; while ((nextDispatch = popChain()) != null) { try { final O previousResponse = response; final ChainedDispatch<O> tempNext = nextDispatch; response = txControl.required(() -> tempNext.dispatch(previousResponse, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } } log.info("Service response: " + response); return response; }  }
ServiceDispatcher implements ServiceDispatcherApi<I, O> { @Override public O dispatch(I request) throws Exception { log.info("Service dispatch " + this.getClass().getSimpleName() + ". User: " + this.userContext.getCurrentUser() + ", Request: " + request); if (Server.isInMaintenance()) { log.warn("Incoming request (pid:" + ServerUtil.getCurrentPid() + ") while server is in maintenance mode."); throw new VmidcException(Server.PRODUCT_NAME + " server is in maintenance mode."); } if (this.em == null) { this.em = getEntityManager(); } TransactionControl txControl = getTransactionControl(); O response = null; try { response = txControl.required(() -> exec(request, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } ChainedDispatch<O> nextDispatch; while ((nextDispatch = popChain()) != null) { try { final O previousResponse = response; final ChainedDispatch<O> tempNext = nextDispatch; response = txControl.required(() -> tempNext.dispatch(previousResponse, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } } log.info("Service response: " + response); return response; }  @Override O dispatch(I request); }
ServiceDispatcher implements ServiceDispatcherApi<I, O> { @Override public O dispatch(I request) throws Exception { log.info("Service dispatch " + this.getClass().getSimpleName() + ". User: " + this.userContext.getCurrentUser() + ", Request: " + request); if (Server.isInMaintenance()) { log.warn("Incoming request (pid:" + ServerUtil.getCurrentPid() + ") while server is in maintenance mode."); throw new VmidcException(Server.PRODUCT_NAME + " server is in maintenance mode."); } if (this.em == null) { this.em = getEntityManager(); } TransactionControl txControl = getTransactionControl(); O response = null; try { response = txControl.required(() -> exec(request, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } ChainedDispatch<O> nextDispatch; while ((nextDispatch = popChain()) != null) { try { final O previousResponse = response; final ChainedDispatch<O> tempNext = nextDispatch; response = txControl.required(() -> tempNext.dispatch(previousResponse, this.em)); } catch (ScopedWorkException e) { handleException(e.getCause()); } } log.info("Service response: " + response); return response; }  @Override O dispatch(I request);  }