More fixes for unit test - Spring tests tightened up around transactions.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2143 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-01-19 09:19:51 +00:00
parent e61136aace
commit 597b67a99b

View File

@@ -200,7 +200,7 @@ public class RoutingContentServiceTest extends BaseSpringTest
{ {
// set the property, but with a null URL // set the property, but with a null URL
ContentData contentData = new ContentData(null, null, 0L, null); ContentData contentData = new ContentData(null, null, 0L, null);
nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, null); nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, contentData);
// get the reader // get the reader
ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
@@ -230,12 +230,13 @@ public class RoutingContentServiceTest extends BaseSpringTest
tempFile.delete(); tempFile.delete();
assertFalse("File not deleted", tempFile.exists()); assertFalse("File not deleted", tempFile.exists());
// now attempt to get the reader for the node
ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
assertFalse("Reader should indicate that content is missing", reader.exists());
// check the indexing doesn't spank everthing // check the indexing doesn't spank everthing
setComplete(); setComplete();
endTransaction(); endTransaction();
// now attempt to get the reader for the node
ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
} }
/** /**
@@ -421,8 +422,16 @@ public class RoutingContentServiceTest extends BaseSpringTest
// rollback and check that the content has 'disappeared' // rollback and check that the content has 'disappeared'
txn.rollback(); txn.rollback();
// need a new transaction
txn = getUserTransaction();
txn.begin();
txn.setRollbackOnly();
reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT);
assertNull("Transaction was rolled back - no content should be visible", reader); assertNull("Transaction was rolled back - no content should be visible", reader);
txn.rollback();
} }
public synchronized void testConcurrentWritesWithMultipleTxns() throws Exception public synchronized void testConcurrentWritesWithMultipleTxns() throws Exception
@@ -482,6 +491,14 @@ public class RoutingContentServiceTest extends BaseSpringTest
public void testTransformation() throws Exception public void testTransformation() throws Exception
{ {
// commit node so that threads can see node
setComplete();
endTransaction();
UserTransaction txn = getUserTransaction();
txn.begin();
txn.setRollbackOnly();
// get a regular writer // get a regular writer
ContentWriter writer = contentService.getTempWriter(); ContentWriter writer = contentService.getTempWriter();
writer.setMimetype("text/xml"); writer.setMimetype("text/xml");
@@ -503,6 +520,14 @@ public class RoutingContentServiceTest extends BaseSpringTest
{ {
// expected // expected
} }
// at this point, the transaction is unusable
txn.rollback();
txn = getUserTransaction();
txn.begin();
txn.setRollbackOnly();
writer.setMimetype("text/plain"); writer.setMimetype("text/plain");
contentService.transform(reader, writer); contentService.transform(reader, writer);
// get the content from the writer // get the content from the writer
@@ -511,6 +536,8 @@ public class RoutingContentServiceTest extends BaseSpringTest
writer.getMimetype(), reader.getMimetype()); writer.getMimetype(), reader.getMimetype());
String contentCheck = reader.getContentString(); String contentCheck = reader.getContentString();
assertEquals("Content check failed", content, contentCheck); assertEquals("Content check failed", content, contentCheck);
txn.rollback();
} }
/** /**