2016-09-21 5 views
2

私はJPA QueryDSLの例で取り組んでいます。この例ではPersonDaoTest.javaを作成しました。以前私はを使用していたのでクライアントの最新バージョンを更新するように頼んだので、spring-testの下位バージョンを使用していました。私がこのバージョンを使用したとき、私はimport org.springframework.test.context.transaction.TransactionConfiguration;が推奨されていないことを確認しました。誰でも私に最新のバージョンでimport org.springframework.test.context.transaction.TransactionConfiguration;の交換が何かを教えてくれますか?インポートorg.springframework.test.context.transaction.TransactionConfigurationの置き換え。 Springテスト4.3.1のバージョンで?

PersonDaoTest.java

@ContextConfiguration("/test-context.xml") 
@RunWith(SpringJUnit4ClassRunner.class) 
@Transactional 
@TransactionConfiguration(defaultRollback = true) 
public class PersonDaoTest { 

    @Autowired 
    private PersonDao personDao; 

    // 

    @Test 
    public void testCreation() { 
     personDao.save(new Person("Erich", "Gamma")); 
     final Person person = new Person("Kent", "Beck"); 
     personDao.save(person); 
     personDao.save(new Person("Ralph", "Johnson")); 

     final Person personFromDb = personDao.findPersonsByFirstnameQueryDSL("Kent").get(0); 
     Assert.assertEquals(person.getId(), personFromDb.getId()); 
    } 

    @Test 
    public void testMultipleFilter() { 
     personDao.save(new Person("Erich", "Gamma")); 
     final Person person = personDao.save(new Person("Ralph", "Beck")); 
     final Person person2 = personDao.save(new Person("Ralph", "Johnson")); 

     final Person personFromDb = personDao.findPersonsByFirstnameAndSurnameQueryDSL("Ralph", "Johnson").get(0); 
     Assert.assertNotSame(person.getId(), personFromDb.getId()); 
     Assert.assertEquals(person2.getId(), personFromDb.getId()); 
    } 

    @Test 
    public void testOrdering() { 
     final Person person = personDao.save(new Person("Kent", "Gamma")); 
     personDao.save(new Person("Ralph", "Johnson")); 
     final Person person2 = personDao.save(new Person("Kent", "Zivago")); 

     final Person personFromDb = personDao.findPersonsByFirstnameInDescendingOrderQueryDSL("Kent").get(0); 
     Assert.assertNotSame(person.getId(), personFromDb.getId()); 
     Assert.assertEquals(person2.getId(), personFromDb.getId()); 
    } 

    @Test 
    public void testMaxAge() { 
     personDao.save(new Person("Kent", "Gamma", 20)); 
     personDao.save(new Person("Ralph", "Johnson", 35)); 
     personDao.save(new Person("Kent", "Zivago", 30)); 

     final int maxAge = personDao.findMaxAge(); 
     Assert.assertTrue(maxAge == 35); 
    } 

    @Test 
    public void testMaxAgeByName() { 
     personDao.save(new Person("Kent", "Gamma", 20)); 
     personDao.save(new Person("Ralph", "Johnson", 35)); 
     personDao.save(new Person("Kent", "Zivago", 30)); 

     final Map<String, Integer> maxAge = personDao.findMaxAgeByName(); 
     Assert.assertTrue(maxAge.size() == 2); 
     Assert.assertSame(35, maxAge.get("Ralph")); 
     Assert.assertSame(30, maxAge.get("Kent")); 
    } 
} 

enter image description here

+0

https://jira.spring.io/browse/SPR-13472 – Prateek

答えて

2

ドキュメントは理由が存在する:あなたはそれを読むことが期待されている開発者として!

Javadoc for @TransactionConfigurationは、明示的に述べている:

推奨されていません。スプリングフレームワーク4.2のよう

、クラス レベルと@TransactionaltransactionManager修飾子で@Rollback又は@Commitを使用します。

したがって、あなたの質問に対する答えは、単に@Rollbackです。

@TransactionConfiguration(defaultRollback=true)の宣言は、デフォルトはtrueなので役に立たないと思います。だからあなたはそれだけを削除することができます。

よろしく、

サム(春TestContextフレームワークの著者)

+1

感謝。これは私の1000件以上のテストケースで変更する必要があります。またサービスレベルでも。 –

+0

IDE、テキストエディタ、またはperl、sed、awkなどのコマンドラインから簡単な検索と置換を行うだけで、それを達成できます。 –

関連する問題