use of org.alfresco.service.cmr.action.ActionService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method setUp.
@Before
public void setUp() throws Exception {
searchService = ctx.getBean("SearchService", SearchService.class);
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
nodeService = ctx.getBean("NodeService", NodeService.class);
transactionService = ctx.getBean("transactionService", TransactionService.class);
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
authenticationService = ctx.getBean("authenticationService", MutableAuthenticationService.class);
personService = ctx.getBean("PersonService", PersonService.class);
lockService = ctx.getBean("LockService", LockService.class);
contentService = ctx.getBean("contentService", ContentService.class);
checkOutCheckInService = ctx.getBean("CheckOutCheckInService", CheckOutCheckInService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
namespaceService = ctx.getBean("namespaceService", NamespaceService.class);
actionService = ctx.getBean("ActionService", ActionService.class);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
companyHomeNodeRef = repositoryHelper.getCompanyHome();
txn = transactionService.getUserTransaction();
txn.begin();
createUser(USER1_NAME);
createUser(USER2_NAME);
InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
InputStream davLockInfoAdminIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_ADMIN);
InputStream davLockInfoUser2IS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_USER2);
testDataFile = IOUtils.toByteArray(testDataIS);
davLockInfoAdminFile = IOUtils.toByteArray(davLockInfoAdminIS);
davLockInfoUser2File = IOUtils.toByteArray(davLockInfoUser2IS);
testDataIS.close();
davLockInfoAdminIS.close();
davLockInfoUser2IS.close();
// Create a test file with versionable aspect and content
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
versionableDocName = "doc-" + GUID.generate();
properties.put(ContentModel.PROP_NAME, versionableDocName);
versionableDoc = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, versionableDocName), ContentModel.TYPE_CONTENT, properties).getChildRef();
contentService.getWriter(versionableDoc, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");
nodeService.addAspect(versionableDoc, ContentModel.ASPECT_VERSIONABLE, null);
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
}
use of org.alfresco.service.cmr.action.ActionService in project alfresco-remote-api by Alfresco.
the class PutMethodTest method testPutNullContent.
/**
* Negative test to check that a temp file will be deleted from the repo if writing the content fails
*/
@Test
public void testPutNullContent() throws Exception {
String fileName = "file-" + GUID.generate();
NodeRef fileNoderef = null;
// Lock the node
try {
executeMethod(WebDAV.METHOD_LOCK, fileName, davLockInfoAdminFile, null);
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), "/app:company_home/cm:" + fileName, null, namespaceService, false);
fileNoderef = refs.get(0);
} catch (Exception e) {
throw new RuntimeException("Failed to lock a file", e);
}
txn.commit();
txn = transactionService.getUserTransaction();
txn.begin();
// Construct IF HEADER
String lockToken = fileNoderef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + AuthenticationUtil.getAdminUserName();
String lockHeaderValue = "(<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">)";
HashMap<String, String> headers = new HashMap<String, String>();
headers.put(WebDAV.HEADER_IF, lockHeaderValue);
// Simulate any failure during the content write
// null content is no longer null in MockHttpServletRequest (Spring 5)
ActionService mockActionService = mock(ActionService.class);
when(mockActionService.createAction(ContentMetadataExtracter.EXECUTOR_NAME)).thenThrow(new AlfrescoRuntimeException("Negative test"));
try {
webDAVHelper.setActionService(mockActionService);
// setting a null content
executeMethod(WebDAV.METHOD_PUT, fileName, null, headers);
fail("The execution should fail.");
} catch (WebDAVServerException wse) {
if (nodeService.exists(fileNoderef)) {
nodeService.deleteNode(fileNoderef);
fail("File exist, but should not.");
}
} catch (Exception e) {
throw new RuntimeException("Failed to upload a file", e);
} finally {
webDAVHelper.setActionService(actionService);
}
if (fileNoderef != null && nodeService.exists(fileNoderef)) {
nodeService.deleteNode(fileNoderef);
}
}
Aggregations