From 4a7f585ae8a89f4a47b8a759ace1fdb4be3151ec Mon Sep 17 00:00:00 2001 From: Stephanie Buadu <47737608+acn-sbuad@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:06:20 +0100 Subject: [PATCH] Renamed gateway settings file #GCPActive (#12) * Added logging on failure for sms client #GCPActive * renamed gateway config file * fixed test --- .../Configuration/ServiceCollectionExtensions.cs | 4 ++-- .../LinkMobility/AltinnGatewayClient.cs | 2 +- .../LinkMobility/SmsClient.cs | 9 ++++++++- ...GatewayConfiguration.cs => SmsGatewaySettings.cs} | 2 +- src/Altinn.Notifications.Sms/appsettings.json | 2 +- .../ServiceCollectionExtensionsTests.cs | 4 ++-- .../Sms.Integrations/SmsClientTests.cs | 12 ++++++++---- 7 files changed, 23 insertions(+), 12 deletions(-) rename src/Altinn.Notifications.Sms.Integrations/LinkMobility/{SmsGatewayConfiguration.cs => SmsGatewaySettings.cs} (94%) diff --git a/src/Altinn.Notifications.Sms.Integrations/Configuration/ServiceCollectionExtensions.cs b/src/Altinn.Notifications.Sms.Integrations/Configuration/ServiceCollectionExtensions.cs index 5e2a21f..5dbf4fb 100644 --- a/src/Altinn.Notifications.Sms.Integrations/Configuration/ServiceCollectionExtensions.cs +++ b/src/Altinn.Notifications.Sms.Integrations/Configuration/ServiceCollectionExtensions.cs @@ -27,8 +27,8 @@ public static IServiceCollection AddIntegrationServices(this IServiceCollection { throw new ArgumentNullException(nameof(config), "Required Kafka settings is missing from application configuration"); } - - SmsGatewayConfiguration smsGatewaySettings = config!.GetSection(nameof(SmsGatewayConfiguration)).Get()!; + + SmsGatewaySettings smsGatewaySettings = config!.GetSection(nameof(SmsGatewaySettings)).Get()!; if (smsGatewaySettings == null) { diff --git a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/AltinnGatewayClient.cs b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/AltinnGatewayClient.cs index 5ee1933..4a133a2 100644 --- a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/AltinnGatewayClient.cs +++ b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/AltinnGatewayClient.cs @@ -19,7 +19,7 @@ public class AltinnGatewayClient : IAltinnGatewayClient /// /// Initializes a new instance of the class. /// - public AltinnGatewayClient(SmsGatewayConfiguration gatewayConfig) + public AltinnGatewayClient(SmsGatewaySettings gatewayConfig) { _client = new(new XmlTransport(gatewayConfig.Username, gatewayConfig.Password, new Uri(gatewayConfig.Endpoint))); } diff --git a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsClient.cs b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsClient.cs index 7a9971a..002316f 100644 --- a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsClient.cs +++ b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsClient.cs @@ -2,8 +2,11 @@ using Altinn.Notifications.Sms.Core.Sending; using Altinn.Notifications.Sms.Core.Shared; using Altinn.Notifications.Sms.Core.Status; + using LinkMobility.PSWin.Client.Model; +using Microsoft.Extensions.Logging; + using LinkMobilityModel = global::LinkMobility.PSWin.Client.Model; namespace Altinn.Notifications.Sms.Integrations.LinkMobility @@ -15,14 +18,17 @@ namespace Altinn.Notifications.Sms.Integrations.LinkMobility public class SmsClient : ISmsClient { private readonly IAltinnGatewayClient _client; + private readonly ILogger _logger; /// /// Initializes a new instance of the class. /// /// Gateway Client - public SmsClient(IAltinnGatewayClient client) + /// Logger + public SmsClient(IAltinnGatewayClient client, ILogger logger) { _client = client; + _logger = logger; } /// @@ -40,6 +46,7 @@ public async Task> SendAsync(Core.Sending return new SmsClientErrorResponse { SendResult = SmsSendResult.Failed_InvalidReceiver, ErrorMessage = result.StatusText }; } + _logger.LogInformation("// SmsClient // SendAsync // Failed to send SMS. Status: {StatusText}", result.StatusText); return new SmsClientErrorResponse { SendResult = SmsSendResult.Failed }; } } diff --git a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewayConfiguration.cs b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewaySettings.cs similarity index 94% rename from src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewayConfiguration.cs rename to src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewaySettings.cs index a76ca4e..e9423cb 100644 --- a/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewayConfiguration.cs +++ b/src/Altinn.Notifications.Sms.Integrations/LinkMobility/SmsGatewaySettings.cs @@ -3,7 +3,7 @@ /// /// Configuration for the LinkMobility SMS gateway /// - public class SmsGatewayConfiguration + public class SmsGatewaySettings { /// /// Username to use for authentication towards the SMS gateway diff --git a/src/Altinn.Notifications.Sms/appsettings.json b/src/Altinn.Notifications.Sms/appsettings.json index 4cc0e44..d7e7231 100644 --- a/src/Altinn.Notifications.Sms/appsettings.json +++ b/src/Altinn.Notifications.Sms/appsettings.json @@ -26,7 +26,7 @@ "SendSmsQueueRetryTopicName": "altinn.notifications.sms.queue.retry", "AltinnServiceUpdateTopicName ": "altinn.platform.service.updated" }, - "SmsGatewayConfiguration": { + "SmsGatewaySettings": { "Username": "", "Password": "", "Endpoint": "https://xml-test.pswin.com" diff --git a/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/ServiceCollectionExtensionsTests.cs b/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/ServiceCollectionExtensionsTests.cs index ce5dc96..d23f940 100644 --- a/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/ServiceCollectionExtensionsTests.cs +++ b/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/ServiceCollectionExtensionsTests.cs @@ -30,7 +30,7 @@ public void AddIntegrationServices_MissingKafkaConfig_ThrowsException() { // Arrange Environment.SetEnvironmentVariable("KafkaSettings__BrokerAddress", null, EnvironmentVariableTarget.Process); - Environment.SetEnvironmentVariable("SmsGatewayConfiguration__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable("SmsGatewaySettings__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process); string expectedExceptionMessage = "Required Kafka settings is missing from application configuration (Parameter 'config')"; var config = new ConfigurationBuilder().AddEnvironmentVariables().Build(); @@ -48,7 +48,7 @@ public void AddIntegrationServices_MissingKafkaConfig_ThrowsException() public void AddIntegrationServices_SmsGatewayConfigIncluded_NoException() { // Arrange - Environment.SetEnvironmentVariable("SmsGatewayConfiguration__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process); + Environment.SetEnvironmentVariable("SmsGatewaySettings__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("KafkaSettings__BrokerAddress", "localhost:9092", EnvironmentVariableTarget.Process); var config = new ConfigurationBuilder().AddEnvironmentVariables().Build(); diff --git a/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/SmsClientTests.cs b/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/SmsClientTests.cs index a59e2ee..de549fe 100644 --- a/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/SmsClientTests.cs +++ b/test/Altinn.Notifications.Sms.Tests/Sms.Integrations/SmsClientTests.cs @@ -1,9 +1,12 @@ -using Altinn.Notifications.Sms.Core.Status; +using Altinn.Notifications.Sms.Core.Dependencies; +using Altinn.Notifications.Sms.Core.Status; using Altinn.Notifications.Sms.Integrations.LinkMobility; using LinkMobility.PSWin.Client.Model; +using Microsoft.Extensions.Logging; + using Moq; using LinkMobilityModel = global::LinkMobility.PSWin.Client.Model; @@ -13,6 +16,7 @@ namespace Altinn.Notifications.Sms.Tests.Sms.Integrations public class SmsClientTests { private readonly Mock _clientMock = new(); + private readonly Mock> _loggerMock = new(); [Fact] public async Task SendAsync_GatewayReturnsNonSuccess_UnknownError() @@ -23,7 +27,7 @@ public async Task SendAsync_GatewayReturnsNonSuccess_UnknownError() _clientMock.Setup(cm => cm.SendAsync(It.IsAny())) .ReturnsAsync(gatewayResult); - SmsClient smsClient = new(_clientMock.Object); + SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object); // Act var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms()); @@ -52,7 +56,7 @@ public async Task SendAsync_GatewayReturnsNonSuccess_InvalidReceiver() _clientMock.Setup(cm => cm.SendAsync(It.IsAny())) .ReturnsAsync(gatewayResult); - SmsClient smsClient = new(_clientMock.Object); + SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object); // Act var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms()); @@ -84,7 +88,7 @@ public async Task SendAsync_GatewayReturnsSuccess_GatewayRefReturned() _clientMock.Setup(cm => cm.SendAsync(It.IsAny())) .ReturnsAsync(gatewayResult); - SmsClient smsClient = new(_clientMock.Object); + SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object); // Act var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms());