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

Common static server address : Fix #424 #425

Merged
merged 6 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -40,7 +40,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.VersionService;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.Utilities;
Expand All @@ -66,6 +67,7 @@ public void Setup()
this.context = new TestContext();
this.versionService = new Mock<IVersionService>();
this.sessionService = new Mock<ISessionService>();
this.serverConnexionService = new Mock<IServerConnexionService>();
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved
this.sourceList = new SourceList<Iteration>();
this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList);

Expand All @@ -79,6 +81,7 @@ public void Setup()
this.context.Services.AddSingleton(this.authenticationService.Object);
this.context.Services.AddSingleton(this.sessionService.Object);
this.context.Services.AddSingleton(this.versionService.Object);
this.context.Services.AddSingleton(this.serverConnexionService.Object);
this.context.Services.AddSingleton<ILoginViewModel, LoginViewModel>();
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton(this.registrationService.Object);
Expand All @@ -100,6 +103,7 @@ public void Teardown()
private TestContext context;
private Mock<IVersionService> versionService;
private Mock<ISessionService> sessionService;
private Mock<IServerConnexionService> serverConnexionService;
private Mock<IAuthenticationService> authenticationService;
private TestAuthorizationContext authorization;
private SourceList<Iteration> sourceList;
Expand Down
10 changes: 7 additions & 3 deletions COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Components;
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Model.DTO;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;

Expand All @@ -49,13 +50,16 @@ public class LoginTestFixture
private ILoginViewModel viewModel;
private TestContext context;
private Mock<IAuthenticationService> authenticationService;
private Mock<IServerConnexionService> serverConnexionService;

[SetUp]
[SetUp]
public void Setup()
{
this.authenticationService = new Mock<IAuthenticationService>();
this.serverConnexionService = new Mock<IServerConnexionService>();
this.serverConnexionService.Setup(x => x.ServerAddress).Returns("http://localhost.com");
this.context = new TestContext();
this.viewModel = new LoginViewModel(this.authenticationService.Object);
this.viewModel = new LoginViewModel(this.authenticationService.Object, this.serverConnexionService.Object);
this.context.Services.AddSingleton(this.viewModel);
this.context.ConfigureDevExpressBlazor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace COMET.Web.Common.Tests.Components
using COMET.Web.Common.Components.Selectors;
using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Test.Helpers;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Selectors;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void Setup()
this.viewModel.Setup(x => x.SessionService).Returns(sessionService.Object);
this.context.Services.AddSingleton(this.viewModel.Object);
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton<IServerConnexionService, ServerConnexionService>();
this.context.Services.AddSingleton(new Mock<IConfigurationService>().Object);
this.context.Services.AddSingleton(sessionService.Object);
this.context.ConfigureDevExpressBlazor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServerConnexionServiceTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25
// Annex A and Annex C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace COMET.Web.Common.Tests.Services.ServerConnexionService
{
using System.Net;

using COMET.Web.Common.Model;
using COMET.Web.Common.Services.ServerConnexionService;

using Microsoft.Extensions.Options;

using Moq;
using Moq.Protected;

using NUnit.Framework;

[TestFixture]
public class ServerConnexionServiceTestFixture
{
private IServerConnexionService serverConnexionService;

[Test]
public async Task VerifyService()
{
var globalOptions = new GlobalOptions
{
ServerConfigurationFile = null,
};

var options = new Mock<IOptions<GlobalOptions>>();
options.Setup(x => x.Value).Returns(globalOptions);

var handlerMock = new Mock<HttpMessageHandler>();

var json = """
{
"ServerAddress": "http://localhost:5000/"
}
""";

handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(json)
})
.Verifiable();

var httpClient = new HttpClient(handlerMock.Object)
{
BaseAddress = new Uri("http://localhost")
};

this.serverConnexionService = new ServerConnexionService(options.Object, httpClient);

Assert.That(this.serverConnexionService, Is.Not.Null);

await this.serverConnexionService.InitializeService();

Assert.Multiple(() =>
{
Assert.That(this.serverConnexionService.ServerAddress, Is.Not.Null);
Assert.That(this.serverConnexionService.ServerAddress, Is.EqualTo("http://localhost:5000/"));
});
}
}
}
3 changes: 3 additions & 0 deletions COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
<Content Update="wwwroot\DefaultTextConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\server_configuration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
19 changes: 11 additions & 8 deletions COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
<EditForm Context="editFormContext" Model="@(this.ViewModel.AuthenticationDto)" OnValidSubmit="this.ExecuteLogin">
<DataAnnotationsValidator/>
<DxFormLayout CaptionPosition="CaptionPosition.Vertical">
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
<DxTextBox Id="sourceaddress" @bind-Text="@(this.ViewModel.AuthenticationDto.SourceAddress)"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
NullText="Enter the url for the server"
Enabled="@string.IsNullOrEmpty(this.RequestedServer)"/>
</Template>
</DxFormLayoutItem>
@if(this.ViewModel.serverConnexionService.ServerAddress == null)
{
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
<DxTextBox Id="sourceaddress" @bind-Text="@(this.ViewModel.AuthenticationDto.SourceAddress)"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Auto"
NullText="Enter the url for the server"
Enabled="@string.IsNullOrEmpty(this.RequestedServer)" />
</Template>
</DxFormLayoutItem>
}
<DxFormLayoutItem Caption="UserName:" BeginRow="true" ColSpanLg="12">
<Template>
<DxTextBox Id="username" @bind-Text="@(this.ViewModel.AuthenticationDto.UserName)"
Expand Down
1 change: 1 addition & 0 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace COMET.Web.Common.Components
{
using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.ViewModels.Components;

using Microsoft.AspNetCore.Components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace COMET.Web.Common.Components
using CDP4Dal.Events;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.Utilities;
using COMET.Web.Common.ViewModels.Components;

Expand Down Expand Up @@ -70,6 +71,12 @@ public partial class SingleIterationApplicationTemplate: DisposableComponent
[Inject]
public NavigationManager NavigationManager { get; set; }

/// <summary>
/// The <see cref="IServerConnexionService" />
/// </summary>
[Inject]
public IServerConnexionService ServerConnexionService { get; set; }

/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
Expand Down Expand Up @@ -136,7 +143,7 @@ internal void SetCorrectUrl()
{
currentOptions[QueryKeys.IterationKey] = this.ViewModel.SelectedIteration.Iid.ToShortGuid();
currentOptions[QueryKeys.ModelKey] = this.ViewModel.SelectedIteration.IterationSetup.Container.Iid.ToShortGuid();
currentOptions[QueryKeys.ServerKey] = this.ViewModel.SessionService.Session.DataSourceUri;
currentOptions[QueryKeys.ServerKey] = this.ViewModel.SessionService.Session.DataSourceUri;
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved
currentOptions[QueryKeys.DomainKey] = this.ViewModel.SessionService.GetDomainOfExpertise(this.ViewModel.SelectedIteration).Iid.ToShortGuid();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
using COMET.Web.Common.Services.ConfigurationService;
using COMET.Web.Common.Services.NotificationService;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.ServerConnexionService;
using COMET.Web.Common.Services.SessionManagement;
using COMET.Web.Common.Services.VersionService;
using COMET.Web.Common.ViewModels.Components;
using COMET.Web.Common.ViewModels.Components.Publications;
Expand Down Expand Up @@ -82,7 +83,8 @@
private static void RegisterServices(this WebAssemblyHostBuilder builder)
{
builder.Services.AddScoped<IConfigurationService, ConfigurationService>();
builder.Services.AddSingleton<ISessionService, SessionService>();
builder.Services.AddScoped<IServerConnexionService, ServerConnexionService>();
builder.Services.AddSingleton<ISessionService, SessionService>();

Check warning on line 87 in COMET.Web.Common/Extensions/WebAssemblyHostBuilderExtensions.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Extensions/WebAssemblyHostBuilderExtensions.cs#L86-L87

Added lines #L86 - L87 were not covered by tests
builder.Services.AddSingleton<AuthenticationStateProvider, CometWebAuthStateProvider>();
builder.Services.AddSingleton<IAuthenticationService, AuthenticationService>();
builder.Services.AddSingleton<IAutoRefreshService, AutoRefreshService>();
Expand Down
10 changes: 8 additions & 2 deletions COMET.Web.Common/Extensions/WebAssemblyHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace COMET.Web.Common.Extensions
{
using COMET.Web.Common.Services.ConfigurationService;

using COMET.Web.Common.Services.ServerConnexionService;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
nabilatrhea marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
Expand All @@ -42,11 +42,17 @@
public static async Task InitializeServices(this WebAssemblyHost host)
{
var service = host.Services.GetService(typeof(IConfigurationService));
var serverConnexionService = host.Services.GetService(typeof(IServerConnexionService));

Check warning on line 45 in COMET.Web.Common/Extensions/WebAssemblyHostExtensions.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Extensions/WebAssemblyHostExtensions.cs#L45

Added line #L45 was not covered by tests

if (service is ConfigurationService configurationService)
{
await configurationService.InitializeService();
}
}

if (serverConnexionService is ServerConnexionService serverConfigurationService)
{
await serverConfigurationService.InitializeService();
}
}

Check warning on line 56 in COMET.Web.Common/Extensions/WebAssemblyHostExtensions.cs

View check run for this annotation

Codecov / codecov/patch

COMET.Web.Common/Extensions/WebAssemblyHostExtensions.cs#L53-L56

Added lines #L53 - L56 were not covered by tests
}
}
1 change: 0 additions & 1 deletion COMET.Web.Common/Model/DTO/AuthenticationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class AuthenticationDto
/// <summary>
/// Gets or sets the address of the datasource to connect to
/// </summary>
[Required]
[Url]
public string SourceAddress { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions COMET.Web.Common/Model/GlobalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public class GlobalOptions
/// </summary>
public string JsonConfigurationFile { get; set; }

/// <summary>
/// Gets or sets the configuration file used to set server address.
/// </summary>
public string ServerConfigurationFile { get; set; }

/// <summary>
/// Defines the <see cref="Type" /> that should be used as MainLayout
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IServerConnexionService.cs" company="RHEA System S.A.">
// Copyright (c) 2023 RHEA System S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
//
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25
// Annex A and Annex C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Services.ServerConnexionService
{
/// <summary>
/// Service that holds the text data from the configuration file
/// </summary>
public interface IServerConnexionService
{
/// <summary>
/// The Server Address to use
/// </summary>
string ServerAddress { get; }

/// <summary>
/// Initializes the <see cref="IServerConnexionService"/>
/// </summary>
/// <returns>an asynchronous operation</returns>
Task InitializeService();
}
}
Loading
Loading