public async Task GivenAUserWithoutImportPermissions_WhenImportData_ThenServerShouldReturnForbidden() { TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.ReadOnlyUser, TestApplications.NativeClient); string patientNdJsonResource = Samples.GetNdJson("Import-Patient"); (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 = "Patient", }, }, }; request.Mode = ImportConstants.InitialLoadMode; request.Force = true; FhirException fhirException = await Assert.ThrowsAsync <FhirException>(async() => await tempClient.ImportAsync(request.ToParameters(), CancellationToken.None)); Assert.Equal(ForbiddenMessage, fhirException.Message); Assert.Equal(HttpStatusCode.Forbidden, fhirException.StatusCode); }
public async Task GivenAUserWithImportPermissions_WhenImportData_TheServerShouldReturnSuccess() { TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.BulkImportUser, TestApplications.NativeClient); 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 = "Patient", }, }, }; await ImportCheckAsync(request, tempClient); }
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); }
public async Task GivenImportOperationEnabled_WhenImportOperationTriggeredWithoutEtag_ThenDataShouldBeImported() { string patientNdJsonResource = Samples.GetNdJson("Import-Patient"); patientNdJsonResource = Regex.Replace(patientNdJsonResource, "##PatientID##", m => Guid.NewGuid().ToString("N")); (Uri location, string _) = 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 = "Patient", }, }, }; await ImportCheckAsync(request); }
public async Task GivenImportOperationEnabled_WhenImportDuplicatedResource_ThenDupResourceShouldBeCleaned() { string patientNdJsonResource = Samples.GetNdJson("Import-DupPatientTemplate"); string resourceId = Guid.NewGuid().ToString("N"); patientNdJsonResource = patientNdJsonResource.Replace("##PatientID##", resourceId); (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", }, }, }; await ImportCheckAsync(request, errorCount : 1); await ImportCheckAsync(request, errorCount : 2); Patient patient = await _client.ReadAsync <Patient>(ResourceType.Patient, resourceId); Assert.Equal(resourceId, patient.Id); }
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); } }
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); } }
public async Task GivenImportOperationEnabled_WhenImportDuplicatedResource_ThenDupResourceShouldBeCleaned() { _metricHandler?.ResetCount(); string patientNdJsonResource = Samples.GetNdJson("Import-DupPatientTemplate"); string resourceId = Guid.NewGuid().ToString("N"); patientNdJsonResource = patientNdJsonResource.Replace("##PatientID##", resourceId); (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", }, }, }; await ImportCheckAsync(request, errorCount : 1); await ImportCheckAsync(request, errorCount : 2); Patient patient = await _client.ReadAsync <Patient>(ResourceType.Patient, resourceId); Assert.Equal(resourceId, patient.Id); // Only check metric for local tests if (_fixture.IsUsingInProcTestServer) { var notificationList = _metricHandler.NotificationMapping[typeof(ImportTaskMetricsNotification)]; Assert.Equal(2, notificationList.Count); var notification1 = notificationList.First() as ImportTaskMetricsNotification; Assert.Equal(TaskResult.Success.ToString(), notification1.Status); Assert.Equal(1, notification1.SucceedCount); Assert.Equal(1, notification1.FailedCount); var notification2 = notificationList[1] as ImportTaskMetricsNotification; Assert.Equal(TaskResult.Success.ToString(), notification1.Status); Assert.Equal(0, notification2.SucceedCount); Assert.Equal(2, notification2.FailedCount); } }
public async Task GivenImportOperationEnabled_WhenImportOperationTriggeredWithMultipleFiles_ThenDataShouldBeImported() { _metricHandler?.ResetCount(); string patientNdJsonResource = Samples.GetNdJson("Import-SinglePatientTemplate"); string resourceId1 = Guid.NewGuid().ToString("N"); string patientNdJsonResource1 = patientNdJsonResource.Replace("##PatientID##", resourceId1); string resourceId2 = Guid.NewGuid().ToString("N"); string patientNdJsonResource2 = patientNdJsonResource.Replace("##PatientID##", resourceId2); (Uri location1, string _) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource1, _fixture.CloudStorageAccount); (Uri location2, string _) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource2, _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 = location1, Type = "Patient", }, new InputResource() { Url = location2, Type = "Patient", }, }, }; await ImportCheckAsync(request); // Only check metric for local tests if (_fixture.IsUsingInProcTestServer) { var resourceCount = Regex.Matches(patientNdJsonResource, "{\"resourceType\":").Count * 2; 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(resourceCount, notification.SucceedCount); Assert.Equal(0, notification.FailedCount); } }
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); }
public static async Task ImportToServerAsync(TestFhirClient testFhirClient, CloudStorageAccount cloudStorageAccount, params Resource[] resources) { Dictionary <string, StringBuilder> contentBuilders = new Dictionary <string, StringBuilder>(); foreach (Resource resource in resources) { string resourceType = resource.TypeName.ToString(); if (!contentBuilders.ContainsKey(resourceType)) { contentBuilders[resourceType] = new StringBuilder(); } contentBuilders[resourceType].AppendLine(_fhirJsonSerializer.SerializeToString(resource)); } var inputFiles = new List <InputResource>(); foreach ((string key, StringBuilder builder) in contentBuilders) { (Uri location, string etag) = await ImportTestHelper.UploadFileAsync(builder.ToString(), cloudStorageAccount); inputFiles.Add(new InputResource() { Etag = etag, Url = location, Type = key, }); } var request = new ImportRequest() { InputFormat = "application/fhir+ndjson", InputSource = new Uri("https://other-server.example.org"), StorageDetail = new ImportRequestStorageDetail() { Type = "azure-blob" }, Input = inputFiles, }; await ImportCheckAsync(testFhirClient, request); }
public async Task GivenAUserWithImportPermissions_WhenImportData_TheServerShouldReturnSuccess() { _metricHandler?.ResetCount(); TestFhirClient tempClient = _client.CreateClientForUser(TestUsers.BulkImportUser, TestApplications.NativeClient); 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 = "Patient", }, }, }; await ImportCheckAsync(request, tempClient); // 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(resourceCount, notification.SucceedCount); Assert.Equal(0, notification.FailedCount); } }
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)); } }
public async Task GivenImportOperationEnabled_WhenImportOperationTriggeredWithMultipleFiles_ThenDataShouldBeImported() { string patientNdJsonResource = Samples.GetNdJson("Import-SinglePatientTemplate"); string resourceId1 = Guid.NewGuid().ToString("N"); string patientNdJsonResource1 = patientNdJsonResource.Replace("##PatientID##", resourceId1); string resourceId2 = Guid.NewGuid().ToString("N"); string patientNdJsonResource2 = patientNdJsonResource.Replace("##PatientID##", resourceId2); (Uri location1, string _) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource1, _fixture.CloudStorageAccount); (Uri location2, string _) = await ImportTestHelper.UploadFileAsync(patientNdJsonResource2, _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 = location1, Type = "Patient", }, new InputResource() { Url = location2, Type = "Patient", }, }, }; await ImportCheckAsync(request); }