Dave Ward c1d11e0f3a Merged V4.1-BUG-FIX to HEAD
47745: ALF-18302: Merged V4.0.2 (4.0.2.29) to V4.1-BUG-FIX (4.1.5)
      47498: MNT-317: CIFS: Image document version history lost intermittently after saving content in Preview on Mac Mountain Lion
      - Candidate fix by Dmitry Vaserin
   47753: ALF-12264: Domain-filtering also done with new approach of fetching WorklfowTasks
   47778: Merged DEV to V4.1-BUG-FIX
      ALF-18151: CMIS cannot delete folders that have rules applied
                 - Will throw 'CMISConstraintException' exception only if 'ContentModel.ASSOC_CONTAINS'
                   child association exist for the folder what is deleted.
                 - Added and succesfully executed two unit test for openCMIS and CMIS.
   47794: ALF-18302: Merged DEV to V4.1-BUG-FIX
      47631: MNT-317: CIFS: Image document version history lost intermittently after saving content in Preview on Mac Mountain Lion
      Add class description describing the shuffle on ScenarioRenameDeleteMove.
      Add proper unit test.
   47795: Merged back build fix from HEAD (thanks Neil)
   47803: Merged PATCHES/V4.1.4 to V4.1-BUG-FIX
      47680: Merged DEV to PATCHES/V4.1.4
         47677: ALF-18270 Cannot open properties of model
         In FormUIGet.processFieldConstraints() was added check: (fieldConfig != null && fieldConfig.getConstraintDefinitionMap() != null).
      47738: ALF-18301: Alfresco fails to start up because of NPE error, when debug logging for 'org.alfresco.repo.cache.AbstractAsynchronouslyRefreshedCache' is enabled
      - Fix by Dmitry Velichkevich 
      47754: Merged DEV to PATCHES/V4.1.4
         47751: ALF-17644 : Document version was increased after canceling editing.
         Unnecessary calls for property deletion was removed.
      47767: ALF-18088: Add Implementation-Edition + limit Specification-Version to 3 digits in war MANIFEST files
      47786: Fixed ALF-18137 "It's impossible to create a new item in the data list."
   47804: Merged PATCHES/V4.1.4 to V4.1-BUG-FIX (RECORD ONLY)
      47755: Merged V4.1-BUG-FIX to PATCHES/V4.1.4
         47753: ALF-12264: Domain-filtering also done with new approach of fetching WorklfowTasks


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@47807 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2013-03-08 14:10:56 +00:00

180 lines
7.7 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.cmis.mapping;
import java.util.Date;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import junit.framework.TestCase;
import org.alfresco.cmis.CMISAccessControlService;
import org.alfresco.cmis.CMISDictionaryService;
import org.alfresco.cmis.CMISQueryService;
import org.alfresco.cmis.CMISRenditionService;
import org.alfresco.cmis.CMISServices;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.NamespaceDAOImpl;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.security.permissions.impl.ModelDAO;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentService;
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.rule.RuleService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* Base CMIS test
* Basic TX control and authentication
*
* @author andyh
*/
public abstract class BaseCMISTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
protected CMISMapping cmisMapping;
protected CMISServices cmisService;
protected CMISDictionaryService cmisDictionaryService;
protected CMISRenditionService cmisRenditionService;
protected CMISAccessControlService cmisAccessControlService;
protected DictionaryService dictionaryService;
protected TransactionService transactionService;
protected AuthenticationComponent authenticationComponent;
protected UserTransaction testTX;
protected NodeService nodeService;
protected NodeRef rootNodeRef;
protected FileFolderService fileFolderService;
protected ServiceRegistry serviceRegistry;
protected NamespaceService namespaceService;
protected CMISQueryService cmisQueryService;
private MutableAuthenticationService authenticationService;
private MutableAuthenticationDao authenticationDAO;
protected SearchService searchService;
protected ContentService contentService;
protected PermissionService permissionService;
protected ThumbnailService thumbnailService;
protected ModelDAO permissionModelDao;
protected DictionaryDAO dictionaryDAO;
protected NamespaceDAOImpl namespaceDao;
protected VersionService versionService;
protected ActionService actionService;
protected RuleService ruleService;
protected Repository repositoryHelper;
public void setUp() throws Exception
{
serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
cmisDictionaryService = (CMISDictionaryService) ctx.getBean("CMISDictionaryService");
cmisMapping = (CMISMapping) ctx.getBean("CMISMapping");
cmisQueryService = (CMISQueryService) ctx.getBean("CMISQueryService");
cmisService = (CMISServices) ctx.getBean("CMISService");
cmisRenditionService = (CMISRenditionService) ctx.getBean("CMISRenditionService");
cmisAccessControlService = (CMISAccessControlService) ctx.getBean("CMISAccessControlService");
dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
nodeService = (NodeService) ctx.getBean("nodeService");
fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
namespaceService = (NamespaceService) ctx.getBean("namespaceService");
transactionService = (TransactionService) ctx.getBean("transactionComponent");
authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
searchService = (SearchService) ctx.getBean("searchService");
contentService = (ContentService) ctx.getBean("contentService");
permissionService = (PermissionService) ctx.getBean("permissionService");
versionService = (VersionService) ctx.getBean("versionService");
actionService = (ActionService)ctx.getBean("actionService");
ruleService = (RuleService)ctx.getBean("ruleService");
repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
thumbnailService = (ThumbnailService) ctx.getBean("thumbnailService");
permissionModelDao = (ModelDAO) ctx.getBean("permissionsModelDAO");
dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
namespaceDao = (NamespaceDAOImpl) ctx.getBean("namespaceDAO");
testTX = transactionService.getUserTransaction();
testTX.begin();
this.authenticationComponent.setSystemUserAsCurrentUser();
String storeName = "CMISTest-" + getStoreName() + "-" + (new Date().getTime());
StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, storeName);
rootNodeRef = nodeService.getRootNode(storeRef);
if(authenticationDAO.userExists("cmis"))
{
authenticationService.deleteAuthentication("cmis");
}
authenticationService.createAuthentication("cmis", "cmis".toCharArray());
}
private String getStoreName()
{
String testName = getName();
testName = testName.replace("_", "-");
testName = testName.replace("%", "-");
return testName;
}
protected void runAs(String userName)
{
authenticationService.authenticate(userName, userName.toCharArray());
assertNotNull(authenticationService.getCurrentUserName());
}
@Override
protected void tearDown() throws Exception
{
if (testTX.getStatus() == Status.STATUS_ACTIVE)
{
testTX.rollback();
}
AuthenticationUtil.clearCurrentSecurityContext();
super.tearDown();
}
}