Search in sources :

Example 1 with AuthenticationUtil

use of org.alfresco.repo.security.authentication.AuthenticationUtil in project alfresco-remote-api by Alfresco.

the class WebDAVLockServiceImplTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    davLockService = new WebDAVLockServiceImpl();
    davLockService.setNodeService(nodeService);
    davLockService.setCheckOutCheckInService(cociService);
    davLockService.setCurrentSession(session);
    davLockService.setLockService(lockService);
    // Train the mock LockStore to respond to get() requests for certain noderefs.
    nodeRef1 = new NodeRef("workspace://SpacesStore/f6e3f82a-cfef-445b-9fca-7986a14181cc");
    lockInfo1 = new LockInfoImplTest.LockInfoImplEx();
    lockState1 = LockState.createLock(nodeRef1, LockType.WRITE_LOCK, "user1", null, Lifetime.EPHEMERAL, null);
    Mockito.when(lockService.getLockState(nodeRef1)).thenReturn(lockState1);
    nodeRef2 = new NodeRef("workspace://SpacesStore/a6a4371c-99b9-4618-8cd2-e71d7d96aa87");
    lockInfo2 = new LockInfoImplTest.LockInfoImplEx();
    lockInfo2.setExclusiveLockToken("a-random-token");
    lockInfo2.setDepth("infinity");
    lockInfo2.setScope(WebDAV.XML_EXCLUSIVE);
    lockState2 = LockState.createLock(nodeRef2, LockType.WRITE_LOCK, "user2", new Date(999L), Lifetime.EPHEMERAL, lockInfo2.toJSON());
    Mockito.when(lockService.getLockState(nodeRef2)).thenReturn(lockState2);
    // The mock HttpSession should return the mock session list.
    Mockito.when(session.getAttribute("_webdavLockedResources")).thenReturn(sessionList);
    // Provide a user name for our fictional user.
    authenticationUtil = new AuthenticationUtil();
    authenticationUtil.afterPropertiesSet();
    AuthenticationUtil.setFullyAuthenticatedUser("some_user_name");
    Mockito.when(txHelper.doInTransaction(any(RetryingTransactionCallback.class), anyBoolean())).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RetryingTransactionCallback<Void> callback = (RetryingTransactionCallback<Void>) args[0];
            callback.execute();
            return null;
        }
    });
    Mockito.when(transactionService.getRetryingTransactionHelper()).thenReturn(txHelper);
    davLockService.setTransactionService(transactionService);
}
Also used : Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Answer(org.mockito.stubbing.Answer) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Aggregations

Date (java.util.Date)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1