@Test(expected = EJBTransactionRequiredException.class) public void getTemplateProducts_NoTransaction() { // given // when localService.getTemplateProducts(); // then EJBTransactionRequiredException happens }
@Test(expected = EJBTransactionRequiredException.class) public void getProductsForVendor_NoTransaction() { // given // when localService.getProductsForVendor(); // then EJBTransactionRequiredException happens }
private void assertAttribute(final String attribute, final Method method) throws Exception { final MethodTransactionInfo info = (MethodTransactionInfo) attributes.get(method); assertEquals(method.toString(), attribute, info.transAttribute); try { final Object[] args = new Object[method.getParameterTypes().length]; final Object result = method.invoke(bean, args); assertEquals(attribute, result); } catch (final InvocationTargetException e) { assertEquals(attribute, "Mandatory"); assertTrue(e.getTargetException() instanceof EJBTransactionRequiredException); } }
@Test(expected = EJBTransactionRequiredException.class) public void testMANDATORY_NoTx() throws Exception { TransactionInvocationHandlers.TX_MANDATORY.call( callableReturns(new Object()), ctxStub); }
public Object call(Callable<Object> callable, IInvocationCtx ctx) throws Exception { throw new EJBTransactionRequiredException( "Transaction required (MANDATORY)."); }
@Test(expected = EJBTransactionRequiredException.class) public void getAllMarketplace_TransactionMandatory() { marketplaceLocalService.getAllMarketplaces(); }
@Test(expected = EJBTransactionRequiredException.class) public void testPersistWithNoTx() { employeeDAO.persist(new Employee()); }
/** * Renamed method so it shows up with a much more understandable purpose as it * will be the top element in the stacktrace * * @param e Throwable * @param method Method * @param interfce Class */ protected Throwable convertException(Throwable e, final Method method, final Class interfce) { final boolean rmiRemote = Remote.class.isAssignableFrom(interfce); if (e instanceof TransactionRequiredException) { if (!rmiRemote && interfaceType.isBusiness()) { return new EJBTransactionRequiredException(e.getMessage()).initCause(getCause(e)); } else if (interfaceType.isLocal()) { return new TransactionRequiredLocalException(e.getMessage()).initCause(getCause(e)); } else { return e; } } if (e instanceof TransactionRolledbackException) { if (!rmiRemote && interfaceType.isBusiness()) { return new EJBTransactionRolledbackException(e.getMessage()).initCause(getCause(e)); } else if (interfaceType.isLocal()) { return new TransactionRolledbackLocalException(e.getMessage()).initCause(getCause(e)); } else { return e; } } if (e instanceof NoSuchObjectException) { if (!rmiRemote && interfaceType.isBusiness()) { return new NoSuchEJBException(e.getMessage()).initCause(getCause(e)); } else if (interfaceType.isLocal()) { return new NoSuchObjectLocalException(e.getMessage()).initCause(getCause(e)); } else { return e; } } if (e instanceof AccessException) { if (!rmiRemote && interfaceType.isBusiness()) { return new AccessLocalException(e.getMessage()).initCause(getCause(e)); } else if (interfaceType.isLocal()) { return new AccessLocalException(e.getMessage()).initCause(getCause(e)); } else { return e; } } if (e instanceof RemoteException) { if (!rmiRemote && interfaceType.isBusiness()) { return new EJBException(e.getMessage()).initCause(getCause(e)); } else if (interfaceType.isLocal()) { return new EJBException(e.getMessage()).initCause(getCause(e)); } else { return e; } } for (final Class<?> type : method.getExceptionTypes()) { if (type.isAssignableFrom(e.getClass())) { return e; } } // Exception is undeclared // Try and find a runtime exception in there while (e.getCause() != null && !(e instanceof RuntimeException)) { e = e.getCause(); } return e; }