use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method DISABLED_testScenarioEmacsSave.
// testScenarioWord2007 save
/**
* This test tries to simulate the cifs shuffling that is done to
* support EMACS
*
* a) emacsTest.txt
* b) Rename original file to emacsTest.txt~
* c) Create emacsTest.txt
*/
public void DISABLED_testScenarioEmacsSave() throws Exception {
logger.debug("testScenarioEmacsSave");
final String FILE_NAME = "emacsTest.txt";
final String FILE_OLD_TEMP = "emacsTest.txt~";
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\\testScenarioEmacsSave";
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 = "Emacs shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
return null;
}
};
tran.doInTransaction(writeFileCB);
/**
* b) rename the old file out of the way
*/
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);
/**
* c) Save the new file
*/
RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.newFileHandle);
String testContent = "EMACS 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);
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));
return null;
}
};
tran.doInTransaction(validateCB);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testZeroByteRules.
// Scenario frame maker save
/**
* Test that rules fire on zero byte long files.
* In this case check that a new file gets the versionable
* aspect added.
*/
public void testZeroByteRules() throws Exception {
logger.debug("testZeroByteRules");
final String FILE_NAME_ZERO = "Zero.docx";
final String FILE_NAME_NON_ZERO = "NonZero.docx";
class TestContext {
NodeRef testDirNodeRef;
NodeRef testZeroNodeRef;
NodeRef testNonZeroNodeRef;
NetworkFile firstFileHandle;
NetworkFile secondFileHandle;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testZeroByteRules";
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> deleteGarbageDirCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteDirectory(testSession, testConnection, TEST_DIR);
return null;
}
};
try {
tran.doInTransaction(deleteGarbageDirCB);
} catch (Exception e) {
// expect to go here
}
logger.debug("create Test directory" + TEST_DIR);
RetryingTransactionCallback<Void> createTestDirCB = 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);
testContext.testDirNodeRef = getNodeForPath(testConnection, TEST_DIR);
assertNotNull("testDirNodeRef is null", testContext.testDirNodeRef);
return null;
}
};
tran.doInTransaction(createTestDirCB);
logger.debug("Create rule on test dir");
RetryingTransactionCallback<Void> createRuleCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
rule.applyToChildren(true);
rule.setRuleDisabled(false);
rule.setTitle("Make Versionable");
rule.setDescription("ContentDiskDriverTest Test Zero Byte files");
Map<String, Serializable> props = new HashMap<String, Serializable>(1);
props.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
Action addVersionable = actionService.createAction("add-features", props);
ActionCondition noCondition1 = actionService.createActionCondition(NoConditionEvaluator.NAME);
addVersionable.addActionCondition(noCondition1);
ActionCondition noCondition2 = actionService.createActionCondition(NoConditionEvaluator.NAME);
CompositeAction compAction = actionService.createCompositeAction();
compAction.setTitle("Make Versionablea");
compAction.setDescription("Add Aspect - Versionable");
compAction.addAction(addVersionable);
compAction.addActionCondition(noCondition2);
rule.setAction(compAction);
ruleService.saveRule(testContext.testDirNodeRef, rule);
logger.debug("add aspect versionable rule created");
return null;
}
};
tran.doInTransaction(createRuleCB, false, true);
/**
* Create a file in the test directory
*/
logger.debug("create test file in test directory");
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the zero byte file we are going to use to test
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
testContext.testZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_ZERO);
assertNotNull("testContext.testNodeRef is null", testContext.testZeroNodeRef);
/**
* Create the non zero byte file we are going to use to test
*/
FileOpenParams createFileParams2 = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_NON_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams2);
assertNotNull(testContext.secondFileHandle);
testContext.testNonZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_NON_ZERO);
assertNotNull("testContext.testNodeRef is null", testContext.testNonZeroNodeRef);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
logger.debug("step b: close the file with zero byte content");
/**
* Write ContentDiskDriverTest1.docx to the test file,
*/
RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
logger.debug("close the file, firstFileHandle");
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
// Write hello world into the second file
byte[] stuff = "Hello World".getBytes();
driver.writeFile(testSession, testConnection, testContext.secondFileHandle, stuff, 0, stuff.length, 0);
logger.debug("close the second non zero file, secondFileHandle");
driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
logger.debug("Step c: validate versioble aspect has been applied.");
/**
* c: check zero byte file has the versionable aspect.
*/
RetryingTransactionCallback<Void> validateFirstExtractionCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
assertTrue("versionable aspect not applied to non zero file.", nodeService.hasAspect(testContext.testNonZeroNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertTrue("versionable aspect not applied to zero byte file.", nodeService.hasAspect(testContext.testZeroNodeRef, ContentModel.ASPECT_VERSIONABLE));
return null;
}
};
tran.doInTransaction(validateFirstExtractionCB, false, true);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMountainLionWord2011.
// testMacDragAndDrop
/**
* Mountain Lion 2011 Word
* a) Create new file (Word Work File D2.tmp)
* (Actually in real life its renamed from a temp directory.
* c) Existing file rename out of the way. (Word Work File L_5.tmp)
* d) New file rename into place. (MacWord1.docx)
* e) Old file deleted
*/
public void testScenarioMountainLionWord2011() throws Exception {
logger.debug("testScenarioMountainLionWord2011");
final String FILE_NAME = "MacWord1.docx";
final String FILE_OLD_TEMP = "Word Work File L_5.tmp";
final String FILE_NEW_TEMP = "Word Work File D_2.tmp";
class TestContext {
NetworkFile firstFileHandle;
String mimetype;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMountainLionWord2011";
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/ContentDiskDriverTest3.doc");
assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", 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 ContentDiskDriverTest3.doc,
*/
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/ContentDiskDriverTest3.doc");
assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", 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) delete the old file");
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);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSPowerpoint2011MacSaveShuffle.
// testScenarioLionTextEdit
/**
* Simulates a Save from Powerpoint 2011 Mac
* 0. FileA.pptx already exists.
* 1. Create new document FileA1.pptx
* 2. Delete FileA.pptx
* 3. Rename FileA1.pptx to FileA.pptx
*/
public void testScenarioMSPowerpoint2011MacSaveShuffle() throws Exception {
logger.debug("testScenarioMSPowerpoint2011MacSaveShuffle(");
final String FILE_NAME = "FileA.pptx";
final String FILE_NEW_TEMP = "FileA1.pptx";
class TestContext {
NetworkFile firstFileHandle;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSPowerpoint2011MacSaveShuffle";
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.pptx)
*/
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.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioRenameVersionableFile.
// testRenameFile
/**
* Unit test of rename versionable file
*/
public void testScenarioRenameVersionableFile() throws Exception {
logger.debug("testScenarioRenameVersionableFile");
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_PATH2 = TEST_ROOT_DOS_PATH + "\\SourceFile2.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);
/**
* Make Node 1 versionable
*/
final String LAST_NAME = "Bloggs";
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 rename versionable");
nodeService.setProperty(file1NodeRef, ContentModel.PROP_LASTNAME, LAST_NAME);
nodeService.setProperty(file1NodeRef, TransferModel.PROP_ENDPOINT_PROTOCOL, "http");
return null;
}
};
tran.doInTransaction(makeVersionableCB, false, true);
/**
* Step 1: Successfully rename a versionable file - check the name, props and content.
* TODO Check primary assoc, peer assocs, child assocs, modified date, created date, nodeid, permissions.
*/
driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH2);
RetryingTransactionCallback<Void> validateVersionableCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef file2NodeRef = getNodeForPath(testConnection, FILE_PATH2);
assertNotNull("file2 node ref is null", file2NodeRef);
// assertEquals(nodeService.getProperty(file2NodeRef, ContentModel.PROP_LASTNAME), LAST_NAME);
assertTrue("does not have versionable aspect", nodeService.hasAspect(file2NodeRef, ContentModel.ASPECT_VERSIONABLE));
assertTrue("sample property is null", nodeService.getProperty(file2NodeRef, TransferModel.PROP_ENDPOINT_PROTOCOL) != null);
return null;
}
};
tran.doInTransaction(validateVersionableCB, false, true);
}
Aggregations