From 058c59c0d270eb7605b4acc4738a736fa65fd6e6 Mon Sep 17 00:00:00 2001 From: Mitali Singh Date: Thu, 11 Jan 2024 13:21:22 +0530 Subject: [PATCH] refactored Ft's AB#107519 --- .../FunctionalTests/RoSWebhookScenarios.cs | 6 ++--- .../Helpers/RoSXMLHelper.cs | 1 - .../Service/RoSWebhookEndpoint.cs | 22 +++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/UKHO.ERPFacade.API.FunctionalTests/FunctionalTests/RoSWebhookScenarios.cs b/tests/UKHO.ERPFacade.API.FunctionalTests/FunctionalTests/RoSWebhookScenarios.cs index a6ea618c..dde5b10c 100644 --- a/tests/UKHO.ERPFacade.API.FunctionalTests/FunctionalTests/RoSWebhookScenarios.cs +++ b/tests/UKHO.ERPFacade.API.FunctionalTests/FunctionalTests/RoSWebhookScenarios.cs @@ -133,14 +133,14 @@ public async Task WhenValidRoSEventsReceivedWithValidPayloadsForMerging_ThenWebh //Send first event string firstEventPayloadJsonFilePath = Path.Combine(_projectDir, Config.TestConfig.PayloadFolder, "RoSPayloadTestData", firstEventPayloadJsonFileName); - RestResponse firstEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXML(generatedCorrelationId, firstEventPayloadJsonFilePath, true, false, generatedXmlFolder, null, await _authToken.GetAzureADToken(false)); + RestResponse firstEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXml(generatedCorrelationId, firstEventPayloadJsonFilePath, true, false, generatedXmlFolder, null, await _authToken.GetAzureADToken(false)); //Assert if ROS webhook returns OK firstEventResponse.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); //Send last event - Additionally we need to send list of all json files to compare total unitofsales items with final XML payload string lastEventPayloadJsonFilePath = Path.Combine(_projectDir, Config.TestConfig.PayloadFolder, "RoSPayloadTestData", lastEventPayloadJsonFileName); - RestResponse lastEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXML(generatedCorrelationId, lastEventPayloadJsonFilePath, false, true, generatedXmlFolder, listOfEventJsons, await _authToken.GetAzureADToken(false)); + RestResponse lastEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXml(generatedCorrelationId, lastEventPayloadJsonFilePath, false, true, generatedXmlFolder, listOfEventJsons, await _authToken.GetAzureADToken(false)); //Assert if ROS webhook returns OK lastEventResponse.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); @@ -157,7 +157,7 @@ public async Task WhenValidRoSMigrateLicencePublishedEventReceivedWithValidPaylo string generatedXmlFolder = Path.Combine(_projectDir, Config.TestConfig.GeneratedXMLFolder, "RoSPayloadTestData"); List listOfEventJsons2 = await JsonHelper.GetEventJsonListUsingFileNameAsync(new List { firstEventPayloadJsonFileName }); string firstEventPayloadJsonFilePath = Path.Combine(_projectDir, Config.TestConfig.PayloadFolder, "RoSPayloadTestData", firstEventPayloadJsonFileName); - RestResponse firstEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXML(generatedCorrelationId, firstEventPayloadJsonFilePath, true, true, generatedXmlFolder, listOfEventJsons2, await _authToken.GetAzureADToken(false)); + RestResponse firstEventResponse = await RosWebhookEndpoint.PostWebhookResponseAsyncForXml(generatedCorrelationId, firstEventPayloadJsonFilePath, true, true, generatedXmlFolder, listOfEventJsons2, await _authToken.GetAzureADToken(false)); firstEventResponse.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); } } diff --git a/tests/UKHO.ERPFacade.API.FunctionalTests/Helpers/RoSXMLHelper.cs b/tests/UKHO.ERPFacade.API.FunctionalTests/Helpers/RoSXMLHelper.cs index 04058cbe..b693313c 100644 --- a/tests/UKHO.ERPFacade.API.FunctionalTests/Helpers/RoSXMLHelper.cs +++ b/tests/UKHO.ERPFacade.API.FunctionalTests/Helpers/RoSXMLHelper.cs @@ -250,7 +250,6 @@ public static async Task CheckXmlAttributes(string generatedXmlFilePath, s s_attrNotMatched.Add(nameof(rosXmlPayload.LTYPE)); if (!rosXmlPayload.LICDUR.Equals(roSJsonPayload.licenceDuration)) s_attrNotMatched.Add(nameof(rosXmlPayload.LICDUR)); - if (!rosXmlPayload.PO.Equals(roSJsonPayload.poref)) s_attrNotMatched.Add(nameof(rosXmlPayload.PO)); if (!rosXmlPayload.ADSORDNO.Equals(roSJsonPayload.ordernumber)) diff --git a/tests/UKHO.ERPFacade.API.FunctionalTests/Service/RoSWebhookEndpoint.cs b/tests/UKHO.ERPFacade.API.FunctionalTests/Service/RoSWebhookEndpoint.cs index 8ca5f76e..52248035 100644 --- a/tests/UKHO.ERPFacade.API.FunctionalTests/Service/RoSWebhookEndpoint.cs +++ b/tests/UKHO.ERPFacade.API.FunctionalTests/Service/RoSWebhookEndpoint.cs @@ -1,7 +1,6 @@ using NUnit.Framework; using RestSharp; using System.Net; -using Microsoft.Identity.Client; using UKHO.ERPFacade.API.FunctionalTests.Configuration; using UKHO.ERPFacade.API.FunctionalTests.Helpers; using UKHO.ERPFacade.API.FunctionalTests.Model; @@ -13,10 +12,9 @@ public class RoSWebhookEndpoint { private readonly RestClient _client; private readonly AzureBlobStorageHelper _azureBlobStorageHelper; - private const string RoSWebhookRequestEndPoint = "/webhook/recordofsalepublishedeventreceived"; - public static string generatedCorrelationId = string.Empty; - public static string recordOfSalesContainerName = "recordofsaleblobs"; + public static string GeneratedCorrelationId = string.Empty; + public static string RecordOfSalesContainerName = "recordofsaleblobs"; public RoSWebhookEndpoint() { @@ -43,8 +41,8 @@ public async Task PostWebhookResponseAsync(string payloadFilePath, requestBody = streamReader.ReadToEnd(); } - generatedCorrelationId = SAPXmlHelper.GenerateRandomCorrelationId(); - requestBody = SAPXmlHelper.UpdateTimeAndCorrIdField(requestBody, generatedCorrelationId); + GeneratedCorrelationId = SAPXmlHelper.GenerateRandomCorrelationId(); + requestBody = SAPXmlHelper.UpdateTimeAndCorrIdField(requestBody, GeneratedCorrelationId); var request = new RestRequest(RoSWebhookRequestEndPoint, Method.Post); request.AddHeader("Content-Type", "application/json"); @@ -54,14 +52,14 @@ public async Task PostWebhookResponseAsync(string payloadFilePath, if (response.StatusCode == HttpStatusCode.OK) { - bool isBlobCreated = _azureBlobStorageHelper.VerifyBlobExists(recordOfSalesContainerName, generatedCorrelationId); - Assert.That(isBlobCreated, Is.True, $"Blob {generatedCorrelationId} not created"); + bool isBlobCreated = _azureBlobStorageHelper.VerifyBlobExists(RecordOfSalesContainerName, GeneratedCorrelationId); + Assert.That(isBlobCreated, Is.True, $"Blob {GeneratedCorrelationId} not created"); } return response; } - public async Task PostWebhookResponseAsyncForXML(string correlationId, string payloadFilePath, bool isFirstEvent, bool isLastEvent, string generatedXmlFolder, List listOfEventJsons, string token) + public async Task PostWebhookResponseAsyncForXml(string correlationId, string payloadFilePath, bool isFirstEvent, bool isLastEvent, string generatedXmlFolder, List listOfEventJsons, string token) { string requestBody; List blobList = new(); @@ -86,11 +84,11 @@ public async Task PostWebhookResponseAsyncForXML(string correlatio if (isFirstEvent) { - bool isBlobCreated = _azureBlobStorageHelper.VerifyBlobExists(recordOfSalesContainerName, correlationId); + bool isBlobCreated = _azureBlobStorageHelper.VerifyBlobExists(RecordOfSalesContainerName, correlationId); Assert.That(isBlobCreated, Is.True, $"Blob for {correlationId} not created"); } - blobList = _azureBlobStorageHelper.GetBlobNamesInFolder(recordOfSalesContainerName, correlationId); + blobList = _azureBlobStorageHelper.GetBlobNamesInFolder(RecordOfSalesContainerName, correlationId); switch (isLastEvent) { @@ -99,7 +97,7 @@ public async Task PostWebhookResponseAsyncForXML(string correlatio //10minutes polling after every 30 seconds to check if xml payload is generated during webjob execution. while (!blobList.Contains("SapXmlPayload") && DateTime.UtcNow - startTime < TimeSpan.FromMinutes(10)) { - blobList = _azureBlobStorageHelper.GetBlobNamesInFolder(recordOfSalesContainerName, correlationId); + blobList = _azureBlobStorageHelper.GetBlobNamesInFolder(RecordOfSalesContainerName, correlationId); await Task.Delay(30000); } Assert.That(blobList, Does.Contain("SapXmlPayload"), $"XML is not generated for {correlationId} at {DateTime.Now}.");