use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioSmultronSave.
// testScenarioViSave
/**
* This test tries to simulate the cifs shuffling that is done to
* support smultron
*
* a) smultronTest.txt
* b) Save new file to .dat04cd.004
* c) Delete smultronTest.txt
* c) Rename .dat04cd.004 to smultronTest.txt
*/
public void testScenarioSmultronSave() throws Exception {
logger.debug("testScenarioSmultronSave");
final String FILE_NAME = "smultronTest.txt";
final String FILE_NEW_TEMP = ".dat04cd.004";
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\\testScenarioSmultronSave";
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);
// 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);
return null;
}
};
tran.doInTransaction(createFileCB);
/**
* a) Write some content to the test file
*/
RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
String testContent = "Smultron shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
return null;
}
};
tran.doInTransaction(writeFileCB);
/**
* 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 = "Smultron shuffle test This is new content";
byte[] testContentBytes = testContent.getBytes();
testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
driver.closeFile(testSession, testConnection, testContext.newFileHandle);
return null;
}
};
tran.doInTransaction(saveNewFileCB);
/**
* c) Delete the old file
*/
RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(deleteOldFileCB);
/**
* d) 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);
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);
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSExcel2011MacSaveShuffle.
// testScenarioMSPowerpoint2011MacSaveShuffle
/**
* Simulates a Save from Excel 2011 Mac
* 0. FileA.xlsx already exists.
* 1. Create new document ._A8A09200
* 2. Delete FileA.xlsx
* 3. Rename ._A8A09200 to FileA.xlsx
*/
public void testScenarioMSExcel2011MacSaveShuffle() throws Exception {
logger.debug("testScenarioMSExcel2011MacSaveShuffle(");
final String FILE_NAME = "FileA.xlsx";
final String FILE_NEW_TEMP = "._A8A09200";
class TestContext {
NetworkFile firstFileHandle;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSExcel2011MacSaveShuffle";
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 {
logger.debug("expect to get exception - cleaning garbage");
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
logger.debug("0) 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 use (FileA.xlsx)
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(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 ContentDiskDriverTest3.doc to the test file,
*/
logger.debug("b) write some content");
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/ContentDiskDriverTest3.doc");
assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
byte[] buffer = new byte[1000];
InputStream is = fileResource.getInputStream();
try {
long offset = 0;
int i = is.read(buffer, 0, buffer.length);
while (i > 0) {
testContext.firstFileHandle.writeFile(buffer, i, 0, offset);
offset += i;
i = is.read(buffer, 0, buffer.length);
}
} finally {
is.close();
}
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
/**
* c) delete the old file
*/
logger.debug("c) delete old file");
RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
/**
* d) Move the new file into place, stuff should get shuffled
*/
logger.debug("d) rename 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);
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", 26112, data.getSize());
assertEquals("mimeType is wrong", "application/msword", data.getMimetype());
assertTrue("versionable aspect missing", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertTrue("hidden aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_HIDDEN));
assertTrue("temporary aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_TEMPORARY));
return null;
}
};
tran.doInTransaction(validateCB, true, true);
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testMimetypeWithSufficientData.
// testScenarioMountainLionWord2011EditByEditor_ALF_16257
/**
* Guess mimetype with sufficient data - originally related to ACE-4523
* Simulate creating a plain text document via Alfresco Share
* then updating it via CIFS/FTP
*
* 1. create a document called "foo" with just a little data with an explicit (incorrect) mimetype set.
* 2. update the document with different text
* 3. check the mimetype of the test doc has changed (since it can be guessed)
*/
public void testMimetypeWithSufficientData() throws Exception {
logger.debug("testMimetypeWithInsufficiantData");
// a file without a clue about mimetype
final String FILE_NAME = "foo";
class TestContext {
NetworkFile firstFileHandle;
String mimetype;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testMimetypeWithSufficientData";
// this is a made up mimetype - so there is no way that it could be guessed.
final String TEST_MIMETYPE = "text\bar";
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);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestTxt1.txt");
// Add the test content via the content writer to simulate being created via Share.
NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
ContentWriter contentWriter2 = contentService.getWriter(file1NodeRef, ContentModel.PROP_CONTENT, true);
// this is a made up mimetype - so there is no way that it could be guessed.
contentWriter2.setMimetype(TEST_MIMETYPE);
contentWriter2.putContent(fileResource.getFile());
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* b) Update the file via CIFS
*/
logger.debug("b) update file via CIFS");
RetryingTransactionCallback<Void> updateFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Exception {
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile file = driver.openFile(testSession, testConnection, createFileParams);
assertNotNull(file);
String testContent = "Bar";
byte[] testContentBytes = testContent.getBytes();
file.writeFile(testContentBytes, testContentBytes.length, 0, 0);
driver.closeFile(testSession, testConnection, file);
return null;
}
};
tran.doInTransaction(updateFileCB, false, true);
logger.debug("c) 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);
/**
* Validate mimetype has changed - we can guess that it is text !
*/
assertEquals("mimeType is wrong", MimetypeMap.MIMETYPE_TEXT_PLAIN, data.getMimetype());
return null;
}
};
tran.doInTransaction(validateCB, true, true);
logger.debug("end testMimetypeWithSufficientData");
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testFileInformationUpdatingByEditorUserForAlf8808.
// testDirListing
public void testFileInformationUpdatingByEditorUserForAlf8808() throws Exception {
final Holder<org.alfresco.service.cmr.model.FileInfo> editorFolder = new Holder<org.alfresco.service.cmr.model.FileInfo>();
final Holder<org.alfresco.service.cmr.model.FileInfo> testFile = new Holder<org.alfresco.service.cmr.model.FileInfo>();
// Configuring test server with test server configuration and getting test tree connection for test shared device
ServerConfiguration config = new ServerConfiguration(ContentDiskDriverTest.TEST_SERVER_NAME);
TestServer server = new TestServer(ContentDiskDriverTest.TEST_SERVER_NAME, config);
DiskSharedDevice device = getDiskSharedDevice();
final TreeConnection treeConnection = server.getTreeConnection(device);
// Getting target entity for testing - ContentDiskDriver
final ExtendedDiskInterface deviceInterface = (ExtendedDiskInterface) treeConnection.getInterface();
// Creating mock-session
final SrvSession session = new TestSrvSession(13, server, ContentDiskDriverTest.TEST_PROTOTYPE_NAME, ContentDiskDriverTest.TEST_REMOTE_NAME);
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
NodeRef rootNode = repositoryHelper.getCompanyHome();
// Creating test user to invite him as Editor for test content. This user will be created correctly (with person and authentication options)
createUser(ContentDiskDriverTest.TEST_USER_AUTHORITY, ContentDiskDriverTest.TEST_USER_AUTHORITY, rootNode);
// Safely creating folder for test content
editorFolder.value = getOrCreateNode(rootNode, PermissionService.EDITOR, ContentModel.TYPE_FOLDER).getFirst();
// Creating test content which will be editable by user created above
testFile.value = getOrCreateNode(rootNode, "Test.txt", ContentModel.TYPE_CONTENT).getFirst();
// Applying 'Editor' role for test user to test file
permissionService.setPermission(testFile.value.getNodeRef(), ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);
try {
// Creating data for target method invocation
final FileInfo updatedInfo = new FileInfo();
updatedInfo.setFileName(testFile.value.getName());
updatedInfo.setFileId(DefaultTypeConverter.INSTANCE.intValue(testFile.value.getProperties().get(ContentModel.PROP_NODE_DBID)));
// Testing ContentDiskDriver.setFileInformation() with test user authenticated who has 'Editor' role for test content.
// This method should fail if check on 'DELETE' permission was not moved to 'DeleteOnClose' context
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
deviceInterface.setFileInformation(session, treeConnection, testFile.value.getName(), updatedInfo);
return null;
}
}, ContentDiskDriverTest.TEST_USER_AUTHORITY);
} catch (Exception e) {
// Informing about test failure. Expected exception is 'org.alfresco.jlan.server.filesys.AccessDeniedException'
if (e.getCause() instanceof AccessDeniedException) {
fail("For user='" + TEST_USER_AUTHORITY + "' " + e.getCause().toString());
} else {
fail("Unexpected exception was caught: " + e.toString());
}
}
} finally {
if (authenticationService.authenticationExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
authenticationService.deleteAuthentication(ContentDiskDriverTest.TEST_USER_AUTHORITY);
}
if (personService.personExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
personService.deletePerson(ContentDiskDriverTest.TEST_USER_AUTHORITY);
}
try {
if (null != testFile.value) {
nodeService.deleteNode(testFile.value.getNodeRef());
}
} catch (Exception e) {
// Doing nothing
}
try {
if (null != editorFolder.value) {
nodeService.deleteNode(editorFolder.value.getNodeRef());
}
} catch (Exception e) {
// Doing nothing
}
}
return null;
}
}, false, true);
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSWord2007Save.
// testScenarioMSWord2003SaveShuffleWithBackup
/**
* This test tries to simulate the cifs shuffling that is done to
* support MS Word 2007
*
* a) TEST.DOCX
* b) Save new to 00000001.TMP
* c) Rename TEST.DOCX to 00000002.TMP
* d) Rename 000000001.TMP to TEST.DOCX
* e) Delete 000000002.TMP
*/
public void testScenarioMSWord2007Save() throws Exception {
logger.debug("testScenarioMSWord2007SaveShuffle");
final String FILE_NAME = "TEST.DOCX";
final String FILE_OLD_TEMP = "788A1D3D.tmp";
final String FILE_NEW_TEMP = "19ECA1A.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\\testScenarioMSWord2007Save";
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);
// 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);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* a) Write some content to the test file
*/
RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
String testContent = "MS Word 2007 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 2007 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);
/**
* c) 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);
/**
* d) 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> 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);
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);
}
Aggregations