use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testGetFileInformation.
/**
* Test Get File Information
*/
public void testGetFileInformation() throws Exception {
logger.debug("testGetFileInformation");
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();
class TestContext {
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
/**
* Test 1 : Get the root info
*/
FileInfo finfo = driver.getFileInformation(testSession, testConnection, "");
assertNotNull("root info is null", finfo);
assertEquals("root has a unexpected file name", "", finfo.getFileName());
}
use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testSetFileScenario.
// Test Word Save Locked File
/**
* ALF-10686
* This scenario is executed by windows explorer.
*
* A file is created and the file handle kept open.
* stuff is written
* Then the modified date is set
* Then the file is closed.
* @throws Exception
*/
public void testSetFileScenario() 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 = "testSetFileScenario.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);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetModifyDate);
info.setModifyDateTime(MODIFIED.getTime());
info.setNetworkFile(file);
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(writeStuffCB);
RetryingTransactionCallback<Void> closeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// This close is in a different position to the simple setFileInformation scenarios above.
driver.closeFile(testSession, testConnection, file);
return null;
}
};
tran.doInTransaction(closeFileCB);
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);
// clean up so we could run the test again
RetryingTransactionCallback<Void> deleteFile = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, FILE_PATH);
return null;
}
};
tran.doInTransaction(deleteFile, false, true);
}
use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testMacDragAndDrop.
// testScenarioMSMacWord20011SaveWithBackup save
/**
* Simulates a Mac Lion Drag and Drop
* 0. ALF-15158.diff already exists and is versionable
* 1. Delete ALF-15158.diff
* 2. Create new document ALF-15158.diff
*/
public void testMacDragAndDrop() throws Exception {
logger.debug("testMacDragAndDrop()");
final String FILE_NAME = "ALF-15158.diff";
class TestContext {
NetworkFile firstFileHandle;
NodeRef file1NodeRef;
}
;
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\MacDragAndDrop";
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<TestContext> createFileCB = 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 (FileA.pptx)
*/
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);
nodeService.addAspect(ctx.file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return ctx;
}
};
final TestContext testContext = tran.doInTransaction(createFileCB, false, true);
/**
* 1) delete the old file
*/
logger.debug("1) 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);
/**
* 2) CreateNewFile and write some new content
*/
logger.debug("2) write some content");
RetryingTransactionCallback<Void> restoreFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 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(restoreFileCB, 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);
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));
assertEquals("Node ref has changed", shuffledNodeRef, testContext.file1NodeRef);
return null;
}
};
tran.doInTransaction(validateCB, true, true);
logger.debug("end testMacDragAndDrop");
}
use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testOpenCloseVersionableFile.
// testOpenCloseFileScenarioTwo
/**
* Unit test of open read/write close versionable file - should not do anything.
* <p>
* This is done with a CIFS shuffle from word. Basically Word holds the file open with a read/write lock while the
* shuffle is going on.
* <p>
* Create a file.
* Apply versionable aspect
* Open the file ReadWrite + OpLocks
* Close the file
* Check Version has not incremented.
*/
public void testOpenCloseVersionableFile() throws Exception {
logger.debug("testOpenCloseVersionableFile");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
final String FILE_PATH1 = TEST_ROOT_DOS_PATH + "\\OpenCloseFile.new";
class TestContext {
}
;
final TestContext testContext = new TestContext();
FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
driver.createDirectory(testSession, testConnection, dirParams);
FileOpenParams params1 = new FileOpenParams(FILE_PATH1, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
driver.closeFile(testSession, testConnection, file1);
/**
* Make Node 1 versionable
*/
RetryingTransactionCallback<Void> makeVersionableCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef file1NodeRef = getNodeForPath(testConnection, FILE_PATH1);
nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
ContentWriter contentWriter2 = contentService.getWriter(file1NodeRef, ContentModel.PROP_CONTENT, true);
contentWriter2.putContent("test open close versionable node");
return null;
}
};
tran.doInTransaction(makeVersionableCB, false, true);
RetryingTransactionCallback<String> readVersionCB = new RetryingTransactionCallback<String>() {
@Override
public String execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, FILE_PATH1);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
assertTrue("versionable aspect not present", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
props.get(ContentModel.PROP_VERSION_LABEL);
return (String) props.get(ContentModel.PROP_VERSION_LABEL);
}
};
String version = tran.doInTransaction(readVersionCB, false, true);
/**
* Step 1: Open The file Read/Write
* TODO Check primary assoc, peer assocs, child assocs, modified date, created date, nodeid, permissions.
*/
NetworkFile file = driver.openFile(testSession, testConnection, params1);
assertNotNull("file is null", file);
/**
* Step 2: Close the file
*/
driver.closeFile(testSession, testConnection, file);
/**
* Validate that there is no version increment.
*/
String version2 = tran.doInTransaction(readVersionCB, false, true);
assertEquals("version has incremented", version, version2);
/**
* Now do an update and check the version increments
*/
file = driver.openFile(testSession, testConnection, params1);
assertNotNull("file is null", file);
byte[] stuff = "Hello World".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
/**
* Step 2: Close the file
*/
driver.closeFile(testSession, testConnection, file);
String version3 = tran.doInTransaction(readVersionCB, false, true);
assertFalse("version not incremented", version.equals(version3));
}
use of org.alfresco.jlan.server.config.ServerConfiguration in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testScenarioMSWord20011MacSaveWithBackup.
// testScenarioMSExcel2011MacSaveShuffle
/**
* This test tries to simulate the cifs shuffling that is done to
* support MS Word 2011 on Mac with backup turned on.
*
* a) TEST.DOCX
* b) Create new temp file in temp dir Word Work File D_.tmp
* c) Delete backup file.
* c) Rename TEST.DOCX to Backup of TEST.docx
* d) Move temp file to target dir
* d) Rename Word Work File D_.tmp to TEST.docx
*/
public void testScenarioMSWord20011MacSaveWithBackup() throws Exception {
logger.debug("testScenarioMSWord20011MacSaveWithBackup");
final String FILE_NAME = "TEST.DOCX";
final String FILE_BACKUP = "Backup of TEST.docx";
final String FILE_NEW_TEMP = "Word Work File D_.tmp";
class TestContext {
NetworkFile firstFileHandle;
NetworkFile newFileHandle;
// node ref of test.doc
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord20011MacSaveWithBackup";
final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord20011MacSaveWithBackup\\.Temporary Items";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "cifs", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
logger.debug("Step 0 - initialise");
/**
* Create a file in the test directory
*/
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
driver.createDirectory(testSession, testConnection, createTempDirParams);
/**
* Create the file we are going to use
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
// no need to test lots of different properties, that's already been tested above
testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
String testContent = "MS Word 2011 shuffle test";
byte[] testContentBytes = testContent.getBytes();
testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.firstFileHandle.close();
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* a) Save the temp file in the temp dir
*/
logger.debug("Step a - create a temp file in the temp dir");
RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams createFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.newFileHandle);
String testContent = "MS Word 2011 shuffle test This is new content";
byte[] testContentBytes = testContent.getBytes();
testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
testContext.newFileHandle.close();
return null;
}
};
tran.doInTransaction(saveNewFileCB, false, true);
/*
* Step b not used in test case
*/
/**
* c) rename the target file to a backup file
*/
logger.debug("Step c - rename the target file");
RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_BACKUP);
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
/**
* d) Move the new file into target dir
*/
logger.debug("Step d - move new file into target dir");
RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NEW_TEMP);
return null;
}
};
tran.doInTransaction(moveNewFileCB, false, true);
/**
* e) Rename temp file into place.
*/
logger.debug("Step e - rename temp file into place");
RetryingTransactionCallback<Void> renameTempFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(renameTempFileCB, false, true);
/**
* Validate
*/
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
return null;
}
};
tran.doInTransaction(validateCB, false, true);
}
Aggregations