Ошибка отката при тестировании (junit5) - PullRequest
0 голосов
/ 18 апреля 2019

Я провожу некоторые тесты с БД и хотел бы активировать откат, чтобы мне не пришлось сбрасывать данные после каждого теста, но все мои попытки пока тщетны.Аннотации отката игнорируются, а данные удаляются.

Я использую Spring jdbc и junit5

У кого-нибудь есть идеи?

Ниже мой тестовый класс

@ Откат для класса и метода -> fail @EnableTransactionManagement / @Transactionnal -> fail

@Transactional
@Rollback
@ContextConfiguration
@EnableTransactionManagement
class ComptabiliteDaoImplTest extends DBTestCase {

    private ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("/com/dummy/myerp/consumer/applicationContextTest.xml");


    private ComptabiliteDao comptabiliteDao;

    @Override
    protected IDataSet getDataSet() throws Exception {
        return new FlatXmlDataSetBuilder().build(new FileInputStream("dataset.xml"));
    }

    @BeforeEach
    void initDao() {
        comptabiliteDao = new ComptabiliteDaoImpl();

    }



    @Test
    @Rollback
    @Transactional
        //@Disabled
    void deleteEcritureComptable() {
        comptabiliteDao.deleteEcritureComptable(3);
    }


}

Вот контекст моей базы данных:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


    <!-- ====================   Consumer   ==================== -->
    <!-- AbstractDbConsumer -->
    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="com.dummy.myerp.consumer.db.AbstractDbConsumer"/>
        <property name="targetMethod" value="configure"/>
        <property name="arguments">
            <map>
                <entry value-ref="dataSourceMYERP">
                    <key>
                        <value type="com.dummy.myerp.consumer.db.DataSourcesEnum">MYERP</value>
                    </key>
                </entry>

            </map>
        </property>
    </bean>

    <!-- Enable Annotation based Declarative Transaction Management -->
    <tx:annotation-driven proxy-target-class="true"
                          transaction-manager="transactionManager" />

    <!-- Creating TransactionManager Bean, since JDBC we are creating of type
        DataSourceTransactionManager -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceMYERP" />
    </bean>
    <!-- dataSource configuration -->

    <bean id="dataSourceMYERP"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://127.0.0.1:9032/db_myerp"/>
        <property name="username" value="usr_myerp"/>
        <property name="password" value="myerp"/>
    </bean>

    <!-- dataSource configuration -->


    <!-- ==================== Consumer-Proxy ==================== -->

    <!-- ConsumerHelper -->
    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="com.dummy.myerp.consumer.ConsumerHelper"/>
        <property name="targetMethod" value="configure"/>
        <property name="arguments">
            <list>
                <ref bean="DaoProxy"/>
            </list>
        </property>
    </bean>

    <!-- DaoProxy -->
    <bean id="DaoProxy" class="com.dummy.myerp.consumer.dao.impl.DaoProxyImpl" factory-method="getInstance">
        <property name="comptabiliteDao" ref="ComptabiliteDaoImpl"/>
    </bean>

    <!-- ========== SQL ========== -->
    <import resource="sqlContext.xml"/>
</beans>

Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...