use of org.junit.jupiter.api.extension.ExtendWith in project spring-boot by spring-projects.
the class JtaAutoConfigurationTests method transactionManagerFromJndi.
@ParameterizedTest
@ExtendWith(JndiExtension.class)
@MethodSource("transactionManagerJndiEntries")
void transactionManagerFromJndi(JndiEntry jndiEntry, InitialContext initialContext) throws NamingException {
jndiEntry.register(initialContext);
this.context = new AnnotationConfigApplicationContext(JtaAutoConfiguration.class);
JtaTransactionManager transactionManager = this.context.getBean(JtaTransactionManager.class);
if (jndiEntry.value instanceof UserTransaction) {
assertThat(transactionManager.getUserTransaction()).isEqualTo(jndiEntry.value);
assertThat(transactionManager.getTransactionManager()).isNull();
} else {
assertThat(transactionManager.getUserTransaction()).isInstanceOf(UserTransactionAdapter.class);
assertThat(transactionManager.getTransactionManager()).isEqualTo(jndiEntry.value);
}
}
use of org.junit.jupiter.api.extension.ExtendWith in project spring-boot by spring-projects.
the class JtaAutoConfigurationTests method disableJtaSupport.
@Test
@ExtendWith(JndiExtension.class)
void disableJtaSupport(InitialContext initialContext) throws NamingException {
new JndiEntry("java:comp/UserTransaction", UserTransaction.class).register(initialContext);
this.context = new AnnotationConfigApplicationContext();
TestPropertyValues.of("spring.jta.enabled:false").applyTo(this.context);
this.context.register(JtaAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBeansOfType(JtaTransactionManager.class)).isEmpty();
}
use of org.junit.jupiter.api.extension.ExtendWith in project jgnash by ccavanaugh.
the class TransactionTest method testBackEnd.
@Test
@ExtendWith(TemporaryFolderExtension.class)
void testBackEnd(final TemporaryFolder testFolder) throws IOException {
assertNotNull(testFolder);
final String database = testFolder.createFile("transaction-test.xml").getAbsolutePath();
EngineFactory.deleteDatabase(database);
try {
Engine e = EngineFactory.bootLocalEngine(database, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.XML);
e.setCreateBackups(false);
CurrencyNode defaultCurrency = DefaultCurrencies.buildCustomNode("USD");
e.addCurrency(defaultCurrency);
e.setDefaultCurrency(defaultCurrency);
CurrencyNode cadCurrency = DefaultCurrencies.buildCustomNode("CAD");
e.addCurrency(cadCurrency);
Account incomeAccount = new Account(AccountType.INCOME, defaultCurrency);
incomeAccount.setName("Income Account");
e.addAccount(e.getRootAccount(), incomeAccount);
Account expenseAccount = new Account(AccountType.EXPENSE, defaultCurrency);
expenseAccount.setName("Expense Account");
e.addAccount(e.getRootAccount(), expenseAccount);
Account usdBankAccount = new Account(AccountType.BANK, defaultCurrency);
usdBankAccount.setName("USD Bank Account");
e.addAccount(e.getRootAccount(), usdBankAccount);
Account cadBankAccount = new Account(AccountType.BANK, cadCurrency);
cadBankAccount.setName("CAD Bank Account");
e.addAccount(e.getRootAccount(), cadBankAccount);
TransactionEntry entry = new TransactionEntry();
entry.setDebitAccount(incomeAccount);
entry.setDebitAmount(new BigDecimal("-500.00"));
entry.setCreditAmount(new BigDecimal("500.00"));
entry.setCreditAccount(usdBankAccount);
entry.setMemo("Income transaction");
Transaction transaction = new Transaction();
transaction.addTransactionEntry(entry);
transaction.setPayee("Employer");
e.addTransaction(transaction);
assertEquals(new BigDecimal("500.00"), transaction.getAmount(usdBankAccount));
assertEquals(new BigDecimal("500.00"), usdBankAccount.getBalance());
EngineFactory.closeEngine(EngineFactory.DEFAULT);
} catch (final Exception e) {
fail(e.getMessage());
}
}
Aggregations