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