forked from morganstanley/ComposeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fdc3 App Directory based Module Catalog (morganstanley#396)
* Change IModuleCatalog methods to async * feat(fdc3): Added FDC3 App Directory based Module Catalog implementation
- Loading branch information
Showing
13 changed files
with
268 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/fdc3/dotnet/AppDirectory/src/AppDirectory/Fdc3ModuleCatalog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Morgan Stanley makes this available to you under the Apache License, | ||
* Version 2.0 (the "License"). You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. 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. | ||
*/ | ||
|
||
using MorganStanley.ComposeUI.ModuleLoader; | ||
using MorganStanley.Fdc3.AppDirectory; | ||
|
||
namespace MorganStanley.ComposeUI.Fdc3.AppDirectory; | ||
|
||
public sealed class Fdc3ModuleCatalog : IModuleCatalog | ||
{ | ||
private readonly IAppDirectory _appDirectory; | ||
|
||
public Fdc3ModuleCatalog(IAppDirectory fdc3AppDirectory) | ||
{ | ||
_appDirectory = fdc3AppDirectory; | ||
} | ||
|
||
public async Task<IModuleManifest> GetManifest(string moduleId) | ||
{ | ||
var app = await _appDirectory.GetApp(moduleId); | ||
|
||
switch (app.Type) | ||
{ | ||
case AppType.Web: | ||
return new Fdc3WebModuleManifest(app); | ||
|
||
default: | ||
throw new NotSupportedException($"Unsupported module type: {Enum.GetName(app.Type)}"); | ||
} | ||
} | ||
|
||
public async Task<IEnumerable<string>> GetModuleIds() | ||
{ | ||
var apps = await _appDirectory.GetApps(); | ||
return apps.Select(x => x.AppId); | ||
} | ||
|
||
private class Fdc3WebModuleManifest : IModuleManifest<WebManifestDetails> | ||
{ | ||
public Fdc3WebModuleManifest(Fdc3App app) | ||
{ | ||
if (app.Type != AppType.Web) | ||
{ | ||
throw new ArgumentException("The provided app is not a web app.", nameof(app)); | ||
} | ||
|
||
Id = app.AppId; | ||
Name = app.Name; | ||
|
||
var iconSrc = app.Icons?.FirstOrDefault()?.Src; | ||
var url = new Uri(((WebAppDetails) app.Details).Url, UriKind.Absolute); | ||
|
||
Details = new WebManifestDetails | ||
{ | ||
Url = url, | ||
IconUrl = iconSrc != null ? new Uri(iconSrc, UriKind.Absolute) : null | ||
}; | ||
} | ||
|
||
public WebManifestDetails Details { get; init; } | ||
|
||
public string Id { get; init; } | ||
|
||
public string Name { get; init; } | ||
|
||
public string ModuleType => ModuleLoader.ModuleType.Web; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/fdc3/dotnet/AppDirectory/test/AppDirectory.Tests/Fdc3ModuleCatalog.GetManifest.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Morgan Stanley makes this available to you under the Apache License, | ||
* Version 2.0 (the "License"). You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. 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. | ||
*/ | ||
|
||
using MorganStanley.ComposeUI.ModuleLoader; | ||
|
||
namespace MorganStanley.ComposeUI.Fdc3.AppDirectory; | ||
|
||
public partial class Fdc3ModuleCatalogTests | ||
{ | ||
private readonly IModuleCatalog _catalog; | ||
|
||
public Fdc3ModuleCatalogTests() | ||
{ | ||
var fileSystem = TestUtils.SetUpFileSystemWithSingleFile( | ||
path: "/apps.json", | ||
contents: """ | ||
[ | ||
{ | ||
"appId": "app1", | ||
"name": "App", | ||
"type": "web", | ||
"icons": [ { | ||
"src": "https://example.com/app1/icon.png", | ||
"size": "256x256", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "https://example.com/app1/icon_small.png", | ||
"size": "64x64", | ||
"type": "image/png" | ||
}], | ||
"details": { "url": "https://example.com/app1" } | ||
}, | ||
{ | ||
"appId": "app2", | ||
"name": "AppWithoutIcon", | ||
"type": "web", | ||
"details": { "url": "https://example.com/app2" } | ||
} | ||
] | ||
"""); | ||
|
||
var appDirectory = new AppDirectory( | ||
new AppDirectoryOptions { Source = new Uri("file:///apps.json") }, | ||
fileSystem: fileSystem); | ||
|
||
_catalog = new Fdc3ModuleCatalog(appDirectory); | ||
} | ||
|
||
[Fact] | ||
public async Task GetManifest_returns_web_module_manifest_by_appId() | ||
{ | ||
const string appId = "app1"; | ||
const string appName = "App"; | ||
Uri appUri = new Uri("https://example.com/app1", UriKind.Absolute); | ||
Uri iconUri = new Uri("https://example.com/app1/icon.png", UriKind.Absolute); | ||
var manifest = await _catalog.GetManifest(appId); | ||
manifest.Should().NotBeNull(); | ||
manifest.Id.Should().Be(appId); | ||
manifest.ModuleType.Should().Be(ModuleType.Web); | ||
manifest.Name.Should().Be(appName); | ||
manifest.TryGetDetails<WebManifestDetails>(out var details).Should().BeTrue(); | ||
details.Should().NotBeNull(); | ||
details.Url.Should().Be(appUri); | ||
details.IconUrl.Should().Be(iconUri); | ||
} | ||
|
||
[Fact] | ||
public async Task GetManifest_without_icon_returns_web_module_manifest_by_appId() | ||
{ | ||
const string appId = "app2"; | ||
const string appName = "AppWithoutIcon"; | ||
Uri appUri = new Uri("https://example.com/app2", UriKind.Absolute); | ||
var manifest = await _catalog.GetManifest(appId); | ||
manifest.Should().NotBeNull(); | ||
manifest.Id.Should().Be(appId); | ||
manifest.ModuleType.Should().Be(ModuleType.Web); | ||
manifest.Name.Should().Be(appName); | ||
manifest.TryGetDetails<WebManifestDetails>(out var details).Should().BeTrue(); | ||
details.Should().NotBeNull(); | ||
details.Url.Should().Be(appUri); | ||
details.IconUrl.Should().BeNull(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/fdc3/dotnet/AppDirectory/test/AppDirectory.Tests/Fdc3ModuleCatalog.GetModuleIds.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Morgan Stanley makes this available to you under the Apache License, | ||
* Version 2.0 (the "License"). You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. 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. | ||
*/ | ||
|
||
using MorganStanley.Fdc3.AppDirectory; | ||
|
||
namespace MorganStanley.ComposeUI.Fdc3.AppDirectory; | ||
|
||
public partial class Fdc3ModuleCatalogTests | ||
{ | ||
[Fact] | ||
public async Task GetModuleIds_returns_available_appIds() | ||
{ | ||
var moduleIds = await _catalog.GetModuleIds(); | ||
|
||
moduleIds.Should().HaveCount(2).And.Contain(new[] { "app1", "app2" }); | ||
} | ||
|
||
[Fact] | ||
public async Task GetModuleIds_returns_empty_collection_on_empty_directory() | ||
{ | ||
var directory = new Mock<IAppDirectory>(); | ||
directory.Setup(x => x.GetApps()).Returns(Task.FromResult(Enumerable.Empty<Fdc3App>())); | ||
|
||
var catalog = new Fdc3ModuleCatalog(directory.Object); | ||
|
||
var moduleIds = await catalog.GetModuleIds(); | ||
moduleIds.Should().NotBeNull().And.BeEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.