Search in sources :

Example 76 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.

the class UnlockMethodTest method setUp.

@Before
public void setUp() throws Exception {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    unlockMethod = new UnlockMethod();
    unlockMethod.setDetails(request, response, davHelper, null);
    lockMethod = new LockMethod();
    lockMethod.setDetails(request, null, davHelper, null);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 77 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.

the class WebDAVMethodTest method checkLockedNodeTestWork.

private void checkLockedNodeTestWork() throws WebDAVServerException {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
    String rootPath = "/app:company_home";
    String storeName = "workspace://SpacesStore";
    StoreRef storeRef = new StoreRef(storeName);
    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
    NodeRef defaultRootNode = nodeRefs.get(0);
    lockMethod = new LockMethod();
    NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
    String strPath = "/" + "testLockedNode" + GUID.generate();
    lockMethod.createExclusive = true;
    lockMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    lockMethod.m_strPath = strPath;
    // Lock the node (will create a new one).
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            lockMethod.executeImpl();
            return null;
        }
    });
    // Prepare for PUT
    req.addHeader(WebDAV.HEADER_IF, "(<" + lockMethod.lockToken + ">)");
    putMethod = new PutMethod();
    putMethod.setDetails(req, resp, webDAVHelper, rootNodeRef);
    putMethod.parseRequestHeaders();
    putMethod.m_strPath = strPath;
    String content = "test content stream";
    req.setContent(content.getBytes());
    // Issue a put request
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            putMethod.executeImpl();
            return null;
        }
    });
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 78 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.

the class WebDAVMethodTest method expiryLockTest.

/* MNT-10555 Test */
@Test
public void expiryLockTest() {
    // ACE-4347 extra debug logging just for this test so we can see what's going on when it next fails
    Level repoWebdavSaveLogLevel = Logger.getLogger("org.alfresco.repo.webdav").getLevel();
    Logger.getLogger("org.alfresco.repo.webdav").setLevel(Level.ALL);
    Level webdavProtocolSaveLogLevel = Logger.getLogger("org.alfresco.webdav.protocol").getLevel();
    Logger.getLogger("org.alfresco.webdav.protocol").setLevel(Level.ALL);
    try {
        setUpApplicationContext();
        req = new MockHttpServletRequest();
        resp = new MockHttpServletResponse();
        String rootPath = "/app:company_home";
        StoreRef storeRef = new StoreRef("workspace://SpacesStore");
        NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
        NodeRef defaultRootNode = nodeRefs.get(0);
        NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);
        // Create test folder.
        NodeRef folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_FOLDER, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "WebDavMethodExpiryLockTest" + System.currentTimeMillis())).getChildRef();
        // Create test document.
        NodeRef nodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT, Collections.<QName, Serializable>singletonMap(ContentModel.PROP_NAME, "text.txt")).getChildRef();
        lockMethod = new LockMethod();
        lockMethod.createExclusive = true;
        lockMethod.m_timeoutDuration = 1;
        lockMethod.setDetails(req, resp, webDAVHelper, nodeRef);
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {

            @Override
            public Object execute() throws Throwable {
                try {
                    // LOCK document.
                    lockMethod.executeImpl();
                    // wait for the lock to expire up to 5 seconds
                    int timeout = 5;
                    while (timeout > 0 && !lockMethod.lockInfo.isExpired()) {
                        Thread.sleep(1000);
                        timeout--;
                    }
                    // LOCK against an expired lock.
                    lockMethod.executeImpl();
                } catch (WebDAVServerException e) {
                    logger.debug(e);
                    Assert.fail("Document was not locked again, when lock has expired.");
                }
                return null;
            }
        });
        // Remove test folder.
        nodeService.deleteNode(folderNodeRef);
    } finally {
        Logger.getLogger("org.alfresco.webdav.protocol").setLevel(webdavProtocolSaveLogLevel);
        Logger.getLogger("org.alfresco.repo.webdav").setLevel(repoWebdavSaveLogLevel);
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) QName(org.alfresco.service.namespace.QName) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Level(org.apache.log4j.Level) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 79 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.

the class WebDAVMethodTest method createRequestObjects.

private void createRequestObjects() {
    method = new TestWebDAVMethod();
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 80 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.

the class WebDAVonContentUpdateTest method executeMethod.

/**
 * Executes WebDAV method for testing
 * <p>
 * Sets content to request from a test file
 *
 * @param methodName Method name to prepare, should be initialized (PUT, LOCK, UNLOCK are supported)
 * @param fileName the name of the file set to the context, can be used with path, i.e. "path/to/file/fileName.txt"
 * @param content If <b>not null</b> adds test content to the request
 * @param headers to set to request, can be null
 * @throws Exception
 */
private void executeMethod(String methodName, String fileName, byte[] content, Map<String, String> headers) throws Exception {
    if (methodName == WebDAV.METHOD_PUT)
        method = new PutMethod();
    else if (methodName == WebDAV.METHOD_LOCK)
        method = new LockMethod();
    else if (methodName == WebDAV.METHOD_UNLOCK)
        method = new UnlockMethod();
    if (method != null) {
        request = new MockHttpServletRequest(methodName, "/alfresco/webdav/" + fileName);
        response = new MockHttpServletResponse();
        request.setServerPort(8080);
        request.setServletPath("/webdav");
        if (content != null) {
            request.setContent(content);
        }
        if (headers != null && !headers.isEmpty()) {
            for (String key : headers.keySet()) {
                request.addHeader(key, headers.get(key));
            }
        }
        method.setDetails(request, response, webDAVHelper, companyHomeNodeRef);
        method.execute();
    }
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2338 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1986 Test (org.junit.jupiter.api.Test)1412 lombok.val (lombok.val)946 Test (org.junit.Test)558 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)484 MockServletContext (org.springframework.mock.web.MockServletContext)462 MockRequestContext (org.springframework.webflow.test.MockRequestContext)460 MockFilterChain (org.springframework.mock.web.MockFilterChain)239 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)184 JEEContext (org.pac4j.core.context.JEEContext)159 FilterChain (jakarta.servlet.FilterChain)117 Authentication (org.springframework.security.core.Authentication)116 BeforeEach (org.junit.jupiter.api.BeforeEach)106 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)97 HashMap (java.util.HashMap)84 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)83 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)67 MockHttpSession (org.springframework.mock.web.MockHttpSession)65 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)64