protected BaseHubIntegrationTest()
        {
            ObjectFactory.Initialize();
            ObjectFactory.Configure(Hub.StructureMap.StructureMapBootStrapper.LiveConfiguration);
            ObjectFactory.Configure(Infrastructure.StructureMap.StructureMapBootStrapper.LiveConfiguration);

            // Use a common HttpClient for all REST operations within testing session
            // to ensure the presense of the authentication cookie.
            _httpClient             = new HttpClient();
            _httpClient.BaseAddress = GetHubBaseUrl();
            _httpClient.Timeout     = TimeSpan.FromMinutes(2);

            Crate                = new CrateManager();
            _baseUrl             = GetHubApiBaseUrl();
            RestfulServiceClient = new RestfulServiceClient(_httpClient);

            // Get auth cookie from the Hub and save it to HttpClient's internal cookie storage
            LoginUser(TestUserEmail, TestUserPassword).Wait();

            // Initailize EmailAssert utility.
            TestEmail     = ConfigurationManager.AppSettings["TestEmail"];
            TestEmailName = ConfigurationManager.AppSettings["TestEmail_Name"];
            string hostname = ConfigurationManager.AppSettings["TestEmail_Pop3Server"];
            int    port     = int.Parse(ConfigurationManager.AppSettings["TestEmail_Port"]);
            bool   useSsl   = ConfigurationManager.AppSettings["TestEmail_UseSsl"] == "true" ? true : false;
            string username = ConfigurationManager.AppSettings["TestEmail_Username"];
            string password = ConfigurationManager.AppSettings["TestEmail_Password"];

            EmailAssert.InitEmailAssert(TestEmail, hostname, port, useSsl, username, password);
        }
Example #2
0
        private async Task <ActivityPayload> GetPayload(Guid activityId)
        {
            var activity = await RestfulServiceClient.GetAsync(new Uri(GetHubApiBaseUrl() + "activities/get/" + activityId));

            var DTO = JsonConvert.DeserializeObject <ActivityDTO>(activity);

            return(Mapper.Map <ActivityPayload>(DTO));
        }
 public BaseHealthMonitorTest()
 {
     ObjectFactory.Initialize();
     ObjectFactory.Configure(Hub.StructureMap.StructureMapBootStrapper.LiveConfiguration);
     RestfulServiceClient = new RestfulServiceClient();
     Crate       = new CrateManager();
     HMACService = new Fr8HMACService();
 }
Example #4
0
        private async Task ConfigureJira(Guid activityId, string userId)
        {
            var payloadJira = await GetPayload(activityId);

            SetDDL(payloadJira, "AvailableProjects", "fr8test");
            DeleteSprint(payloadJira);
            var DTO = Mapper.Map <ActivityDTO>(payloadJira);
            await RestfulServiceClient.PostAsync(new Uri(GetHubApiBaseUrl() + "activities/configure"), DTO, null, GetFr8HubAuthorizationHeader("terminalGoogle", "1", userId));
        }
Example #5
0
        private async Task ConfigureMessage(Guid activityId, string userId, string guid)
        {
            var payloadMessage = await GetPayload(activityId);

            var messageCrates = payloadMessage.CrateStorage.CrateContentsOfType <StandardConfigurationControlsCM>().First();
            var bodyTextBox   = (BuildMessageAppender)messageCrates.FindByName("Body");

            bodyTextBox.Value = "testing terminal submission " + guid;
            var DTO = Mapper.Map <ActivityDTO>(payloadMessage);
            await RestfulServiceClient.PostAsync(new Uri(GetHubApiBaseUrl() + "activities/configure"), DTO, null, GetFr8HubAuthorizationHeader("terminalGoogle", "1", userId));
        }
Example #6
0
        private async Task ConfigureSlack(Guid activityId, string userId)
        {
            var payloadSlack = await GetPayload(activityId);

            var slackCrates = payloadSlack.CrateStorage.CrateContentsOfType <StandardConfigurationControlsCM>().First();

            SetDDL(payloadSlack, slackCrates.Controls[0].Name, "#general");
            var DTO = Mapper.Map <ActivityDTO>(payloadSlack);

            await RestfulServiceClient.PostAsync(new Uri(GetHubApiBaseUrl() + "activities/save"), DTO, null, GetFr8HubAuthorizationHeader("terminalGoogle", "1", userId));
        }
        public BasePlanDirectoryIntegrationTest()
        {
            ObjectFactory.Initialize();
            ObjectFactory.Configure(Hub.StructureMap.StructureMapBootStrapper.LiveConfiguration);
            ObjectFactory.Configure(Fr8.Infrastructure.StructureMap.StructureMapBootStrapper.LiveConfiguration);

            // Use a common HttpClient for all REST operations within testing session
            // to ensure the presense of the authentication cookie.
            _httpClient             = new HttpClient();
            _httpClient.BaseAddress = GetPlanDirectoryBaseUri();
            _httpClient.Timeout     = TimeSpan.FromMinutes(2);

            Crate                = new CrateManager();
            _baseUrl             = GetPlanDirectoryBaseApiUrl();
            RestfulServiceClient = new RestfulServiceClient(_httpClient);

            // Get auth cookie from the Hub and save it to HttpClient's internal cookie storage
            AuthenticateWebApi(TestUserEmail, TestUserPassword).Wait();
        }
Example #8
0
        static void Main(string[] args)
        {
            using (var wcfProxy = new RestfulServiceClient())
            {

                var data = wcfProxy.GetJsonData(value: "1");
                data = wcfProxy.GetXmlData(value: "2");

                var compositeInstance = new CompositeType
                {
                    BoolValue = true,
                    StringValue = "new data from consoleUI"
                };

                CompositeType result = wcfProxy.AddData(composite: compositeInstance);

                Console.WriteLine("Press any key to exit ...");
                Console.ReadKey();
            }
        }
 public BaseIntegrationTest()
 {
     RestfulServiceClient = new RestfulServiceClient();
     Crate = new CrateManager();
 }
        public async Task <TResponse> HttpGetAsync <TResponse>(string url)
        {
            var uri = new Uri(url);

            return(await RestfulServiceClient.GetAsync <TResponse>(uri));
        }
 public async Task HttpDeleteAsync(string url)
 {
     var uri = new Uri(url);
     await RestfulServiceClient.DeleteAsync(uri, null, null);
 }
        public async Task <TResponse> HttpPostAsync <TResponse>(string url, HttpContent content)
        {
            var uri = new Uri(url);

            return(await RestfulServiceClient.PostAsync <TResponse>(uri, content, null, null));
        }
        public async Task <TResponse> HttpPostAsync <TRequest, TResponse>(string url, TRequest request)
        {
            var uri = new Uri(url);

            return(await RestfulServiceClient.PostAsync <TRequest, TResponse>(uri, request, null, await GetHMACHeader(uri, "testUser", request)));
        }
        public static void ExecuteSchedulledJob(PollingDataDTO pollingData, string terminalToken)
        {
            IRestfulServiceClient _client = new RestfulServiceClient();

            try
            {
                //renewing token
                if (!RenewAuthToken(pollingData, terminalToken).Result)
                {
                    RecurringJob.RemoveIfExists(pollingData.JobId);
                    Logger.Info($"Polling: token is missing, removing the job for {pollingData.ExternalAccountId}");
                }

                var request = RequestPolling(pollingData, terminalToken, _client);
                var result  = request.Result;

                if (result != null)
                {
                    if (!result.Result)
                    {
                        Logger.Info($"Polling: got result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Deschedulling the job");
                        if (pollingData.RetryCounter > 3)
                        {
                            Logger.Info($"Polling: for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Deschedulling the job");
                            RecurringJob.RemoveIfExists(pollingData.JobId);
                        }
                        else
                        {
                            pollingData.RetryCounter++;
                            Logger.Info($"Polling: got result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Starting Retry {pollingData.RetryCounter}");
                            RecurringJob.AddOrUpdate(pollingData.JobId, () => SchedullerHelper.ExecuteSchedulledJob(result, terminalToken), "*/" + result.PollingIntervalInMinutes + " * * * *");
                        }
                    }
                    else
                    {
                        Logger.Info($"Polling: got result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Success");
                        RecurringJob.AddOrUpdate(pollingData.JobId, () => SchedullerHelper.ExecuteSchedulledJob(result, terminalToken), "*/" + result.PollingIntervalInMinutes + " * * * *");
                    }
                }
                else
                {
                    Logger.Info($"Polling: no result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Terminal didn't answer");
                    //we didn't get any response from the terminal (it might have not started yet, for example) Let's give it one more chance, and if it will fail - the job will be descheduled cause of Result set to false;
                    if (pollingData.Result) //was the job successfull last time we polled?
                    {
                        Logger.Info($"Polling: no result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Last polling was successfull");

                        //in case of ongoing deployment when we have a minimal polling interval, could happen to remove the job. Add default polling interval of 10 minutes in this case as retry
                        pollingData.Result = false;
                        RecurringJob.AddOrUpdate(pollingData.JobId, () => SchedullerHelper.ExecuteSchedulledJob(pollingData, terminalToken), "*/" + pollingData.PollingIntervalInMinutes + " * * * *");
                    }
                    else
                    {
                        if (pollingData.RetryCounter > 20)
                        {
                            Logger.Info($"Polling: no result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Remove Job");
                            //last polling was unsuccessfull, so let's deschedulle it
                            RecurringJob.RemoveIfExists(pollingData.JobId);
                        }
                        else
                        {
                            Logger.Info($"Polling: no result for {pollingData.ExternalAccountId} from a terminal {terminalToken}. Retry Counter {pollingData.RetryCounter}");
                            pollingData.RetryCounter++;
                            RecurringJob.AddOrUpdate(pollingData.JobId, () => SchedullerHelper.ExecuteSchedulledJob(pollingData, terminalToken), "*/" + pollingData.PollingIntervalInMinutes + " * * * *");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (pollingData != null && !string.IsNullOrWhiteSpace(pollingData.JobId))
                {
                    RecurringJob.RemoveIfExists(pollingData.JobId);
                }

                Logger.Error("Scheduled job failed", ex);
            }
        }
        public async Task <TResponse> HttpPostAsync <TRequest, TResponse>(string url, TRequest request)
        {
            var uri = new Uri(url);

            return(await RestfulServiceClient.PostAsync <TRequest, TResponse>(uri, request));
        }
Example #16
0
        public async Task MonitorTerminalSubmissionPlan()
        {
            AutoMapperBootstrapper.ConfigureAutoMapper();

            var guidTestId = Guid.NewGuid();

            var userId = AddTokens();

            var googleEventUrl = ConfigurationManager.AppSettings["GoogleFormEventWebServerUrl"];

            //Trigger creating Plan
            Debug.WriteLine("Trigger creating Plan");

            var terminalAuthenticationHeader = GetFr8TerminalAuthorizationHeader("terminalGoogle", "1", userId);
            await RestfulServiceClient.PostAsync(new Uri(googleEventUrl), new { fr8_user_id = userId }, null, terminalAuthenticationHeader);

            //Reconfiguring plan activities
            var url      = $"{GetHubApiBaseUrl()}/plans?name=MonitorSubmissionTerminalForm&visibility=2";
            var response = await RestfulServiceClient.GetAsync(new Uri(url), null, terminalAuthenticationHeader);

            var plans = JsonConvert.DeserializeObject <IEnumerable <PlanDTO> >(response).ToArray();
            var plan  = plans.FirstOrDefault().SubPlans.FirstOrDefault();

            // deactivate plan before editing
            Debug.WriteLine("deactivate plan before editing");
            var deactivateUrl = GetHubApiBaseUrl() + "plans/deactivate?planId=" + plans.FirstOrDefault().Id;
            await RestfulServiceClient.PostAsync(new Uri(deactivateUrl), new List <CrateDTO>(), null, terminalAuthenticationHeader);

            Debug.WriteLine("Reconfiguring plan activities");

            if (plan.Activities.FirstOrDefault(a => a.Ordering == 8) != null)
            {
                var deleteActivityUrl = GetHubApiBaseUrl() + "activities/delete/" + plan.Activities.Where(a => a.Ordering == 8).FirstOrDefault().Id;
                await RestfulServiceClient.DeleteAsync(new Uri(deleteActivityUrl), null, terminalAuthenticationHeader);
            }

            await ConfigureJira(plan.Activities.FirstOrDefault(a => a.Ordering == 5).Id, userId);
            await ConfigureMessage(plan.Activities.FirstOrDefault(a => a.Ordering == 6).Id, userId, guidTestId.ToString());
            await ConfigureSlack(plan.Activities.FirstOrDefault(a => a.Ordering == 7).Id, userId);

            //Run plan again after reconfigure
            Debug.WriteLine("Run plan again after reconfigure");
            var runUrl = GetHubApiBaseUrl() + "plans/run?planId=" + plans.FirstOrDefault().Id;
            await RestfulServiceClient.PostAsync(new Uri(runUrl), new List <CrateDTO>(), null, terminalAuthenticationHeader);

            await SubmitForm(googleEventUrl, guidTestId.ToString());

            //Waiting 10 seconds for Plan execution
            Debug.WriteLine("Waiting 10 seconds for Plan execution");
            await Task.Delay(PlanExecutionPeriod);


            Jira jira = CreateRestClient(AtlassianToken);

            Issue[] issues = new Issue[0];

            var slackUrl           = "https://slack.com/api/search.messages?token=" + SlackAuthToken + "&query=" + guidTestId.ToString();
            var totalMessagesFound = 0;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.ElapsedMilliseconds <= MaxAwaitPeriod)
            {
                if (issues.Length == 0)
                {
                    //Searching for created jira issue
                    issues = jira.GetIssuesFromJql("summary ~ " + guidTestId.ToString()).ToArray();
                    Debug.WriteLine("found jira issues " + issues.Length + " after elapsed " + stopwatch.ElapsedMilliseconds + " milliseconds");
                }

                if (totalMessagesFound == 0)
                {
                    //Searching for slack message
                    var result = await RestfulServiceClient.GetAsync(new Uri(slackUrl));

                    var searchResult = JObject.Parse(result);
                    totalMessagesFound = (int)searchResult.SelectToken("messages.pagination.total_count");
                    Debug.WriteLine("found slack messages " + totalMessagesFound + " after elapsed " + stopwatch.ElapsedMilliseconds + " milliseconds");
                }

                if (issues.Count() != 0 && totalMessagesFound != 0)
                {
                    break;
                }
                await Task.Delay(SingleAwaitPeriod);
            }

            //Deleting test issues
            foreach (var issue in issues)
            {
                jira.DeleteIssue(issue);
            }

            Assert.IsTrue(issues.Length > 0, "Couldn't find jira issue");

            Assert.IsTrue(totalMessagesFound != 0, "Couldn't find slack message");
        }