use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testGedit.
// testScenarioMacMountainLionKeynote_MNT_8558
/**
* Gedit has the nasty behaviour of renaming an open file.
* 1) create file (gedit12345678.txt)
* 2) create temp file (.goutputStream-IRYDPW) write and flush
* 3) rename (fails name collision)
* 4) delete target
* 5) rename this one succeeds
* 6) close temp file
*/
public void testGedit() throws Exception {
logger.debug("testGEdit");
final String FILE_NAME = "gedit12345678.txt";
final String FILE_TITLE = "Gedit";
final String FILE_DESCRIPTION = "This is a test document to test CIFS shuffle";
final String TEMP_FILE_NAME = ".goutputStream-IRYDPW";
final String UPDATE_TEXT = "Shuffle an open file";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile tempFileHandle;
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testGEdit";
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 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> createTestFileFirstTime = 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);
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_TITLE, FILE_TITLE);
nodeService.setProperty(testContext.testNodeRef, ContentModel.PROP_DESCRIPTION, FILE_DESCRIPTION);
String testContent = "Gedit shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
tran.doInTransaction(createTestFileFirstTime, false, true);
/**
* Create the temp file
* add content
* leave open
*/
RetryingTransactionCallback<Void> createTempFile = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams params = new FileOpenParams(TEST_DIR + "\\" + TEMP_FILE_NAME, FileAction.TruncateExisting, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile file = driver.createFile(testSession, testConnection, params);
testContext.tempFileHandle = file;
String testContent = UPDATE_TEXT;
byte[] testContentBytes = testContent.getBytes();
testContext.tempFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
return null;
}
};
tran.doInTransaction(createTempFile, false, true);
/**
* rename the test file to the temp
*/
RetryingTransactionCallback<Void> renameTestFileToTemp = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + TEMP_FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
// expect this one to fail
try {
tran.doInTransaction(renameTestFileToTemp, false, true);
fail("should have failed");
} catch (Exception e) {
// expect to go here
}
/**
* delete the target file
*/
RetryingTransactionCallback<Void> deleteTargetFile = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(deleteTargetFile, false, true);
// This one should succeed
tran.doInTransaction(renameTestFileToTemp, false, true);
RetryingTransactionCallback<Void> closeTempFile = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
return null;
}
};
tran.doInTransaction(closeTempFile, false, true);
// Now validate
RetryingTransactionCallback<Void> validate = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
ContentReader reader = contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT);
String s = reader.getContentString();
assertEquals("content not written", UPDATE_TEXT, s);
assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
return null;
}
};
tran.doInTransaction(validate, false, true);
logger.debug("end testGedit");
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testRenameFile.
// testFileExists
/**
* Unit test of rename file
*/
public void testRenameFile() throws Exception {
logger.debug("testRenameFile");
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 + "\\SourceFile1.new";
final String FILE_NAME2 = "SourceFile2.new";
final String FILE_PATH2 = TEST_ROOT_DOS_PATH + "\\" + FILE_NAME2;
final String FILE_PATH3 = TEST_ROOT_DOS_PATH + "\\SourceFile3.new";
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);
final NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
FileOpenParams params3 = new FileOpenParams(FILE_PATH3, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
final NetworkFile file3 = driver.createFile(testSession, testConnection, params3);
/**
* Step 1 : Negative test, Call Rename for a file which does not exist
*/
try {
driver.renameFile(testSession, testConnection, "\\Wibble\\wobble", FILE_PATH1);
fail("rename did not detect missing file");
} catch (IOException e) {
// expect to go here
}
/**
* Step 2: Negative test, Call Rename for a destination that does not exist.
*/
try {
driver.renameFile(testSession, testConnection, FILE_PATH1, "\\wibble\\wobble");
fail("rename did not detect missing file");
} catch (IOException e) {
// expect to go here
}
/**
* Step 3: Rename a file to a destination that is a file rather than a directory
*/
try {
driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH3);
fail("rename did not detect missing file");
} catch (IOException e) {
// expect to go here
}
/**
* Step 4: Successfully rename a file - check the name, props and content.
*/
final String LAST_NAME = "Bloggs";
RetryingTransactionCallback<Void> setPropertiesCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
final NodeRef file1NodeRef = getNodeForPath(testConnection, FILE_PATH1);
assertNotNull("node ref not found", file1NodeRef);
nodeService.setProperty(file1NodeRef, ContentModel.PROP_LASTNAME, LAST_NAME);
return null;
}
};
tran.doInTransaction(setPropertiesCB, false, true);
driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH2);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef file2NodeRef = getNodeForPath(testConnection, FILE_PATH2);
// assertEquals("node ref has changed on a rename", file1NodeRef, file2NodeRef);
assertEquals(nodeService.getProperty(file2NodeRef, ContentModel.PROP_LASTNAME), LAST_NAME);
ChildAssociationRef parentRef = nodeService.getPrimaryParent(file2NodeRef);
assertTrue("file has wrong assoc local name", parentRef.getQName().getLocalName().equals(FILE_NAME2));
assertTrue("not primary assoc", parentRef.isPrimary());
return null;
}
};
tran.doInTransaction(validateCB, false, true);
/**
* Step 5: Rename to another directory
*/
String DIR_NEW_PATH = TEST_ROOT_DOS_PATH + "\\NewDir";
final String NEW_PATH = DIR_NEW_PATH + "\\File2";
FileOpenParams params5 = new FileOpenParams(DIR_NEW_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, params5);
final NodeRef newDirNodeRef = getNodeForPath(testConnection, DIR_NEW_PATH);
driver.renameFile(testSession, testConnection, FILE_PATH2, NEW_PATH);
RetryingTransactionCallback<Void> validateStep5CB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef file5NodeRef = getNodeForPath(testConnection, NEW_PATH);
ChildAssociationRef parentRef5 = nodeService.getPrimaryParent(file5NodeRef);
assertTrue(parentRef5.getParentRef().equals(newDirNodeRef));
return null;
}
};
tran.doInTransaction(validateStep5CB, false, true);
// /**
// * Step 5: rename to self - check no damage.
// */
// try
// {
// driver.renameFile(testSession, testConnection, FILE_PATH2, FILE_PATH2);
// fail("rename did not detect rename to self");
// }
// catch (IOException e)
// {
// expect to go here
// }
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testExcel2003SaveShuffle.
/**
* Excel 2003 With Versionable file
*
* CreateFile 5EE27100
* RenameFile oldPath:\Espaces Utilisateurs\System\Cherries.xls,
* newPath:\Espaces Utilisateurs\System\Cherries.xls~RF172f241.TMP
* RenameFile oldName=\Espaces Utilisateurs\System\5EE27100,
* newName=\Espaces Utilisateurs\System\Cherries.xls, session:WNB0
*
* Set Delete On Close for Cherries.xls~RF172f241.TMP
*/
public void testExcel2003SaveShuffle() throws Exception {
// fail("not yet implemented");
logger.debug("testScenarioExcel2003SaveShuffle");
final String FILE_NAME = "Cherries.xls";
final String FILE_TITLE = "Cherries";
final String FILE_DESCRIPTION = "This is a test document to test CIFS shuffle";
final String FILE_OLD_TEMP = "Cherries.xls~RF172f241.TMP";
final String FILE_NEW_TEMP = "5EE27100";
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 + "\\testScenarioMSExcel2003SaveShuffle";
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);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
// 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 Excel 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);
/**
* 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);
// 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));
// 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.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testNFS.
// Test Word 7 Explorer Update
/**
* 0. test.txt and ~test.txt exist.
* 1. Delete test.txt
* 2. Rename test.txt~ to test.txt
*/
public void testNFS() throws Exception {
logger.debug("testNFS()");
final String FILE_NAME = "test.txt";
final String FILE_NAME_TEMP = "test.txt~";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile tempFileHandle;
NodeRef file1NodeRef;
}
;
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testNFS";
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;
}
};
RetryingTransactionCallback<Void> deleteGarbageFileCB2 = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME_TEMP);
return null;
}
};
try {
logger.debug("expect to get exception - cleaning garbage");
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
try {
logger.debug("expect to get exception - cleaning garbage");
tran.doInTransaction(deleteGarbageFileCB2);
} catch (Exception e) {
// expect to go here
}
logger.debug("0) create new file");
RetryingTransactionCallback<TestContext> setupCB = new RetryingTransactionCallback<TestContext>() {
@Override
public TestContext execute() throws Throwable {
TestContext ctx = new TestContext();
/**
* 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);
ctx.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(ctx.firstFileHandle);
driver.closeFile(testSession, testConnection, ctx.firstFileHandle);
ctx.file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
}
{
FileOpenParams createTempFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
ctx.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
assertNotNull(ctx.tempFileHandle);
driver.closeFile(testSession, testConnection, ctx.tempFileHandle);
}
return ctx;
}
};
final TestContext testContext = tran.doInTransaction(setupCB, false, true);
/**
* 1) delete the old file
*/
logger.debug("1) delete 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, false, true);
logger.debug("2) remame temp file");
RetryingTransactionCallback<Void> renameTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(renameTempFileCB, false, true);
logger.debug("3) 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);
// assertTrue("versionable aspect missing", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("Node ref has changed", shuffledNodeRef, testContext.file1NodeRef);
return null;
}
};
tran.doInTransaction(validateCB, true, true);
logger.debug("end testNFS");
}
use of org.alfresco.jlan.server.SrvSession in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMacMountainLionPreview_MNT_263.
// testScenarioMountainLionPreview
/**
* This test tries to simulate the cifs shuffling that is done
* from Save from Mac Mountain Lion by Preview when document is saved first time
*
* a) Temp file created in temporary folder (temp\image.jpg.sb-1e5e1543-ajn3cR)
* b) Temp file renamed to original name (temp\image.jpg.sb-1e5e1543-ajn3cR -> temp\image.jpg)
* c) Original document renamed to backup copy name (test\image.jpg -> test\image.jpg.sb-1e5e1543-ajn3cR)
* d) Renamed temp file moved to original (temp\image.jpg -> test\image.jpg)
*/
public void testScenarioMacMountainLionPreview_MNT_263() throws Exception {
logger.debug("testScenarioMacMountainLionPreview_MNT_263");
final String FILE_NAME = "image.jpg";
final String TEMP_FILE_NAME = "image.jpg.sb-1e5e1543-ajn3cR";
final String UPDATED_TEXT = "Mac Lion Preview Updated Content";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile tempFileHandle;
// node ref image.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 Lion Preview 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> renameTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + TEMP_FILE_NAME, TEST_TEMP_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(renameTempFileCB, false, true);
RetryingTransactionCallback<Void> renameFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + TEMP_FILE_NAME);
return null;
}
};
tran.doInTransaction(renameFileCB, false, true);
RetryingTransactionCallback<Void> moveRenamedTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(moveRenamedTempFileCB, 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);
}
Aggregations