Files
alfresco-community-repo/source/test-java/org/alfresco/opencmis/AlfrescoCmisExceptionInterceptorTest.java
Alan Davis 91eb2644ad Merged 5.2.N (5.2.1) to HEAD (5.2)
125781 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
         125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-06-03 16:40:56 +00:00

119 lines
4.1 KiB
Java

package org.alfresco.opencmis;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.coci.CheckOutCheckInServiceException;
import org.alfresco.service.cmr.lock.NodeLockedException;
import org.alfresco.service.cmr.model.FileExistsException;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException;
import org.junit.Assert;
import org.junit.Test;
/**
* Ensure that CMIS handles specific types of Alfresco exceptions
*
* @author Derek Hulley
* @since 4.3
*/
public class AlfrescoCmisExceptionInterceptorTest
{
private AlfrescoCmisExceptionInterceptor interceptor = new AlfrescoCmisExceptionInterceptor();
/**
* Does the mock call ensuring that the exception is thrown
* @throws Throwable the exception provided
*/
private void doMockCall(Exception toThrow, Class<?> toCatch) throws Throwable
{
MethodInvocation mi = mock(MethodInvocation.class);
when(mi.proceed()).thenThrow(toThrow);
try
{
interceptor.invoke(mi);
fail("Expected an exception to be thrown here.");
}
catch (Exception e)
{
Assert.assertEquals("Incorrect exception thrown: ", toCatch, e.getClass());
}
}
@Test
public void testNoException() throws Throwable
{
MethodInvocation mi = mock(MethodInvocation.class);
when(mi.proceed()).thenReturn("BOB");
interceptor.invoke(mi);
}
@Test
public void testAuthenticationException() throws Throwable
{
Exception e = new AuthenticationException("x");
Class<?> toCatch = CmisPermissionDeniedException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
@Test
public void testCheckOutCheckInServiceException() throws Throwable
{
Exception e = new CheckOutCheckInServiceException("x");
Class<?> toCatch = CmisVersioningException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
@Test
public void testFileExistsException() throws Throwable
{
Exception e = new FileExistsException(null, null);
Class<?> toCatch = CmisContentAlreadyExistsException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
@Test
public void testIntegrityException() throws Throwable
{
Exception e = new IntegrityException(null);
Class<?> toCatch = CmisConstraintException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
@Test
public void testAccessDeniedException() throws Throwable
{
Exception e = new AccessDeniedException("x");
Class<?> toCatch = CmisPermissionDeniedException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
@Test
public void testNodeLockedException() throws Throwable
{
Exception e = new NodeLockedException();
Class<?> toCatch = CmisUpdateConflictException.class;
doMockCall(e, toCatch);
doMockCall(new RuntimeException(new RuntimeException(e)), toCatch);
}
}