Unit test Suite for DAOs and some extra content clean tests and fallout

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14838 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley 2009-06-22 17:57:48 +00:00
parent dc5c8b61e2
commit 2d45a887c0
7 changed files with 290 additions and 131 deletions

View File

@ -27,7 +27,9 @@ package org.alfresco.repo.content;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import javax.transaction.RollbackException; import javax.transaction.RollbackException;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
@ -791,4 +793,44 @@ public class RoutingContentServiceTest extends TestCase
assertNotNull("Should be able to get reader", reader); assertNotNull("Should be able to get reader", reader);
assertEquals("Unknown mimetype was changed", bogusMimetype, reader.getMimetype()); assertEquals("Unknown mimetype was changed", bogusMimetype, reader.getMimetype());
} }
/**
* Checks that node copy and delete behaviour behaves correctly w.r.t. cleanup and shared URLs
*/
public void testPostCopyContentRetrieval() throws Exception
{
ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent("Some content");
ContentData writerContentData = writer.getContentData();
ContentData nodeContentData = (ContentData) nodeService.getProperty(contentNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(nodeContentData);
assertEquals("ContentData not the same from NodeService and from ContentWriter", writerContentData, nodeContentData);
Map<QName, Serializable> copyProperties = nodeService.getProperties(contentNodeRef);
copyProperties.remove(ContentModel.PROP_NODE_UUID);
// Copy the node
NodeRef contentCopyNodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, GUID.generate()),
ContentModel.TYPE_CONTENT,
copyProperties).getChildRef();
// Now get and check the ContentData for the copy
ContentData copyNodeContentData = (ContentData) nodeService.getProperty(contentCopyNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(copyNodeContentData);
// The copy should share the same URL even
assertEquals("Copied node's cm:content ContentData was different", writerContentData, copyNodeContentData);
// Delete the first node and ensure that the second valud remains good and the content is editable
nodeService.deleteNode(contentNodeRef);
copyNodeContentData = (ContentData) nodeService.getProperty(contentCopyNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(copyNodeContentData);
assertEquals("Post-delete value didn't remain the same", writerContentData, copyNodeContentData);
ContentReader copyNodeContentReader = contentService.getReader(contentCopyNodeRef, ContentModel.PROP_CONTENT);
assertTrue("Physical content was removed", copyNodeContentReader.exists());
txn.commit();
txn = null;
}
} }

View File

@ -27,6 +27,7 @@ package org.alfresco.repo.content.cleanup;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -45,6 +46,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
@ -96,6 +98,7 @@ public class ContentStoreCleanerTest extends TestCase
ContentDataDAO contentDataDAO = (ContentDataDAO) ctx.getBean("contentDataDAO"); ContentDataDAO contentDataDAO = (ContentDataDAO) ctx.getBean("contentDataDAO");
eagerCleaner = (EagerContentStoreCleaner) ctx.getBean("eagerContentStoreCleaner"); eagerCleaner = (EagerContentStoreCleaner) ctx.getBean("eagerContentStoreCleaner");
eagerCleaner.setEagerOrphanCleanup(false);
// we need a store // we need a store
store = new FileContentStore(ctx, TempFileProvider.getTempDir().getAbsolutePath()); store = new FileContentStore(ctx, TempFileProvider.getTempDir().getAbsolutePath());
@ -225,61 +228,66 @@ public class ContentStoreCleanerTest extends TestCase
assertFalse("Newly created content should be removed.", contentReaderNew.exists()); assertFalse("Newly created content should be removed.", contentReaderNew.exists());
} }
// /** /**
// * TODO: This test must be replaced with one that checks that the raw content binary lives * Create ContentData set it on a Node, delete the Node, then set the ContentData on a new node
// * as long as there is a reference to it. Once the RM-hacks are removed, content * and check that the content is preserved during eager cleanup.
// * will once again be shared and must therefore be cleaned up based on unlinking of */
// * references. public void testEagerCleanupDereferencing() throws Exception
// */ {
// public void testEagerCleanupAfterCopy() throws Exception eagerCleaner.setEagerOrphanCleanup(true);
// {
// // Get the context-defined cleaner final StoreRef storeRef = nodeService.createStore("test", getName() + "-" + GUID.generate());
// ContentStoreCleaner cleaner = (ContentStoreCleaner) ctx.getBean("contentStoreCleaner"); RetryingTransactionCallback<ContentData> testCallback = new RetryingTransactionCallback<ContentData>()
// // Force eager cleanup {
// cleaner.setEagerOrphanCleanup(true); public ContentData execute() throws Throwable
// cleaner.init(); {
// // Create a new file, copy it // Create some content
// RetryingTransactionCallback<Pair<NodeRef, NodeRef>> copyFileCallback = new RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
// { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13);
// public Pair<NodeRef, NodeRef> execute() throws Throwable properties.put(ContentModel.PROP_NAME, (Serializable)"test.txt");
// { NodeRef contentNodeRef = nodeService.createNode(
// // Create some content rootNodeRef,
// StoreRef storeRef = nodeService.createStore("test", "testEagerCleanupAfterCopy-" + GUID.generate()); ContentModel.ASSOC_CHILDREN,
// NodeRef rootNodeRef = nodeService.getRootNode(storeRef); ContentModel.ASSOC_CHILDREN,
// Map<QName, Serializable> properties = Collections.singletonMap(ContentModel.PROP_NAME, (Serializable)"test.txt"); ContentModel.TYPE_CONTENT,
// NodeRef contentNodeRef = nodeService.createNode( properties).getChildRef();
// rootNodeRef, ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
// ContentModel.ASSOC_CHILDREN, writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
// ContentModel.ASSOC_CHILDREN, writer.putContent("INITIAL CONTENT");
// ContentModel.TYPE_CONTENT, ContentData contentData = writer.getContentData();
// properties).getChildRef();
// ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); // Delete the first node
// writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); nodeService.deleteNode(contentNodeRef);
// writer.putContent("INITIAL CONTENT");
// // Now copy it ContentReader reader = contentService.getRawReader(contentData.getContentUrl());
// NodeRef copiedNodeRef = copyService.copy( assertNotNull(reader);
// contentNodeRef, assertTrue("Content was cleaned before end of transaction", reader.exists());
// rootNodeRef,
// ContentModel.ASSOC_CHILDREN, // Make a new copy using the same ContentData
// ContentModel.ASSOC_CHILDREN); properties.put(ContentModel.PROP_NAME, (Serializable)"test2.txt");
// // Done properties.put(ContentModel.PROP_CONTENT, contentData);
// return new Pair<NodeRef, NodeRef>(contentNodeRef, copiedNodeRef); contentNodeRef = nodeService.createNode(
// } rootNodeRef,
// }; ContentModel.ASSOC_CHILDREN,
// Pair<NodeRef, NodeRef> nodeRefPair = transactionService.getRetryingTransactionHelper().doInTransaction(copyFileCallback); ContentModel.ASSOC_CHILDREN,
// // Check that the readers of the content have different URLs ContentModel.TYPE_CONTENT,
// ContentReader contentReaderSource = contentService.getReader(nodeRefPair.getFirst(), ContentModel.PROP_CONTENT); properties).getChildRef();
// assertNotNull("Expected reader for source cm:content", contentReaderSource);
// assertTrue("Expected content for source cm:content", contentReaderSource.exists()); reader = contentService.getRawReader(contentData.getContentUrl());
// ContentReader contentReaderCopy = contentService.getReader(nodeRefPair.getSecond(), ContentModel.PROP_CONTENT); assertNotNull(reader);
// assertNotNull("Expected reader for copy cm:content", contentReaderCopy); assertTrue("Content was cleaned before end of transaction", reader.exists());
// assertTrue("Expected content for copy cm:content", contentReaderCopy.exists());
// String contentUrlSource = contentReaderSource.getContentUrl(); // Done
// String contentUrlCopy = contentReaderCopy.getContentUrl(); return contentData;
// assertFalse("Source and copy must have different URLs", }
// EqualsHelper.nullSafeEquals(contentUrlSource, contentUrlCopy)); };
// } ContentData contentData = transactionService.getRetryingTransactionHelper().doInTransaction(testCallback);
// // Make sure that the content URL still exists
ContentReader reader = contentService.getRawReader(contentData.getContentUrl());
assertNotNull(reader);
assertTrue("Content was cleaned despite being re-referenced in the transaction", reader.exists());
}
public void testImmediateRemoval() throws Exception public void testImmediateRemoval() throws Exception
{ {
cleaner.setProtectDays(0); cleaner.setProtectDays(0);

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.alfresco.repo.domain.contentdata.ContentDataDAOTest;
import org.alfresco.repo.domain.encoding.EncodingDAOTest;
import org.alfresco.repo.domain.hibernate.HibernateSessionHelperTest;
import org.alfresco.repo.domain.locks.LockDAOTest;
import org.alfresco.repo.domain.mimetype.MimetypeDAOTest;
/**
* Suite for domain-related tests.
*
* @author Derek Hulley
*/
public class DomainTestSuite extends TestSuite
{
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(ContentDataDAOTest.class);
suite.addTestSuite(EncodingDAOTest.class);
suite.addTestSuite(HibernateSessionHelperTest.class);
suite.addTestSuite(LockDAOTest.class);
suite.addTestSuite(MimetypeDAOTest.class);
suite.addTestSuite(LocaleDAOTest.class);
suite.addTestSuite(PropertyValueTest.class);
suite.addTestSuite(QNameDAOTest.class);
return suite;
}
}

View File

@ -26,12 +26,16 @@ package org.alfresco.repo.domain.contentdata;
import java.io.Serializable; import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.content.cleanup.EagerContentStoreCleaner; import org.alfresco.repo.content.cleanup.EagerContentStoreCleaner;
import org.alfresco.repo.domain.LocaleDAO; import org.alfresco.repo.domain.LocaleDAO;
import org.alfresco.repo.domain.encoding.EncodingDAO; import org.alfresco.repo.domain.encoding.EncodingDAO;
import org.alfresco.repo.domain.mimetype.MimetypeDAO; import org.alfresco.repo.domain.mimetype.MimetypeDAO;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.repo.transaction.TransactionalResourceHelper;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -52,9 +56,13 @@ import org.springframework.dao.ConcurrencyFailureException;
*/ */
public abstract class AbstractContentDataDAOImpl implements ContentDataDAO public abstract class AbstractContentDataDAOImpl implements ContentDataDAO
{ {
private static Log logger = LogFactory.getLog(AbstractContentDataDAOImpl.class); /**
* Content URL IDs to delete before final commit.
*/
private static final String KEY_PRE_COMMIT_CONTENT_URL_DELETIONS = "AbstractContentDataDAOImpl.PreCommitContentUrlDeletions";
private static final Long CACHE_NULL_LONG = Long.MIN_VALUE; private static final Long CACHE_NULL_LONG = Long.MIN_VALUE;
private static Log logger = LogFactory.getLog(AbstractContentDataDAOImpl.class);
private MimetypeDAO mimetypeDAO; private MimetypeDAO mimetypeDAO;
private EncodingDAO encodingDAO; private EncodingDAO encodingDAO;
@ -100,21 +108,22 @@ public abstract class AbstractContentDataDAOImpl implements ContentDataDAO
*/ */
protected void registerNewContentUrl(String contentUrl) protected void registerNewContentUrl(String contentUrl)
{ {
if (contentStoreCleaner != null) contentStoreCleaner.registerNewContentUrl(contentUrl);
{
contentStoreCleaner.registerNewContentUrl(contentUrl);
}
} }
/** /**
* Register orphaned content for post-commit handling * A <b>content_url</b> entity was dereferenced. This makes no assumptions about the
* current references - dereference deletion is handled in the commit phase.
*/ */
protected void registerOrphanedContentUrl(String contentUrl) protected void registerDereferenceContentUrl(String contentUrl)
{ {
if (contentStoreCleaner != null) Set<String> contentUrls = TransactionalResourceHelper.getSet(KEY_PRE_COMMIT_CONTENT_URL_DELETIONS);
if (contentUrls.size() == 0)
{ {
contentStoreCleaner.registerOrphanedContentUrl(contentUrl); ContentUrlDeleteTransactionListener listener = new ContentUrlDeleteTransactionListener();
AlfrescoTransactionSupport.bindListener(listener);
} }
contentUrls.add(contentUrl);
} }
/** /**
@ -288,6 +297,13 @@ public abstract class AbstractContentDataDAOImpl implements ContentDataDAO
*/ */
protected abstract ContentUrlEntity getContentUrlEntity(String contentUrl); protected abstract ContentUrlEntity getContentUrlEntity(String contentUrl);
/**
* @param contentUrl the URL of the <b>content url</b> entity
* @return Return the entity or <tt>null</tt> if it doesn't exist or is still
* referenced by a <b>content_data</b> entity
*/
protected abstract ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl);
/** /**
* Delete the entity with the given ID * Delete the entity with the given ID
* @return Returns the number of rows deleted * @return Returns the number of rows deleted
@ -315,4 +331,38 @@ public abstract class AbstractContentDataDAOImpl implements ContentDataDAO
* @return Returns the number of rows deleted * @return Returns the number of rows deleted
*/ */
protected abstract int deleteContentDataEntity(Long id); protected abstract int deleteContentDataEntity(Long id);
/**
* Transactional listener that deletes unreferenced <b>content_url</b> entities.
*
* @author Derek Hulley
*/
public class ContentUrlDeleteTransactionListener extends TransactionListenerAdapter
{
@Override
public void beforeCommit(boolean readOnly)
{
// Ignore read-only
if (readOnly)
{
return;
}
Set<String> contentUrls = TransactionalResourceHelper.getSet(KEY_PRE_COMMIT_CONTENT_URL_DELETIONS);
for (String contentUrl : contentUrls)
{
ContentUrlEntity contentUrlEntity = getContentUrlEntityUnreferenced(contentUrl);
if (contentUrlEntity == null)
{
// It is still referenced, so ignore it
continue;
}
// It needs to be deleted
Long contentUrlId = contentUrlEntity.getId();
deleteContentUrlEntity(contentUrlId);
// Pop this in the queue for deletion from the content store
contentStoreCleaner.registerOrphanedContentUrl(contentUrl);
}
contentUrls.clear();
}
}
} }

View File

@ -46,10 +46,10 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
{ {
private static final String SELECT_CONTENT_URL_BY_ID = "select.ContentUrlById"; private static final String SELECT_CONTENT_URL_BY_ID = "select.ContentUrlById";
private static final String SELECT_CONTENT_URL_BY_KEY = "select.ContentUrlByKey"; private static final String SELECT_CONTENT_URL_BY_KEY = "select.ContentUrlByKey";
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "select.ContentUrlByKeyUnreferenced";
private static final String SELECT_CONTENT_URLS = "select.ContentUrls"; private static final String SELECT_CONTENT_URLS = "select.ContentUrls";
private static final String SELECT_CONTENT_DATA_BY_ID = "select.ContentDataById"; private static final String SELECT_CONTENT_DATA_BY_ID = "select.ContentDataById";
private static final String SELECT_CONTENT_DATA_BY_NODE_AND_QNAME = "select.ContentDataByNodeAndQName"; private static final String SELECT_CONTENT_DATA_BY_NODE_AND_QNAME = "select.ContentDataByNodeAndQName";
private static final String SELECT_CONTENT_DATA_BY_URL_ID = "select.ContentDataByContentUrlId";
private static final String INSERT_CONTENT_URL = "insert.ContentUrl"; private static final String INSERT_CONTENT_URL = "insert.ContentUrl";
private static final String INSERT_CONTENT_DATA = "insert.ContentData"; private static final String INSERT_CONTENT_DATA = "insert.ContentData";
private static final String DELETE_CONTENT_DATA = "delete.ContentData"; private static final String DELETE_CONTENT_DATA = "delete.ContentData";
@ -105,6 +105,16 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
return template.delete(DELETE_CONTENT_URL, params); return template.delete(DELETE_CONTENT_URL, params);
} }
@Override
protected ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override @Override
protected ContentDataEntity createContentDataEntity( protected ContentDataEntity createContentDataEntity(
Long contentUrlId, Long contentUrlId,
@ -166,22 +176,13 @@ public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
} }
// Only check the content URLs if one is present // Only check the content URLs if one is present
String contentUrl = contentDataEntity.getContentUrl(); String contentUrl = contentDataEntity.getContentUrl();
Long contentUrlId = contentDataEntity.getContentUrlId();
// Delete the ContentData entity // Delete the ContentData entity
deleteContentData(id); deleteContentData(id);
// Check if the content URL was orphaned // Check if the content URL was orphaned
if (contentUrlId != null) if (contentUrl != null)
{ {
params.clear(); // It has been dereferenced and may be orphaned - we'll check later
params.put("id", contentUrlId); registerDereferenceContentUrl(contentUrl);
@SuppressWarnings("unchecked")
List<ContentDataEntity> contentDataEntities = (List<ContentDataEntity>) template.queryForList(SELECT_CONTENT_DATA_BY_URL_ID, params);
// If there is still ContentData associated with the content URL, then leave it
if (contentDataEntities.size() == 0)
{
// Orphaned
registerOrphanedContentUrl(contentUrl);
}
} }
} }
} }

View File

@ -4,6 +4,10 @@ import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.AuditableProperties; import org.alfresco.repo.domain.AuditableProperties;
import org.alfresco.repo.domain.Node; import org.alfresco.repo.domain.Node;
@ -11,16 +15,32 @@ import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.domain.Server; import org.alfresco.repo.domain.Server;
import org.alfresco.repo.domain.Store; import org.alfresco.repo.domain.Store;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.BaseSpringTest; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.engine.EntityKey; import org.hibernate.engine.EntityKey;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
public class HibernateSessionHelperTest extends BaseSpringTest public class HibernateSessionHelperTest extends TestCase
{ {
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
protected void onTearDownInTransaction() private UserTransaction txn;
private SessionFactory sessionFactory;
@Override
protected void setUp() throws Exception
{ {
sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
TransactionService transactionService = serviceRegistry.getTransactionService();
txn = transactionService.getUserTransaction();
txn.begin();
// force a flush to ensure that the database updates succeed // force a flush to ensure that the database updates succeed
try try
{ {
@ -33,6 +53,28 @@ public class HibernateSessionHelperTest extends BaseSpringTest
} }
} }
private Session getSession()
{
return SessionFactoryUtils.getSession(sessionFactory, true);
}
@Override
protected void tearDown()
{
if (txn != null)
{
try
{
txn.rollback();
}
catch (Throwable e)
{
// Don't let this hide errors coming from the tests
e.printStackTrace();
}
}
}
public void testSimpleMark() public void testSimpleMark()
{ {
assertEquals(0, getSession().getStatistics().getEntityCount()); assertEquals(0, getSession().getStatistics().getEntityCount());
@ -56,7 +98,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(2, getSession().getStatistics().getEntityCount()); assertEquals(2, getSession().getStatistics().getEntityCount());
HibernateSessionHelper helper = (HibernateSessionHelper)getApplicationContext().getBean("hibernateSessionHelper"); HibernateSessionHelper helper = (HibernateSessionHelper) ctx.getBean("hibernateSessionHelper");
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
helper.mark(); helper.mark();
assertTrue(SessionSizeResourceManager.isDisableInTransaction()); assertTrue(SessionSizeResourceManager.isDisableInTransaction());
@ -92,7 +134,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(0, getSession().getStatistics().getEntityCount()); assertEquals(0, getSession().getStatistics().getEntityCount());
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
QNameDAO qnameDAO = (QNameDAO) getApplicationContext().getBean("qnameDAO"); QNameDAO qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
Long baseQNameId = qnameDAO.getOrCreateQName(ContentModel.TYPE_BASE).getFirst(); Long baseQNameId = qnameDAO.getOrCreateQName(ContentModel.TYPE_BASE).getFirst();
StoreImpl store = new StoreImpl(); StoreImpl store = new StoreImpl();
@ -118,7 +160,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(4, getSession().getStatistics().getEntityCount()); assertEquals(4, getSession().getStatistics().getEntityCount());
HibernateSessionHelper helper = (HibernateSessionHelper)getApplicationContext().getBean("hibernateSessionHelper"); HibernateSessionHelper helper = (HibernateSessionHelper)ctx.getBean("hibernateSessionHelper");
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
helper.mark(); helper.mark();
assertTrue(SessionSizeResourceManager.isDisableInTransaction()); assertTrue(SessionSizeResourceManager.isDisableInTransaction());
@ -284,7 +326,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(2, getSession().getStatistics().getEntityCount()); assertEquals(2, getSession().getStatistics().getEntityCount());
HibernateSessionHelper helper = (HibernateSessionHelper)getApplicationContext().getBean("hibernateSessionHelper"); HibernateSessionHelper helper = (HibernateSessionHelper)ctx.getBean("hibernateSessionHelper");
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
helper.mark("One"); helper.mark("One");
assertTrue(SessionSizeResourceManager.isDisableInTransaction()); assertTrue(SessionSizeResourceManager.isDisableInTransaction());
@ -320,7 +362,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(0, getSession().getStatistics().getEntityCount()); assertEquals(0, getSession().getStatistics().getEntityCount());
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
QNameDAO qnameDAO = (QNameDAO) getApplicationContext().getBean("qnameDAO"); QNameDAO qnameDAO = (QNameDAO) ctx.getBean("qnameDAO");
Long baseQNameId = qnameDAO.getOrCreateQName(ContentModel.TYPE_BASE).getFirst(); Long baseQNameId = qnameDAO.getOrCreateQName(ContentModel.TYPE_BASE).getFirst();
StoreImpl store = new StoreImpl(); StoreImpl store = new StoreImpl();
@ -346,7 +388,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(4, getSession().getStatistics().getEntityCount()); assertEquals(4, getSession().getStatistics().getEntityCount());
HibernateSessionHelper helper = (HibernateSessionHelper)getApplicationContext().getBean("hibernateSessionHelper"); HibernateSessionHelper helper = (HibernateSessionHelper)ctx.getBean("hibernateSessionHelper");
assertNull(helper.getCurrentMark()); assertNull(helper.getCurrentMark());
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
helper.mark("One"); helper.mark("One");
@ -504,7 +546,7 @@ public class HibernateSessionHelperTest extends BaseSpringTest
assertEquals(3, getSession().getStatistics().getEntityCount()); assertEquals(3, getSession().getStatistics().getEntityCount());
HibernateSessionHelper helper = (HibernateSessionHelper)getApplicationContext().getBean("hibernateSessionHelper"); HibernateSessionHelper helper = (HibernateSessionHelper)ctx.getBean("hibernateSessionHelper");
assertFalse(SessionSizeResourceManager.isDisableInTransaction()); assertFalse(SessionSizeResourceManager.isDisableInTransaction());
helper.mark("One"); helper.mark("One");
helper.mark("Two"); helper.mark("Two");

View File

@ -281,48 +281,6 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
} }
} }
/**
* Checks that the string_value retrieval against a property type is working
*/
public void testGetContentDataValues() throws Exception
{
final DataTypeDefinition contentDataType = dictionaryService.getDataType(DataTypeDefinition.CONTENT);
ContentData contentDataSingle = new ContentData("url-single", MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null);
ContentData contentDataMultiple = new ContentData("url-multiple", MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null);
// put this in as a random single property
nodeService.setProperty(
rootNodeRef,
QName.createQName(NAMESPACE, "random-single"),
contentDataSingle);
// create a collection of mixed types
ArrayList<Serializable> collection = new ArrayList<Serializable>(3);
collection.add("abc");
collection.add(new Integer(123));
collection.add(contentDataMultiple);
nodeService.setProperty(
rootNodeRef,
QName.createQName(NAMESPACE, "random-multiple"),
collection);
// get a list of all content values
final List<Serializable> allContentDatas = new ArrayList<Serializable>(500);
NodePropertyHandler handler = new NodePropertyHandler()
{
public void handle(NodeRef nodeRef, QName nodeTypeQName, QName propertyQName, Serializable value)
{
allContentDatas.add(value);
}
};
nodeDaoService.getPropertyValuesByActualType(contentDataType, handler);
assertTrue("At least two instances expected", allContentDatas.size() >= 2);
assertTrue("Single content data not present in results",
allContentDatas.contains(contentDataSingle));
assertTrue("Multi-valued buried content data not present in results",
allContentDatas.contains(contentDataMultiple));
}
public void testMLTextValues() throws Exception public void testMLTextValues() throws Exception
{ {
// Set the server default locale // Set the server default locale