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);
}
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;
}
});
}
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);
}
}
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();
}
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();
}
}
Aggregations