Search in sources :

Example 6 with ExtendWith

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);
    }
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 7 with ExtendWith

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();
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 8 with ExtendWith

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());
    }
}
Also used : BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Aggregations

ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Test (org.junit.jupiter.api.Test)7 Credentials (org.apache.hadoop.security.Credentials)3 Log4jConfig (org.apache.hive.testutils.junit.extensions.Log4jConfig)3 UserTransaction (jakarta.transaction.UserTransaction)2 Path (java.nio.file.Path)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Pattern (java.util.regex.Pattern)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)1