mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-1043 : Camel upgrade to 3.7.0 (#235)
ACS-1043: Upgrade Camel version
This commit is contained in:
@@ -18,9 +18,10 @@
|
||||
*/
|
||||
package org.alfresco.util.transaction;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
@@ -138,8 +139,8 @@ public class SpringAwareUserTransaction
|
||||
/** make sure that we clean up the thread transaction stack properly */
|
||||
private boolean finalized = false;
|
||||
|
||||
private Collection<String> labels = Collections.emptyList();
|
||||
|
||||
private Collection<String> labels = emptyList();
|
||||
|
||||
/**
|
||||
* Creates a user transaction that defaults to {@link TransactionDefinition#PROPAGATION_REQUIRED}.
|
||||
*
|
||||
@@ -212,7 +213,7 @@ public class SpringAwareUserTransaction
|
||||
public void setLabels(Collection<String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<String> getLabels()
|
||||
{
|
||||
|
@@ -100,26 +100,25 @@ public abstract class BaseApplicationContextHelper
|
||||
classpath[i] = resources[i].getURL();
|
||||
}
|
||||
// Let's give our classloader 'child-first' resource loading qualities!
|
||||
ClassLoader classLoader = new URLClassLoader(classpath, Thread.currentThread().getContextClassLoader())
|
||||
{
|
||||
@Override
|
||||
public URL getResource(String name)
|
||||
{
|
||||
URL ret = findResource(name);
|
||||
return ret == null ? super.getResource(name) : ret;
|
||||
}
|
||||
return new URLClassLoader(classpath, Thread.currentThread().getContextClassLoader())
|
||||
{
|
||||
@Override
|
||||
public URL getResource(String name)
|
||||
{
|
||||
URL ret = findResource(name);
|
||||
return ret == null ? super.getResource(name) : ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Enumeration<URL> getResources(String name) throws IOException
|
||||
{
|
||||
Enumeration[] tmp = new Enumeration[2];
|
||||
tmp[0] = findResources(name);
|
||||
tmp[1] = super.getResources(name);
|
||||
return new CompoundEnumeration<URL>(tmp);
|
||||
}
|
||||
};
|
||||
return classLoader;
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Enumeration<URL> getResources(String name) throws IOException
|
||||
{
|
||||
Enumeration[] tmp = new Enumeration[2];
|
||||
tmp[0] = findResources(name);
|
||||
tmp[1] = super.getResources(name);
|
||||
return new CompoundEnumeration<URL>(tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -95,11 +95,6 @@
|
||||
<classifier>tests</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- required by GDocs-->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
47
pom.xml
47
pom.xml
@@ -56,7 +56,7 @@
|
||||
<dependency.spring.version>5.3.2</dependency.spring.version>
|
||||
<dependency.antlr.version>3.5.2</dependency.antlr.version>
|
||||
<dependency.jackson.version>2.12.1</dependency.jackson.version>
|
||||
<dependency.jackson-databind.version>2.11.2</dependency.jackson-databind.version>
|
||||
<dependency.jackson-databind.version>${dependency.jackson.version}</dependency.jackson-databind.version>
|
||||
<dependency.cxf.version>3.4.2</dependency.cxf.version>
|
||||
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
|
||||
<dependency.webscripts.version>8.15</dependency.webscripts.version>
|
||||
@@ -82,7 +82,7 @@
|
||||
<dependency.ooxml-schemas.version>1.4</dependency.ooxml-schemas.version>
|
||||
<dependency.keycloak.version>12.0.1</dependency.keycloak.version>
|
||||
<dependency.jboss.logging.version>3.4.1.Final</dependency.jboss.logging.version>
|
||||
<dependency.camel.version>2.25.3</dependency.camel.version>
|
||||
<dependency.camel.version>3.7.0</dependency.camel.version>
|
||||
<dependency.activemq.version>5.16.0</dependency.activemq.version>
|
||||
<dependency.apache.taglibs.version>1.2.5</dependency.apache.taglibs.version>
|
||||
<dependency.awaitility.version>4.0.3</dependency.awaitility.version>
|
||||
@@ -243,11 +243,6 @@
|
||||
<artifactId>commons-digester</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
@@ -637,6 +632,44 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${dependency.gson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-spring</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-amqp</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<exclusions>
|
||||
<!-- conflicts with activemq geronimo-jms_1.1_spec -->
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jms_2.0_spec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-jackson</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-directvm</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-direct</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-mock</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@@ -207,6 +207,11 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-mock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
|
@@ -23,77 +23,77 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.web.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
/**
|
||||
* Tests for the HttpRangeProcessor class.
|
||||
*
|
||||
* @author Ray Gauss II
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HttpRangeProcessorTest
|
||||
{
|
||||
private HttpRangeProcessor httpRangeProcessor;
|
||||
private @Mock ContentReader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
httpRangeProcessor = new HttpRangeProcessor(null);
|
||||
when(reader.getMimetype()).thenReturn("image/jpeg");
|
||||
when(reader.getSize()).thenReturn(19133L);
|
||||
when(reader.getContentInputStream()).thenReturn(this.getClass().getResourceAsStream("/test.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidRange() throws IOException
|
||||
{
|
||||
testRange("700-800", HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartOnlyRange() throws IOException
|
||||
{
|
||||
testRange("19000-", HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeRange() throws IOException
|
||||
{
|
||||
testRange("800-700", HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondLengthRange() throws IOException
|
||||
{
|
||||
testRange("20000-", HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
}
|
||||
|
||||
protected void testRange(String range, int expectedStatus) throws IOException
|
||||
{
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
boolean result = httpRangeProcessor.processRange(response, reader, range, null, null, null, null);
|
||||
|
||||
assertTrue(result);
|
||||
assertEquals(expectedStatus, response.getStatus());
|
||||
reader.getContentInputStream().close();
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
/**
|
||||
* Tests for the HttpRangeProcessor class.
|
||||
*
|
||||
* @author Ray Gauss II
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HttpRangeProcessorTest
|
||||
{
|
||||
private HttpRangeProcessor httpRangeProcessor;
|
||||
private @Mock ContentReader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
httpRangeProcessor = new HttpRangeProcessor(null);
|
||||
when(reader.getMimetype()).thenReturn("image/jpeg");
|
||||
when(reader.getSize()).thenReturn(19133L);
|
||||
when(reader.getContentInputStream()).thenReturn(this.getClass().getResourceAsStream("/test.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidRange() throws IOException
|
||||
{
|
||||
testRange("700-800", HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartOnlyRange() throws IOException
|
||||
{
|
||||
testRange("19000-", HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNegativeRange() throws IOException
|
||||
{
|
||||
testRange("800-700", HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondLengthRange() throws IOException
|
||||
{
|
||||
testRange("20000-", HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
}
|
||||
|
||||
protected void testRange(String range, int expectedStatus) throws IOException
|
||||
{
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
boolean result = httpRangeProcessor.processRange(response, reader, range, null, null, null, null);
|
||||
|
||||
assertTrue(result);
|
||||
assertEquals(expectedStatus, response.getStatus());
|
||||
reader.getContentInputStream().close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,307 +1,307 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.audit.AuditQueryParameters;
|
||||
import org.alfresco.service.cmr.audit.AuditService;
|
||||
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.testing.category.LuceneTests;
|
||||
import org.apache.chemistry.opencmis.commons.spi.Holder;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests {@link GetMethod} in real environment, using {@link Mock} HTTP request and {@link Mock} HTTP response
|
||||
*
|
||||
* @author Dmitry Velichkevich
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Category(LuceneTests.class)
|
||||
public class GetMethodRegressionTest extends TestCase
|
||||
{
|
||||
private static final int DOCUMENTS_AMOUNT_FOR_GET_METHOD_TEST = 25;
|
||||
|
||||
|
||||
private static final String HTTP_METHOD_GET = "GET";
|
||||
|
||||
private static final String TEST_ENCODING = "UTF-8";
|
||||
|
||||
private static final String TEST_MIMETYPE = "text/plain";
|
||||
|
||||
private static final String TEST_WEBDAV_URL_PREFIX = "/";
|
||||
|
||||
private static final String AUDIT_REGISTRY_BEAN_NAME = "Audit";
|
||||
|
||||
private static final String PROP_AUDIT_ALFRESCO_ACCESS_ENABLED = "audit.alfresco-access.enabled";
|
||||
|
||||
private static final String ROOT_TEST_FOLDER_NAME = "TestFolder-" + System.currentTimeMillis();
|
||||
|
||||
private static final String TEST_DOCUMENT_NAME_PATTERN = "TestDocument-%d-%d.pdf";
|
||||
|
||||
private static final String TEXT_DOCUMENT_CONTENT_PATTERN = "Text content for '%s' document";
|
||||
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private WebDAVHelper davHelper;
|
||||
|
||||
private AuditService auditService;
|
||||
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
private AuditModelRegistryImpl auditRegistry;
|
||||
|
||||
private TransactionService transactionService;
|
||||
|
||||
|
||||
private UserTransaction transaction;
|
||||
|
||||
private GetMethod testingMethod;
|
||||
|
||||
private NodeRef companyHomeNodeRef;
|
||||
|
||||
private NodeRef rootTestFolder;
|
||||
|
||||
private MockHttpServletResponse mockResponse;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
applicationContext = ApplicationContextHelper.getApplicationContext();
|
||||
ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
davHelper = (WebDAVHelper) applicationContext.getBean(WebDAVHelper.BEAN_NAME);
|
||||
auditRegistry = (AuditModelRegistryImpl) applicationContext.getBean(AUDIT_REGISTRY_BEAN_NAME);
|
||||
|
||||
auditService = registry.getAuditService();
|
||||
fileFolderService = registry.getFileFolderService();
|
||||
transactionService = registry.getTransactionService();
|
||||
|
||||
testingMethod = new GetMethod();
|
||||
mockResponse = new MockHttpServletResponse();
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_NONE);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
|
||||
rootTestFolder = fileFolderService.create(companyHomeNodeRef, ROOT_TEST_FOLDER_NAME, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
|
||||
{
|
||||
transaction.rollback();
|
||||
}
|
||||
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.alfresco.com/jira/browse/MNT-10820">MNT-10820</a>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAuditRecordsAdditionAsbsence() throws Exception
|
||||
{
|
||||
String url = new StringBuilder(TEST_WEBDAV_URL_PREFIX).append(ROOT_TEST_FOLDER_NAME).toString();
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest(HTTP_METHOD_GET, url);
|
||||
testingMethod.setDetails(mockRequest, mockResponse, davHelper, companyHomeNodeRef);
|
||||
|
||||
boolean auditEnabled = auditService.isAuditEnabled();
|
||||
|
||||
if (!auditEnabled)
|
||||
{
|
||||
auditService.setAuditEnabled(true);
|
||||
}
|
||||
|
||||
boolean alfrescoAccessEnabled = Boolean.valueOf(auditRegistry.getProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED));
|
||||
|
||||
if (!alfrescoAccessEnabled)
|
||||
{
|
||||
setAuditRegistryProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED, Boolean.TRUE.toString());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
createTestContent(rootTestFolder, DOCUMENTS_AMOUNT_FOR_GET_METHOD_TEST);
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_COMMIT);
|
||||
|
||||
Long expectedLastTime = getLastAuditRecordTime();
|
||||
|
||||
testingMethod.executeImpl();
|
||||
assertEquals(HttpURLConnection.HTTP_OK, mockResponse.getStatus());
|
||||
|
||||
String contentAsString = mockResponse.getContentAsString();
|
||||
assertNotNull("WebDAV 'GET' method response is empty!", contentAsString);
|
||||
assertTrue(contentAsString.contains(ROOT_TEST_FOLDER_NAME));
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_COMMIT);
|
||||
|
||||
Long actualLastTime = getLastAuditRecordTime();
|
||||
|
||||
if (null == expectedLastTime)
|
||||
{
|
||||
assertNull("Audit entry table is not empty after 'GetMethod.executeImpl()' invocation. But it is expected to be empty!", actualLastTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(expectedLastTime, actualLastTime);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!alfrescoAccessEnabled)
|
||||
{
|
||||
setAuditRegistryProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED, Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
if (!auditEnabled)
|
||||
{
|
||||
auditService.setAuditEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setAuditRegistryProperty(String propertyName, String value)
|
||||
{
|
||||
assertTrue(("'" + propertyName + "' is not updatable!"), auditRegistry.isUpdateable(propertyName));
|
||||
|
||||
auditRegistry.stop();
|
||||
auditRegistry.setProperty(propertyName, value);
|
||||
auditRegistry.start();
|
||||
}
|
||||
|
||||
private void createTestContent(NodeRef parentNode, int documentsAmount)
|
||||
{
|
||||
for (int i = 0; i < documentsAmount; i++)
|
||||
{
|
||||
String testDocumentName = String.format(TEST_DOCUMENT_NAME_PATTERN, i, System.currentTimeMillis());
|
||||
FileInfo testDocument = fileFolderService.create(parentNode, testDocumentName, ContentModel.TYPE_CONTENT);
|
||||
ContentWriter writer = fileFolderService.getWriter(testDocument.getNodeRef());
|
||||
writer.putContent(String.format(TEXT_DOCUMENT_CONTENT_PATTERN, testDocumentName));
|
||||
writer.setMimetype(TEST_MIMETYPE);
|
||||
writer.setEncoding(TEST_ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
private enum TransactionActionEnum
|
||||
{
|
||||
ACTION_NONE,
|
||||
|
||||
ACTION_COMMIT,
|
||||
|
||||
ACTION_ROLLBACK
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits or rolls back or does nothing with the current transaction and begins a new {@link UserTransaction}
|
||||
*
|
||||
* @param transactionAction - one of the {@link TransactionActionEnum} values which specifies action to be done for the current transaction
|
||||
* @throws Exception
|
||||
*/
|
||||
private void restartTransaction(TransactionActionEnum transactionAction) throws Exception
|
||||
{
|
||||
if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
|
||||
{
|
||||
if (TransactionActionEnum.ACTION_COMMIT == transactionAction)
|
||||
{
|
||||
transaction.commit();
|
||||
}
|
||||
else if (TransactionActionEnum.ACTION_ROLLBACK == transactionAction)
|
||||
{
|
||||
transaction.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
transaction = transactionService.getUserTransaction();
|
||||
transaction.begin();
|
||||
}
|
||||
|
||||
private Long getLastAuditRecordTime()
|
||||
{
|
||||
final Holder<Long> lastTime = new Holder<Long>();
|
||||
|
||||
AuditQueryParameters parameters = new AuditQueryParameters();
|
||||
parameters.setForward(false);
|
||||
|
||||
auditService.auditQuery(new AuditQueryCallback()
|
||||
{
|
||||
@Override
|
||||
public boolean valuesRequired()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values)
|
||||
{
|
||||
lastTime.setValue(time);
|
||||
return false;
|
||||
}
|
||||
}, parameters, 1);
|
||||
|
||||
return lastTime.getValue();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.audit.AuditQueryParameters;
|
||||
import org.alfresco.service.cmr.audit.AuditService;
|
||||
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.testing.category.LuceneTests;
|
||||
import org.apache.chemistry.opencmis.commons.spi.Holder;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
/**
|
||||
* Tests {@link GetMethod} in real environment, using {@link Mock} HTTP request and {@link Mock} HTTP response
|
||||
*
|
||||
* @author Dmitry Velichkevich
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Category(LuceneTests.class)
|
||||
public class GetMethodRegressionTest extends TestCase
|
||||
{
|
||||
private static final int DOCUMENTS_AMOUNT_FOR_GET_METHOD_TEST = 25;
|
||||
|
||||
|
||||
private static final String HTTP_METHOD_GET = "GET";
|
||||
|
||||
private static final String TEST_ENCODING = "UTF-8";
|
||||
|
||||
private static final String TEST_MIMETYPE = "text/plain";
|
||||
|
||||
private static final String TEST_WEBDAV_URL_PREFIX = "/";
|
||||
|
||||
private static final String AUDIT_REGISTRY_BEAN_NAME = "Audit";
|
||||
|
||||
private static final String PROP_AUDIT_ALFRESCO_ACCESS_ENABLED = "audit.alfresco-access.enabled";
|
||||
|
||||
private static final String ROOT_TEST_FOLDER_NAME = "TestFolder-" + System.currentTimeMillis();
|
||||
|
||||
private static final String TEST_DOCUMENT_NAME_PATTERN = "TestDocument-%d-%d.pdf";
|
||||
|
||||
private static final String TEXT_DOCUMENT_CONTENT_PATTERN = "Text content for '%s' document";
|
||||
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private WebDAVHelper davHelper;
|
||||
|
||||
private AuditService auditService;
|
||||
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
private AuditModelRegistryImpl auditRegistry;
|
||||
|
||||
private TransactionService transactionService;
|
||||
|
||||
|
||||
private UserTransaction transaction;
|
||||
|
||||
private GetMethod testingMethod;
|
||||
|
||||
private NodeRef companyHomeNodeRef;
|
||||
|
||||
private NodeRef rootTestFolder;
|
||||
|
||||
private MockHttpServletResponse mockResponse;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
applicationContext = ApplicationContextHelper.getApplicationContext();
|
||||
ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
davHelper = (WebDAVHelper) applicationContext.getBean(WebDAVHelper.BEAN_NAME);
|
||||
auditRegistry = (AuditModelRegistryImpl) applicationContext.getBean(AUDIT_REGISTRY_BEAN_NAME);
|
||||
|
||||
auditService = registry.getAuditService();
|
||||
fileFolderService = registry.getFileFolderService();
|
||||
transactionService = registry.getTransactionService();
|
||||
|
||||
testingMethod = new GetMethod();
|
||||
mockResponse = new MockHttpServletResponse();
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_NONE);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
companyHomeNodeRef = registry.getNodeLocatorService().getNode(CompanyHomeNodeLocator.NAME, null, null);
|
||||
rootTestFolder = fileFolderService.create(companyHomeNodeRef, ROOT_TEST_FOLDER_NAME, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
|
||||
{
|
||||
transaction.rollback();
|
||||
}
|
||||
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.alfresco.com/jira/browse/MNT-10820">MNT-10820</a>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAuditRecordsAdditionAsbsence() throws Exception
|
||||
{
|
||||
String url = new StringBuilder(TEST_WEBDAV_URL_PREFIX).append(ROOT_TEST_FOLDER_NAME).toString();
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest(HTTP_METHOD_GET, url);
|
||||
testingMethod.setDetails(mockRequest, mockResponse, davHelper, companyHomeNodeRef);
|
||||
|
||||
boolean auditEnabled = auditService.isAuditEnabled();
|
||||
|
||||
if (!auditEnabled)
|
||||
{
|
||||
auditService.setAuditEnabled(true);
|
||||
}
|
||||
|
||||
boolean alfrescoAccessEnabled = Boolean.valueOf(auditRegistry.getProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED));
|
||||
|
||||
if (!alfrescoAccessEnabled)
|
||||
{
|
||||
setAuditRegistryProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED, Boolean.TRUE.toString());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
createTestContent(rootTestFolder, DOCUMENTS_AMOUNT_FOR_GET_METHOD_TEST);
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_COMMIT);
|
||||
|
||||
Long expectedLastTime = getLastAuditRecordTime();
|
||||
|
||||
testingMethod.executeImpl();
|
||||
assertEquals(HttpURLConnection.HTTP_OK, mockResponse.getStatus());
|
||||
|
||||
String contentAsString = mockResponse.getContentAsString();
|
||||
assertNotNull("WebDAV 'GET' method response is empty!", contentAsString);
|
||||
assertTrue(contentAsString.contains(ROOT_TEST_FOLDER_NAME));
|
||||
|
||||
restartTransaction(TransactionActionEnum.ACTION_COMMIT);
|
||||
|
||||
Long actualLastTime = getLastAuditRecordTime();
|
||||
|
||||
if (null == expectedLastTime)
|
||||
{
|
||||
assertNull("Audit entry table is not empty after 'GetMethod.executeImpl()' invocation. But it is expected to be empty!", actualLastTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(expectedLastTime, actualLastTime);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!alfrescoAccessEnabled)
|
||||
{
|
||||
setAuditRegistryProperty(PROP_AUDIT_ALFRESCO_ACCESS_ENABLED, Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
if (!auditEnabled)
|
||||
{
|
||||
auditService.setAuditEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setAuditRegistryProperty(String propertyName, String value)
|
||||
{
|
||||
assertTrue(("'" + propertyName + "' is not updatable!"), auditRegistry.isUpdateable(propertyName));
|
||||
|
||||
auditRegistry.stop();
|
||||
auditRegistry.setProperty(propertyName, value);
|
||||
auditRegistry.start();
|
||||
}
|
||||
|
||||
private void createTestContent(NodeRef parentNode, int documentsAmount)
|
||||
{
|
||||
for (int i = 0; i < documentsAmount; i++)
|
||||
{
|
||||
String testDocumentName = String.format(TEST_DOCUMENT_NAME_PATTERN, i, System.currentTimeMillis());
|
||||
FileInfo testDocument = fileFolderService.create(parentNode, testDocumentName, ContentModel.TYPE_CONTENT);
|
||||
ContentWriter writer = fileFolderService.getWriter(testDocument.getNodeRef());
|
||||
writer.putContent(String.format(TEXT_DOCUMENT_CONTENT_PATTERN, testDocumentName));
|
||||
writer.setMimetype(TEST_MIMETYPE);
|
||||
writer.setEncoding(TEST_ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
private enum TransactionActionEnum
|
||||
{
|
||||
ACTION_NONE,
|
||||
|
||||
ACTION_COMMIT,
|
||||
|
||||
ACTION_ROLLBACK
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits or rolls back or does nothing with the current transaction and begins a new {@link UserTransaction}
|
||||
*
|
||||
* @param transactionAction - one of the {@link TransactionActionEnum} values which specifies action to be done for the current transaction
|
||||
* @throws Exception
|
||||
*/
|
||||
private void restartTransaction(TransactionActionEnum transactionAction) throws Exception
|
||||
{
|
||||
if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
|
||||
{
|
||||
if (TransactionActionEnum.ACTION_COMMIT == transactionAction)
|
||||
{
|
||||
transaction.commit();
|
||||
}
|
||||
else if (TransactionActionEnum.ACTION_ROLLBACK == transactionAction)
|
||||
{
|
||||
transaction.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
transaction = transactionService.getUserTransaction();
|
||||
transaction.begin();
|
||||
}
|
||||
|
||||
private Long getLastAuditRecordTime()
|
||||
{
|
||||
final Holder<Long> lastTime = new Holder<Long>();
|
||||
|
||||
AuditQueryParameters parameters = new AuditQueryParameters();
|
||||
parameters.setForward(false);
|
||||
|
||||
auditService.auditQuery(new AuditQueryCallback()
|
||||
{
|
||||
@Override
|
||||
public boolean valuesRequired()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values)
|
||||
{
|
||||
lastTime.setValue(time);
|
||||
return false;
|
||||
}
|
||||
}, parameters, 1);
|
||||
|
||||
return lastTime.getValue();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,381 +1,381 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
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.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TestWithUserUtils;
|
||||
import org.junit.Before;
|
||||
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;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UnlockMethodTest
|
||||
{
|
||||
private UnlockMethod unlockMethod;
|
||||
private LockMethod lockMethod;
|
||||
private MockHttpServletRequest request;
|
||||
private MockHttpServletResponse response;
|
||||
private @Mock WebDAVHelper davHelper;
|
||||
ApplicationContext appContext;
|
||||
|
||||
/**
|
||||
* Services used by the tests
|
||||
*/
|
||||
private NodeService nodeService;
|
||||
private CheckOutCheckInService cociService;
|
||||
private ContentService contentService;
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private TransactionService transactionService;
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* Data used by the tests
|
||||
*/
|
||||
private StoreRef storeRef;
|
||||
private NodeRef rootNodeRef;
|
||||
private String userNodeRef;
|
||||
private NodeRef folderNodeRef;
|
||||
private NodeRef fileNodeRef;
|
||||
private NodeRef fileWorkingCopyNodeRef;
|
||||
|
||||
/**
|
||||
* Types and properties used by the tests
|
||||
*/
|
||||
private static final String CONTENT_1 = "This is some content";
|
||||
private static final String TEST_STORE_IDENTIFIER = "test_store-" + System.currentTimeMillis();
|
||||
private static final String TEST_FILE_NAME = "file";
|
||||
|
||||
/**
|
||||
* User details
|
||||
*/
|
||||
private String userName;
|
||||
private static final String PWD = "password";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
unlockMethod = new UnlockMethod();
|
||||
unlockMethod.setDetails(request, response, davHelper, null);
|
||||
lockMethod = new LockMethod();
|
||||
lockMethod.setDetails(request, null, davHelper, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up preconditions for unlock a checked out node
|
||||
*/
|
||||
protected void setUpPreconditionForCheckedOutTest() throws Exception
|
||||
{
|
||||
appContext = ApplicationContextHelper.getApplicationContext(new String[]
|
||||
{
|
||||
"classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
|
||||
"classpath:alfresco/remote-api-context.xml"
|
||||
});
|
||||
|
||||
// Set the services
|
||||
this.cociService = (CheckOutCheckInService) appContext.getBean("checkOutCheckInService");
|
||||
this.contentService = (ContentService) appContext.getBean("contentService");
|
||||
this.authenticationService = (MutableAuthenticationService) appContext.getBean("authenticationService");
|
||||
this.permissionService = (PermissionService) appContext.getBean("permissionService");
|
||||
this.transactionService = (TransactionService) appContext.getBean("TransactionService");
|
||||
this.nodeService = (NodeService) appContext.getBean("NodeService");
|
||||
// Authenticate as system to create initial test data set
|
||||
this.authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
RetryingTransactionCallback<Void> createTestFileCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
// Create the store and get the root node reference
|
||||
storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||
if (!nodeService.exists(storeRef))
|
||||
{
|
||||
storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||
}
|
||||
rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
// Create and authenticate the user
|
||||
userName = "webdavUnlockTest" + GUID.generate();
|
||||
TestWithUserUtils.createUser(userName, PWD, rootNodeRef, nodeService, authenticationService);
|
||||
permissionService.setPermission(rootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true);
|
||||
TestWithUserUtils.authenticateUser(userName, PWD, rootNodeRef, authenticationService);
|
||||
userNodeRef = TestWithUserUtils.getCurrentUser(authenticationService);
|
||||
|
||||
// create test file in test folder
|
||||
folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER,
|
||||
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef();
|
||||
fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT,
|
||||
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef();
|
||||
ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setMimetype("text/plain");
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.putContent(CONTENT_1);
|
||||
|
||||
// Check out test file
|
||||
fileWorkingCopyNodeRef = cociService.checkout(fileNodeRef);
|
||||
assertNotNull(fileWorkingCopyNodeRef);
|
||||
assertEquals(userNodeRef, nodeService.getProperty(fileNodeRef, ContentModel.PROP_LOCK_OWNER));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(createTestFileCallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidLockTokenHeader() throws WebDAVServerException
|
||||
{
|
||||
String lockToken = "976e2f82-40ab-4852-a867-986e9ce11f82:admin";
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
|
||||
assertEquals(lockToken, unlockMethod.getLockToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidLockTokenHeader()
|
||||
{
|
||||
String lockToken = "976e2f82-40ab-4852-a867-986e9ce11f82:admin";
|
||||
String lockHeaderValue = "<wrongprefix:" + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
try
|
||||
{
|
||||
unlockMethod.parseRequestHeaders();
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getHttpStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMissingLockTokenHeader()
|
||||
{
|
||||
// Note: we're not adding the lock token header
|
||||
try
|
||||
{
|
||||
unlockMethod.parseRequestHeaders();
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getHttpStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test MNT-9680: Working copies are open in read-only mode when using Webdav online edit
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void unlockWorkingCopy() throws Exception
|
||||
{
|
||||
setUpPreconditionForCheckedOutTest();
|
||||
try
|
||||
{
|
||||
String workingCopyName = nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_NAME).toString();
|
||||
String lockToken = fileWorkingCopyNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
final WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
|
||||
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
request.setRequestURI("/" + workingCopyName);
|
||||
String content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
|
||||
+ "<d:lockinfo xmlns:d=\"DAV:\">"
|
||||
+ "<d:lockscope><d:exclusive/></d:lockscope>"
|
||||
+ "</d:lockinfo>";
|
||||
|
||||
request.setContent(content.getBytes("UTF-8"));
|
||||
|
||||
lockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
lockMethod.parseRequestHeaders();
|
||||
lockMethod.parseRequestBody();
|
||||
|
||||
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
lockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
|
||||
|
||||
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
|
||||
RetryingTransactionCallback<Void> unlockExecuteImplCallBack = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
unlockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(unlockExecuteImplCallBack);
|
||||
|
||||
assertNull("lockType property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_TYPE));
|
||||
assertNull("lockOwner property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_OWNER));
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clear context for current user
|
||||
this.authenticationComponent.clearCurrentSecurityContext();
|
||||
|
||||
// delete test store as system user
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
nodeService.deleteStore(storeRef);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that it is impossible to unlock a checked out node
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void unlockCheckedOutNode() throws Exception
|
||||
{
|
||||
setUpPreconditionForCheckedOutTest();
|
||||
try
|
||||
{
|
||||
String lockToken = fileNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
request.setRequestURI("/" + TEST_FILE_NAME);
|
||||
|
||||
WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
|
||||
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
unlockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
if (e.getCause() instanceof WebDAVServerException)
|
||||
{
|
||||
WebDAVServerException ee = (WebDAVServerException) e.getCause();
|
||||
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, ee.getHttpStatusCode());
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Incorrect exception thrown.");
|
||||
}
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, e.getHttpStatusCode());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clear context for current user
|
||||
this.authenticationComponent.clearCurrentSecurityContext();
|
||||
|
||||
// delete test store as system user
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
nodeService.deleteStore(storeRef);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
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.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TestWithUserUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UnlockMethodTest
|
||||
{
|
||||
private UnlockMethod unlockMethod;
|
||||
private LockMethod lockMethod;
|
||||
private MockHttpServletRequest request;
|
||||
private MockHttpServletResponse response;
|
||||
private @Mock WebDAVHelper davHelper;
|
||||
ApplicationContext appContext;
|
||||
|
||||
/**
|
||||
* Services used by the tests
|
||||
*/
|
||||
private NodeService nodeService;
|
||||
private CheckOutCheckInService cociService;
|
||||
private ContentService contentService;
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private TransactionService transactionService;
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* Data used by the tests
|
||||
*/
|
||||
private StoreRef storeRef;
|
||||
private NodeRef rootNodeRef;
|
||||
private String userNodeRef;
|
||||
private NodeRef folderNodeRef;
|
||||
private NodeRef fileNodeRef;
|
||||
private NodeRef fileWorkingCopyNodeRef;
|
||||
|
||||
/**
|
||||
* Types and properties used by the tests
|
||||
*/
|
||||
private static final String CONTENT_1 = "This is some content";
|
||||
private static final String TEST_STORE_IDENTIFIER = "test_store-" + System.currentTimeMillis();
|
||||
private static final String TEST_FILE_NAME = "file";
|
||||
|
||||
/**
|
||||
* User details
|
||||
*/
|
||||
private String userName;
|
||||
private static final String PWD = "password";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
unlockMethod = new UnlockMethod();
|
||||
unlockMethod.setDetails(request, response, davHelper, null);
|
||||
lockMethod = new LockMethod();
|
||||
lockMethod.setDetails(request, null, davHelper, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up preconditions for unlock a checked out node
|
||||
*/
|
||||
protected void setUpPreconditionForCheckedOutTest() throws Exception
|
||||
{
|
||||
appContext = ApplicationContextHelper.getApplicationContext(new String[]
|
||||
{
|
||||
"classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
|
||||
"classpath:alfresco/remote-api-context.xml"
|
||||
});
|
||||
|
||||
// Set the services
|
||||
this.cociService = (CheckOutCheckInService) appContext.getBean("checkOutCheckInService");
|
||||
this.contentService = (ContentService) appContext.getBean("contentService");
|
||||
this.authenticationService = (MutableAuthenticationService) appContext.getBean("authenticationService");
|
||||
this.permissionService = (PermissionService) appContext.getBean("permissionService");
|
||||
this.transactionService = (TransactionService) appContext.getBean("TransactionService");
|
||||
this.nodeService = (NodeService) appContext.getBean("NodeService");
|
||||
// Authenticate as system to create initial test data set
|
||||
this.authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
RetryingTransactionCallback<Void> createTestFileCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
// Create the store and get the root node reference
|
||||
storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||
if (!nodeService.exists(storeRef))
|
||||
{
|
||||
storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||
}
|
||||
rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
// Create and authenticate the user
|
||||
userName = "webdavUnlockTest" + GUID.generate();
|
||||
TestWithUserUtils.createUser(userName, PWD, rootNodeRef, nodeService, authenticationService);
|
||||
permissionService.setPermission(rootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true);
|
||||
TestWithUserUtils.authenticateUser(userName, PWD, rootNodeRef, authenticationService);
|
||||
userNodeRef = TestWithUserUtils.getCurrentUser(authenticationService);
|
||||
|
||||
// create test file in test folder
|
||||
folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER,
|
||||
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef();
|
||||
fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT,
|
||||
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef();
|
||||
ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setMimetype("text/plain");
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.putContent(CONTENT_1);
|
||||
|
||||
// Check out test file
|
||||
fileWorkingCopyNodeRef = cociService.checkout(fileNodeRef);
|
||||
assertNotNull(fileWorkingCopyNodeRef);
|
||||
assertEquals(userNodeRef, nodeService.getProperty(fileNodeRef, ContentModel.PROP_LOCK_OWNER));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(createTestFileCallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValidLockTokenHeader() throws WebDAVServerException
|
||||
{
|
||||
String lockToken = "976e2f82-40ab-4852-a867-986e9ce11f82:admin";
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
|
||||
assertEquals(lockToken, unlockMethod.getLockToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidLockTokenHeader()
|
||||
{
|
||||
String lockToken = "976e2f82-40ab-4852-a867-986e9ce11f82:admin";
|
||||
String lockHeaderValue = "<wrongprefix:" + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
try
|
||||
{
|
||||
unlockMethod.parseRequestHeaders();
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getHttpStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMissingLockTokenHeader()
|
||||
{
|
||||
// Note: we're not adding the lock token header
|
||||
try
|
||||
{
|
||||
unlockMethod.parseRequestHeaders();
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getHttpStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test MNT-9680: Working copies are open in read-only mode when using Webdav online edit
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void unlockWorkingCopy() throws Exception
|
||||
{
|
||||
setUpPreconditionForCheckedOutTest();
|
||||
try
|
||||
{
|
||||
String workingCopyName = nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_NAME).toString();
|
||||
String lockToken = fileWorkingCopyNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
final WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
|
||||
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
request.setRequestURI("/" + workingCopyName);
|
||||
String content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
|
||||
+ "<d:lockinfo xmlns:d=\"DAV:\">"
|
||||
+ "<d:lockscope><d:exclusive/></d:lockscope>"
|
||||
+ "</d:lockinfo>";
|
||||
|
||||
request.setContent(content.getBytes("UTF-8"));
|
||||
|
||||
lockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
lockMethod.parseRequestHeaders();
|
||||
lockMethod.parseRequestBody();
|
||||
|
||||
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
lockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
|
||||
|
||||
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
|
||||
RetryingTransactionCallback<Void> unlockExecuteImplCallBack = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
unlockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(unlockExecuteImplCallBack);
|
||||
|
||||
assertNull("lockType property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_TYPE));
|
||||
assertNull("lockOwner property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_OWNER));
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clear context for current user
|
||||
this.authenticationComponent.clearCurrentSecurityContext();
|
||||
|
||||
// delete test store as system user
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
nodeService.deleteStore(storeRef);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that it is impossible to unlock a checked out node
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void unlockCheckedOutNode() throws Exception
|
||||
{
|
||||
setUpPreconditionForCheckedOutTest();
|
||||
try
|
||||
{
|
||||
String lockToken = fileNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
|
||||
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
|
||||
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
|
||||
request.setRequestURI("/" + TEST_FILE_NAME);
|
||||
|
||||
WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
|
||||
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
|
||||
unlockMethod.parseRequestHeaders();
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
unlockMethod.executeImpl();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
fail("Exception should have been thrown, but wasn't.");
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
if (e.getCause() instanceof WebDAVServerException)
|
||||
{
|
||||
WebDAVServerException ee = (WebDAVServerException) e.getCause();
|
||||
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, ee.getHttpStatusCode());
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Incorrect exception thrown.");
|
||||
}
|
||||
}
|
||||
catch (WebDAVServerException e)
|
||||
{
|
||||
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, e.getHttpStatusCode());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clear context for current user
|
||||
this.authenticationComponent.clearCurrentSecurityContext();
|
||||
|
||||
// delete test store as system user
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
nodeService.deleteStore(storeRef);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,100 +23,100 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
* Tests for the WebDAVHelper class.
|
||||
*
|
||||
* @see RenameShuffleDetectionTest
|
||||
* @author Matt Ward
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WebDAVHelperTest
|
||||
{
|
||||
private WebDAVHelper davHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
davHelper = new WebDAVHelper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetUrlPathPrefixWhenExplicitlySet()
|
||||
{
|
||||
// Path prefix explicitly set on helper.
|
||||
davHelper.setUrlPathPrefix("/my/prefix");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/my/prefix/folder/filename.txt");
|
||||
String prefix = davHelper.getUrlPathPrefix(request);
|
||||
assertEquals("/my/prefix/", prefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetUrlPathPrefixFromServletPath()
|
||||
{
|
||||
// Path prefix not explicitly set on helper.
|
||||
davHelper.setUrlPathPrefix("");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/before/the-servlet/folder/filename.txt");
|
||||
// Servlet path will be used to determine path prefix.
|
||||
request.setServletPath("/the-servlet");
|
||||
String prefix = davHelper.getUrlPathPrefix(request);
|
||||
assertEquals("/before/the-servlet/", prefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetDestinationPathWhenNoServletName()
|
||||
{
|
||||
assertPathForURL("/the-tenant.com/the-site/path/to/file",
|
||||
"http://webdav.alfresco.com/the-tenant.com/the-site/path/to/file");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* THOR-1459: WebDAV: site names cannot start with 'webdav'.
|
||||
* <p>
|
||||
* <code>/webdav-test</code> begins with servlet path <code>/webdav</code>
|
||||
*/
|
||||
@Test
|
||||
public void canGetDestinationPathWhenPathElementStartsWithServletPath()
|
||||
{
|
||||
assertPathForURL("/t/webdav-test/path/to/file",
|
||||
"http://webdav.alfresco.com/t/webdav-test/path/to/file");
|
||||
|
||||
// Looks like /contextPath/servletName in URL's path prefix, but isn't
|
||||
assertPathForURL("/alfresco/webdav-test/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav-test/path/to/file");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetDestinationPathWhenPrefixedWithContextPathAndServletName()
|
||||
{
|
||||
assertPathForURL("/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/path/to/file");
|
||||
|
||||
assertPathForURL("/alfresco/webdav/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/alfresco/webdav/path/to/file");
|
||||
|
||||
assertPathForURL("/my/folder/alfresco/webdav/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/my/folder/alfresco/webdav/path/to/file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the expected path was extracted from a given URL.
|
||||
*
|
||||
* @param path The expected path.
|
||||
* @param url URL to extract the path from.
|
||||
*/
|
||||
private void assertPathForURL(String path, String url)
|
||||
{
|
||||
assertEquals(path, davHelper.getDestinationPath("/alfresco", "/webdav", url));
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
* Tests for the WebDAVHelper class.
|
||||
*
|
||||
* @see RenameShuffleDetectionTest
|
||||
* @author Matt Ward
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WebDAVHelperTest
|
||||
{
|
||||
private WebDAVHelper davHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
davHelper = new WebDAVHelper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetUrlPathPrefixWhenExplicitlySet()
|
||||
{
|
||||
// Path prefix explicitly set on helper.
|
||||
davHelper.setUrlPathPrefix("/my/prefix");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/my/prefix/folder/filename.txt");
|
||||
String prefix = davHelper.getUrlPathPrefix(request);
|
||||
assertEquals("/my/prefix/", prefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetUrlPathPrefixFromServletPath()
|
||||
{
|
||||
// Path prefix not explicitly set on helper.
|
||||
davHelper.setUrlPathPrefix("");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/before/the-servlet/folder/filename.txt");
|
||||
// Servlet path will be used to determine path prefix.
|
||||
request.setServletPath("/the-servlet");
|
||||
String prefix = davHelper.getUrlPathPrefix(request);
|
||||
assertEquals("/before/the-servlet/", prefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetDestinationPathWhenNoServletName()
|
||||
{
|
||||
assertPathForURL("/the-tenant.com/the-site/path/to/file",
|
||||
"http://webdav.alfresco.com/the-tenant.com/the-site/path/to/file");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* THOR-1459: WebDAV: site names cannot start with 'webdav'.
|
||||
* <p>
|
||||
* <code>/webdav-test</code> begins with servlet path <code>/webdav</code>
|
||||
*/
|
||||
@Test
|
||||
public void canGetDestinationPathWhenPathElementStartsWithServletPath()
|
||||
{
|
||||
assertPathForURL("/t/webdav-test/path/to/file",
|
||||
"http://webdav.alfresco.com/t/webdav-test/path/to/file");
|
||||
|
||||
// Looks like /contextPath/servletName in URL's path prefix, but isn't
|
||||
assertPathForURL("/alfresco/webdav-test/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav-test/path/to/file");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetDestinationPathWhenPrefixedWithContextPathAndServletName()
|
||||
{
|
||||
assertPathForURL("/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/path/to/file");
|
||||
|
||||
assertPathForURL("/alfresco/webdav/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/alfresco/webdav/path/to/file");
|
||||
|
||||
assertPathForURL("/my/folder/alfresco/webdav/path/to/file",
|
||||
"http://webdav.alfresco.com/alfresco/webdav/my/folder/alfresco/webdav/path/to/file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the expected path was extracted from a given URL.
|
||||
*
|
||||
* @param path The expected path.
|
||||
* @param url URL to extract the path from.
|
||||
*/
|
||||
private void assertPathForURL(String path, String url)
|
||||
{
|
||||
assertEquals(path, davHelper.getDestinationPath("/alfresco", "/webdav", url));
|
||||
}
|
||||
}
|
||||
|
@@ -23,234 +23,234 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.repo.lock.mem.Lifetime;
|
||||
import org.alfresco.repo.lock.mem.LockState;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.LockStatus;
|
||||
import org.alfresco.service.cmr.lock.LockType;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WebDAVLockServiceImplTest
|
||||
{
|
||||
private WebDAVLockServiceImpl davLockService;
|
||||
private @Mock HttpSession session;
|
||||
private @Mock List<Pair<String, NodeRef>> sessionList;
|
||||
private @Mock AuthenticationUtil authenticationUtil;
|
||||
private @Mock TransactionService transactionService;
|
||||
private @Mock RetryingTransactionHelper txHelper;
|
||||
private @Mock NodeService nodeService;
|
||||
private @Mock LockService lockService;
|
||||
private @Mock CheckOutCheckInService cociService;
|
||||
private NodeRef nodeRef1;
|
||||
private NodeRef nodeRef2;
|
||||
private LockInfoImpl lockInfo1;
|
||||
private LockState lockState1;
|
||||
private LockInfoImpl lockInfo2;
|
||||
private LockState lockState2;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
davLockService = new WebDAVLockServiceImpl();
|
||||
davLockService.setNodeService(nodeService);
|
||||
davLockService.setCheckOutCheckInService(cociService);
|
||||
davLockService.setCurrentSession(session);
|
||||
davLockService.setLockService(lockService);
|
||||
|
||||
// Train the mock LockStore to respond to get() requests for certain noderefs.
|
||||
nodeRef1 = new NodeRef("workspace://SpacesStore/f6e3f82a-cfef-445b-9fca-7986a14181cc");
|
||||
lockInfo1 = new LockInfoImplTest.LockInfoImplEx();
|
||||
lockState1 = LockState.createLock(nodeRef1, LockType.WRITE_LOCK, "user1", null, Lifetime.EPHEMERAL, null);
|
||||
Mockito.when(lockService.getLockState(nodeRef1)).thenReturn(lockState1);
|
||||
nodeRef2 = new NodeRef("workspace://SpacesStore/a6a4371c-99b9-4618-8cd2-e71d7d96aa87");
|
||||
lockInfo2 = new LockInfoImplTest.LockInfoImplEx();
|
||||
lockInfo2.setExclusiveLockToken("a-random-token");
|
||||
lockInfo2.setDepth("infinity");
|
||||
lockInfo2.setScope(WebDAV.XML_EXCLUSIVE);
|
||||
lockState2 = LockState.createLock(nodeRef2, LockType.WRITE_LOCK, "user2", new Date(999L), Lifetime.EPHEMERAL, lockInfo2.toJSON());
|
||||
Mockito.when(lockService.getLockState(nodeRef2)).thenReturn(lockState2);
|
||||
|
||||
// The mock HttpSession should return the mock session list.
|
||||
Mockito.when(session.getAttribute("_webdavLockedResources")).thenReturn(sessionList);
|
||||
|
||||
// Provide a user name for our fictional user.
|
||||
authenticationUtil = new AuthenticationUtil();
|
||||
authenticationUtil.afterPropertiesSet();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser("some_user_name");
|
||||
|
||||
Mockito.when(txHelper.doInTransaction(any(RetryingTransactionCallback.class), anyBoolean())).thenAnswer(new Answer()
|
||||
{
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
Object[] args = invocation.getArguments();
|
||||
RetryingTransactionCallback<Void> callback = (RetryingTransactionCallback<Void>) args[0];
|
||||
callback.execute();
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
Mockito.when(transactionService.getRetryingTransactionHelper()).thenReturn(txHelper);
|
||||
davLockService.setTransactionService(transactionService);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSessionDestroyed()
|
||||
{
|
||||
List<Pair<String, NodeRef>> lockedNodes = new ArrayList<Pair<String, NodeRef>>(2);
|
||||
lockedNodes.add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
lockedNodes.add(new Pair<String, NodeRef>("another_user_name", nodeRef2));
|
||||
Mockito.when(sessionList.size()).thenReturn(2);
|
||||
Mockito.when(sessionList.iterator()).thenReturn(lockedNodes.iterator());
|
||||
|
||||
Mockito.when(nodeService.exists(nodeRef1)).thenReturn(true);
|
||||
Mockito.when(nodeService.exists(nodeRef2)).thenReturn(true);
|
||||
|
||||
Mockito.when(lockService.getLockStatus(nodeRef1)).thenReturn(LockStatus.LOCKED);
|
||||
Mockito.when(lockService.getLockStatus(nodeRef2)).thenReturn(LockStatus.LOCKED);
|
||||
|
||||
// We're not going to do anything with nodeRef2
|
||||
NodeRef wcNodeRef2 = new NodeRef("workspace://SpacesStore/a6e3f82a-cfef-363d-9fca-3986a14180a0");
|
||||
Mockito.when(cociService.getWorkingCopy(nodeRef2)).thenReturn(wcNodeRef2);
|
||||
|
||||
davLockService.sessionDestroyed();
|
||||
|
||||
// nodeRef1 is unlocked
|
||||
Mockito.verify(lockService).unlock(nodeRef1);
|
||||
|
||||
// nodeRef2 is not unlocked
|
||||
Mockito.verify(lockService, Mockito.never()).unlock(nodeRef2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockLessThan24Hours()
|
||||
{
|
||||
lockInfo1.setTimeoutSeconds(100);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, 100, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
// 100 seconds (in millis) should have been added to the date/time stamp.
|
||||
assertEquals(86500000, lockInfo1.getExpires().getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockGreaterThan24Hours()
|
||||
{
|
||||
int timeout25hours = WebDAV.TIMEOUT_24_HOURS + 3600;
|
||||
lockInfo1.setTimeoutSeconds(timeout25hours);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, WebDAV.TIMEOUT_24_HOURS, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
Mockito.verify(sessionList).add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
// Timeout should be capped at 24 hours.
|
||||
assertEquals(WebDAV.TIMEOUT_24_HOURS, lockInfo1.getRemainingTimeoutSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockForInfinityTime()
|
||||
{
|
||||
lockInfo1.setTimeoutSeconds(WebDAV.TIMEOUT_INFINITY);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, WebDAV.TIMEOUT_24_HOURS, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
Mockito.verify(sessionList).add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
// Timeout should be capped at 24 hours.
|
||||
assertEquals(WebDAV.TIMEOUT_24_HOURS, lockInfo1.getRemainingTimeoutSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canUnlock()
|
||||
{
|
||||
davLockService.unlock(nodeRef1);
|
||||
|
||||
// NodeRef should have been unlocked.
|
||||
Mockito.verify(lockService).unlock(nodeRef1);
|
||||
// Node should have been removed from the list in the user's session.
|
||||
Mockito.verify(sessionList).remove(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetLockInfo()
|
||||
{
|
||||
NodeRef nodeRef3 = new NodeRef("workspace://SpacesStore/a6a4371c-99b9-4618-8cd2-e71d28374859");
|
||||
Mockito.when(lockService.getLockState(nodeRef1)).thenReturn(lockState1);
|
||||
Mockito.when(lockService.getLockState(nodeRef2)).thenReturn(lockState2);
|
||||
Mockito.when(lockService.getLockState(nodeRef3)).thenReturn(null);
|
||||
|
||||
// nodeRef1
|
||||
LockInfo lockInfo = davLockService.getLockInfo(nodeRef1);
|
||||
assertEquals(null, lockInfo.getExpires());
|
||||
assertEquals("user1", lockInfo.getOwner());
|
||||
|
||||
// nodeRef2
|
||||
lockInfo = davLockService.getLockInfo(nodeRef2);
|
||||
assertEquals(new Date(999L), lockInfo.getExpires());
|
||||
assertEquals("user2", lockInfo.getOwner());
|
||||
assertEquals("a-random-token", lockInfo.getExclusiveLockToken());
|
||||
assertEquals("infinity", lockInfo.getDepth());
|
||||
assertEquals(WebDAV.XML_EXCLUSIVE, lockInfo.getScope());
|
||||
|
||||
// nodeRef3
|
||||
lockInfo = davLockService.getLockInfo(nodeRef3);
|
||||
assertEquals(null, lockInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mnt13183LockInfo()
|
||||
{
|
||||
// CIFS lock node to 1 hour
|
||||
lockService.lock(nodeRef1, LockType.WRITE_LOCK, 3600, Lifetime.EPHEMERAL, "lock_info_that_is_not_from_webdav");
|
||||
|
||||
// WebDAV get lock info
|
||||
LockInfo lockInfoNodeRef1 = davLockService.getLockInfo(nodeRef1);
|
||||
assertNull("exclusiveLockToken is null", lockInfoNodeRef1.getExclusiveLockToken());
|
||||
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
// WebDav lock, check marker
|
||||
davLockService.lock(nodeRef2, user, 3600);
|
||||
|
||||
LockState lockState2 = lockService.getLockState(nodeRef2);
|
||||
assertNotNull("lockState is not null", lockState2);
|
||||
|
||||
String additionalInfo2 = lockState2.getAdditionalInfo();
|
||||
assertNotNull("additionalInfo is not null", additionalInfo2);
|
||||
assertTrue("Check WEBDAV_LOCK marker", additionalInfo2.startsWith(LockInfoImpl.ADDINFO_WEBDAV_MARKER));
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.webdav;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.repo.lock.mem.Lifetime;
|
||||
import org.alfresco.repo.lock.mem.LockState;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.LockStatus;
|
||||
import org.alfresco.service.cmr.lock.LockType;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WebDAVLockServiceImplTest
|
||||
{
|
||||
private WebDAVLockServiceImpl davLockService;
|
||||
private @Mock HttpSession session;
|
||||
private @Mock List<Pair<String, NodeRef>> sessionList;
|
||||
private @Mock AuthenticationUtil authenticationUtil;
|
||||
private @Mock TransactionService transactionService;
|
||||
private @Mock RetryingTransactionHelper txHelper;
|
||||
private @Mock NodeService nodeService;
|
||||
private @Mock LockService lockService;
|
||||
private @Mock CheckOutCheckInService cociService;
|
||||
private NodeRef nodeRef1;
|
||||
private NodeRef nodeRef2;
|
||||
private LockInfoImpl lockInfo1;
|
||||
private LockState lockState1;
|
||||
private LockInfoImpl lockInfo2;
|
||||
private LockState lockState2;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
davLockService = new WebDAVLockServiceImpl();
|
||||
davLockService.setNodeService(nodeService);
|
||||
davLockService.setCheckOutCheckInService(cociService);
|
||||
davLockService.setCurrentSession(session);
|
||||
davLockService.setLockService(lockService);
|
||||
|
||||
// Train the mock LockStore to respond to get() requests for certain noderefs.
|
||||
nodeRef1 = new NodeRef("workspace://SpacesStore/f6e3f82a-cfef-445b-9fca-7986a14181cc");
|
||||
lockInfo1 = new LockInfoImplTest.LockInfoImplEx();
|
||||
lockState1 = LockState.createLock(nodeRef1, LockType.WRITE_LOCK, "user1", null, Lifetime.EPHEMERAL, null);
|
||||
Mockito.when(lockService.getLockState(nodeRef1)).thenReturn(lockState1);
|
||||
nodeRef2 = new NodeRef("workspace://SpacesStore/a6a4371c-99b9-4618-8cd2-e71d7d96aa87");
|
||||
lockInfo2 = new LockInfoImplTest.LockInfoImplEx();
|
||||
lockInfo2.setExclusiveLockToken("a-random-token");
|
||||
lockInfo2.setDepth("infinity");
|
||||
lockInfo2.setScope(WebDAV.XML_EXCLUSIVE);
|
||||
lockState2 = LockState.createLock(nodeRef2, LockType.WRITE_LOCK, "user2", new Date(999L), Lifetime.EPHEMERAL, lockInfo2.toJSON());
|
||||
Mockito.when(lockService.getLockState(nodeRef2)).thenReturn(lockState2);
|
||||
|
||||
// The mock HttpSession should return the mock session list.
|
||||
Mockito.when(session.getAttribute("_webdavLockedResources")).thenReturn(sessionList);
|
||||
|
||||
// Provide a user name for our fictional user.
|
||||
authenticationUtil = new AuthenticationUtil();
|
||||
authenticationUtil.afterPropertiesSet();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser("some_user_name");
|
||||
|
||||
Mockito.when(txHelper.doInTransaction(any(RetryingTransactionCallback.class), anyBoolean())).thenAnswer(new Answer()
|
||||
{
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
Object[] args = invocation.getArguments();
|
||||
RetryingTransactionCallback<Void> callback = (RetryingTransactionCallback<Void>) args[0];
|
||||
callback.execute();
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
Mockito.when(transactionService.getRetryingTransactionHelper()).thenReturn(txHelper);
|
||||
davLockService.setTransactionService(transactionService);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSessionDestroyed()
|
||||
{
|
||||
List<Pair<String, NodeRef>> lockedNodes = new ArrayList<Pair<String, NodeRef>>(2);
|
||||
lockedNodes.add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
lockedNodes.add(new Pair<String, NodeRef>("another_user_name", nodeRef2));
|
||||
Mockito.when(sessionList.size()).thenReturn(2);
|
||||
Mockito.when(sessionList.iterator()).thenReturn(lockedNodes.iterator());
|
||||
|
||||
Mockito.when(nodeService.exists(nodeRef1)).thenReturn(true);
|
||||
Mockito.when(nodeService.exists(nodeRef2)).thenReturn(true);
|
||||
|
||||
Mockito.when(lockService.getLockStatus(nodeRef1)).thenReturn(LockStatus.LOCKED);
|
||||
Mockito.when(lockService.getLockStatus(nodeRef2)).thenReturn(LockStatus.LOCKED);
|
||||
|
||||
// We're not going to do anything with nodeRef2
|
||||
NodeRef wcNodeRef2 = new NodeRef("workspace://SpacesStore/a6e3f82a-cfef-363d-9fca-3986a14180a0");
|
||||
Mockito.when(cociService.getWorkingCopy(nodeRef2)).thenReturn(wcNodeRef2);
|
||||
|
||||
davLockService.sessionDestroyed();
|
||||
|
||||
// nodeRef1 is unlocked
|
||||
Mockito.verify(lockService).unlock(nodeRef1);
|
||||
|
||||
// nodeRef2 is not unlocked
|
||||
Mockito.verify(lockService, Mockito.never()).unlock(nodeRef2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockLessThan24Hours()
|
||||
{
|
||||
lockInfo1.setTimeoutSeconds(100);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, 100, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
// 100 seconds (in millis) should have been added to the date/time stamp.
|
||||
assertEquals(86500000, lockInfo1.getExpires().getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockGreaterThan24Hours()
|
||||
{
|
||||
int timeout25hours = WebDAV.TIMEOUT_24_HOURS + 3600;
|
||||
lockInfo1.setTimeoutSeconds(timeout25hours);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, WebDAV.TIMEOUT_24_HOURS, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
Mockito.verify(sessionList).add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
// Timeout should be capped at 24 hours.
|
||||
assertEquals(WebDAV.TIMEOUT_24_HOURS, lockInfo1.getRemainingTimeoutSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockForInfinityTime()
|
||||
{
|
||||
lockInfo1.setTimeoutSeconds(WebDAV.TIMEOUT_INFINITY);
|
||||
|
||||
davLockService.lock(nodeRef1, lockInfo1);
|
||||
|
||||
Mockito.verify(lockService).lock(nodeRef1, LockType.WRITE_LOCK, WebDAV.TIMEOUT_24_HOURS, Lifetime.EPHEMERAL, lockInfo1.toJSON());
|
||||
Mockito.verify(sessionList).add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
// Timeout should be capped at 24 hours.
|
||||
assertEquals(WebDAV.TIMEOUT_24_HOURS, lockInfo1.getRemainingTimeoutSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canUnlock()
|
||||
{
|
||||
davLockService.unlock(nodeRef1);
|
||||
|
||||
// NodeRef should have been unlocked.
|
||||
Mockito.verify(lockService).unlock(nodeRef1);
|
||||
// Node should have been removed from the list in the user's session.
|
||||
Mockito.verify(sessionList).remove(new Pair<String, NodeRef>("some_user_name", nodeRef1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canGetLockInfo()
|
||||
{
|
||||
NodeRef nodeRef3 = new NodeRef("workspace://SpacesStore/a6a4371c-99b9-4618-8cd2-e71d28374859");
|
||||
Mockito.when(lockService.getLockState(nodeRef1)).thenReturn(lockState1);
|
||||
Mockito.when(lockService.getLockState(nodeRef2)).thenReturn(lockState2);
|
||||
Mockito.when(lockService.getLockState(nodeRef3)).thenReturn(null);
|
||||
|
||||
// nodeRef1
|
||||
LockInfo lockInfo = davLockService.getLockInfo(nodeRef1);
|
||||
assertEquals(null, lockInfo.getExpires());
|
||||
assertEquals("user1", lockInfo.getOwner());
|
||||
|
||||
// nodeRef2
|
||||
lockInfo = davLockService.getLockInfo(nodeRef2);
|
||||
assertEquals(new Date(999L), lockInfo.getExpires());
|
||||
assertEquals("user2", lockInfo.getOwner());
|
||||
assertEquals("a-random-token", lockInfo.getExclusiveLockToken());
|
||||
assertEquals("infinity", lockInfo.getDepth());
|
||||
assertEquals(WebDAV.XML_EXCLUSIVE, lockInfo.getScope());
|
||||
|
||||
// nodeRef3
|
||||
lockInfo = davLockService.getLockInfo(nodeRef3);
|
||||
assertEquals(null, lockInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mnt13183LockInfo()
|
||||
{
|
||||
// CIFS lock node to 1 hour
|
||||
lockService.lock(nodeRef1, LockType.WRITE_LOCK, 3600, Lifetime.EPHEMERAL, "lock_info_that_is_not_from_webdav");
|
||||
|
||||
// WebDAV get lock info
|
||||
LockInfo lockInfoNodeRef1 = davLockService.getLockInfo(nodeRef1);
|
||||
assertNull("exclusiveLockToken is null", lockInfoNodeRef1.getExclusiveLockToken());
|
||||
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
// WebDav lock, check marker
|
||||
davLockService.lock(nodeRef2, user, 3600);
|
||||
|
||||
LockState lockState2 = lockService.getLockState(nodeRef2);
|
||||
assertNotNull("lockState is not null", lockState2);
|
||||
|
||||
String additionalInfo2 = lockState2.getAdditionalInfo();
|
||||
assertNotNull("additionalInfo is not null", additionalInfo2);
|
||||
assertTrue("Check WEBDAV_LOCK marker", additionalInfo2.startsWith(LockInfoImpl.ADDINFO_WEBDAV_MARKER));
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -35,7 +35,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.alfresco.rest.api.probes.ProbeEntityResource.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -630,34 +630,6 @@
|
||||
<artifactId>gytheio-messaging-camel</artifactId>
|
||||
<version>${dependency.gytheio.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-core</artifactId>
|
||||
@@ -671,92 +643,32 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-spring</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-expression</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-amqp</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<!-- conflicts with activemq geronimo-jms_1.1_spec -->
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jms_2.0_spec</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-jackson</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<exclusions>
|
||||
<!-- Duplicate classes from com.sun.activation:jakarta.activation-->
|
||||
<exclusion>
|
||||
<groupId>jakarta.activation</groupId>
|
||||
<artifactId>jakarta.activation-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-directvm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-direct</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-mock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
<version>${dependency.activemq.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
@@ -764,30 +676,10 @@
|
||||
<version>${dependency.activemq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-camel</artifactId>
|
||||
<version>${dependency.activemq.version}</version>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-activemq</artifactId>
|
||||
<version>${dependency.camel.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<!-- Duplicates classes from jakarta.transaction:jakarta.transaction-api -->
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
@@ -800,14 +692,6 @@
|
||||
<artifactId>activemq-pool</artifactId>
|
||||
<version>${dependency.activemq.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<!-- Duplicates classes from jakarta.transaction:jakarta.transaction-api -->
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.messaging.camel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.model.ModelCamelContext;
|
||||
import org.apache.camel.model.RouteDefinition;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -65,7 +66,9 @@ public class SpringContextRouteLoader implements ApplicationContextAware, Initia
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addRoutesToCamelContext() throws Exception
|
||||
{
|
||||
ModelCamelContext modelCamelContext = (ModelCamelContext) applicationContext.getBean(camelContextId);
|
||||
ModelCamelContext modelCamelContext = applicationContext
|
||||
.getBean(camelContextId, CamelContext.class)
|
||||
.adapt(ModelCamelContext.class);
|
||||
ArrayList<RouteDefinition> routeDefinitions = (ArrayList<RouteDefinition>) applicationContext.getBean(routeContextId);
|
||||
modelCamelContext.addRouteDefinitions(routeDefinitions);
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import javax.jms.ConnectionFactory;
|
||||
import org.alfresco.encryption.AlfrescoKeyStore;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.ActiveMQSslConnectionFactory;
|
||||
import org.apache.camel.component.jms.JmsComponent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -80,6 +81,12 @@ public class ConnectionFactoryConfiguration
|
||||
return createConnectionFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JmsComponent jms()
|
||||
{
|
||||
return JmsComponent.jmsComponent(activeMqConnectionFactory());
|
||||
}
|
||||
|
||||
protected ConnectionFactory createConnectionFactory()
|
||||
{
|
||||
return new ActiveMQConnectionFactory(username, password, brokerUrl);
|
||||
|
@@ -39,7 +39,7 @@ import org.alfresco.repo.rawevents.types.OnContentUpdatePolicyEvent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.camel.spring.SpringRouteBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -52,7 +52,7 @@ import org.springframework.stereotype.Component;
|
||||
* @author Cristian Turlica
|
||||
*/
|
||||
@Component
|
||||
public class OnContentUpdateRenditionRoute extends SpringRouteBuilder
|
||||
public class OnContentUpdateRenditionRoute extends RouteBuilder
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(OnContentUpdateRenditionRoute.class);
|
||||
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.messaging.camel.routes;
|
||||
|
||||
import org.apache.camel.spring.SpringRouteBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -33,11 +33,11 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Route builder for Repo node events
|
||||
*
|
||||
*
|
||||
* @author sglover
|
||||
*/
|
||||
@Component
|
||||
public class RepoNodeEventsRouteBuilder extends SpringRouteBuilder
|
||||
public class RepoNodeEventsRouteBuilder extends RouteBuilder
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(RepoNodeEventsRouteBuilder.class);
|
||||
|
||||
@@ -60,8 +60,10 @@ public class RepoNodeEventsRouteBuilder extends SpringRouteBuilder
|
||||
logger.debug("targetTopic is "+targetTopic);
|
||||
}
|
||||
|
||||
from(sourceQueue).routeId("alfresco.events -> topic:alfresco.repo.events")
|
||||
.marshal("defaultDataFormat").to(targetTopic)
|
||||
.end();
|
||||
from(sourceQueue)
|
||||
.routeId("alfresco.events -> topic:alfresco.repo.events")
|
||||
.marshal("defaultDataFormat")
|
||||
.to(targetTopic)
|
||||
.end();
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@
|
||||
package org.alfresco.messaging.camel.routes;
|
||||
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.spring.SpringRouteBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -43,7 +43,7 @@ import java.util.concurrent.Executors;
|
||||
* @author aepure
|
||||
*/
|
||||
@Component
|
||||
public class TransformRequestConsumer extends SpringRouteBuilder
|
||||
public class TransformRequestConsumer extends RouteBuilder
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(TransformRequestConsumer.class);
|
||||
|
||||
|
@@ -71,7 +71,7 @@
|
||||
<!-- Any RouteBuilder in this enterprise package will be fired up -->
|
||||
<context:component-scan base-package="org.alfresco.enterprise.repo.routes"/>
|
||||
|
||||
<camelContext id="alfrescoCamelContext" xmlns="http://camel.apache.org/schema/spring">
|
||||
<camelContext id="alfrescoCamelContext" xmlns="http://camel.apache.org/schema/spring" useBreadcrumb="true">
|
||||
<contextScan/>
|
||||
<camel:jmxAgent id="agent" mbeanObjectDomainName="Alfresco.Camel" />
|
||||
<template id="camelProducerTemplate" defaultEndpoint="direct:alfresco.default" />
|
||||
|
@@ -47,28 +47,28 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = "/test-messaging-context.xml")
|
||||
public class CamelRoutesTest
|
||||
{
|
||||
@EndpointInject(uri = "mock:result1")
|
||||
@EndpointInject("mock:result1")
|
||||
protected MockEndpoint resultEndpoint1;
|
||||
|
||||
@EndpointInject(uri = "mock:result2")
|
||||
@EndpointInject("mock:result2")
|
||||
protected MockEndpoint resultEndpoint2;
|
||||
|
||||
@EndpointInject(uri = "mock:dlq")
|
||||
@EndpointInject("mock:dlq")
|
||||
protected MockEndpoint dlqEndpoint;
|
||||
|
||||
@Autowired
|
||||
protected CamelContext camelContext;
|
||||
|
||||
@Produce(uri = "direct-vm:alfresco.test.1")
|
||||
@Produce("direct-vm:alfresco.test.1")
|
||||
protected ProducerTemplate template1;
|
||||
|
||||
@Produce(uri = "direct-vm:alfresco.test.2")
|
||||
@Produce("direct-vm:alfresco.test.2")
|
||||
protected ProducerTemplate template2;
|
||||
|
||||
@Produce(uri = "direct-vm:alfresco.default")
|
||||
@Produce("direct-vm:alfresco.default")
|
||||
protected ProducerTemplate template3;
|
||||
|
||||
@Produce(uri = "direct-vm:alfresco.test.transacted")
|
||||
@Produce("direct-vm:alfresco.test.transacted")
|
||||
protected ProducerTemplate template4;
|
||||
|
||||
@Autowired
|
||||
|
@@ -25,7 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.messaging.camel.routes;
|
||||
|
||||
import org.apache.camel.spring.SpringRouteBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -34,13 +34,14 @@ import org.springframework.stereotype.Component;
|
||||
* @author Ray Gauss II
|
||||
*/
|
||||
@Component
|
||||
public class TestingRouteBuilder extends SpringRouteBuilder
|
||||
public class TestingRouteBuilder extends RouteBuilder
|
||||
{
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception
|
||||
{
|
||||
from("direct-vm:alfresco.test.2").to("mock:result2");
|
||||
from("direct-vm:alfresco.test.2")
|
||||
.to("mock:result2");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -131,10 +131,9 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
// authenticate as admin
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
|
||||
this.rootNodeRef = retryingTransactionHelper.doInTransaction(() -> {
|
||||
rootNodeRef = retryingTransactionHelper.doInTransaction(() -> {
|
||||
// create a store and get the root node
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
|
||||
this.getClass().getName());
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getClass().getName());
|
||||
if (!nodeService.exists(storeRef))
|
||||
{
|
||||
storeRef = nodeService.createStore(storeRef.getProtocol(),
|
||||
|
@@ -29,14 +29,13 @@ import static org.mockito.Mockito.doThrow;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.rawevents.types.OnContentUpdatePolicyEvent;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Message;
|
||||
import org.apache.camel.impl.DefaultExchange;
|
||||
import org.apache.camel.support.DefaultExchange;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@@ -34,7 +34,7 @@ import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
Reference in New Issue
Block a user