-
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.
Return relevant items in STAC search (#267)
- Loading branch information
Showing
10 changed files
with
260 additions
and
7 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
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,15 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace Geopilot.Api; | ||
|
||
internal sealed class GeopilotApiApp : WebApplicationFactory<GeopilotApiApp> | ||
{ | ||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
base.ConfigureWebHost(builder); | ||
|
||
builder.UseEnvironment("Development"); | ||
builder.UseContentRoot(Directory.GetCurrentDirectory()); | ||
} | ||
} |
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,42 @@ | ||
using Geopilot.Api; | ||
using Geopilot.Api.StacServices; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Mvc.ApplicationParts; | ||
using Microsoft.AspNetCore.StaticFiles; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Stac.Api.WebApi; | ||
|
||
// This entry point is used by GeopilotApiApp for integration tests. | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddApiVersioning(); | ||
builder.Services.AddCors(); | ||
|
||
builder.Services | ||
.AddControllers() | ||
.ConfigureApplicationPartManager(options => | ||
{ | ||
options.ApplicationParts.Add(new AssemblyPart(typeof(Context).Assembly)); | ||
options.ApplicationParts.Add(new AssemblyPart(typeof(StacApiController).Assembly)); | ||
}); | ||
|
||
var contentTypeProvider = new FileExtensionContentTypeProvider(); | ||
contentTypeProvider.Mappings.TryAdd(".log", "text/plain"); | ||
contentTypeProvider.Mappings.TryAdd(".xtf", "application/interlis+xml"); | ||
builder.Services.AddSingleton<IContentTypeProvider>(contentTypeProvider); | ||
|
||
var factory = new Mock<IDbContextFactory<Context>>(); | ||
factory.Setup(f => f.CreateDbContext()).Returns(AssemblyInitialize.DbFixture.GetTestContext); | ||
builder.Services.AddSingleton(factory.Object); | ||
builder.Services.AddTransient((provider) => provider.GetRequiredService<IDbContextFactory<Context>>().CreateDbContext()); | ||
|
||
builder.Services.AddStacData(builder => { }); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseCors(); | ||
app.MapControllers(); | ||
|
||
app.Run(); |
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,41 @@ | ||
using Newtonsoft.Json.Schema; | ||
using Stac; | ||
using Stac.Schemas; | ||
|
||
namespace Geopilot.Api.StacApi; | ||
|
||
[TestClass] | ||
public class CatalogTest | ||
{ | ||
private GeopilotApiApp app; | ||
private HttpClient httpClient; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
app = new GeopilotApiApp(); | ||
httpClient = app.CreateClient(); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
app.Dispose(); | ||
httpClient.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ValidateCatalogAsync() | ||
{ | ||
var stacValidator = new StacValidator(new JSchemaUrlResolver()); | ||
const string catalogUri = "/"; | ||
|
||
var json = await httpClient.GetStringAsync(catalogUri); | ||
|
||
Assert.IsTrue(stacValidator.ValidateJson(json)); | ||
|
||
var catalog = StacConvert.Deserialize<StacCatalog>(json); | ||
Assert.AreEqual("geopilot", catalog.Id); | ||
Assert.AreEqual("1.0.0", catalog.StacVersion); | ||
} | ||
} |
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,42 @@ | ||
using Stac.Api.Clients.Collections; | ||
|
||
namespace Geopilot.Api.StacApi; | ||
|
||
[TestClass] | ||
public class CollectionsTest | ||
{ | ||
private GeopilotApiApp app; | ||
private HttpClient httpClient; | ||
private CollectionsClient collectionsClient; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
app = new GeopilotApiApp(); | ||
httpClient = app.CreateClient(); | ||
collectionsClient = new CollectionsClient(httpClient); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
app.Dispose(); | ||
httpClient.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetCollectionsAsync() | ||
{ | ||
var collections = await collectionsClient.GetCollectionsAsync(); | ||
|
||
Assert.AreEqual(10, collections.Collections.Count); | ||
} | ||
|
||
[TestMethod] | ||
public async Task DescribeCollectionAsync() | ||
{ | ||
var collection = await collectionsClient.DescribeCollectionAsync("coll_1"); | ||
|
||
Assert.AreEqual("Handmade Soft Cheese", collection.Title); | ||
} | ||
} |
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,44 @@ | ||
using Stac.Api.Clients.Features; | ||
|
||
namespace Geopilot.Api.StacApi; | ||
|
||
[TestClass] | ||
public class FeaturesTest | ||
{ | ||
private GeopilotApiApp app; | ||
private HttpClient httpClient; | ||
private FeaturesClient featuresClient; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
app = new GeopilotApiApp(); | ||
httpClient = app.CreateClient(); | ||
featuresClient = new FeaturesClient(httpClient); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
app.Dispose(); | ||
httpClient.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetFeaturesAsync() | ||
{ | ||
var featureCollection = await featuresClient.GetFeaturesAsync("coll_1", null, null, null); | ||
|
||
Assert.AreEqual(2, featureCollection.NumberMatched); | ||
CollectionAssert.AreEqual(new[] { "item_6", "item_14" }, featureCollection.Features.Select(f => f.Id).ToList()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetFeatureByIdAsync() | ||
{ | ||
var feature = await featuresClient.GetFeatureAsync("coll_1", "item_14"); | ||
|
||
StringAssert.StartsWith(feature.Title, "Datenlieferung_2023-07"); | ||
Assert.AreEqual(3, feature.Assets.Count); | ||
} | ||
} |
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,57 @@ | ||
using Stac.Api.Clients.ItemSearch; | ||
|
||
namespace Geopilot.Api.StacApi; | ||
|
||
[TestClass] | ||
public class SearchTest | ||
{ | ||
private GeopilotApiApp app; | ||
private HttpClient httpClient; | ||
private ItemSearchClient searchClient; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
app = new GeopilotApiApp(); | ||
httpClient = app.CreateClient(); | ||
searchClient = new ItemSearchClient(httpClient); | ||
} | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
app.Dispose(); | ||
httpClient.Dispose(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SearchCollection1() | ||
{ | ||
var result = await searchClient.PostItemSearchAsync(new SearchBody | ||
{ | ||
Collections = new[] { "coll_1" }, | ||
Limit = 12, | ||
}); | ||
|
||
Assert.AreEqual(2, result.Items.Count()); | ||
Assert.AreEqual(2, result.NumberMatched); | ||
Assert.AreEqual(2, result.NumberReturned); | ||
|
||
CollectionAssert.AreEqual(new[] { "item_6", "item_14" }, result.Items.Select(i => i.Id).ToList()); | ||
} | ||
|
||
[TestMethod] | ||
public async Task SearchLimit() | ||
{ | ||
const int limit = 8; | ||
var result = await searchClient.PostItemSearchAsync(new SearchBody | ||
{ | ||
Collections = Array.Empty<string>(), | ||
Limit = limit, | ||
}); | ||
|
||
Assert.AreEqual(limit, result.Items.Count()); | ||
Assert.AreEqual(20, result.NumberMatched); | ||
Assert.AreEqual(limit, result.NumberReturned); | ||
} | ||
} |