use of org.alfresco.jlan.server.filesys.NetworkFile in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMacMountainLionPreview.
// Test Word 2011 Mountain Lion
/**
* This test tries to simulate the cifs shuffling that is done
* from Save from Mac Mountain Lion by Preview
*
* a) Temp file created in temporary folder (Crysanthemum.jpg)
* b) Target file deleted by open / delete on close flag / close
* c) Temp file moved to target file.
*/
public void testScenarioMacMountainLionPreview() throws Exception {
logger.debug("testScenarioMountainLionPreview");
final String FILE_NAME = "Crysanthemeum.jpg";
final String TEMP_FILE_NAME = "Crysanthemeum.jpg";
final String UPDATED_TEXT = "Mac Lion Preview Updated Content";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile tempFileHandle;
// node ref Crysanthemenum.jpg
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview";
final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview\\.Temporary Items";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
driver.createDirectory(testSession, testConnection, createTempDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
String testContent = "Mac Mountain Lion Text";
byte[] testContentBytes = testContent.getBytes();
driver.writeFile(testSession, testConnection, testContext.firstFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
/**
* Create the temp file we are going to use
*/
FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
assertNotNull(testContext.tempFileHandle);
testContent = UPDATED_TEXT;
testContentBytes = testContent.getBytes();
driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
/**
* Also add versionable to target file
*/
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
// /**
// * b) Delete the target file by opening it and set the delete on close bit
// */
// RetryingTransactionCallback<Void> deleteTargetFileCB = new RetryingTransactionCallback<Void>() {
//
// @Override
// public Void execute() throws Throwable
// {
// FileOpenParams openFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
// testContext.tempFileHandle = driver.openFile(testSession, testConnection, openFileParams);
// FileInfo info = new FileInfo();
// info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
// info.setDeleteOnClose(true);
// testContext.tempFileHandle.setDeleteOnClose(true);
//
// driver.setFileInformation(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, info);
//
// assertNotNull(testContext.tempFileHandle);
// logger.debug("this close should result in a file being deleted");
// driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
// return null;
// }
// };
// tran.doInTransaction(deleteTargetFileCB, false, true);
/**
* b) Delete the target file by a simple delete
*/
RetryingTransactionCallback<Void> deleteTargetFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(deleteTargetFileCB, false, true);
/**
* c) Move the temp file into target directory
*/
RetryingTransactionCallback<Void> moveTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(moveTempFileCB, false, true);
/**
* Validate results.
*/
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
return null;
}
};
tran.doInTransaction(validateCB, false, true);
}
use of org.alfresco.jlan.server.filesys.NetworkFile in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSWord2003SaveShuffle.
// testRenameVersionable
/**
* This test tries to simulate the shuffling that is done by MS Word 2003 upon file save
*
* a) TEST.DOC
* b) Save to ~WRDnnnn.TMP
* c) Delete ~WRLnnnn.TMP
* d) Rename TEST.DOC ~WDLnnnn.TMP
* e) Delete TEST.DOC
* f) Rename ~WRDnnnn.TMP to TEST.DOC
* g) Delete ~WRLnnnn.TMP
*
* We need to check that properties, aspects, primary assocs, secondary assocs, peer assocs, node type,
* version history, creation date are maintained.
*/
public void testScenarioMSWord2003SaveShuffle() throws Exception {
logger.debug("testScenarioMSWord2003SaveShuffle");
final String FILE_NAME = "TEST.DOC";
final String FILE_TITLE = "Test document";
final String FILE_DESCRIPTION = "This is a test document to test CIFS shuffle";
final String FILE_OLD_TEMP = "~WRL0002.TMP";
final String FILE_NEW_TEMP = "~WRD0002.TMP";
final QName RESIDUAL_MTTEXT = QName.createQName("{gsxhjsx}", "whatever");
class TestContext {
NetworkFile firstFileHandle;
NetworkFile newFileHandle;
NetworkFile oldFileHandle;
// node ref of test.doc
NodeRef testNodeRef;
Serializable testCreatedDate;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSWord2003SaveShuffle";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Clean up just in case garbage is left from a previous run
*/
RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
try {
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
// now load up the node with lots of other stuff that we will test to see if it gets preserved during the
// shuffle.
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
// test non CM namespace property
nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
// test CM property not related to an aspect
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_ADDRESSEE, "Fred");
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_TITLE);
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION, FILE_DESCRIPTION);
/**
* MLText value - also a residual value in a non cm namespace
*/
MLText mltext = new MLText();
mltext.addValue(Locale.FRENCH, "Bonjour");
mltext.addValue(Locale.ENGLISH, "Hello");
mltext.addValue(Locale.ITALY, "Buongiorno");
mlAwareNodeService.setProperty(testContext.testNodeRef, RESIDUAL_MTTEXT, mltext);
// classifiable chosen since its not related to any properties.
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_CLASSIFIABLE, null);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* Write some content to the test file
*/
RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
String testContent = "MS Word 2003 shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
testContext.testCreatedDate = nodeService.getProperty(testContext.testNodeRef, ContentModel.PROP_CREATED);
MLText multi = (MLText) mlAwareNodeService.getProperty(testContext.testNodeRef, RESIDUAL_MTTEXT);
multi.getValues();
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
/**
* b) Save the new file
*/
RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.newFileHandle);
String testContent = "MS Word 2003 shuffle test This is new content";
byte[] testContentBytes = testContent.getBytes();
testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.newFileHandle.close();
return null;
}
};
tran.doInTransaction(saveNewFileCB, false, true);
/**
* rename the old file
*/
RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
RetryingTransactionCallback<Void> validateOldFileGoneCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
} catch (IOException e) {
// expect to go here since previous step renamed the file.
}
return null;
}
};
tran.doInTransaction(validateOldFileGoneCB, false, true);
logger.debug("Shuffle step next");
/**
* Move the new file into place, stuff should get shuffled
*/
RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(moveNewFileCB, false, true);
logger.debug("end of shuffle step");
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
// Check trx:enabled has been shuffled.
assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
// check my residual MLText has been transferred
assertTrue(props.containsKey(RESIDUAL_MTTEXT));
// Check the titled aspect is correct
assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
assertEquals("title wrong", FILE_TITLE, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_TITLE));
assertEquals("description wrong", FILE_DESCRIPTION, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_DESCRIPTION));
// ALF-7641 - CIFS shuffle, does not preseve MLText values.
Map<QName, Serializable> mlProps = mlAwareNodeService.getProperties(shuffledNodeRef);
MLText multi = (MLText) mlAwareNodeService.getProperty(shuffledNodeRef, RESIDUAL_MTTEXT);
assertTrue("MLText has lost values", multi.getValues().size() > 2);
// // ALF-7635 check auditable properties
assertEquals("creation date not preserved", ((java.util.Date) testContext.testCreatedDate).getTime(), ((java.util.Date) nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_CREATED)).getTime());
// ALF-7628 - preserve addressee and classifiable
assertEquals("ADDRESSEE PROPERTY Not copied", "Fred", nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_ADDRESSEE));
assertTrue("CLASSIFIABLE aspect not present", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_CLASSIFIABLE));
// ALF-7584 - preserve node ref.
assertEquals("noderef changed", testContext.testNodeRef, shuffledNodeRef);
return null;
}
};
tran.doInTransaction(validateCB, true, true);
/**
* Clean up just in case garbage is left from a previous run
*/
RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP);
return null;
}
};
tran.doInTransaction(deleteOldFileCB, false, true);
}
use of org.alfresco.jlan.server.filesys.NetworkFile in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMacLionTextEditByEditor_ALF_16257.
/**
* 0. test.txt exist in folder where user has Editor permissions
* 1. as Editor create temporary file in temporary directory
* 2. as Editor rename test.txt to test.txt.sb-1eefba7a-rkC6XE
* 3. as Editor move temporary file to working directory
*/
public void testScenarioMacLionTextEditByEditor_ALF_16257() throws Exception {
logger.debug("test Collaborator/editor edit txt file on Mac Os Mountain Lion : Alf16257");
final String FILE_NAME = "test.txt";
final String FILE_BACKUP = "test.txt.sb-1eefba7a-rkC6XE";
// the same but in temp dir
final String FILE_NEW_TEMP = FILE_NAME;
class TestContext {
NetworkFile firstFileHandle;
NetworkFile newFileHandle;
// node ref of FILE_NAME
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = TEST_ROOT_DIR + "\\testALF16257txt";
final String TEST_TEMP_DIR = TEST_DIR + "\\.TemporaryItems";
final String UPDATED_TEXT = "This is new content";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "cifs", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Clean up just in case garbage is left from a previous run
*/
RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
try {
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
logger.debug("Step 0 - initialise");
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
driver.createDirectory(testSession, testConnection, createTempDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
// no need to test lots of different properties, that's already been tested above
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
String testContent = "CIFS: Collaborator/editor could not edit file on Mac Os Mountain Lion";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
// Apply 'Editor' role for test user to test folder
permissionService.setPermission(getNodeForPath(testConnection, TEST_DIR), ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);
// Apply full control on temporary directory
permissionService.setPermission(getNodeForPath(testConnection, TEST_TEMP_DIR), PermissionService.ALL_AUTHORITIES, PermissionService.ALL_PERMISSIONS, true);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* a) Save the temp file in the temp dir
*/
logger.debug("Step a - create a temp file in the temp dir");
RunAsWork<Void> saveNewFileCB = new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
FileOpenParams createFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.newFileHandle);
byte[] testContentBytes = UPDATED_TEXT.getBytes();
driver.writeFile(testSession, testConnection, testContext.newFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.newFileHandle);
NodeRef tempNodeRef = getNodeForPath(testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP);
ContentReader reader = contentService.getReader(tempNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(reader);
String actualContent = reader.getContentString();
assertEquals("new contents were not written to temporary file", UPDATED_TEXT, actualContent);
return null;
}
};
doTransactionWorkAsEditor(saveNewFileCB, tran);
/**
* b) rename the target file to a backup file
*/
logger.debug("Step b - rename the target file as Editor");
RunAsWork<Void> renameOldFileCB = new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_BACKUP);
return null;
}
};
doTransactionWorkAsEditor(renameOldFileCB, tran);
/**
* c) Move the new file into target dir, stuff should get shuffled
*/
logger.debug("Step c - move new file into target dir as Editor");
RunAsWork<Void> moveNewFileCB = new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
doTransactionWorkAsEditor(moveNewFileCB, tran);
/**
* Validate
*/
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
ContentReader reader = contentService.getReader(testContext.testNodeRef, ContentModel.PROP_CONTENT);
assertNotNull(reader);
String actualContent = reader.getContentString();
assertEquals("contents were not updated", UPDATED_TEXT, actualContent);
return null;
}
};
tran.doInTransaction(validateCB, false, true);
logger.debug("end testScenarioMacLionTextEditByEditor For ALF-16257");
}
use of org.alfresco.jlan.server.filesys.NetworkFile in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testExcel2013SaveShuffle.
/**
* Excel 2013 With Versionable file (MNT-13078)
*
* CreateFile Cherries.xlsx
* CreateFile ~herries.tmp
* CreateFile Cherries.xlsx~RF172f241.TMP
* DeleteFile Cherries.xlsx~RF172f241.TMP
* RenameFile oldName: Cherries.xls,
* newName: Cherries.xlsx~RF172f241.TMP
* Delete On Close for Cherries.xlsx~RF172f241.TMP
* RenameFile oldName: ~herries.tmp,
* newName: Cherries.xlsx
*/
public void testExcel2013SaveShuffle() throws Exception {
logger.debug("testScenarioExcel2013SaveShuffle");
final String FILE_NAME = "Cherries.xlsx";
final String FILE_ORIGINAL_TITLE = "Original";
final String FILE_UNUSED_TEMP = "Cherries.xlsx~RF172f241.TMP";
final String FILE_USED_TEMP = "~herries.tmp";
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSExcel2013SaveShuffle";
class TestContext {
NetworkFile firstFileHandle;
// node ref of test.doc
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Clean up just in case garbage is left from a previous run
*/
RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
try {
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createOriginalFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
String testContent = "MS Word 2013 shuffle test. This is first file content";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
// now load up the node with lots of other stuff that we will test to see if it gets preserved during the
// shuffle.
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
// need to remove. Otherwise file will be deleted (not placed into archive spaces store)
nodeService.removeAspect(testContext.testNodeRef, ContentModel.ASPECT_NO_CONTENT);
// test non CM namespace property
nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_ORIGINAL_TITLE);
return null;
}
};
tran.doInTransaction(createOriginalFileCB, false, true);
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createUsedTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_USED_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile fileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(fileHandle);
String testContent = "MS Word 2013 shuffle test. This is used file content";
byte[] testContentBytes = testContent.getBytes();
fileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
fileHandle.close();
NodeRef usedRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_USED_TEMP);
nodeService.addAspect(usedRef, ContentModel.ASPECT_VERSIONABLE, null);
nodeService.removeAspect(usedRef, ContentModel.ASPECT_NO_CONTENT);
nodeService.setProperty(usedRef, ContentModel.PROP_TITLE, "Used");
return null;
}
};
tran.doInTransaction(createUsedTempFileCB, false, true);
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createUnusedTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_UNUSED_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile unusedFile = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(unusedFile);
NodeRef unusedNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
nodeService.addAspect(unusedNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
nodeService.setProperty(unusedNodeRef, TransferModel.PROP_ENABLED, true);
nodeService.setProperty(unusedNodeRef, ContentModel.PROP_TITLE, "Unused");
return null;
}
};
tran.doInTransaction(createUnusedTempFileCB, false, true);
/**
* Delete unused temporary file
*/
RetryingTransactionCallback<Void> deleteUnusedFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
} catch (IOException e) {
// expect to go here since previous step renamed the file.
}
return null;
}
};
tran.doInTransaction(deleteUnusedFileCB, false, true);
/**
* Rename the original file to unused file
*/
RetryingTransactionCallback<Void> renameToUnusedFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_UNUSED_TEMP);
return null;
}
};
tran.doInTransaction(renameToUnusedFileCB, false, true);
/**
* Delete unused temporary file
*/
tran.doInTransaction(deleteUnusedFileCB, false, true);
/**
* Rename the used temporary file to original file
*/
RetryingTransactionCallback<Void> renameToUsedFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_USED_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(renameToUsedFileCB, false, true);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
// Check trx:enabled has been shuffled.
assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
assertTrue("node doesn't contain property 'TITLE'", props.containsKey(ContentModel.PROP_TITLE));
assertEquals("propety 'TITLE' isn't correct", FILE_ORIGINAL_TITLE, props.get(ContentModel.PROP_TITLE));
assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
return null;
}
};
tran.doInTransaction(validateCB, true, true);
}
use of org.alfresco.jlan.server.filesys.NetworkFile in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMacMountainLionKeynote_MNT_8558.
// testScenarioMacMountainLionPreview_MNT_317
/**
* This test tries to simulate the cifs shuffling that is done
* from Save from Mac Mountain Lion by Keynote when document is saved first time
*
* a) Temp file created in temporary folder (temp\test.key)
* b) Original document renamed to backup copy name (test\test.key -> test\test~.key)
* c) Temp file moved to original name (temp\test.key -> test\test.key)
*/
public void testScenarioMacMountainLionKeynote_MNT_8558() throws Exception {
logger.debug("testScenarioMacMountainLionKeynote_MNT_8558");
final String FILE_NAME = "test.key";
final String BCKP_FILE_NAME = "test~.key";
final String TEMP_FILE_NAME = "test.key";
final String UPDATED_TEXT = "Mac Mountain Lion Keynote Updated Content";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile tempFileHandle;
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionKeynote";
final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionKeynote\\.Temporary Items";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
driver.createDirectory(testSession, testConnection, createTempDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
String testContent = "Mac Mountain Lion Keynote Content";
byte[] testContentBytes = testContent.getBytes();
driver.writeFile(testSession, testConnection, testContext.firstFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
/**
* Create the temp file we are going to use
*/
FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
assertNotNull(testContext.tempFileHandle);
testContent = UPDATED_TEXT;
testContentBytes = testContent.getBytes();
driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
/**
* Also add versionable to target file
*/
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
RetryingTransactionCallback<Void> renameFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + BCKP_FILE_NAME);
return null;
}
};
tran.doInTransaction(renameFileCB, false, true);
RetryingTransactionCallback<Void> moveTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(moveTempFileCB, false, true);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
assertEquals("Unexpected content size", contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT).getSize(), UPDATED_TEXT.length());
return null;
}
};
tran.doInTransaction(validateCB, false, true);
// Make sure that during second rename test.key->test~.key deleted test~.key is not restored and version history doesn't lost.
RetryingTransactionCallback<Void> prepareForSecondRunCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + BCKP_FILE_NAME);
FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
String testContent = UPDATED_TEXT;
byte[] testContentBytes = testContent.getBytes();
driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
return null;
}
};
tran.doInTransaction(prepareForSecondRunCB, false, true);
tran.doInTransaction(renameFileCB, false, true);
tran.doInTransaction(moveTempFileCB, false, true);
tran.doInTransaction(validateCB, false, true);
}
Aggregations