use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testSetFileInfo.
/**
* Test Set Info
*
* Three flags set
* <ol>
* <li>SetDeleteOnClose</li>
* <li>SetCreationDate</li>
* <li>SetModifyDate</li>
* </ol>
*/
public void testSetFileInfo() throws Exception {
logger.debug("testSetFileInfo");
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();
Date now = new Date();
// CREATE 6 hours ago
final Date CREATED = new Date(now.getTime() - 1000 * 60 * 60 * 6);
// Modify one hour ago
final Date MODIFIED = new Date(now.getTime() - 1000 * 60 * 60 * 1);
class TestContext {
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
/**
* Step 1 : Create a new file in read/write mode and add some content.
* Call SetInfo to set the creation date
*/
int openAction = FileAction.CreateNotExist;
final String FILE_NAME = "testSetFileInfo.txt";
final String FILE_PATH = "\\" + FILE_NAME;
// Clean up junk if it exists
try {
driver.deleteFile(testSession, testConnection, FILE_PATH);
} catch (IOException ie) {
// expect to go here
}
final 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();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
driver.closeFile(testSession, testConnection, file);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetModifyDate);
info.setModifyDateTime(MODIFIED.getTime());
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(writeStuffCB);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
testContext.testNodeRef = newNode;
assertNotNull("can't find new node", newNode);
Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
assertNotNull("content is null", content);
Date modified = (Date) nodeService.getProperty(newNode, ContentModel.PROP_MODIFIED);
assertEquals("modified time not set correctly", MODIFIED, modified);
return null;
}
};
tran.doInTransaction(validateCB);
/**
* Step 2: Change the created date
*/
logger.debug("Step 2: Change the created date");
RetryingTransactionCallback<Void> changeCreatedCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetCreationDate);
info.setCreationDateTime(CREATED.getTime());
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(changeCreatedCB);
RetryingTransactionCallback<Void> validateCreatedCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
testContext.testNodeRef = newNode;
assertNotNull("can't find new node", newNode);
Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
assertNotNull("content is null", content);
Date created = (Date) nodeService.getProperty(newNode, ContentModel.PROP_CREATED);
assertEquals("created time not set correctly", CREATED, created);
return null;
}
};
tran.doInTransaction(validateCreatedCB);
/**
* Step 3: Test
*/
logger.debug("Step 3: test deleteOnClose");
RetryingTransactionCallback<Void> deleteOnCloseCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NetworkFile f2 = driver.openFile(testSession, testConnection, params);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
file.setDeleteOnClose(true);
byte[] stuff = "Update".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
driver.closeFile(testSession, testConnection, file);
return null;
}
};
tran.doInTransaction(deleteOnCloseCB);
RetryingTransactionCallback<Void> validateDeleteOnCloseCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
assertNull("can still find new node", newNode);
return null;
}
};
tran.doInTransaction(validateDeleteOnCloseCB);
// clean up so we could run the test again
// driver.deleteFile(testSession, testConnection, FILE_PATH);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testDirListing.
// testScenarioMetadataExtractionForMac
public void testDirListing() throws Exception {
logger.debug("testDirListing");
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();
final String FOLDER_NAME = "parentFolder" + System.currentTimeMillis();
final String HIDDEN_FOLDER_NAME = "hiddenFolder" + System.currentTimeMillis();
RetryingTransactionCallback<NodeRef> createNodesCB = new RetryingTransactionCallback<NodeRef>() {
@Override
public NodeRef execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef parentNode = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, FOLDER_NAME), ContentModel.TYPE_FOLDER).getChildRef();
nodeService.setProperty(parentNode, ContentModel.PROP_NAME, FOLDER_NAME);
NodeRef hiddenNode = nodeService.createNode(parentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, HIDDEN_FOLDER_NAME), ForumModel.TYPE_FORUM).getChildRef();
nodeService.setProperty(hiddenNode, ContentModel.PROP_NAME, HIDDEN_FOLDER_NAME);
return parentNode;
}
};
final NodeRef parentFolder = tran.doInTransaction(createNodesCB);
List<String> excludedTypes = new ArrayList<String>();
excludedTypes.add(ForumModel.TYPE_FORUM.toString());
cifsHelper.setExcludedTypes(excludedTypes);
SearchContext result = driver.startSearch(testSession, testConnection, "\\" + FOLDER_NAME + "\\*", 0);
while (result.hasMoreFiles()) {
if (result.nextFileName().equals(HIDDEN_FOLDER_NAME)) {
fail("Exluded types mustn't be shown in cifs");
}
}
RetryingTransactionCallback<Void> deleteNodeCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
nodeService.deleteNode(parentFolder);
return null;
}
};
tran.doInTransaction(deleteNodeCB, false, true);
}
use of org.alfresco.jlan.server.filesys.DiskSharedDevice 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.filesys.DiskSharedDevice 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.filesys.DiskSharedDevice 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");
}
Aggregations