Skip to content

Commit

Permalink
added external testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-raoul committed May 11, 2018
1 parent 3f1de4a commit 0242456
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CmisSync.Console/CmisSyncOnce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CmisSyncOnce
/// </summary>
public static int Main (string[] args)
{
System.Console.WriteLine("Started CmisSyncOnce");
Utils.ConfigureLogging();
Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version);

Expand Down Expand Up @@ -67,6 +68,9 @@ public static int Main (string[] args)
// Synchronize all
bool success = once.Sync();

//System.Console.WriteLine("Press enter to close...");
//System.Console.ReadLine();

// Exit code 0 if synchronization was successful or not needed,
// 1 if synchronization failed, or could not run.
return success ? 0 : 1;
Expand Down
1 change: 1 addition & 0 deletions CmisSync.Lib/RepoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public RepoInfo(string name, string cmisDatabaseFolder)
[Obsolete("Use other contructor outside of testings")]
public RepoInfo(string name, string cmisDatabaseFolder, string remotePath, string address, string user, string password, string repoID, double pollInterval, Boolean isSuspended, DateTime lastSuccessedSync, bool syncAtStartup)
{
// TODO call simple constructor above instead of duplicated code.
Name = name;
name = name.Replace("\\", "_");
name = name.Replace("/", "_");
Expand Down
187 changes: 187 additions & 0 deletions CmisSync/TestLibrary/ExternalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
// using System.Windows.Automation; Requires .NET 4.5 it seems.
using DotCMIS;
using DotCMIS.Client;
using DotCMIS.Client.Impl;
using DotCMIS.Data.Impl;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;

/**
* Tests for the CmisSync.exe program, called externally without any knowledge about the internals of the algorithm.
*
* To use them, first create a JSON file containing the credentials/parameters to a test folder on your CMIS server(s)
* Put it in TestLibrary/test-servers.json and use this format:
[
[
"unittest1",
"/mylocalpath",
"/myremotepath",
"http://example.com/p8cmis/resources/Service",
"myuser",
"mypassword",
"repository987080"
],
[
"unittest2",
"/mylocalpath",
"/myremotepath",
"http://example.org:8080/Nemaki/cmis",
"myuser",
"mypassword",
"repo3"
]
]
* Warning: All previous content of these folders will be deleted by the tests.
*/
namespace TestLibrary
{
using System.Collections;
using CmisSync.Lib;
using CmisSync.Lib.Cmis;
using CmisSync.Lib.Sync;
using log4net.Appender;
using NUnit.Framework;
using CmisSync.Auth;
using CmisSync.Lib.Database;
using System.Diagnostics;
using System.Threading;

[TestFixture]
public class ExternalTests
{
public static IEnumerable<object[]> TestServers
{
get
{
string path = "../../test-servers.json";
bool exists = File.Exists(path);

if (!exists)
{
path = "../CmisSync/TestLibrary/test-servers.json";
}

return JsonConvert.DeserializeObject<List<object[]>>(
File.ReadAllText(path));
}
}

public static IEnumerable<object[]> TestServersFuzzy
{
get
{
string path = "../../test-servers-fuzzy.json";
bool exists = File.Exists(path);

if (!exists)
{
path = "../CmisSync/TestLibrary/test-servers-fuzzy.json";
}

try
{
return JsonConvert.DeserializeObject<List<object[]>>(
File.ReadAllText(path));
}
catch (Exception e)
{
return Enumerable.Empty<object[]>();
}
}
}

public ExternalTests()
{
}

/*public static IEnumerable<AutomationElement> EnumNotificationIcons()
{
foreach (var button in AutomationElement.RootElement.Find(
"User Promoted Notification Area").EnumChildButtons())
{
yield return button;
}
foreach (var button in AutomationElement.RootElement.Find(
"System Promoted Notification Area").EnumChildButtons())
{
yield return button;
}
var chevron = AutomationElement.RootElement.Find("Notification Chevron");
if (chevron != null && chevron.InvokeButton())
{
foreach (var button in AutomationElement.RootElement.Find(
"Overflow Notification Area").EnumChildButtons())
{
yield return button;
}
}
}*/

[Test, Category("Fast")]
public void Placebo()
{
Assert.AreEqual(4, 2 + 2);
}

[Test, Category("Fast")]
public void StartStopUI()
{
// TODO Change this to your CmisSync
Process process = Process.Start(@"C:\Users\win7pro32bit\Documents\GitHub\CmisSync\CmisSync\Windows\bin\Debug\CmisSync.exe");
if (null == process)
Assert.Fail("Could not start process, maybe an existing process has been reused?");

//Wait for CmisSync's UI to start properly.
Thread.Sleep(2000);

/*foreach (var icon in EnumNotificationIcons())
{
var name = icon.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
Console.WriteLine(name);
if (name.StartsWith("CmisSync"))
{
Console.WriteLine(@"Click!");
icon.InvokeButton();
break;
}
}*/

// Close as if the user had clicked "Exit".
process.Kill(); // More violent than we would want.
//process.Close(); // Only close the connection to the program, not the program itself.
//process.CloseMainWindow(); // Does not work because CmisSync lives as a tray icon rather than a window.

// Wait for CmisSync to finish what it is doing and exit normally. This might take a few minutes if a big sync was going on.
process.WaitForExit();
Console.Write("Exiting StartStopUI");
}


[Test, Category("Fast")]
public void StartStopConsole()
{
// TODO Change this to your CmisSync
Process process = Process.Start(@"C:\Users\win7pro32bit\Documents\GitHub\CmisSync\CmisSync.Console\bin\Debug\CmisSync.Console.exe");
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);

// Wait for CmisSync to finish what it is doing and exit normally. This might take a few minutes if a big sync was going on.
process.WaitForExit();
Console.Write("Exiting StartStopConsole");
}
}
}
17 changes: 10 additions & 7 deletions CmisSync/TestLibrary/SyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ public void RenameRemoteDocument(string canonicalName, string localPath, string
{
return File.Exists(path1);
}));
Console.WriteLine("Document: " + doc1.Id);
Console.WriteLine("Folder: " + remoteFolder.Id);

Console.WriteLine("Rename remote document");
IDocument doc2 = RenameRemoteDocument(doc1, name2);
Expand Down Expand Up @@ -653,18 +655,19 @@ public void RenameRemoteFolder(string canonicalName, string localPath, string re
{
return Directory.Exists(path1);
}));

// rename folder
Console.WriteLine(" Remote rename folder");
Assert.IsTrue(Directory.Exists(path1));
Assert.IsFalse(Directory.Exists(path2));
Console.WriteLine("Base folder: " + remoteFolder.Id);
Console.WriteLine("Sub-folder: " + remoteSubFolder.Id);

// rename the sub-folder
Console.WriteLine("Rename remote sub-folder");
IFolder folder2 = RenameRemoteFolder(remoteSubFolder, name2);
Assert.IsTrue(SyncAndWaitUntilCondition(synchronizedFolder, delegate
success = synchronizedFolder.Sync();
Assert.IsTrue(success);
Assert.IsTrue(WaitUntilCondition(delegate
{
return !Directory.Exists(path1) && Directory.Exists(path2);
}));
Assert.IsFalse(Directory.Exists(path1));
Assert.IsTrue(Directory.Exists(path2));
}

[Test, TestCaseSource("TestServers"), Category("Slow")]
Expand Down
1 change: 1 addition & 0 deletions CmisSync/TestLibrary/TestLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="CmisDatabaseTest.cs" />
<Compile Include="CmisSyncLibUtilsTest.cs" />
<Compile Include="ConfigurationTest.cs" />
<Compile Include="ExternalTests.cs" />
<Compile Include="EncodingTest.cs" />
<Compile Include="LocalFilesystemActivityGenerator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
12 changes: 10 additions & 2 deletions CmisSync/TestLibraryRunner/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void test(string path)

tests.Init();
// Enter the unit test method to debug below.
tests.DeleteRemoteDocument((string)server[0], (string)server[1],
tests.RenameRemoteFolder((string)server[0], (string)server[1],
(string)server[2], (string)server[3], (string)server[4], (string)server[5], (string)server[6]);
tests.TearDown();
}
Expand All @@ -61,8 +61,16 @@ static void testFuzzy()
new SyncTests().GetRepositoriesFuzzy((string)server[0], (string)server[1], (string)server[2]);
}

static void testExternal()
{
new ExternalTests().StartStopConsole();
}

static void Main(string[] args)
{
testExternal();
return;

ServicePointManager.CertificatePolicy = new TrustAlways();
bool firstRun = ! File.Exists(ConfigManager.CurrentConfigFile);

Expand Down Expand Up @@ -91,7 +99,7 @@ static void Main(string[] args)
log4net.Config.XmlConfigurator.Configure(ConfigManager.CurrentConfig.GetLog4NetConfig());
}

test(path == null ? "../../../TestLibrary/test-servers.json" : path);
//test(path == null ? "../../../TestLibrary/test-servers.json" : path);
//testFuzzy();
//new CmisSyncTests().TestCrypto();

Expand Down

0 comments on commit 0242456

Please sign in to comment.