use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testOpenCloseVersionableFile.
// testOpenCloseFileScenarioTwo
/**
* Unit test of open read/write close versionable file - should not do anything.
* <p>
* This is done with a CIFS shuffle from word. Basically Word holds the file open with a read/write lock while the
* shuffle is going on.
* <p>
* Create a file.
* Apply versionable aspect
* Open the file ReadWrite + OpLocks
* Close the file
* Check Version has not incremented.
*/
public void testOpenCloseVersionableFile() throws Exception {
logger.debug("testOpenCloseVersionableFile");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
final String FILE_PATH1 = TEST_ROOT_DOS_PATH + "\\OpenCloseFile.new";
class TestContext {
}
;
final TestContext testContext = new TestContext();
FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
driver.createDirectory(testSession, testConnection, dirParams);
FileOpenParams params1 = new FileOpenParams(FILE_PATH1, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
driver.closeFile(testSession, testConnection, file1);
/**
* Make Node 1 versionable
*/
RetryingTransactionCallback<Void> makeVersionableCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef file1NodeRef = getNodeForPath(testConnection, FILE_PATH1);
nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
ContentWriter contentWriter2 = contentService.getWriter(file1NodeRef, ContentModel.PROP_CONTENT, true);
contentWriter2.putContent("test open close versionable node");
return null;
}
};
tran.doInTransaction(makeVersionableCB, false, true);
RetryingTransactionCallback<String> readVersionCB = new RetryingTransactionCallback<String>() {
@Override
public String execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, FILE_PATH1);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
assertTrue("versionable aspect not present", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
props.get(ContentModel.PROP_VERSION_LABEL);
return (String) props.get(ContentModel.PROP_VERSION_LABEL);
}
};
String version = tran.doInTransaction(readVersionCB, false, true);
/**
* Step 1: Open The file Read/Write
* TODO Check primary assoc, peer assocs, child assocs, modified date, created date, nodeid, permissions.
*/
NetworkFile file = driver.openFile(testSession, testConnection, params1);
assertNotNull("file is null", file);
/**
* Step 2: Close the file
*/
driver.closeFile(testSession, testConnection, file);
/**
* Validate that there is no version increment.
*/
String version2 = tran.doInTransaction(readVersionCB, false, true);
assertEquals("version has incremented", version, version2);
/**
* Now do an update and check the version increments
*/
file = driver.openFile(testSession, testConnection, params1);
assertNotNull("file is null", file);
byte[] stuff = "Hello World".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
/**
* Step 2: Close the file
*/
driver.closeFile(testSession, testConnection, file);
String version3 = tran.doInTransaction(readVersionCB, false, true);
assertFalse("version not incremented", version.equals(version3));
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSWord20011MacSaveWithBackup.
// testScenarioMSExcel2011MacSaveShuffle
/**
* This test tries to simulate the cifs shuffling that is done to
* support MS Word 2011 on Mac with backup turned on.
*
* a) TEST.DOCX
* b) Create new temp file in temp dir Word Work File D_.tmp
* c) Delete backup file.
* c) Rename TEST.DOCX to Backup of TEST.docx
* d) Move temp file to target dir
* d) Rename Word Work File D_.tmp to TEST.docx
*/
public void testScenarioMSWord20011MacSaveWithBackup() throws Exception {
logger.debug("testScenarioMSWord20011MacSaveWithBackup");
final String FILE_NAME = "TEST.DOCX";
final String FILE_BACKUP = "Backup of TEST.docx";
final String FILE_NEW_TEMP = "Word Work File D_.tmp";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile newFileHandle;
// node ref of test.doc
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord20011MacSaveWithBackup";
final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord20011MacSaveWithBackup\\.Temporary Items";
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();
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 = "MS Word 2011 shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
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");
RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
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);
String testContent = "MS Word 2011 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);
/*
* Step b not used in test case
*/
/**
* c) rename the target file to a backup file
*/
logger.debug("Step c - rename the target file");
RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_BACKUP);
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
/**
* d) Move the new file into target dir
*/
logger.debug("Step d - move new file into target dir");
RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NEW_TEMP);
return null;
}
};
tran.doInTransaction(moveNewFileCB, false, true);
/**
* e) Rename temp file into place.
*/
logger.debug("Step e - rename temp file into place");
RetryingTransactionCallback<Void> renameTempFileCB = 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(renameTempFileCB, false, true);
/**
* 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));
return null;
}
};
tran.doInTransaction(validateCB, false, true);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testDeleteFile.
/**
* Unit test of delete file
*/
public void testDeleteFile() throws Exception {
logger.debug("testDeleteFile");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Step 1 : Create a new file in read/write mode and add some content.
*/
int openAction = FileAction.CreateNotExist;
String FILE_PATH = "\\testDeleteFile.new";
FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
final NetworkFile file = driver.createFile(testSession, testConnection, params);
assertNotNull("file is null", file);
assertFalse("file is read only, should be read-write", file.isReadOnly());
RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
byte[] stuff = "Hello World".getBytes();
file.writeFile(stuff, stuff.length, 0, 0);
// needed to actually flush content to node
file.close();
return null;
}
};
tran.doInTransaction(writeStuffCB);
/**
* Step 1: Delete file by path
*/
driver.deleteFile(testSession, testConnection, FILE_PATH);
/**
* Step 2: Negative test - Delete file again
*/
try {
driver.deleteFile(testSession, testConnection, FILE_PATH);
fail("delete a non existent file");
} catch (IOException fe) {
// expect to go here
}
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSWord2003SaveShuffleWithBackup.
// testScenarioMSWord2003SaveShuffle
/**
* This test tries to simulate the shuffling that is done by MS Word 2003
* with backup enabled upon file save
*
* a) TEST.DOC
* b) Save to ~WRDnnnn.TMP
* c) Delete "Backup of TEST.DOC"
* d) Rename TEST.DOC to "Backup of TEST.DOC"
* e) Delete TEST.DOC
* f) Rename ~WRDnnnn.TMP to TEST.DOC
*
* We need to check that properties, aspects, primary assocs, secondary assocs, peer assocs, node type,
* version history, creation date are maintained.
*/
public void testScenarioMSWord2003SaveShuffleWithBackup() throws Exception {
logger.debug("testScenarioMSWord2003SaveShuffleWithBackup");
final String FILE_NAME = "TEST.DOC";
final String FILE_OLD_TEMP = "Backup of TEST.DOC";
final String FILE_NEW_TEMP = "~WRD0002.TMP";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile newFileHandle;
// node ref of test.doc
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord2003SaveShuffleWithBackup";
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);
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.getProperty(testContext.testNodeRef, ContentModel.PROP_CREATED);
// 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();
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);
/**
* 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);
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));
// assertEquals("noderef changed", testContext.testNodeRef, shuffledNodeRef);
return null;
}
};
tran.doInTransaction(validateCB, false, true);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioFrameMakerShuffle.
// OpenCloseVersionableFile
/**
* Frame maker save
* a) Lock File Created (X.fm.lck)
* b) Create new file (X.fm.C29)
* c) Existing file rename out of the way. (X.backup.fm)
* d) New file rename into place. (X.fm.C29)
* e) Old file deleted (open with delete on close)
* f) Lock file deleted (open with delete on close)
*/
public void testScenarioFrameMakerShuffle() throws Exception {
logger.debug("testScenarioFramemakerShuffle");
final String LOCK_FILE = "X.fm.lck";
final String FILE_NAME = "X.fm";
final String FILE_OLD_TEMP = "X.backup.fm";
final String FILE_NEW_TEMP = "X.fm.C29";
class TestContext {
NetworkFile firstFileHandle;
String mimetype;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioFramemakerShuffle";
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
}
logger.debug("a) create new file");
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 test
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
ClassPathResource fileResource = new ClassPathResource("filesys/X1.fm");
assertNotNull("unable to find test resource filesys/X1.fm", fileResource);
writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* b) Save the new file
* Write X2.fm to the test file,
*/
logger.debug("b) move new file into place");
RetryingTransactionCallback<Void> writeFileCB = 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.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
ClassPathResource fileResource = new ClassPathResource("filesys/X2.fm");
assertNotNull("unable to find test resource filesys/X2.fm", fileResource);
writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
Map<QName, Serializable> props = nodeService.getProperties(file1NodeRef);
ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
assertNotNull("data is null", data);
assertEquals("size is wrong", 166912, data.getSize());
testContext.mimetype = data.getMimetype();
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
/**
* c) rename the old file
*/
logger.debug("c) rename 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);
/**
* d) Move the new file into place, stuff should get shuffled
*/
logger.debug("d) move new file into place");
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);
/**
* d) Delete the old file
*/
logger.debug("d) move new file into place");
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);
logger.debug("e) validate results");
/**
* Now validate everything is correct
*/
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);
ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
assertNotNull("data is null", data);
assertEquals("size is wrong", 123904, data.getSize());
NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
assertTrue("file has lost versionable aspect", nodeService.hasAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("mimeType is wrong", testContext.mimetype, data.getMimetype());
return null;
}
};
tran.doInTransaction(validateCB, true, true);
}
Aggregations