Files
alfresco-community-repo/source/test-java/org/alfresco/opencmis/AlfrescoCmisExceptionInterceptorTest.java
Tatyana Valkevych 7dd2291753 Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
107541: Merged 5.0.N (5.0.3) to HEAD-BUG-FIX (5.1/Cloud) (PARTIAL MERGE)
      107413: Merged DEV to 5.0.N (5.0.3)
         106858 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code
            - Cleaning of Javadoc,
   107565: MNT-13545 Fix compilation after merge of Javadoc


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@107633 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2015-07-02 16:13:03 +00:00

137 lines
4.9 KiB
Java

/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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);
}
}