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.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.transaction.UserTransaction;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource; 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.content.MimetypeMap;
import org.alfresco.repo.i18n.MessageService; import org.alfresco.repo.i18n.MessageService;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.tenant.TenantAdminService; import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; 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.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition; import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException; import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ModelDefinition; import org.alfresco.service.cmr.dictionary.ModelDefinition;
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.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; 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.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.util.BaseAlfrescoSpringTest; import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.PropertyMap; import org.alfresco.util.PropertyMap;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
@@ -62,7 +68,7 @@ import org.springframework.util.ResourceUtils;
* @author Roy Wetherall, janv * @author Roy Wetherall, janv
*/ */
@Category(BaseSpringTestsCategory.class) @Category(BaseSpringTestsCategory.class)
public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest public class DictionaryModelTypeTest extends BaseSpringTest
{ {
/** QNames of the test models */ /** QNames of the test models */
@@ -351,16 +357,40 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
private CheckOutCheckInService cociService; private CheckOutCheckInService cociService;
private DictionaryDAO dictionaryDAO; private DictionaryDAO dictionaryDAO;
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
private NodeService nodeService;
/** private ContentService contentService;
* On setup in transaction override private MutableAuthenticationService authenticationService;
*/ private StoreRef storeRef;
private NodeRef rootNodeRef;
private ActionService actionService;
private TransactionService transactionService;
private AuthenticationComponent authenticationComponent;
private UserTransaction txn;
@Override @Override
protected void onSetUpInTransaction() throws Exception protected void onSetUp() throws Exception
{ {
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
super.onSetUpInTransaction(); 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");
// 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 // Get the required services
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService"); this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService"); this.namespaceService = (NamespaceService)this.applicationContext.getBean("namespaceService");
@@ -368,44 +398,56 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
this.dictionaryDAO = (DictionaryDAO)this.applicationContext.getBean("dictionaryDAO"); this.dictionaryDAO = (DictionaryDAO)this.applicationContext.getBean("dictionaryDAO");
this.nodeService = (NodeService)this.applicationContext.getBean("NodeService"); this.nodeService = (NodeService)this.applicationContext.getBean("NodeService");
this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent"); this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
TenantAdminService tenantAdminService = (TenantAdminService)this.applicationContext.getBean("tenantAdminService"); TenantAdminService tenantAdminService = (TenantAdminService)this.applicationContext.getBean("tenantAdminService");
MessageService messageService = (MessageService)this.applicationContext.getBean("messageService"); MessageService messageService = (MessageService)this.applicationContext.getBean("messageService");
List<String> storeUrlsToValidate = new ArrayList<String>(1); List<String> storeUrlsToValidate = new ArrayList<String>(1);
storeUrlsToValidate.add(this.storeRef.toString()); storeUrlsToValidate.add(this.storeRef.toString());
ModelValidatorImpl modelValidator = (ModelValidatorImpl)this.applicationContext.getBean("modelValidator"); ModelValidatorImpl modelValidator = (ModelValidatorImpl)this.applicationContext.getBean("modelValidator");
modelValidator.setStoreUrls(storeUrlsToValidate); modelValidator.setStoreUrls(storeUrlsToValidate);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
DictionaryRepositoryBootstrap bootstrap = new DictionaryRepositoryBootstrap(); DictionaryRepositoryBootstrap bootstrap = new DictionaryRepositoryBootstrap();
bootstrap.setContentService(this.contentService); bootstrap.setContentService(this.contentService);
bootstrap.setDictionaryDAO(this.dictionaryDAO); bootstrap.setDictionaryDAO(this.dictionaryDAO);
bootstrap.setTransactionService(this.transactionService); bootstrap.setTransactionService(this.transactionService);
bootstrap.setTenantAdminService(tenantAdminService); bootstrap.setTenantAdminService(tenantAdminService);
bootstrap.setNodeService(this.nodeService); bootstrap.setNodeService(this.nodeService);
bootstrap.setNamespaceService(this.namespaceService); bootstrap.setNamespaceService(this.namespaceService);
bootstrap.setMessageService(messageService); bootstrap.setMessageService(messageService);
bootstrap.setPolicyComponent(policyComponent); bootstrap.setPolicyComponent(policyComponent);
RepositoryLocation location = new RepositoryLocation(); RepositoryLocation location = new RepositoryLocation();
location.setStoreProtocol(this.storeRef.getProtocol()); location.setStoreProtocol(this.storeRef.getProtocol());
location.setStoreId(this.storeRef.getIdentifier()); location.setStoreId(this.storeRef.getIdentifier());
location.setQueryLanguage(RepositoryLocation.LANGUAGE_PATH); location.setQueryLanguage(RepositoryLocation.LANGUAGE_PATH);
// NOTE: we are not setting the path for now .. in doing so we are searching the root node only // NOTE: we are not setting the path for now .. in doing so we are searching the root node only
List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>(); List<RepositoryLocation> locations = new ArrayList<RepositoryLocation>();
locations.add(location); locations.add(location);
bootstrap.setRepositoryModelsLocations(locations); bootstrap.setRepositoryModelsLocations(locations);
// register with dictionary service // register with dictionary service
bootstrap.register(); bootstrap.register();
txn.commit();
}
@Override
protected void onTearDown() throws Exception
{
authenticationService.clearCurrentSecurityContext();
} }
/** /**
* Test the creation of dictionary model nodes * Test the creation of dictionary model nodes
*/ */
public void testCreateAndUpdateDictionaryModelNodeContent() public void testCreateAndUpdateDictionaryModelNodeContent() throws Exception
{ {
try try
{ {
@@ -425,7 +467,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// Create a model node // Create a model node
PropertyMap properties = new PropertyMap(1); PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true); properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
txn = transactionService.getUserTransaction();
txn.begin();
final NodeRef modelNode = this.nodeService.createNode( final NodeRef modelNode = this.nodeService.createNode(
this.rootNodeRef, this.rootNodeRef,
ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN,
@@ -439,11 +484,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.setEncoding("UTF-8"); contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML); contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
contentWriter.putContent(MODEL_ONE_XML); contentWriter.putContent(MODEL_ONE_XML);
// End the transaction to force update // End the transaction to force update
setComplete(); txn.commit();
endTransaction();
final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
{ {
public NodeRef execute() throws Exception public NodeRef execute() throws Exception
@@ -555,7 +599,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
}); });
} }
public void testUpdateDictionaryModelPropertyDelete() public void testUpdateDictionaryModelPropertyDelete() throws Exception
{ {
try try
{ {
@@ -571,7 +615,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// Check that the namespace is not yet in the namespace service // Check that the namespace is not yet in the namespace service
String uri = this.namespaceService.getNamespaceURI("test1"); String uri = this.namespaceService.getNamespaceURI("test1");
assertNull(uri); assertNull(uri);
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node // Create a model node
PropertyMap properties = new PropertyMap(1); PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true); properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
@@ -590,9 +637,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_ONE_MODIFIED_XML); contentWriter.putContent(MODEL_ONE_MODIFIED_XML);
// End the transaction to force update // End the transaction to force update
setComplete(); txn.commit();
endTransaction();
// create node using new type // create node using new type
final NodeRef node1 = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() 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 try
{ {
@@ -711,7 +757,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// Check that the namespace is not yet in the namespace service // Check that the namespace is not yet in the namespace service
String uri = this.namespaceService.getNamespaceURI("test2"); String uri = this.namespaceService.getNamespaceURI("test2");
assertNull(uri); assertNull(uri);
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node // Create a model node
PropertyMap properties = new PropertyMap(1); PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true); properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
@@ -730,9 +779,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_TWO_XML); contentWriter.putContent(MODEL_TWO_XML);
// End the transaction to force update // End the transaction to force update
setComplete(); txn.commit();
endTransaction();
final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() final NodeRef workingCopy = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
{ {
public NodeRef execute() throws Exception public NodeRef execute() throws Exception
@@ -817,7 +865,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
}); });
} }
public void testIsActiveFlagAndDelete() public void testIsActiveFlagAndDelete() throws Exception
{ {
try try
{ {
@@ -830,6 +878,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// We expect this exception // We expect this exception
} }
txn = transactionService.getUserTransaction();
txn.begin();
// Create a model node // Create a model node
PropertyMap properties = new PropertyMap(1); PropertyMap properties = new PropertyMap(1);
final NodeRef modelNode = this.nodeService.createNode( final NodeRef modelNode = this.nodeService.createNode(
@@ -847,9 +897,8 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_ONE_XML); contentWriter.putContent(MODEL_ONE_XML);
// End the transaction to force update // End the transaction to force update
setComplete(); txn.commit();
endTransaction();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception
@@ -948,7 +997,7 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
* Test for MNT-11653 * Test for MNT-11653
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testOverrideMandatoryProperty() public void testOverrideMandatoryProperty() throws Exception
{ {
try try
{ {
@@ -968,7 +1017,10 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
// Create a model node // Create a model node
PropertyMap properties = new PropertyMap(1); PropertyMap properties = new PropertyMap(1);
properties.put(ContentModel.PROP_MODEL_ACTIVE, true); properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
txn = transactionService.getUserTransaction();
txn.begin();
final NodeRef modelNode = this.nodeService.createNode( final NodeRef modelNode = this.nodeService.createNode(
this.rootNodeRef, this.rootNodeRef,
ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN,
@@ -984,9 +1036,9 @@ public class DictionaryModelTypeTest extends BaseAlfrescoSpringTest
contentWriter.putContent(MODEL_THREE_XML); contentWriter.putContent(MODEL_THREE_XML);
// End the transaction to force update // End the transaction to force update
setComplete();
endTransaction(); txn.commit();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception