Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connector discovery endpoint without body #543

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.IO;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
Expand Down Expand Up @@ -335,12 +336,12 @@ private static void RemoveConnectorAssignedOfferSubscriptions(Guid connectorId,
}

/// <inheritdoc/>
public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync(IEnumerable<string> bpns)
public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync(IEnumerable<string>? bpns)
{
if (bpns.Any(bpn => !bpnRegex.IsMatch(bpn)))
{
throw ControllerArgumentException.Create(AdministrationConnectorErrors.CONNECTOR_ARGUMENT_INCORRECT_BPN, new ErrorParameter[] { new("bpns", string.Join(", ", bpns.Where(bpn => !bpnRegex.IsMatch(bpn)))) });
}
bpns ??= Enumerable.Empty<string>();

bpns.Where(bpn => !bpnRegex.IsMatch(bpn)).IfAny(invalid =>
throw ControllerArgumentException.Create(AdministrationConnectorErrors.CONNECTOR_ARGUMENT_INCORRECT_BPN, new ErrorParameter[] { new("bpns", string.Join(", ", invalid)) }));

return _portalRepositories.GetInstance<IConnectorsRepository>()
.GetConnectorEndPointDataAsync(bpns.Select(x => x.ToUpper()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface IConnectorsBusinessLogic
/// </summary>
/// <param name="bpns"></param>
/// <returns></returns>
IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync(IEnumerable<string> bpns);
IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync(IEnumerable<string>? bpns);

/// <summary>
/// Processes the clearinghouse self description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task<IActionResult> DeleteConnectorAsync([FromRoute] Guid connector
[Authorize(Roles = "view_connectors")]
[ProducesResponseType(typeof(IAsyncEnumerable<ConnectorEndPointData>), StatusCodes.Status200OK)]
[PublicUrl(CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.ACTIVE_PARTICIPANT)]
public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync([FromBody] IEnumerable<string> bpns) =>
public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync([FromBody] IEnumerable<string>? bpns = null) =>
_businessLogic.GetCompanyConnectorEndPointAsync(bpns);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,31 @@ public async Task GetCompanyConnectorEndPoint_WithValidData_ReturnsExpectedResul
result.Should().HaveCount(3).And.Satisfy(
x => x.Bpn == "BPNL00000002CRHL" && x.ConnectorEndpoint.Count() == 1 && x.ConnectorEndpoint.Contains("www.googlr5.com"),
x => x.Bpn == "BPNL00000003CRHL" && x.ConnectorEndpoint.Count() == 2 && x.ConnectorEndpoint.Contains("www.googlr0.com") && x.ConnectorEndpoint.Contains("www.googlr1.com"),
x => x.Bpn == "BPNL00000004CRHL" && x.ConnectorEndpoint.Count() == 3 && x.ConnectorEndpoint.Contains("www.googlr2.com") && x.ConnectorEndpoint.Contains("www.googlr3.com") && x.ConnectorEndpoint.Contains("www.googlr4.com")
);
x => x.Bpn == "BPNL00000004CRHL" && x.ConnectorEndpoint.Count() == 3 && x.ConnectorEndpoint.Contains("www.googlr2.com") && x.ConnectorEndpoint.Contains("www.googlr3.com") && x.ConnectorEndpoint.Contains("www.googlr4.com"));
}

[Fact]
public async Task GetCompanyConnectorEndPoint_WithNull_ReturnsExpectedResult()
{
//Arrange
A.CallTo(() => _connectorsRepository.GetConnectorEndPointDataAsync(A<IEnumerable<string>>._))
.Returns(new[] {
(BusinessPartnerNumber: "BPNL00000002CRHL", ConnectorEndPoint: "www.googlr5.com"),
(BusinessPartnerNumber: "BPNL00000003CRHL", ConnectorEndPoint: "www.googlr0.com"),
(BusinessPartnerNumber: "BPNL00000003CRHL", ConnectorEndPoint: "www.googlr1.com"),
(BusinessPartnerNumber: "BPNL00000004CRHL", ConnectorEndPoint: "www.googlr2.com"),
(BusinessPartnerNumber: "BPNL00000004CRHL", ConnectorEndPoint: "www.googlr3.com"),
(BusinessPartnerNumber: "BPNL00000004CRHL", ConnectorEndPoint: "www.googlr4.com")
}.ToAsyncEnumerable());

//Act
var result = await _logic.GetCompanyConnectorEndPointAsync(null).ToListAsync().ConfigureAwait(false);

//Assert
result.Should().HaveCount(3).And.Satisfy(
x => x.Bpn == "BPNL00000002CRHL" && x.ConnectorEndpoint.Count() == 1 && x.ConnectorEndpoint.Contains("www.googlr5.com"),
x => x.Bpn == "BPNL00000003CRHL" && x.ConnectorEndpoint.Count() == 2 && x.ConnectorEndpoint.Contains("www.googlr0.com") && x.ConnectorEndpoint.Contains("www.googlr1.com"),
x => x.Bpn == "BPNL00000004CRHL" && x.ConnectorEndpoint.Count() == 3 && x.ConnectorEndpoint.Contains("www.googlr2.com") && x.ConnectorEndpoint.Contains("www.googlr3.com") && x.ConnectorEndpoint.Contains("www.googlr4.com"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;
using Org.Eclipse.TractusX.Portal.Backend.SdFactory.Library.Models;
using Org.Eclipse.TractusX.Portal.Backend.Tests.Shared.Extensions;
using System.Collections.Immutable;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Tests.Controllers;

Expand Down Expand Up @@ -59,7 +60,7 @@ public async Task GetManagedConnectorsForCurrentUserAsync_WithValidData_ReturnsE
.Returns(paginationResponse);

//Act
var result = await this._controller.GetManagedConnectorsForCurrentUserAsync().ConfigureAwait(false);
var result = await _controller.GetManagedConnectorsForCurrentUserAsync().ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.GetManagedConnectorForCompany(0, 15)).MustHaveHappenedOnceExactly();
Expand All @@ -80,7 +81,7 @@ public async Task CreateConnectorAsync_WithValidData_ReturnsExpectedResult()
.Returns(connectorId);

//Act
var result = await this._controller.CreateConnectorAsync(connectorInputModel, CancellationToken.None).ConfigureAwait(false);
var result = await _controller.CreateConnectorAsync(connectorInputModel, CancellationToken.None).ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.CreateConnectorAsync(connectorInputModel, A<CancellationToken>._)).MustHaveHappenedOnceExactly();
Expand All @@ -103,7 +104,7 @@ public async Task CreateManagedConnectorAsync_WithValidData_ReturnsExpectedResul
.Returns(connectorId);

//Act
var result = await this._controller.CreateManagedConnectorAsync(connectorInputModel, CancellationToken.None).ConfigureAwait(false);
var result = await _controller.CreateManagedConnectorAsync(connectorInputModel, CancellationToken.None).ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.CreateManagedConnectorAsync(connectorInputModel, A<CancellationToken>._)).MustHaveHappenedOnceExactly();
Expand All @@ -120,7 +121,7 @@ public async Task GetCompanyConnectorsForCurrentUser_WithValidData_ReturnsExpect
.Returns(paginationResponse);

//Act
var result = await this._controller.GetCompanyConnectorsForCurrentUserAsync().ConfigureAwait(false);
var result = await _controller.GetCompanyConnectorsForCurrentUserAsync().ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.GetAllCompanyConnectorDatas(0, 15)).MustHaveHappenedOnceExactly();
Expand All @@ -137,7 +138,7 @@ public async Task GetCompanyConnectorByIdForCurrentUserAsync_WithValidData_Retur
.Returns(data);

//Act
var result = await this._controller.GetCompanyConnectorByIdForCurrentUserAsync(connectorId).ConfigureAwait(false);
var result = await _controller.GetCompanyConnectorByIdForCurrentUserAsync(connectorId).ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.GetCompanyConnectorData(connectorId)).MustHaveHappenedOnceExactly();
Expand All @@ -151,7 +152,7 @@ public async Task DeleteConnector_WithValidData_ReturnsExpectedResult()
var connectorId = Guid.NewGuid();

//Act
await this._controller.DeleteConnectorAsync(connectorId).ConfigureAwait(false);
await _controller.DeleteConnectorAsync(connectorId).ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.DeleteConnectorAsync(connectorId)).MustHaveHappenedOnceExactly();
Expand All @@ -161,21 +162,40 @@ public async Task DeleteConnector_WithValidData_ReturnsExpectedResult()
public async Task GetCompanyConnectorEndPoint_WithValidData_ReturnsExpectedResult()
{
//Arrange
var data = _fixture.CreateMany<ConnectorEndPointData>(5);
var data = _fixture.CreateMany<ConnectorEndPointData>(5).ToImmutableArray();
var bpns = new[]
{
"1",
"2"
};
A.CallTo(() => _logic.GetCompanyConnectorEndPointAsync(bpns))
A.CallTo(() => _logic.GetCompanyConnectorEndPointAsync(A<IEnumerable<string>?>._))
.Returns(data.ToAsyncEnumerable());

//Act
var result = await this._controller.GetCompanyConnectorEndPointAsync(bpns).ToListAsync().ConfigureAwait(false);
var result = await _controller.GetCompanyConnectorEndPointAsync(bpns).ToListAsync().ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.GetCompanyConnectorEndPointAsync(bpns)).MustHaveHappenedOnceExactly();
result.Should().HaveCount(5);
result.Should().HaveSameCount(data)
.And.ContainInOrder(data);
}

[Fact]
public async Task GetCompanyConnectorEndPoint_WithNull_ReturnsExpectedResult()
{
//Arrange
var data = _fixture.CreateMany<ConnectorEndPointData>(5).ToImmutableArray();

A.CallTo(() => _logic.GetCompanyConnectorEndPointAsync(A<IEnumerable<string>?>._))
.Returns(data.ToAsyncEnumerable());

//Act
var result = await _controller.GetCompanyConnectorEndPointAsync().ToListAsync().ConfigureAwait(false);

//Assert
A.CallTo(() => _logic.GetCompanyConnectorEndPointAsync(null)).MustHaveHappenedOnceExactly();
result.Should().HaveSameCount(data)
.And.ContainInOrder(data);
}

[Fact]
Expand All @@ -185,7 +205,7 @@ public async Task ProcessClearinghouseSelfDescription_ReturnsExpectedResult()
var data = new SelfDescriptionResponseData(Guid.NewGuid(), SelfDescriptionStatus.Confirm, null, "{ \"test\": true }");

// Act
var result = await this._controller.ProcessClearinghouseSelfDescription(data, CancellationToken.None);
var result = await _controller.ProcessClearinghouseSelfDescription(data, CancellationToken.None);

// Assert
A.CallTo(() => _logic.ProcessClearinghouseSelfDescription(data, A<CancellationToken>._)).MustHaveHappenedOnceExactly();
Expand All @@ -200,7 +220,7 @@ public async Task UpdateConnectorUrl_ReturnsExpectedResult()
var data = new ConnectorUpdateRequest("https://test.com");

// Act
var result = await this._controller.UpdateConnectorUrl(connectorId, data);
var result = await _controller.UpdateConnectorUrl(connectorId, data);

// Assert
A.CallTo(() => _logic.UpdateConnectorUrl(connectorId, data)).MustHaveHappenedOnceExactly();
Expand All @@ -211,14 +231,15 @@ public async Task UpdateConnectorUrl_ReturnsExpectedResult()
public async Task GetConnectorOfferSubscriptionData_ReturnsExpectedResult()
{
// Arrange
var offerSubscriptionData = _fixture.CreateMany<OfferSubscriptionConnectorData>(5);
var offerSubscriptionData = _fixture.CreateMany<OfferSubscriptionConnectorData>(5).ToImmutableArray();
A.CallTo(() => _logic.GetConnectorOfferSubscriptionData(null))
.Returns(offerSubscriptionData.ToAsyncEnumerable());

// Act
var result = await this._controller.GetConnectorOfferSubscriptionData(null).ToListAsync().ConfigureAwait(false);
var result = await _controller.GetConnectorOfferSubscriptionData(null).ToListAsync().ConfigureAwait(false);

// Assert
result.Should().HaveCount(5);
result.Should().HaveSameCount(offerSubscriptionData)
.And.ContainInOrder(offerSubscriptionData);
}
}
Loading