ca.gc.aafc.dina.testsupport.TransactionTestingHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dina-test-support Show documentation
Show all versions of dina-test-support Show documentation
Base DINA API test support package
package ca.gc.aafc.dina.testsupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionTemplate;
import javax.inject.Inject;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Helper class to run testing methods in their own transactions and commit.
* Only use when the transaction should absolutely be committed in order to create a valid test.
*/
@Service
public class TransactionTestingHelper {
@Inject
private TransactionTemplate txTemplate;
public T doInTransaction(Supplier operation) {
return txTemplate.execute(status -> operation.get());
}
public void doInTransactionWithoutResult(Consumer operation) {
txTemplate.executeWithoutResult(operation);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy