/*
* Copyright (C) 2005-2013 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 .
*/
package org.alfresco.repo.webdav;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
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.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import com.ibm.icu.impl.Assert;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
/**
* Tests for the WebDAVMethod class.
*
* @author Matt Ward
*/
@RunWith(MockitoJUnitRunner.class)
public class WebDAVMethodTest
{
private WebDAVMethod method;
private MockHttpServletRequest req;
private MockHttpServletResponse resp;
private @Mock WebDAVHelper davHelper;
private NodeService nodeService;
private SearchService searchService;
private NamespaceService namespaceService;
private TenantService tenantService;
private TransactionService transactionService;
private WebDAVHelper webDAVHelper;
private TenantAdminService tenantAdminService;
private @Mock LockMethod lockMethod;
private @Mock PutMethod putMethod;
private @Mock DeleteMethod deleteMethod;
private @Mock UnlockMethod unlockMethod;
public static final String TEST_RUN = System.currentTimeMillis()+"";
public static final String TEST_TENANT_DOMAIN = TEST_RUN+".my.test";
public static final String DEFAULT_ADMIN_PW = "admin";
protected void setUpApplicationContext()
{
ApplicationContext appContext = ApplicationContextHelper.getApplicationContext(new String[]
{
"classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
"classpath:alfresco/remote-api-context.xml"
});
this.nodeService = (NodeService) appContext.getBean("NodeService");
this.searchService = (SearchService) appContext.getBean("SearchService");
this.namespaceService = (NamespaceService) appContext.getBean("NamespaceService");
this.tenantService = (TenantService) appContext.getBean("tenantService");
this.transactionService = (TransactionService) appContext.getBean("transactionService");
this.webDAVHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
this.tenantAdminService = (TenantAdminService) appContext.getBean("tenantAdminService");
// Authenticate as system to create initial test data set
AuthenticationComponent authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
}
private void checkLockedNodeTestWork() throws WebDAVServerException
{
req = new MockHttpServletRequest();
resp = new MockHttpServletResponse();
String rootPath = "/app:company_home";
String storeName = "workspace://SpacesStore";
StoreRef storeRef = new StoreRef(storeName);
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
List nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
NodeRef defaultRootNode = nodeRefs.get(0);
lockMethod = new LockMethod();
NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
String strPath = "/" + "testLockedNode" + GUID.generate();
lockMethod.createExclusive = true;
lockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
lockMethod.m_strPath = strPath;
// Lock the node (will create a new one).
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback