public void LocalFileCreationWithOnlyWatcher(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare remote folder. ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath); // Month-long sync interval, meaning that in fact only the watcher can trigger syncs. sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId, CmisSyncProcess.MONTH_LONG_SYNC_INTERVAL); // Wait a few seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); ////////////////////////////////////////////// Local file creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb); // Check that file is present server-side. Thread.Sleep(20 * 1000); IDocument doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; }
public void Real(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Clear the remote folder. ClearRemoteCMISFolder(url, user, password, repositoryId, remoteFolderPath); // Create temporary folder for configuration and data files. string tempFolder = Path.Combine(Path.GetTempPath(), "CmisSync_test_" + Path.GetRandomFileName()); Console.Write("Test folder: " + tempFolder); string configurationFolder = Path.Combine(tempFolder, "configuration"); string localDataFolder = Path.Combine(tempFolder, "data"); Directory.CreateDirectory(tempFolder); Directory.CreateDirectory(configurationFolder); Directory.CreateDirectory(localDataFolder); // Create XML config file. string customConfigPath = Path.Combine(configurationFolder, "config.xml"); string logPath = Path.Combine(configurationFolder, "debug_log.txt"); string customConfig = File.ReadAllText(@"../../config.xml"); // Replace variables in template customConfig = customConfig.Replace("{LOG}", logPath); customConfig = customConfig.Replace("{LOCAL_FOLDER}", localDataFolder); customConfig = customConfig.Replace("{REMOTE_FOLDER}", remoteFolderPath); customConfig = customConfig.Replace("{URL}", url); customConfig = customConfig.Replace("{USER}", user); customConfig = customConfig.Replace("{PASSWORD}", password); customConfig = customConfig.Replace("{REPOSITORY}", repositoryId); // Write config file. File.WriteAllText(customConfigPath, customConfig); // Start CmiSync. string arguments = "-p -c " + customConfigPath; Console.Write("Executing: " + CONSOLE_EXE + " " + arguments); Process process = Process.Start(CONSOLE_EXE, arguments); if (null == process) { Assert.Fail("Could not start process, maybe an existing process has been reused?"); } process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data); process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data); ////////////////////////////////////////////// File creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(localDataFolder, filename), sizeKb); // Wait a few seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); // Check that file is present server-side. IDocument doc = null; try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; ////////////////////////////////////////////// File append // Append to file string dataToAppend = "let's add a bit more data to that file"; byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend); using (var fileStream = new FileStream(Path.Combine(localDataFolder, filename), FileMode.Append, FileAccess.Write, FileShare.None)) using (var bw = new BinaryWriter(fileStream)) { bw.Write(bytes); } // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(1024 * sizeKb + dataToAppend.Length, doc.ContentStreamLength); ////////////////////////////////////////////// Folder creation // Create local folder. string foldername = "folder 1"; Directory.CreateDirectory(Path.Combine(localDataFolder, foldername)); // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); IFolder folder = null; try { folder = (IFolder)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + foldername, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Folder failed to get synced to the server.", e); } ////////////////////////////////////////////// File rename // Rename the document string newFilename = "moved_" + filename; File.Move(Path.Combine(localDataFolder, filename), Path.Combine(localDataFolder, newFilename)); filename = newFilename; // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); // Check that the remote document has been renamed, and still has the same object id. doc = null; try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); string newDocId = doc.Id; //FIXME Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was renamed: " + docId + " -> " + newDocId); ////////////////////////////////////////////// File delete // Delete the file. File.Delete(Path.Combine(localDataFolder, filename)); // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); // Check that file is not present server-side. doc = null; try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); // Should have failed. Assert.Fail("Deleted document still exists on server: " + doc); } catch (CmisObjectNotFoundException e) { // That's the correct outcome } // Exit the process to avoid any possible interference with subsequent tests. process.Kill(); // TODO does not always get killed. }
public void LocalFileAppend(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare remote folder and CmisSync process. ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath); sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId); // Local file creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb); // Check that file is present server-side. Thread.Sleep(20 * 1000); IDocument doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; // Local file append // Append to file string dataToAppend = "let's add a bit more data to that file"; byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend); using (var fileStream = new FileStream(Path.Combine(sync.Folder(), filename), FileMode.Append, FileAccess.Write, FileShare.None)) using (var bw = new BinaryWriter(fileStream)) { bw.Write(bytes); } // Check on server Thread.Sleep(10 * 1000); try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.True(1 - (1024 * sizeKb + dataToAppend.Length) / doc.ContentStreamLength < 0.1); // Text file size can vary a bit }
public void _CurrentlyFailing_LocalFileMove(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare remote folder and CmisSync process. ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath); sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId); ////////////////////////////////////////////// Local file creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb); // Wait a few seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); // Check that file is present server-side. IDocument doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; ////////////////////////////////////////////// Local folder creation // Create local folder. string foldername = "folder 1"; Directory.CreateDirectory(Path.Combine(sync.Folder(), foldername)); // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); IFolder folder = null; try { folder = (IFolder)session.GetObjectByPath(remoteFolderPath + "/" + foldername, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Folder failed to get synced to the server.", e); } // Move local file to other folder string destinationFilename = foldername + Path.DirectorySeparatorChar + filename; File.Move(Path.Combine(sync.Folder(), filename), Path.Combine(sync.Folder(), destinationFilename)); // Check that the remote document has been renamed, and still has the same object id. Thread.Sleep(20 * 1000); doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + foldername + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get moved on server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); string newDocId = doc.Id; // Current status: Fails. Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was moved: " + docId + " -> " + newDocId); }
public void LocalFileRename(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare remote folder and CmisSync process. ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath); sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId); ////////////////////////////////////////////// Local file creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb); // Wait a few seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); // Check that file is present server-side. IDocument doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; ////////////////////////////////////////////// Local file rename // Rename the document string newFilename = "moved_" + filename; File.Move(Path.Combine(sync.Folder(), filename), Path.Combine(sync.Folder(), newFilename)); filename = newFilename; // Check that the remote document has been renamed, and still has the same object id. Thread.Sleep(10 * 1000); doc = null; try { doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); string newDocId = doc.Id; // Current status: The following line sometimes fails, sometimes succeeds. Probably a race condition. Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was renamed: " + docId + " -> " + newDocId); }
public void LongScenario(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath, string url, string user, string password, string repositoryId) { // Prepare remote folder and CmisSync process. ClearRemoteCMISFolder(url, user, password, repositoryId, remoteFolderPath); sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId); ////////////////////////////////////////////// Local file creation // Create random small file. int sizeKb = 3; string filename = "file.doc"; LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb); // Wait a few seconds so that sync gets a chance to sync things. Thread.Sleep(20 * 1000); // Check that file is present server-side. IDocument doc = null; try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength); Assert.AreEqual("application/msword", doc.ContentStreamMimeType); // TODO compare date Assert.AreEqual(, doc.); string docId = doc.Id; ////////////////////////////////////////////// Local file append // Append to file string dataToAppend = "let's add a bit more data to that file"; byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend); using (var fileStream = new FileStream(Path.Combine(sync.Folder(), filename), FileMode.Append, FileAccess.Write, FileShare.None)) using (var bw = new BinaryWriter(fileStream)) { bw.Write(bytes); } // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Document failed to get synced to the server.", e); } Assert.NotNull(doc); Assert.AreEqual(filename, doc.ContentStreamFileName); Assert.AreEqual(filename, doc.Name); Assert.True(1 - (1024 * sizeKb + dataToAppend.Length) / doc.ContentStreamLength < 0.1); // Text file size can vary a bit ////////////////////////////////////////////// Local folder creation // Create local folder. string foldername = "folder 1"; Directory.CreateDirectory(Path.Combine(sync.Folder(), foldername)); // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); IFolder folder = null; try { folder = (IFolder)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + foldername, true); } catch (CmisObjectNotFoundException e) { Assert.Fail("Folder failed to get synced to the server.", e); } ////////////////////////////////////////////// Local file delete // Delete the file. File.Delete(Path.Combine(sync.Folder(), filename)); // Wait so that sync gets a chance to sync things. Thread.Sleep(15 * 1000); // Check that file is not present server-side. doc = null; try { doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); // Should have failed. Assert.Fail("Deleted document still exists on server: " + doc); } catch (CmisObjectNotFoundException e) { // That's the correct outcome } ////////////////////////////////////////////// Remote file creation string[] remoteFilenames = { filename, "いろんなカタチが、見えてくる。", "مشاور", "コンサルティングपरामर्शदाता컨설턴트" }; foreach (string remoteFilename in remoteFilenames) { // Create remote file IFolder remoteBaseFolder = (IFolder)CreateSession(url, user, password, repositoryId).GetObjectByPath(remoteFolderPath, true); IDictionary <string, object> properties = new Dictionary <string, object>(); properties[PropertyIds.Name] = remoteFilename; properties[PropertyIds.ObjectTypeId] = "cmis:document"; byte[] creationContent = UTF8Encoding.UTF8.GetBytes("Hello World!"); ContentStream creationContentStream = new ContentStream(); creationContentStream.FileName = remoteFilename; creationContentStream.MimeType = "text/plain"; creationContentStream.Length = creationContent.Length; creationContentStream.Stream = new MemoryStream(creationContent); remoteBaseFolder.CreateDocument(properties, creationContentStream, null); // Wait for 10 seconds so that sync gets a chance to sync things. Thread.Sleep(10 * 1000); // Check locally Assert.True(File.Exists(Path.Combine(sync.Folder(), (String)properties[PropertyIds.Name]))); } ////////////////////////////////////////////// Remote file modification doc = (IDocument)CreateSession(url, user, password, repositoryId) .GetObjectByPath(remoteFolderPath + "/" + filename, true); string contentString = "Hello World, edited."; byte[] content = UTF8Encoding.UTF8.GetBytes(contentString); ContentStream contentStream = new ContentStream(); contentStream.FileName = filename; contentStream.MimeType = "text/plain"; contentStream.Length = content.Length; contentStream.Stream = new MemoryStream(content); doc.SetContentStream(contentStream, true); // Wait so that sync gets a chance to sync things. Thread.Sleep(30 * 1000); // Check local file string remoteContent = File.ReadAllText(Path.Combine(sync.Folder(), filename)); Assert.AreEqual(contentString, remoteContent); }