org.springframework.test.context.transaction.TestTransaction Java Examples

The following examples show how to use org.springframework.test.context.transaction.TestTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProgrammaticTxMgmtTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: ProgrammaticTxMgmtTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #3
Source File: ProgrammaticTxMgmtTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #4
Source File: ProgrammaticTxMgmtTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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");
}
 
Example #5
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #6
Source File: ExampleUsingStaticDatabaseNameTest.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void storeNewPersonShouldUseTheCorrectDatabase(@Autowired Neo4jClient client) {

	PersonEntity personEntity = new PersonEntity(1929, "Carlo Pedersoli");
	repositoryUnderTest.save(personEntity).getName();

	// It is easier to test using the Neo4j client, as that one participates in the Spring managed transaction
	// For purity, I would prefer using the driver (as above), but Spring will rollback the transaction
	// in a test before the driver is able to verify the data.
	Optional<String> name = client
		.query("MATCH (p:Person) RETURN p.name")
		.in("movies")
		.fetchAs(String.class).one();
	assertThat(name).hasValue(personEntity.getName());

	// For comparision, in the default database
	// Do to this, we have to end the ongoing test transaction, otherwise SDN-RX will rightfully fail with
	// java.lang.IllegalStateException: There is already an ongoing Spring transaction for 'movies', but you request the default database
	TestTransaction.end();

	name = client
		.query("MATCH (p:Person) RETURN p.name")
		.fetchAs(String.class).one();
	assertThat(name).isEmpty();
}
 
Example #7
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #8
Source File: ProgrammaticTxMgmtTestNGTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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");
}
 
Example #9
Source File: PermissionRepositoryTests.java    From spring-boot-practice with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    assertEquals(4, countRowsInTable("permission"));
    assertEquals(4, permissionRepository.count());
    jdbcTemplate.execute("insert into permission (name) values ('foo');");
    assertEquals(5, countRowsInTable("permission"));
    assertEquals(5, permissionRepository.count());

    Permission p = permissionRepository.findOne(1);
    assertNotNull(p);
    assertEquals("CREATE_USER", p.getName());

    jdbcTemplate.execute("update permission set name = 'BAR' where id = 1;");
    // This does not execute select
    p = permissionRepository.findOne(1);
    assertNotNull(p);
    assertEquals("CREATE_USER", p.getName()); // OMG!

    TestTransaction.flagForCommit();
    TestTransaction.end();

    // Transaction has been committed, so we can get the new result
    p = permissionRepository.findOne(1);
    assertEquals("BAR", p.getName()); // This is the really expected result
}
 
Example #10
Source File: ProgrammaticTxMgmtTestNGTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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");
}
 
Example #11
Source File: ProgrammaticTxMgmtTestNGTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #12
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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");
}
 
Example #13
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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");
}
 
Example #14
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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");
}
 
Example #15
Source File: ProgrammaticTxMgmtTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #16
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #17
Source File: ProgrammaticTxMgmtTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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");
}
 
Example #18
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #19
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #20
Source File: VersionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAddVersionableAspectWithMajorVersionType()
{
    // MAJOR version-type specified when adding the aspect
    NodeRef nodeRef = createNodeWithVersionType(VersionType.MAJOR);
    TestTransaction.flagForCommit();
    TestTransaction.end();
    assertCorrectVersionLabel(nodeRef, "1.0");
}
 
Example #21
Source File: DbNodeServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * <a href="https://issues.alfresco.com/jira/browse/ALF-14929">ALF-14929</a>
 */
public synchronized void testTxnCommitTime() throws Exception
{
    String currentTxn = AlfrescoTransactionSupport.getTransactionId();
    assertNotNull("Must have a txn change UUID for all transactions.");
    
    long start = System.currentTimeMillis();
    this.wait(10L);
    
    // The listener
    final TestTxnCommitTimeTxnListener listener = new TestTxnCommitTimeTxnListener();
    AlfrescoTransactionSupport.bindListener(listener);
    
    // First see what the latest transaction is
    long currentTxnCommitTime = listener.getTxnCommitTime(currentTxn, start);
    assertEquals("Should not have found a written txn", 0L, currentTxnCommitTime);
    
    // Now commit
    TestTransaction.flagForCommit();
    TestTransaction.end();

    // Now check again.  The transaction time must be greater than the last time that
    // the listener wrote through.
    long recordedCommitTimeMs = listener.getTxnCommitTime(currentTxn, start);
    assertTrue(
            "DAO txn write time must be greater than last listener write time",
            recordedCommitTimeMs > listener.lastWriteTime);
}
 
Example #22
Source File: ProgrammaticTxMgmtTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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");
}
 
Example #23
Source File: ProgrammaticTxMgmtTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #24
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testCascadeDelete() throws Exception
{
    // build the node and commit the node graph
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph(nodeService, rootNodeRef);
    NodeRef n3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n1_p_n3")).getChildRef();
    NodeRef n4Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n2_p_n4")).getChildRef();
    NodeRef n6Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n3_p_n6")).getChildRef();
    NodeRef n7Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n5_p_n7")).getChildRef();
    NodeRef n8Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n6_p_n8")).getChildRef();

    // control checks
    assertTrue("n6 not present", nodeService.exists(n6Ref));
    assertTrue("n8 not present", nodeService.exists(n8Ref));
    assertTrue("n8 exists failure", nodeService.exists(n8Ref));
    assertEquals("n6 primary parent association not present on n3", 1, countChildrenOfNode(n3Ref));
    assertEquals("n6 secondary parent association not present on n4", 1, countChildrenOfNode(n4Ref));
    assertEquals("n8 secondary parent association not present on n7", 1, countChildrenOfNode(n7Ref));
    
    // delete n6
    nodeService.deleteNode(n6Ref);
    
    // ensure that we can't see cascaded nodes in-transaction
    assertFalse("n8 not cascade deleted in-transaction", nodeService.exists(n8Ref));
    
    // commit to check
    TestTransaction.flagForCommit();
    TestTransaction.end();

    TestTransaction.start();
    assertFalse("n6 not directly deleted", nodeService.exists(n6Ref));
    assertFalse("n8 not cascade deleted", nodeService.exists(n8Ref));
    assertEquals("n6 primary parent association not removed from n3", 0, countChildrenOfNode(n3Ref));
    assertEquals("n6 secondary parent association not removed from n4", 0, countChildrenOfNode(n4Ref));
    assertEquals("n8 secondary parent association not removed from n7", 0, countChildrenOfNode(n7Ref));
}
 
Example #25
Source File: ThumbnailServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * See REPO-1580, MNT-17113, REPO-1644 (and related)
 */
@Test
public void testLastThumbnailModificationDataContentUpdates() throws Exception
{
    final NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    QName qname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "doclib");

    ThumbnailDefinition details = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(qname.getLocalName());
    NodeRef thumbnail = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
            details.getTransformationOptions(), "doclib");
    assertNotNull(thumbnail);

    TestTransaction.flagForCommit();
    TestTransaction.end();
    
    Thread.sleep(1000);

    // Get initial value of property "Last thumbnail modification data"
    String lastThumbnailDataV1 = ((List<String>) this.secureNodeService.getProperty(pdfOrig, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA)).get(0);
    
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            // Update file content
            setNewContent(pdfOrig, "quick-size-limit.", MimetypeMap.MIMETYPE_PDF);
            return null;
        }
    }, false, true);
    
    Thread.sleep(1000);

    // Get modified value of property "Last thumbnail modification data"
    String lastThumbnailDataV2 = ((List<String>) this.secureNodeService.getProperty(pdfOrig, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA)).get(0);

    // Check if property "Last thumbnail modification data" has changed
    assertFalse("Property 'Last thumbnail modification data' has not changed", lastThumbnailDataV1.equals(lastThumbnailDataV2));
}
 
Example #26
Source File: ProgrammaticTxMgmtTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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");
}
 
Example #27
Source File: DataServiceIT.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@WithMockUser(username = USERNAME_WRITE)
@Test
@Order(51)
public void testDeleteReferencedEntity() {
  dataService.delete(refEntityType.getId(), refEntities.get(0));
  Exception exception = assertThrows(ValueReferencedException.class, TestTransaction::end);
  assertThat(exception.getMessage())
      .containsPattern("entityTypeId:DataServiceItEntityType attributeName:ref_id_attr value:0");
}
 
Example #28
Source File: ThumbnailServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testAutoUpdate() throws Exception
{
    checkTransformer();

    final NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);

    ThumbnailDefinition details = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium");
    @SuppressWarnings("unused")
    final NodeRef thumbnail = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, details
                .getMimetype(), details.getTransformationOptions(), details.getName());

    TestTransaction.flagForCommit();
    TestTransaction.end();

    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Exception
        {
            String ext = ThumbnailServiceImplTest.this.mimetypeMap.getExtension(MimetypeMap.MIMETYPE_IMAGE_JPEG);
            File origFile = AbstractContentTransformerTest.loadQuickTestFile(ext);

            ContentWriter writer = ThumbnailServiceImplTest.this.contentService.getWriter(jpgOrig,
                        ContentModel.PROP_CONTENT, true);
            writer.putContent(origFile);

            return null;
        }
    });

    // TODO
    // this test should wait for the async action to run .. will need to
    // commit transaction for that thou!

    // Thread.sleep(1000);
}
 
Example #29
Source File: DbNodeServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Deletes a child node and then iterates over the children of the parent node,
 * getting the QName.  This caused some issues after we did some optimization
 * using lazy loading of the associations.
 */
public void testLazyLoadIssue() throws Exception
{
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph();
    // commit results
    TestTransaction.flagForCommit();
    TestTransaction.end();

    UserTransaction userTransaction = txnService.getUserTransaction();
    
    try
    {
        userTransaction.begin();
        
        ChildAssociationRef n6pn8Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n6_p_n8"));
        NodeRef n6Ref = n6pn8Ref.getParentRef();
        NodeRef n8Ref = n6pn8Ref.getChildRef();
        
        // delete n8
        nodeService.deleteNode(n8Ref);
        
        // get the parent children
        List<ChildAssociationRef> assocs = nodeService.getChildAssocs(n6Ref);
        for (ChildAssociationRef assoc : assocs)
        {
            // just checking
        }
        
        userTransaction.commit();
    }
    catch(Exception e)
    {
        try { userTransaction.rollback(); } catch (IllegalStateException ee) {}
        throw e;
    }
}
 
Example #30
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before() throws Exception
{
    super.before();
    System.out.println("java.io.tmpdir == " + System.getProperty("java.io.tmpdir"));

    // Get the required services
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext
            .getBean("authenticationService");
    this.actionService = (ActionService) this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService) this.applicationContext.getBean("transactionComponent");
    this.authenticationComponent = (AuthenticationComponent) this.applicationContext
            .getBean("authenticationComponent");
    this.receiver = (RepoTransferReceiverImpl) this.applicationContext.getBean("transferReceiver");
    this.policyComponent = (PolicyComponent) this.applicationContext.getBean("policyComponent");
    this.searchService = (SearchService) this.applicationContext.getBean("searchService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.namespaceService = (NamespaceService) this.applicationContext.getBean("namespaceService");
    this.dummyContent = "This is some dummy content.";        
    this.dummyContentBytes = dummyContent.getBytes("UTF-8");
    authenticationComponent.setSystemUserAsCurrentUser();

    guestHome = repositoryHelper.getGuestHome();
    TestTransaction.flagForCommit();
    TestTransaction.end();
}