Exemple #1
0
        private async Task <Uri> ImportCheckAsync(ImportRequest request, TestFhirClient client = null, int?errorCount = null)
        {
            client = client ?? _client;
            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(client, request);

            HttpResponseMessage response;

            while ((response = await client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));
            }

            Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
            ImportTaskResult result = JsonConvert.DeserializeObject <ImportTaskResult>(await response.Content.ReadAsStringAsync());

            Assert.NotEmpty(result.Output);
            if (errorCount != null)
            {
                Assert.Equal(errorCount.Value, result.Error.First().Count);
            }
            else
            {
                Assert.Empty(result.Error);
            }

            Assert.NotEmpty(result.Request);

            return(checkLocation);
        }
Exemple #2
0
        public async Task GivenImportOperationEnabled_WhenImportInvalidResourceUrl_ThenBadRequestShouldBeReturned()
        {
            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = new Uri("https://fhirtest-invalid.com"),
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(
                async() =>
            {
                HttpResponseMessage response;
                while ((response = await _client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            });

            Assert.Equal(HttpStatusCode.BadRequest, fhirException.StatusCode);
        }
Exemple #3
0
        public async Task GivenImportOperationEnabled_WhenImportInvalidResourceType_ThenBadRequestShouldBeReturned()
        {
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Type = "Invalid",
                    },
                },
            };

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(
                async() => await ImportTestHelper.CreateImportTaskAsync(_client, request));

            Assert.Equal(HttpStatusCode.BadRequest, fhirException.StatusCode);
        }
Exemple #4
0
        public async Task GivenImportOperationEnabled_WhenImportResourceWithWrongType_ThenErrorLogShouldBeUploaded()
        {
            _metricHandler?.ResetCount();
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Observation", // not match the resource
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            HttpResponseMessage response;

            while ((response = await _client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));
            }

            Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
            ImportTaskResult result = JsonConvert.DeserializeObject <ImportTaskResult>(await response.Content.ReadAsStringAsync());

            Assert.Single(result.Error);
            Assert.NotEmpty(result.Error.First().Url);

            // Only check metric for local tests
            if (_fixture.IsUsingInProcTestServer)
            {
                var resourceCount    = Regex.Matches(patientNdJsonResource, "{\"resourceType\":").Count;
                var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)];
                Assert.Single(notificationList);
                var notification = notificationList.First() as ImportTaskMetricsNotification;
                Assert.Equal(TaskResult.Success.ToString(), notification.Status);
                Assert.NotNull(notification.DataSize);
                Assert.Equal(0, notification.SucceedCount);
                Assert.Equal(resourceCount, notification.FailedCount);
            }
        }
Exemple #5
0
        public async Task GivenImportOperationEnabled_WhenCancelImportTask_ThenTaskShouldBeCanceled()
        {
            _metricHandler?.ResetCount();
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            var respone = await _client.CancelImport(checkLocation);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await _client.CheckImportAsync(checkLocation));

            Assert.Equal(HttpStatusCode.BadRequest, fhirException.StatusCode);

            // wait task completed
            while (respone.StatusCode != HttpStatusCode.Conflict)
            {
                respone = await _client.CancelImport(checkLocation);

                await Task.Delay(TimeSpan.FromSeconds(3));
            }

            // Only check metric for local tests
            if (_fixture.IsUsingInProcTestServer)
            {
                var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)];
                var notification     = notificationList.First() as ImportTaskMetricsNotification;
                Assert.Single(notificationList);
                Assert.Equal(TaskResult.Canceled.ToString(), notification.Status);
                Assert.Null(notification.SucceedCount);
                Assert.Null(notification.FailedCount);
            }
        }
Exemple #6
0
        public async Task GivenImportOperationEnabled_WhenImportInvalidResource_ThenErrorLogsShouldBeOutput()
        {
            string patientNdJsonResource = Samples.GetNdJson("Import-InvalidPatient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            HttpResponseMessage response;

            while ((response = await _client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));
            }

            Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
            ImportTaskResult result = JsonConvert.DeserializeObject <ImportTaskResult>(await response.Content.ReadAsStringAsync());

            Assert.NotEmpty(result.Output);
            Assert.Equal(1, result.Error.Count);
            Assert.NotEmpty(result.Request);

            string errorLoation = result.Error.ToArray()[0].Url;

            string[] errorContents = (await ImportTestHelper.DownloadFileAsync(errorLoation, _fixture.CloudStorageAccount)).Split("\r\n", StringSplitOptions.RemoveEmptyEntries);
            Assert.Single(errorContents);
        }
Exemple #7
0
        public async Task GivenImportOperationEnabled_WhenImportInvalidResourceUrl_ThenBadRequestShouldBeReturned()
        {
            _metricHandler?.ResetCount();
            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = new Uri("https://fhirtest-invalid.com"),
                        Type = "Patient",
                    },
                },
            };

            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(
                async() =>
            {
                HttpResponseMessage response;
                while ((response = await _client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            });

            Assert.Equal(HttpStatusCode.BadRequest, fhirException.StatusCode);

            // Only check metric for local tests
            if (_fixture.IsUsingInProcTestServer)
            {
                var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)];
                Assert.Single(notificationList);
                var notification = notificationList.First() as ImportTaskMetricsNotification;
                Assert.Equal(TaskResult.Fail.ToString(), notification.Status);
                Assert.Null(notification.DataSize);
                Assert.Null(notification.SucceedCount);
                Assert.Null(notification.FailedCount);
            }
        }
Exemple #8
0
        public async Task GivenImportOperationEnabled_WhenImportOperationTriggeredBeforePreviousTaskCompleted_ThenConflictShouldBeReturned()
        {
            string patientNdJsonResource = Samples.GetNdJson("Import-Patient");

            patientNdJsonResource       = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N"));
            (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource, _fixture.CloudStorageAccount);

            var request = new ImportRequest()
            {
                InputFormat   = "application/fhir+ndjson",
                InputSource   = new Uri("https://other-server.example.org"),
                StorageDetail = new ImportRequestStorageDetail()
                {
                    Type = "azure-blob"
                },
                Input = new List <InputResource>()
                {
                    new InputResource()
                    {
                        Url  = location,
                        Etag = etag,
                        Type = "Patient",
                    },
                },
            };

            request.Mode  = ImportConstants.InitialLoadMode;
            request.Force = true;
            Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

            FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await _client.ImportAsync(request.ToParameters(), CancellationToken.None));

            Assert.Equal(HttpStatusCode.Conflict, fhirException.StatusCode);

            HttpResponseMessage response;

            while ((response = await _client.CheckImportAsync(checkLocation, CancellationToken.None)).StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                await Task.Delay(TimeSpan.FromSeconds(5));
            }
        }