Пример #1
0
        // Guid AddWorkflow(string name, XContainer xDocument)
        Guid AddWorkflow(string name, XContainer xDocument, string pathToWorkflowFile)
        {
            var testLabName = xDocument.Descendants(LogicConstants.WorkflowLoader_TestWorkflow_TestLabNode).FirstOrDefault().Value;

            var testLab = string.IsNullOrEmpty(testLabName) ?
                          GetFirstTestLab() :
                          GetOrCreateTestLab(testLabName);

            // _workflow = new TestWorkflow(testLab) { Name = name };
            _workflow = new TestWorkflow(testLab)
            {
                Name = name, Path = pathToWorkflowFile
            };
            // 20150708
            // if there already is a workflow with the same name
            // merge the new one with the existing
            var replace = false || WorkflowCollection.Workflows.Any(wfl => wfl.Name == _workflow.Name && wfl.Path == _workflow.Path);

            if (replace)
            {
                WorkflowCollection.MergeWorkflow(_workflow);
            }
            else
            {
                WorkflowCollection.AddWorkflow(_workflow);
            }

            ServerObjectFactory.Resolve <TestWorkflowCollectionMethods>().SetDefaultWorkflow();
            return(_workflow.Id);
        }
Пример #2
0
        Negotiator ExportTestResultsFromTestRun(Guid testRunId)
        {
            var testResultsExporter = ServerObjectFactory.Resolve <TestResultsExporter>();
            var currentTestRun      = TestRunQueue.TestRuns.FirstOrDefault(testRun => testRun.Id == testRunId);

            if (currentTestRun == null)
            {
                return(Negotiate.WithStatusCode(HttpStatusCode.NotFound));
            }
            var xDoc = testResultsExporter.GetTestResultsAsXdocument(
                new SearchCmdletBaseDataObject {
                Descending   = false,
                FilterAll    = true,
                FilterFailed = false,
                OrderById    = true
            },
                currentTestRun.TestSuites,
                currentTestRun.TestPlatforms);

            var dataObject = new TestResultsDataObject {
                Data = xDoc.ToString()
            };

            return(null == dataObject.Data ? Negotiate.WithStatusCode(HttpStatusCode.NotFound) : Negotiate.WithModel(dataObject).WithStatusCode(HttpStatusCode.OK).WithFullNegotiation());
        }
Пример #3
0
        Negotiator ReturnListOfTestRunsAndOk()
        {
            var testRunCollectionMethods = ServerObjectFactory.Resolve <TestRunCollectionMethods>();
            var data = testRunCollectionMethods.CreateTestRunExpandoObject();

            return(Negotiate.WithStatusCode(HttpStatusCode.OK).WithView(UrlList.ViewTestRuns_TestRunsPageName).WithModel((ExpandoObject)data));
        }
Пример #4
0
        /// <exception cref="Nancy.TinyIoc.TinyIoCResolutionException">Unable to resolve the type.</exception>
        public virtual string GetReportPage(Guid testRunId, string templateName)
        {
            var model    = ServerObjectFactory.Resolve <ViewsTestRunsModule>().CreateTestRunReportsModel(testRunId);
            var template = GetTemplate(templateName);

            return(template.Render(Hash.FromAnonymousObject(new { @Model = model })));
        }
Пример #5
0
        Negotiator CreateNewTestRun(ITestRunCommand testRunCommand)
        {
            var testRunCollectionMethods = ServerObjectFactory.Resolve <TestRunCollectionMethods>();

            return(!testRunCollectionMethods.SetTestRunDataAndCreateTestRun(testRunCommand, Request.Form) ?
                   Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(ServerLibrary.ReasonPhrase_TestRunsModule_FailedToCreateTestRun) :
                   GetTestRunCollectionExpandoObject(testRunCollectionMethods.CurrentTestRunId));
        }
Пример #6
0
        Negotiator returnTaskToClient_StatusOk(ITestClient testClient, ITestTask actualTask)
        {
            ServerObjectFactory.Resolve <TestTaskCollectionMethods>().UpdateTestClientWithActiveTask(testClient, actualTask);

            // 20141020 squeezing a task to its proxy
            return(Negotiate.WithModel(actualTask).WithStatusCode(HttpStatusCode.OK));
            // return Negotiate.WithModel(actualTask.SqueezeTaskToTaskResultProxy()).WithStatusCode(HttpStatusCode.OK);
            // return Negotiate.WithModel(actualTask.SqueezeTaskToTaskCodeProxy()).WithStatusCode(HttpStatusCode.OK);
        }
        public virtual ITestTask UpdateTask(ITestTask loadedTask, int taskId)
        {
            if (null == loadedTask)
            {
                // throw new UpdateTaskException("Failed to update task with id = " + taskId);
                // throw new UpdateTaskException(string.Format("Failed to update task with id = {0}", taskId));
                throw new UpdateTaskException(string.Format(Messages.UpdateTaskException, taskId));
            }
            var storedTask = TaskPool.TasksForClients.First(task => task.Id == taskId && task.ClientId == loadedTask.ClientId);

            storedTask.TaskStatus = loadedTask.TaskStatus;
            storedTask.TaskResult = loadedTask.TaskResult;
            storedTask.StartTime  = loadedTask.StartTime;
            // 20150908
            storedTask.TestStatus = loadedTask.TestStatus;

            var taskSelector = ServerObjectFactory.Resolve <TaskSelector>();

            if (storedTask.IsFailed())
            {
                taskSelector.CancelFurtherTasksOfTestClient(storedTask.ClientId);
            }
            // 20150908
            if (storedTask.IsFailed() && storedTask.IsCritical)
            {
                taskSelector.CancelFurtherTasksOfTestRun(storedTask.TestRunId);
            }

            if (storedTask.IsFinished())
            {
                CleanUpClientDetailedStatus(storedTask.ClientId);
            }

            // 20150908
            if (storedTask.IsLastTaskInTestRun())
            {
                // 20150909
                // comment it back
                // if (storedTask.IsLastTaskInTestRun() && storedTask.TaskStatus != TestTaskStatuses.Running) // ??
                CompleteTestRun(storedTask);
            }

            if (storedTask.IsFinished())
            {
                storedTask.SetFinishTime();
            }

            if (storedTask.IsCompletedSuccessfully())
            {
                UpdateNextTask(storedTask);
            }

            return(storedTask);
        }
Пример #8
0
        public virtual dynamic CreateTestRunReportsModel(Guid testRunId)
        {
            ITestRun currentTestRun = GetCurrentTestRun(testRunId);
            var      testStatistics = ServerObjectFactory.Resolve <TestStatistics>();

            testStatistics.RefreshAllStatistics(currentTestRun.TestSuites, true);
            var serverUrl  = GetServerUrl();
            var testRunUrl = GetTestRunUrl(testRunId);

            return(new { TestRun = currentTestRun, Suites = currentTestRun.TestSuites.OrderBy(suite => suite.Id), ServerUrl = serverUrl, TestRunUrl = testRunUrl });
        }
Пример #9
0
        Negotiator GetTestRunCollectionExpandoObject(Guid currentTestRunId)
        {
            var     testRunCollectionMethods = ServerObjectFactory.Resolve <TestRunCollectionMethods>();
            dynamic data = testRunCollectionMethods.CreateTestRunExpandoObject();

            data.NewTestRunId = currentTestRunId;
            return(Negotiate
                   .WithStatusCode(HttpStatusCode.Created)
                   .WithView(UrlList.ViewTestRuns_TestRunsPageName)
                   .WithModel((ExpandoObject)data)
                   .WithHeader(Resources.NewTestRun_lastTestRunId, currentTestRunId.ToString()));
        }
Пример #10
0
 static void LoadWorkflows()
 {
     var workflowsDirectoryPath = (new TmxServerRootPathProvider()).GetRootPath() + @"\Workflows";
     if (!Directory.Exists(workflowsDirectoryPath)) return;
     var workflowLoader = ServerObjectFactory.Resolve<WorkflowLoader>();
     foreach (var fileName in Directory.GetFiles(workflowsDirectoryPath)) {
         try {
             workflowLoader.Load(fileName);
         }
         catch {}
     }
 }
Пример #11
0
        public virtual bool CancelTestRun(Guid testRunId)
        {
            var testRun = TestRunQueue.TestRuns.First(tr => tr.Id == testRunId);

            if (null == testRun || testRun.IsCompleted())
            {
                return(false);
            }
            var testRunSelector = ServerObjectFactory.Resolve <TestRunSelector>();

            testRunSelector.CancelTestRun(testRun);
            return(true);
        }
Пример #12
0
        static void LoadDefaults()
        {
            var workflowsDirectoryPath = (new TmxServerRootPathProvider()).GetRootPath() + @"\Workflows";
            if (!Directory.Exists(workflowsDirectoryPath)) return;
            var fileWithDefaults = workflowsDirectoryPath + @"\" + "defaults.xml";

            Trace.TraceInformation("loading defaults...");

            if (File.Exists(fileWithDefaults))
                ServerObjectFactory.Resolve<DefaultsLoader>().Load(fileWithDefaults);

            Trace.TraceInformation("done");
        }
Пример #13
0
        public virtual bool CreateNewClient(ITestClient testClient)
        {
            if (!TestRunQueue.TestRuns.HasActiveTestRuns())
            {
                return(false);
            }
            // TODO: improve the selection of a test run by matching test client to task rules
            var activeWorkflowIds     = WorkflowCollection.Workflows.ActiveWorkflows().Select(wfl => wfl.Id);
            var legitimateWorkflowIds = TaskPool.Tasks
                                        .Where(task => activeWorkflowIds.Contains(task.WorkflowId) &&
                                               (
                                                   Regex.IsMatch(testClient.CustomString ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.EnvironmentVersion ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.Fqdn ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.Hostname ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.OsVersion ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.UserDomainName ?? string.Empty, task.Rule) ||
                                                   Regex.IsMatch(testClient.Username ?? string.Empty, task.Rule)

                                                   /*
                                                    * Regex.IsMatch(task.Rule, testClient.CustomString ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.EnvironmentVersion ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.Fqdn ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.Hostname ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.OsVersion ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.UserDomainName ?? string.Empty) ||
                                                    * Regex.IsMatch(task.Rule, testClient.Username ?? string.Empty)
                                                    */
                                               ))
                                        .Select(task => task.WorkflowId);

            var workflowIds = legitimateWorkflowIds as Guid[] ?? legitimateWorkflowIds.ToArray();

            if (!workflowIds.Any())
            {
                return(false);
            }

            // 20150922
            // testClient.TestRunId = TestRunQueue.TestRuns.First(testRun => testRun.IsActive() && workflowIds.Contains(testRun.WorkflowId)).Id;
            testClient.TestRunId = TestRunQueue.TestRuns.First(testRun => testRun.IsAcceptingNewClients() && workflowIds.Contains(testRun.WorkflowId)).Id;

            ClientsCollection.Clients.Add(testClient);
            var taskSelector   = ServerObjectFactory.Resolve <TaskSelector>();
            var tasksForClient = taskSelector.SelectTasksForClient(testClient.Id, TaskPool.Tasks);

            tasksForClient.ForEach(task => task.TestRunId = testClient.TestRunId);
            TaskPool.TasksForClients.AddRange(tasksForClient);
            return(true);
        }
Пример #14
0
        public HttpStatusCode CreateNewDefaultTestRun(DynamicDictionary parameters)
        {
            var testRunCollectionMethods = ServerObjectFactory.Resolve <TestRunCollectionMethods>();

            if (string.IsNullOrEmpty(parameters[UrlList.TestRuns_DefaultParameterName]))
            {
                return(HttpStatusCode.ExpectationFailed);
            }
            if (string.IsNullOrEmpty(Defaults.Workflow))
            {
                return(HttpStatusCode.ExpectationFailed);
            }
            return(!testRunCollectionMethods.SetTestRunDataAndCreateTestRun(new TestRunCommand
            {
                TestRunName = Defaults.Workflow,
                WorkflowName = Defaults.Workflow
            }, parameters)
                ? HttpStatusCode.ExpectationFailed
                : HttpStatusCode.Created);
        }
Пример #15
0
        protected Negotiator CreateNewDefaultTestRun(DynamicDictionary parameters)
        {
            var testRunCollectionMethods = ServerObjectFactory.Resolve <TestRunCollectionMethods>();

            if (string.IsNullOrEmpty(parameters[UrlList.TestRuns_DefaultParameterName]))
            {
                return(Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(ServerLibrary.ReasonPhrase_TestRunsModule_ThereHasNotBeenSuppliedTheDefaultParameter));
            }

            if (string.IsNullOrEmpty(Defaults.Workflow))
            {
                return(Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(ServerLibrary.ReasonPhrase_TestRunsModule_ThereIsNoDefaultWorkflow));
            }
            return(!testRunCollectionMethods.SetTestRunDataAndCreateTestRun(new TestRunCommand {
                TestRunName = Defaults.Workflow,
                WorkflowName = Defaults.Workflow
            }, parameters) ?
                   Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(ServerLibrary.ReasonPhrase_TestRunsModule_FailedToCreateTestRun) :
                   GetTestRunCollectionExpandoObject(testRunCollectionMethods.CurrentTestRunId));
        }
Пример #16
0
        public virtual bool SetTestRunDataAndCreateTestRun(ITestRunCommand testRunCommand, DynamicDictionary formData)
        {
            CurrentTestRunId = Guid.Empty;
            if (null == testRunCommand)
            {
                testRunCommand = new TestRunCommand {
                    TestRunName = formData[Resources.TestRunCommand_testRunName_param] ?? string.Empty, WorkflowName = formData[Resources.TestRunCommand_workflowName_param] ?? string.Empty
                }
            }
            ;
            if (string.IsNullOrEmpty(testRunCommand.WorkflowName))
            {
                testRunCommand.WorkflowName = formData[Resources.TestRunCommand_workflowName_param] ?? string.Empty;
            }
            if (string.IsNullOrEmpty(testRunCommand.TestRunName))
            {
                testRunCommand.TestRunName = formData[Resources.TestRunCommand_testRunName_param] ?? string.Empty;
            }

            return(PrepareTestRun(testRunCommand, formData));
        }

        bool PrepareTestRun(ITestRunCommand testRunCommand, DynamicDictionary formData)
        {
            var testRunInitializer = ServerObjectFactory.Resolve <TestRunInitializer>();
            var testRun            = testRunInitializer.CreateTestRun(testRunCommand, formData);

            CurrentTestRunId = testRun.Id;

            if (Guid.Empty == testRun.WorkflowId) // ??
            {
                return(false);
            }
            TestRunQueue.TestRuns.Add(testRun);

            foreach (var testRunAction in testRun.BeforeActions)
            {
                testRunAction.Run();
            }
            return(true);
        }
Пример #17
0
        Negotiator ReturnTaskByClientId(Guid clientId)
        {
            Trace.TraceInformation("returnTaskByClientId(Guid clientId).1");

            if (ClientsCollection.Clients.All(client => client.Id != clientId))
            {
                // return Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed);
                // return Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase("There's no test client with id = " + clientId);
                return(Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(string.Format(ServerLibrary.ReasonPhrase_ThereIsNOTestClientWithId, clientId)));
            }

            Trace.TraceInformation("returnTaskByClientId(Guid clientId).2");

            var taskSelector = ServerObjectFactory.Resolve <TaskSelector>();

//try {
//    var taskSel = TinyIoCContainer.Current.Resolve<ITaskSelector>();
//    if (null == taskSel)
//        Console.WriteLine("null == taskSel");
//    else
//        Console.WriteLine("type is {0}", taskSel.GetType().Name);
//}
//catch (Exception ee) {
//    Console.WriteLine(ee.Message);
//}

            Trace.TraceInformation("returnTaskByClientId(Guid clientId).3");

            // 20150908
            // ITestTask actualTask = taskSelector.GetFirstLegitimateTask(clientId);
            var actualTask = taskSelector.GetFirstLegitimateTask(clientId);

            Trace.TraceInformation("returnTaskByClientId(Guid clientId).4 actualTask is null? {0}", null == actualTask);

            var clientInQuestion = ClientsCollection.Clients.First(client => client.Id == clientId);

            Trace.TraceInformation("returnTaskByClientId(Guid clientId).5 clientInQuestion is null? {0}", null == clientInQuestion);
            Trace.TraceInformation("returnTaskByClientId(Guid clientId).6 clientInQuestion.Id = {0}, hostname = {1}", clientInQuestion.Id, clientInQuestion.Hostname);

            return(null == actualTask?returnNoTask_StatusNotFound(clientInQuestion) : returnTaskToClient_StatusOk(clientInQuestion, actualTask));
        }
Пример #18
0
 HttpStatusCode ImportTestResultsToTestRun(Guid testRunId)
 {
     try {
         var dataObject = this.Bind <TestResultsDataObject>();
         if (string.IsNullOrEmpty(dataObject.Data))
         {
             return(HttpStatusCode.Created);
         }
         var xDoc                = XDocument.Parse(dataObject.Data);
         var currentTestRun      = TestRunQueue.TestRuns.First(testRun => testRun.Id == testRunId);
         var testResultsImporter = ServerObjectFactory.Resolve <TestResultsImporter>();
         testResultsImporter.MergeTestPlatforms(currentTestRun.TestPlatforms, testResultsImporter.ImportTestPlatformFromXdocument(xDoc));
         testResultsImporter.MergeTestSuites(currentTestRun.TestSuites, testResultsImporter.ImportTestResultsFromXdocument(xDoc));
         // maybe, there's no such need? // TODO: set current test suite, test scenario, test result?
         return(HttpStatusCode.Created);
     } catch (Exception eFailedToImportTestResults) {
         // TODO: AOP
         Trace.TraceError("importTestResultsToTestRun(Guid testRunId)");
         Trace.TraceError(eFailedToImportTestResults.Message);
         return(HttpStatusCode.ExpectationFailed);
     }
 }
Пример #19
0
        void ProcessServerCommand(IServerCommand serverCommand)
        {
            switch (serverCommand.Command)
            {
            case ServerControlCommands.LoadConfiguraiton:
                var workflowLoader = ServerObjectFactory.Resolve <WorkflowLoader>();
                workflowLoader.Load(serverCommand.Data);
                break;

            case ServerControlCommands.ResetFull:
                ServerControl.Reset();
                break;

            case ServerControlCommands.Stop:
                ServerControl.Stop();
                break;

            case ServerControlCommands.ResetClients:
                ClientsCollection.Clients = new List <ITestClient>();
                break;

            case ServerControlCommands.ResetAllocatedTasks:
                TaskPool.TasksForClients = new List <ITestTask>();
                break;

            case ServerControlCommands.ResetLoadedTasks:
                TaskPool.Tasks = new List <ITestTask>();
                break;

            case ServerControlCommands.ResetWorkflows:
                WorkflowCollection.Workflows = new List <ITestWorkflow>();
                break;
//                case ServerControlCommands.ExportTestResults:
//                    TmxHelper.ExportResultsToXML(new SearchCmdletBaseDataObject { FilterAll = true }, serverCommand.Data);
//                    break;
            }
        }
        public virtual bool UpdateNextTask(ITestTask storedTask)
        {
            ITestTask nextTask;
            var       taskSorter = ServerObjectFactory.Resolve <TaskSelector>();

            try
            {
                nextTask = taskSorter.GetNextLegitimateTask(storedTask.ClientId, storedTask.Id);
            }
            catch (Exception eFailedToGetNextTask)
            {
                // TODO: AOP
                // Trace.TraceError("updateNextTaskAndReturnOk(TaskSelector taskSorter, ITestTask storedTask)");
                // Trace.TraceError(eFailedToGetNextTask.Message);
                throw new FailedToGetNextTaskException(eFailedToGetNextTask.Message);
            }
            if (null == nextTask)
            {
                return(true);
            }
            nextTask.PreviousTaskResult = storedTask.TaskResult;
            nextTask.PreviousTaskId     = storedTask.Id;
            return(true);
        }
Пример #21
0
 Negotiator SetTestRunData(Guid testRunId)
 {
     ServerObjectFactory.Resolve <TestRunCollectionMethods>(); //.CancelTestRun(testRunId);
     return(ReturnListOfTestRunsAndOk());
 }
Пример #22
0
 // 20141020 squeezing a task to its proxy
 HttpStatusCode UpdateTask(ITestTask loadedTask, int taskId)
 // HttpStatusCode updateTask(ITestTaskResultProxy loadedTask, int taskId)
 {
     ServerObjectFactory.Resolve <TestTaskCollectionMethods>().UpdateTask(loadedTask, taskId);
     return(HttpStatusCode.OK);
 }
 void ActivateNextInRowTestRun()
 {
     ServerObjectFactory.Resolve <TestRunSelector>().RunNextInRowTestRun();
 }
Пример #24
0
        Negotiator ReturnClientById(Guid clientId)
        {
            var testClient = ServerObjectFactory.Resolve <TestClientCollectionMethods>().ReturnClientById(clientId);

            return(null != testClient?Negotiate.WithModel(testClient).WithStatusCode(HttpStatusCode.OK) : Negotiate.WithStatusCode(HttpStatusCode.NotFound));
        }
Пример #25
0
 Negotiator DeleteTestRun(Guid testRunId)
 {
     ServerObjectFactory.Resolve <TestRunCollectionMethods>().DeleteTestRun(testRunId);
     return(ReturnListOfTestRunsAndOk());
 }
Пример #26
0
        Negotiator ReturnAllClients()
        {
            var clientCollection = ServerObjectFactory.Resolve <TestClientCollectionMethods>().ReturnAllClients();

            return(0 == clientCollection.Count ? Negotiate.WithStatusCode(HttpStatusCode.NotFound) : Negotiate.WithModel(clientCollection).WithStatusCode(HttpStatusCode.OK));
        }
Пример #27
0
 HttpStatusCode UpdateStatus(Guid clientId, DetailedStatus detailedStatus)
 {
     return(ServerObjectFactory.Resolve <TestClientCollectionMethods>().UpdateStatus(clientId, detailedStatus)
         ? HttpStatusCode.OK
         : HttpStatusCode.NotFound);
 }
Пример #28
0
 HttpStatusCode DeleteClientById(Guid clientId)
 {
     ServerObjectFactory.Resolve <TestClientCollectionMethods>().DeleteClientById(clientId);
     return(HttpStatusCode.NoContent);
 }
Пример #29
0
 Negotiator CreateNewClient(TestClient testClient)
 {
     return(ServerObjectFactory.Resolve <TestClientCollectionMethods>().CreateNewClient(testClient)
         ? Negotiate.WithModel(testClient).WithStatusCode(HttpStatusCode.Created)
         : Negotiate.WithStatusCode(HttpStatusCode.ExpectationFailed).WithReasonPhrase(ServerLibrary.ReasonPhrase_TestClientsModule_FailedToCreateNewTestClient)); // TODO: check that the phrase fits
 }
Пример #30
0
 static void RegisterTypes()
 {
     ServerObjectFactory.Resolve<Initializer>().RegisterTypes();
 }