Ejemplo n.º 1
0
        // public virtual Dictionary<string, string> Load()
        public virtual IDictionary <string, object> Load()
        {
            var url = UrlList.TestData_Root + "/" + ClientSettings.Instance.CurrentClient.TestRunId + UrlList.TestData_CommonData_forClient_relPath;

            // 20141211
            // TODO: AOP
            Trace.TraceInformation("Load(): testRun id = {0}, url = {1}", ClientSettings.Instance.CurrentClient.TestRunId, url);

            var commonDataResponse = _restTemplate.GetForMessage <Dictionary <string, string> >(url);

            Trace.TraceInformation("commonDataResponse is null? {0}", null == commonDataResponse);

            if (null == commonDataResponse)
            {
                throw new Exception("Failed to load data item");
            }

            // var commonData = commonDataResponse.Body;
            if (null == commonDataResponse.Body)
            {
                throw new Exception("Failed to load data item");
            }
            var commonData = new Dictionary <string, object>();

            commonDataResponse.Body.ToList().ForEach(pair => commonData.Add(pair.Key, pair.Value));

            Trace.TraceInformation("commonData is null? {0}", null == commonData);

            // return HttpStatusCode.NotFound == commonDataResponse.StatusCode ? new Dictionary<string, string>() : commonData;
            return(HttpStatusCode.NotFound == commonDataResponse.StatusCode ? new Dictionary <string, object>() : commonData);
        }
Ejemplo n.º 2
0
        public virtual string LoadTestReport()
        {
            try {
                var url = UrlList.TestReports_Root + "/" + ClientSettings.Instance.CurrentClient.TestRunId + UrlList.TestReports_LoadingPoint_relPath;

                var loadingReportResponse = _restTemplate.GetForMessage <TestResultsDataObject>(url);

                if (null == loadingReportResponse || null == loadingReportResponse.Body)
                {
                    throw new LoadingTestReportException("Failed to receive test results.");
                }
                if (HttpStatusCode.OK != loadingReportResponse.StatusCode)
                {
                    throw new LoadingTestReportException("Failed to receive test results. " + loadingReportResponse.StatusCode);
                }

                return(loadingReportResponse.Body.Data);
            }
            catch (RestClientException eLoadingTestResults) {
                // TODO: AOP
                Trace.TraceError("LoadTestReport()");
                Trace.TraceError(eLoadingTestResults.Message);
                throw new LoadingTestReportException("Failed to receive test results. " + eLoadingTestResults.Message);
            }
        }
Ejemplo n.º 3
0
        public virtual bool LoadTestResults()
        {
            try {
                var url = UrlList.TestResults_Root + "/" + ClientSettings.Instance.CurrentClient.TestRunId + UrlList.TestResultsPostingPoint_forClient_relPath;

                // 20141211
                // TODO: AOP
                Trace.TraceInformation("LoadTestResults().1: testRun id = {0}, url = {1}", ClientSettings.Instance.CurrentClient.TestRunId, url);


                var loadingResultsResponse = _restTemplate.GetForMessage <TestResultsDataObject>(url);

                Trace.TraceInformation("LoadTestResults().2: loadingResultsResponse is null?{0}", null == loadingResultsResponse);
                // 20150316
                if (null == loadingResultsResponse)
                {
                    throw  new Exception("Failed to load test resuylts.");
                }

                var testResultsImporter = new TestResultsImporter();

                Trace.TraceInformation("LoadTestResults().3");

                var xDoc = XDocument.Parse(loadingResultsResponse.Body.Data);

                Trace.TraceInformation("LoadTestResults().4");

                testResultsImporter.MergeTestPlatforms(TestData.TestPlatforms, testResultsImporter.ImportTestPlatformFromXdocument(xDoc));

                Trace.TraceInformation("LoadTestResults().5");

                testResultsImporter.MergeTestSuites(TestData.TestSuites, testResultsImporter.ImportTestResultsFromXdocument(xDoc));

                Trace.TraceInformation("LoadTestResults().6");

                // 20141211
                // TODO: AOP
                Trace.TraceInformation("LoadTestResults().7: still okay");


                return(HttpStatusCode.OK == loadingResultsResponse.StatusCode);
            }
            catch (RestClientException eLoadingTestResults) {
                // TODO: AOP
                Trace.TraceError("LoadTestResults()");
                Trace.TraceError(eLoadingTestResults.Message);
                throw new LoadingTestResultsException("Failed to receive test results. " + eLoadingTestResults.Message);
            }
        }
Ejemplo n.º 4
0
        // 20141020 squeezing a task to its proxy
        public virtual ITestTask GetCurrentTask()
        // public virtual ITestTaskCodeProxy GetCurrentTask()
        {
            Trace.TraceInformation("GetCurrentTask().1");

            if (Guid.Empty == ClientSettings.Instance.ClientId)
            {
                throw new ClientNotRegisteredException("Client is not registered. Run the Register-TmxSystemUnderTest cmdlet first");
            }
            // 20141020 squeezing a task to its proxy
            HttpResponseMessage <TestTask> gettingTaskResponse = null;

            // HttpResponseMessage<TestTaskCodeProxy> gettingTaskResponse = null;
            try {
                // 20141211
                // TODO: AOP
                Trace.TraceInformation("GetCurrentTask().2: client id = {0}, url = {1}", ClientSettings.Instance.ClientId, UrlList.TestTasks_Root + "/" + ClientSettings.Instance.ClientId);

                // 20141020 squeezing a task to its proxy
                gettingTaskResponse = _restTemplate.GetForMessage <TestTask>(UrlList.TestTasks_Root + "/" + ClientSettings.Instance.ClientId);
                // gettingTaskResponse = _restTemplate.GetForMessage<TestTaskCodeProxy>(UrnList.TestTasks_Root + "/" + ClientSettings.Instance.ClientId);

                Trace.TraceInformation("GetCurrentTask().3 gettingTaskResponse is null? {0}", null == gettingTaskResponse);
            }
            catch (RestClientException eHttpClientErrorException) {
                // TODO: AOP
                Trace.TraceError("GetCurrentTask()");
                Trace.TraceError(eHttpClientErrorException.Message);
                if (string.Empty != eHttpClientErrorException.Message)
                {
                    if (Regex.IsMatch(eHttpClientErrorException.Message, "resulted in 417"))
                    {
                        // GET request for 'http://172.28.8.105:12340/Tasks/1' resulted in 417 - ExpectationFailed (Expectation Failed).
                        throw new ClientNotRegisteredException("Client is not registered. Run the Register-TmxSystemUnderTest cmdlet first");
                    }
                }
            }

            Trace.TraceInformation("GetCurrentTask().4");

            if (null == gettingTaskResponse)
            {
                // 20150316
                // throw new LoadTaskException("Failed to load task. " + gettingTaskResponse.StatusCode);
                throw new LoadTaskException("Failed to load task.");
            }

            Trace.TraceInformation("GetCurrentTask().5");

            var task = gettingTaskResponse.Body;

            Trace.TraceInformation("GetCurrentTask().6 task is null? {0}", null == task);

            if (HttpStatusCode.NotFound == gettingTaskResponse.StatusCode)
            {
                return(null);                                                           // a waiting task?
            }
            Trace.TraceInformation("GetCurrentTask().7");

            if (HttpStatusCode.ExpectationFailed == gettingTaskResponse.StatusCode)
            {
                throw new ClientNotRegisteredException("Client is not registered. Run the Register-TmxSystemUnderTest cmdlet first");
            }

            Trace.TraceInformation("GetCurrentTask().8 client is registered");

            if (HttpStatusCode.OK == gettingTaskResponse.StatusCode)
            {
                return(AcceptCurrentTask(task));
            }

            Trace.TraceInformation("GetCurrentTask().9");

            // TODO: AOP
            Trace.TraceError("GetCurrentTask().10");
            throw new LoadTaskException("Failed to load task. " + gettingTaskResponse.StatusCode);
        }