Skip to content

Commit

Permalink
refactored Ft's AB#107519
Browse files Browse the repository at this point in the history
  • Loading branch information
MitaliSingh16 committed Jan 11, 2024
1 parent fd9df03 commit 058c59c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -157,7 +157,7 @@ public async Task WhenValidRoSMigrateLicencePublishedEventReceivedWithValidPaylo
string generatedXmlFolder = Path.Combine(_projectDir, Config.TestConfig.GeneratedXMLFolder, "RoSPayloadTestData");
List<JsonInputRoSWebhookEvent> listOfEventJsons2 = await JsonHelper.GetEventJsonListUsingFileNameAsync(new List<string> { 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public static async Task<bool> 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
{
Expand All @@ -43,8 +41,8 @@ public async Task<RestResponse> 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");
Expand All @@ -54,14 +52,14 @@ public async Task<RestResponse> 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<RestResponse> PostWebhookResponseAsyncForXML(string correlationId, string payloadFilePath, bool isFirstEvent, bool isLastEvent, string generatedXmlFolder, List<JsonInputRoSWebhookEvent> listOfEventJsons, string token)
public async Task<RestResponse> PostWebhookResponseAsyncForXml(string correlationId, string payloadFilePath, bool isFirstEvent, bool isLastEvent, string generatedXmlFolder, List<JsonInputRoSWebhookEvent> listOfEventJsons, string token)
{
string requestBody;
List<string> blobList = new();
Expand All @@ -86,11 +84,11 @@ public async Task<RestResponse> 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)
{
Expand All @@ -99,7 +97,7 @@ public async Task<RestResponse> 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}.");
Expand Down

0 comments on commit 058c59c

Please sign in to comment.