/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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 .
* #L%
*/
package org.alfresco.repo.site;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.admin.SysAdminParamsImpl;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.M2Model;
import org.alfresco.repo.dictionary.M2Property;
import org.alfresco.repo.dictionary.M2Type;
import org.alfresco.repo.jscript.ClasspathScriptLocation;
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.repo.node.getchildren.FilterProp;
import org.alfresco.repo.node.getchildren.FilterPropString;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.authority.UnknownAuthorityException;
import org.alfresco.repo.security.person.UserNameMatcherImpl;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptLocation;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteMemberInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.tagging.TaggingService;
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.ApplicationContextHelper;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.junit.experimental.categories.Category;
import org.springframework.extensions.surf.util.I18NUtil;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
/**
* Site service implementation unit test
*
* @author Roy Wetherall
*/
@Category(BaseSpringTestsCategory.class)
public class SiteServiceImplTest extends BaseAlfrescoSpringTest
{
public static final StoreRef SITE_STORE = new StoreRef("workspace://SpacesStore");
private static final String TEST_SITE_PRESET = "testSitePreset";
private static final String TEST_SITE_PRESET_2 = "testSitePreset2";
private static final String TEST_TITLE = "TitleTest This is my title";
private static final String TEST_DESCRIPTION = "DescriptionTest This is my description";
private static final String USER_ONE = "UserOne_SiteServiceImplTest";
private static final String USER_TWO = "UserTwo_SiteServiceImplTest";
private static final String USER_THREE = "UserThree_SiteServiceImplTest";
private static final String USER_FOUR = "UserFour_SiteServiceImplTest";
private static final String GROUP_ONE = "GrpOne_SiteServiceImplTest";
private static final String GROUP_TWO = "GrpTwo_SiteServiceImplTest";
private static final String GROUP_THREE = "GrpThree_SiteServiceImplTest";
private static final String GROUP_FOUR = "GrpFour_SiteServiceImplTest";
private static final String GROUP_ONE_DISPLAY = "DisplayOfGrpOne-SiteServiceImplTest";
private static final String GROUP_TWO_DISPLAY = "DisplayOfGrpTwo-SiteServiceImplTest";
private static boolean IS_FIRST_SETUP = true;
private CopyService copyService;
private ScriptService scriptService;
private NodeService nodeService;
private NamespaceService namespaceService;
private DictionaryService dictionaryService;
private AuthenticationComponent authenticationComponent;
private TaggingService taggingService;
private PersonService personService;
private AuthorityService authorityService;
private FileFolderService fileFolderService;
private NodeArchiveService nodeArchiveService;
private PermissionService permissionService;
private SiteService siteService;
private UserNameMatcherImpl userNameMatcherImpl;
/**
* There are some tests which need access to the unproxied SiteServiceImpl
*/
private SiteServiceImpl siteServiceImpl;
private SysAdminParams sysAdminParams;
private String groupOne;
private String groupTwo;
private String groupThree;
private String groupFour;
/**
* Called during the transaction setup
*/
@SuppressWarnings("deprecation")
protected void onSetUpInTransaction() throws Exception
{
RetryingTransactionCallback