Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

93368: Merged 5.0.N (5.0.1) to HEAD-BUG-FIX (5.1/Cloud)
      93293: Merged DEV (5.0.1) to 5.0.N (5.0.1)
         93287: MNT-13089: RepoAdminServiceImplTest hangs on SQL Server
         Modified DictionaryModelTypeTest to execute before test actions in a separate transaction to pass on MS SQL Server.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94954 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 12:21:18 +00:00
parent c3d26637a4
commit a1ca7da9e8

View File

@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.transaction.UserTransaction;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
@@ -37,21 +37,27 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.i18n.MessageService;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.PropertyMap;
import org.junit.experimental.categories.Category;
import org.springframework.util.ResourceUtils;
@@ -62,7 +68,7 @@ import org.springframework.util.ResourceUtils;
* @author Roy Wetherall, janv
*/
@Category(BaseSpringTestsCategory.class)
public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
public class DictionaryModelTypeTest extends BaseSpringTest
{
/** QNames of the test models */
@@ -351,15 +357,39 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
private CheckOutCheckInService cociService;
private DictionaryDAO dictionaryDAO;
private PolicyComponent policyComponent;
private NodeService nodeService;
private ContentService contentService;
private MutableAuthenticationService authenticationService;
private StoreRef storeRef;
private NodeRef rootNodeRef;
private ActionService actionService;
private TransactionService transactionService;
private AuthenticationComponent authenticationComponent;
private UserTransaction txn;
/**
* On setup in transaction override
*/
@Override
protected void onSetUpInTransaction() throws Exception
protected void onSetUp() throws Exception
{
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");
super.onSetUpInTransaction();
// Authenticate as the system user
authenticationComponent = (AuthenticationComponent) this.applicationContext
.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
txn = transactionService.getUserTransaction();
// Create the store in a separate transaction to run successfully on MS SQL Server
txn.begin();
// Create the store and get the root node
this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
// Get the required services
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
@@ -377,6 +407,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
ModelValidatorImpl modelValidator = (ModelValidatorImpl)this.applicationContext.getBean("modelValidator");
modelValidator.setStoreUrls(storeUrlsToValidate);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
DictionaryRepositoryBootstrap bootstrap = new DictionaryRepositoryBootstrap();
bootstrap.setContentService(this.contentService);
bootstrap.setDictionaryDAO(this.dictionaryDAO);
@@ -400,12 +434,20 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// register with dictionary service
bootstrap.register();
txn.commit();
}
@Override
protected void onTearDown() throws Exception
{
authenticationService.clearCurrentSecurityContext();
}
/**
* Test the creation of dictionary model nodes
*/
public void testCreateAndUpdateDictionaryModelNodeContent()
public void testCreateAndUpdateDictionaryModelNodeContent() throws Exception
{
try
{
@@ -426,6 +468,9 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
txn = transactionService.getUserTransaction();
txn.begin();
final NodeRef modelNode = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
@@ -441,8 +486,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_ONE_XML);
// End the transaction to force update
setComplete();
endTransaction();
txn.commit();
final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
@@ -555,7 +599,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
});
}
public void testUpdateDictionaryModelPropertyDelete()
public void testUpdateDictionaryModelPropertyDelete() throws Exception
{
try
{
@@ -572,6 +616,9 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
String uri = this.namespaceService.getNamespaceURI("test1");
assertNull(uri);
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node
PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
@@ -590,8 +637,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_ONE_MODIFIED_XML);
// End the transaction to force update
setComplete();
endTransaction();
txn.commit();
// create node using new type
final NodeRef node1 = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
@@ -695,7 +741,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
});
}
public void testUpdateDictionaryModelConstraintDelete()
public void testUpdateDictionaryModelConstraintDelete() throws Exception
{
try
{
@@ -712,6 +758,9 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
String uri = this.namespaceService.getNamespaceURI("test2");
assertNull(uri);
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node
PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
@@ -730,8 +779,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_TWO_XML);
// End the transaction to force update
setComplete();
endTransaction();
txn.commit();
final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
@@ -817,7 +865,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
});
}
public void testIsActiveFlagAndDelete()
public void testIsActiveFlagAndDelete() throws Exception
{
try
{
@@ -830,6 +878,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// We expect this exception
}
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node
PropertyMap properties = new PropertyMap(1);
final NodeRef modelNode = this.nodeService.createNode(
@@ -847,8 +897,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_ONE_XML);
// End the transaction to force update
setComplete();
endTransaction();
txn.commit();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{
@@ -948,7 +997,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
* Test for MNT-11653
*/
@SuppressWarnings("deprecation")
public void testOverrideMandatoryProperty()
public void testOverrideMandatoryProperty() throws Exception
{
try
{
@@ -969,6 +1018,9 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
txn = transactionService.getUserTransaction();
txn.begin();
final NodeRef modelNode = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
@@ -984,8 +1036,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_THREE_XML);
// End the transaction to force update
setComplete();
endTransaction();
txn.commit();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{