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

The following examples show how to use org.springframework.test.context.transaction.TestTransaction. These examples are extracted from open source projects. 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 Project: sdn-rx   Source File: ExampleUsingStaticDatabaseNameTest.java    License: 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 2
Source Project: spring-analysis-note   Source File: ProgrammaticTxMgmtTests.java    License: 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 Project: spring-analysis-note   Source File: ProgrammaticTxMgmtTests.java    License: 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 4
@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
@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 6
@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 7
@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 8
@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 9
@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 10
@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 11
Source Project: java-technology-stack   Source File: ProgrammaticTxMgmtTests.java    License: 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 12
@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 13
@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 14
@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 15
@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 16
@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 17
@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
@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 19
Source Project: spring-analysis-note   Source File: ProgrammaticTxMgmtTests.java    License: 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 20
@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 21
Source Project: java-technology-stack   Source File: ProgrammaticTxMgmtTests.java    License: 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 22
@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 23
/**
 * 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 24
/**
 * Test async composite action execution
 */
@Test
public void testAsyncCompositeActionExecute()
{
    // Create the composite action
    Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_LOCKABLE);
    Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
    action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);        
    CompositeAction compAction = this.actionService.createCompositeAction();
    compAction.setTitle("title");
    compAction.setDescription("description");
    compAction.addAction(action1);
    compAction.addAction(action2);
    compAction.setExecuteAsynchronously(true);
    
    // Execute the composite action
    this.actionService.executeAction(compAction, this.nodeRef);

    TestTransaction.flagForCommit();
    TestTransaction.end();
    
    final NodeService finalNodeService = this.nodeService;
    final NodeRef finalNodeRef = this.nodeRef;
    
    postAsyncActionTest(
            this.transactionService,
            1000, 
            10, 
            new AsyncTest()
            {
                public String executeTest() 
                {
                    boolean result = finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_VERSIONABLE) &&
                    finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_LOCKABLE);
                    return result ? null : "Expected aspects Versionable & Lockable";
                };
            });
}
 
Example 25
@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 26
/**
 * See REPO-2519, MNT-17113
 *
 * @throws IOException
 */
@Test
public void testIfNodesExistsAfterCreateThumbnail() throws IOException
{
    // Add the log appender to the root logger
    LogErrorAppender logErrorAppender = new LogErrorAppender();
    Logger.getRootLogger().addAppender(logErrorAppender);

    // create content node for thumbnail node
    NodeRef pdfOrig = createOriginalContent(folder, MimetypeMap.MIMETYPE_PDF);

    QName qname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "doclib");
    ThumbnailDefinition details = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(qname.getLocalName());

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

    // create thumbnail
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            // Delete the content node (pdfOrig) before the afterCommit code is executed
            TestNodeDeleterListener testNodeDeleterListener = new TestNodeDeleterListener(pdfOrig);
            // It needs to have a higher priority as the implemented afterCommit. The priority in order are (0,1,2,3,4)
            AlfrescoTransactionSupport.bindListener(testNodeDeleterListener, 1);

            thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, details.getTransformationOptions(), "doclib");
            return null;
        }
    }, false, true);

    assertEquals("There should be no error anymore", 0, logErrorAppender.getLog().size());
}
 
Example 27
/**
 * 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 28
@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
@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 30
/**
 * <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);
}