Skip to content

Commit

Permalink
fix(#14): Resolves TransactionProviderNotFoundException when no Trans…
Browse files Browse the repository at this point in the history
…actionHandler is found (#15)
  • Loading branch information
rmpestano authored and bartoszmajsak committed Aug 3, 2017
1 parent e485925 commit 93b4caa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import org.jboss.arquillian.container.spi.client.deployment.Deployment;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.core.spi.ServiceLoader;
import org.jboss.arquillian.core.spi.context.ApplicationContext;
import org.jboss.arquillian.test.spi.event.suite.TestEvent;
import org.jboss.arquillian.transaction.impl.lifecycle.ModeChecker;
import org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler;
import org.jboss.arquillian.transaction.spi.provider.TransactionProvider;

public class ClientSideTransactionHandler extends TransactionHandler {

@Inject
private Instance<Deployment> deploymentInstance;

Expand All @@ -36,8 +39,18 @@ public class ClientSideTransactionHandler extends TransactionHandler {
@Inject
private Instance<ApplicationContext> applicationContextInstance;

@Inject
private Instance<ServiceLoader> serviceLoaderInstance;

@Override
public boolean isTransactionSupported(TestEvent testEvent) {

final TransactionProvider transactionProvider =
serviceLoaderInstance.get().onlyOne(TransactionProvider.class);
if (transactionProvider == null) {
return false;
}

return new ModeChecker(deploymentInstance.get(), containerInstance.get()).isClientMode(testEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void registerTransactionProvider(@Observes(precedence = 100) Before befor
final TransactionProvider transactionProvider =
serviceLoaderInstance.get().onlyOne(TransactionProvider.class);
if (transactionProvider == null) {
throw new TransactionProviderNotFoundException(
"Transaction provider for given test case has not been found.");
return;
}
transactionProviderProducer.set(transactionProvider);
} catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ public void shouldNotStartTransaction() throws Exception {
getManager().getContext(ClassContext.class).deactivate();
}

@Test
public void shouldNotStartTransactionWhenNoTransactionProividerIsFound() throws Exception {

when(mockServiceLoader.onlyOne(TransactionProvider.class)).thenReturn(null);

getManager().getContext(ClassContext.class).activate(TestClass.class);

Object instance = new TestClass();
Method testMethod = instance.getClass().getMethod("defaultTest");

getManager().fire(new org.jboss.arquillian.test.spi.event.suite.Before(instance, testMethod));

// checks if the transaction context hasn't been created
verifyZeroInteractions(mockTransactionContext);

// verifies that the transaction hasn't been started
verifyZeroInteractions(mockTransactionProvider);

getManager().getContext(ClassContext.class).deactivate();
}


@Test
public void shouldRollbackTransaction() throws Exception {

Expand Down

0 comments on commit 93b4caa

Please sign in to comment.