Example #1
0
        private string OnExecute(string args)
        {
            var profile = _storageRepository.GetProfile <TestRunImportPluginProfile>();

            _log.InfoFormat("Started synchronizing at {0}", DateTime.Now);

            if (!string.IsNullOrEmpty(args) && profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium)
            {
                using (var reader = new StringReader(args))
                {
                    try
                    {
                        var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults();
                        _log.InfoFormat("{0} items for import detected in resutls source", result.Count == 0 ? "No" : result.Count.ToString());
                        if (result.Count > 0)
                        {
                            _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage
                            {
                                TestRunImportInfo =
                                    new TestRunImportInfo {
                                    TestRunImportResults = result.ToArray()
                                }
                            });
                        }
                    }
                    catch (ApplicationException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException(
                                  string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message), ex);
                    }
                }
            }
            //return new PluginCommandResponseMessage { ResponseData = string.Empty, PluginCommandStatus = PluginCommandStatus.Succeed };
            return(string.Empty);
        }
		public void Handle(TickMessage message)
		{
			var profile = _storageRepository.GetProfile<TestRunImportPluginProfile>();
			if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl)
			{
				return;
			}

			try
			{
				_log.InfoFormat("Started synchronizing at {0}", DateTime.Now);

				var lastModifyResults = _storageRepository.Get<LastModifyResult>();
				var lastModifyResult = lastModifyResults.Empty() ? new LastModifyResult() : lastModifyResults.Single();

				var jenkinsHudsonLastCompletedBuildNumber = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson ?
					GetJenkinsHudsonLastCompletedBuildNumber(profile) : null;

				if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson &&
						(jenkinsHudsonLastCompletedBuildNumber == null || string.CompareOrdinal(lastModifyResult.ETagHeader, jenkinsHudsonLastCompletedBuildNumber) == 0))
				{
					_log.Info("No new modification of results source detected");
					return;
				}

				var uri = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson
										? new Uri(string.Format("{0}/lastCompletedBuild/testReport/api/xml", profile.ResultsFilePath.TrimEnd(new[] { '/', '\\' })))
										: new Uri(profile.ResultsFilePath);
				var factoryResult = _streamFactory.OpenStreamIfModified(uri, lastModifyResult, profile.PassiveMode);

				_log.InfoFormat("{0} modification of results source detected", factoryResult == null ? "No new" : "New");

				if (factoryResult != null)
				{
					if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson)
					{
						factoryResult.LastModifyResult.ETagHeader = jenkinsHudsonLastCompletedBuildNumber;
					}

					lastModifyResults.Clear();
					lastModifyResults.Add(factoryResult.LastModifyResult);

					using (factoryResult.Stream)
					{
						using (var reader = new StreamReader(factoryResult.Stream))
						{
							try
							{
								var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults();
								_log.InfoFormat("{0} items for import detected in resutls source", result.Count == 0 ? "No" : result.Count.ToString(CultureInfo.InvariantCulture));
								if (result.Count > 0)
								{
									_localBus.SendLocal(new TestRunImportResultDetectedLocalMessage
																				{
																					TestRunImportInfo =
																						new TestRunImportInfo { TestRunImportResults = result.ToArray() }
																				});
								}
							}
							catch (ApplicationException)
							{
								throw;
							}
							catch (XmlException ex)
							{
								throw new ApplicationException("Error parsing results XML file", ex);
							}
							catch (Exception ex)
							{
								throw new ApplicationException("Error importing results XML file", ex);
							}
						}
					}
				}
			}
			catch (UriFormatException ex)
			{
				_log.Error(ex.Message);
				throw new ApplicationException(string.Format("Specified path has invalid format. {0}", ex.Message), ex);
			}
			catch (ApplicationException ex)
			{
				_log.Error(ex.Message);
				throw;
			}
			catch (Exception ex)
			{
				_log.ErrorFormat("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message);
				throw new ApplicationException(
					string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message), ex);
			}
		}
        public CheckMappingResult CheckMapping(TestRunImportPluginProfile settings,
                                               IEnumerable <TestCaseTestPlanDTO> testCaseTestPlans,
                                               PluginProfileErrorCollection errors)
        {
            try
            {
                var uri = settings.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson
                                                ? new Uri(string.Format("{0}/lastCompletedBuild/testReport/api/xml", settings.ResultsFilePath.TrimEnd(new[] { '/', '\\' })))
                                                : new Uri(settings.ResultsFilePath);
                var factoryResult = _streamFactory.OpenStream(uri, settings.PassiveMode);

                if (factoryResult != null)
                {
                    using (factoryResult.Stream)
                    {
                        using (var reader = new StreamReader(factoryResult.Stream))
                        {
                            try
                            {
                                var result = _resultsReaderFactory.GetResolver(settings, reader).GetTestRunImportResults();
                                if (result.Count > 0)
                                {
                                    var resolver = _resolverFactory.GetResolver(settings, result, testCaseTestPlans);
                                    return(resolver.ResolveTestCaseNames(errors));
                                }
                            }
                            catch (ApplicationException)
                            {
                                throw;
                            }
                            catch (XmlException ex)
                            {
                                throw new ApplicationException("Error parsing NUnit results XML file", ex);
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException("Error importing NUnit results XML file", ex);
                            }
                        }
                    }
                }
            }
            catch (UriFormatException ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = ex.Message
                });
            }
            catch (ApplicationException ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = ex.Message
                });
            }
            catch (Exception ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = string.Format("Could not read file \"{0}\": {1}", settings.ResultsFilePath, ex.Message)
                });
            }
            return(new CheckMappingResult {
                Errors = errors, NamesMappers = new List <NamesMapper>()
            });
        }
        private PluginCommandResponseMessage OnExecute()
        {
            var resultMessage = new PluginCommandResponseMessage
            {
                ResponseData = string.Empty, PluginCommandStatus = PluginCommandStatus.Succeed
            };

            var profile = _storageRepository.GetProfile <TestRunImportPluginProfile>();

            if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl)
            {
                return(resultMessage);
            }

            try
            {
                var uri           = new Uri(profile.ResultsFilePath);
                var factoryResult = _streamFactory.OpenStreamIfModified(uri, new LastModifyResult(), profile.PassiveMode);
                if (factoryResult != null)
                {
                    _storageRepository.Get <LastModifyResult>().Clear();
                    _storageRepository.Get <LastModifyResult>().Add(factoryResult.LastModifyResult);

                    using (factoryResult.Stream)
                    {
                        using (var reader = new StreamReader(factoryResult.Stream))
                        {
                            try
                            {
                                var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults();
                                if (result.Count > 0)
                                {
                                    _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage
                                    {
                                        TestRunImportInfo =
                                            new TestRunImportInfo {
                                            TestRunImportResults = result.ToArray()
                                        }
                                    });
                                }
                            }
                            catch (ApplicationException ex)
                            {
                                resultMessage.ResponseData        = ex.Message;
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                            catch (XmlException ex)
                            {
                                resultMessage.ResponseData        = string.Format("Error parsing results XML file; {0}", ex.Message);
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                            catch (Exception ex)
                            {
                                resultMessage.ResponseData        = string.Format("Error parsing results XML file; {0}", ex.Message);
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                        }
                    }
                }
            }
            catch (UriFormatException ex)
            {
                resultMessage.ResponseData        = string.Format("Specified path has invalid format. {0}", ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            catch (ApplicationException ex)
            {
                resultMessage.ResponseData        = string.Format("Specified path has invalid format. {0}", ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            catch (Exception ex)
            {
                resultMessage.ResponseData        = string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            return(resultMessage);
        }