當前位置: 首頁>>代碼示例>>Java>>正文


Java TestTransaction類代碼示例

本文整理匯總了Java中org.springframework.test.context.transaction.TestTransaction的典型用法代碼示例。如果您正苦於以下問題:Java TestTransaction類的具體用法?Java TestTransaction怎麽用?Java TestTransaction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TestTransaction類屬於org.springframework.test.context.transaction包,在下文中一共展示了TestTransaction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: commitTxAndStartNewTx

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
public void commitTxAndStartNewTx() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Commit
	TestTransaction.flagForCommit();
	assertFalse(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertInTransaction(false);
	assertFalse(TestTransaction.isActive());
	assertUsers();

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dogbert");

	TestTransaction.start();
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:ProgrammaticTxMgmtTests.java

示例2: commitTxButDoNotStartNewTx

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
public void commitTxButDoNotStartNewTx() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Commit
	TestTransaction.flagForCommit();
	assertFalse(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers();

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dogbert");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ProgrammaticTxMgmtTests.java

示例3: rollbackTxAndStartNewTx

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
public void rollbackTxAndStartNewTx() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback (automatically)
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default rollback semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertTrue(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:ProgrammaticTxMgmtTests.java

示例4: rollbackTxAndStartNewTxWithDefaultCommitSemantics

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:ProgrammaticTxMgmtTests.java

示例5: testTransactional

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
public void testTransactional() throws Exception {
    User user = newUser().address("address").firstName("firstname").lastName("lastname").build();
    user = userRepository.save(user);

    TestTransaction.end();
    Assert.assertEquals(0 , userRepository.findAll().size());


    TestTransaction.start();
    TestTransaction.flagForCommit();
    user = newUser().address("address").firstName("firstname").lastName("lastname").build();
    user = userRepository.save(user);
    TestTransaction.end();

    Assert.assertEquals(user, userRepository.findAll().get(0));
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:18,代碼來源:TransactionalTest.java

示例6: rollbackTxButDoNotStartNewTx

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
public void rollbackTxButDoNotStartNewTx() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback (automatically)
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:ProgrammaticTxMgmtTests.java

示例7: testTransactionalEvent

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Transactional
@Commit
public void testTransactionalEvent() throws Exception {
    publisher.publishEvent(new TransactionalEvent(1));

    Assert.assertEquals(0 , transactionEventListener.getAllEvents().size());

    TestTransaction.end();

    Assert.assertEquals(2 , transactionEventListener.getAllEvents().size());
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:13,代碼來源:TransactionalEventTest.java

示例8: testRollback

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Rollback
public void testRollback() throws Exception {
    User user = newUser().address("address").firstName("firstname").lastName("lastname").build();
    user = userRepository.save(user);

    TestTransaction.end();
    Assert.assertEquals(0 , userRepository.findAll().size());
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:10,代碼來源:TransactionalTest.java

示例9: testCommit

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Commit
public void testCommit() throws Exception {
    User user = newUser().address("address").firstName("firstname").lastName("lastname").build();
    user = userRepository.save(user);

    TestTransaction.end();
    Assert.assertEquals(1 , userRepository.findAll().size());
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:10,代碼來源:TransactionalTest.java

示例10: userTest

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Transactional
@Sql("/sql/create-user.sql")
public void userTest() {
    Assert.assertNotNull(userRepository.findOne(1234l));
    TestTransaction.end();

    Assert.assertNull(userRepository.findOne(1234l));
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:10,代碼來源:SqlTest.java

示例11: USER

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Transactional
@Sql(statements = "INSERT INTO USER (ID, FIRSTNAME,LASTNAME,ADDRESS) VALUES (1234,'Bilbo' , 'Baggins', 'Fondcombe')")
public void userStatementTest() {
    Assert.assertNotNull(userRepository.findOne(1234l));
    TestTransaction.end();
    Assert.assertNull(userRepository.findOne(1234l));
}
 
開發者ID:victorbuckservices,項目名稱:workshop-spring-4.0-to-4.2,代碼行數:9,代碼來源:SqlTest.java

示例12: isActiveWithNonExistentTransactionContext

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void isActiveWithNonExistentTransactionContext() {
	assertFalse(TestTransaction.isActive());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:6,代碼來源:ProgrammaticTxMgmtTests.java

示例13: flagForRollbackWithNonExistentTransactionContext

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void flagForRollbackWithNonExistentTransactionContext() {
	TestTransaction.flagForRollback();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:6,代碼來源:ProgrammaticTxMgmtTests.java

示例14: flagForCommitWithNonExistentTransactionContext

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void flagForCommitWithNonExistentTransactionContext() {
	TestTransaction.flagForCommit();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:6,代碼來源:ProgrammaticTxMgmtTests.java

示例15: isFlaggedForRollbackWithNonExistentTransactionContext

import org.springframework.test.context.transaction.TestTransaction; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void isFlaggedForRollbackWithNonExistentTransactionContext() {
	TestTransaction.isFlaggedForRollback();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:6,代碼來源:ProgrammaticTxMgmtTests.java


注:本文中的org.springframework.test.context.transaction.TestTransaction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。