From 250d13c62e33709ffd07811587f456b66da8959e Mon Sep 17 00:00:00 2001 From: Anton Martynenko Date: Wed, 29 Oct 2025 14:54:33 +0100 Subject: [PATCH] add test for zoom 18 and 500x500 meters image --- .DS_Store | Bin 0 -> 6148 bytes SatelliteProvider.IntegrationTests/Models.cs | 45 +++ SatelliteProvider.IntegrationTests/Program.cs | 270 +----------------- .../RegionTests.cs | 174 +++++++++++ .../TileTests.cs | 106 +++++++ 5 files changed, 332 insertions(+), 263 deletions(-) create mode 100644 .DS_Store create mode 100644 SatelliteProvider.IntegrationTests/Models.cs create mode 100644 SatelliteProvider.IntegrationTests/RegionTests.cs create mode 100644 SatelliteProvider.IntegrationTests/TileTests.cs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bc49e691c6e2d4f63c07089c4f4ee70dca73fae0 GIT binary patch literal 6148 zcmeHKI|>3Z5S{S@f{mqRuHX%V=n3`$3W|*=2nu#vc`lFUn@_VWc3LQJVDgg5yo9`B zXGcVIdEG5UW+F0y8_L6mzS+Kc&juM$ARK4hZ_VX&Jf9A|+;;)vj^!eI*~+fNw;dW4 zpaN8Y3Qz$m@M#6I!cL~2KA7iG0V?qG3fT9dzzu6+8|a@74Bi3&M+m!N?!5%CSO8cP z+dxEM8dP9VHCqe~I^resYGNB0bkS@+G;h}IP}Fb7`Nh*kYamA|Kn1!A3}ZR7`oD(1 z>HoVVuBZSN_$vi;v}#sMJSl5y?{QXZ3w#5&oG082bEjbNat!oxjD?lsxhF+lu{ri@ VVjJjm#GMZ0&w%MdqXOSn-~|HR6x09! literal 0 HcmV?d00001 diff --git a/SatelliteProvider.IntegrationTests/Models.cs b/SatelliteProvider.IntegrationTests/Models.cs new file mode 100644 index 0000000..383eb74 --- /dev/null +++ b/SatelliteProvider.IntegrationTests/Models.cs @@ -0,0 +1,45 @@ +namespace SatelliteProvider.IntegrationTests; + +public record DownloadTileRequest +{ + public double Latitude { get; set; } + public double Longitude { get; set; } + public int ZoomLevel { get; set; } +} + +public record DownloadTileResponse +{ + public Guid Id { get; set; } + public int ZoomLevel { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } + public double TileSizeMeters { get; set; } + public int TileSizePixels { get; set; } + public string ImageType { get; set; } = string.Empty; + public string? MapsVersion { get; set; } + public string FilePath { get; set; } = string.Empty; + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } +} + +public record RequestRegionRequest +{ + public Guid Id { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } + public double SizeMeters { get; set; } + public int ZoomLevel { get; set; } +} + +public record RegionStatusResponse +{ + public Guid Id { get; set; } + public string Status { get; set; } = string.Empty; + public string? CsvFilePath { get; set; } + public string? SummaryFilePath { get; set; } + public int TilesDownloaded { get; set; } + public int TilesReused { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } +} + diff --git a/SatelliteProvider.IntegrationTests/Program.cs b/SatelliteProvider.IntegrationTests/Program.cs index 685dbb5..360fa34 100644 --- a/SatelliteProvider.IntegrationTests/Program.cs +++ b/SatelliteProvider.IntegrationTests/Program.cs @@ -1,15 +1,7 @@ -using System.Net.Http.Json; -using System.Text.Json; - -namespace SatelliteProvider.IntegrationTests; +namespace SatelliteProvider.IntegrationTests; class Program { - private static readonly JsonSerializerOptions JsonOptions = new() - { - PropertyNameCaseInsensitive = true - }; - static async Task Main(string[] args) { var apiUrl = Environment.GetEnvironmentVariable("API_URL") ?? "http://api:8080"; @@ -32,9 +24,13 @@ class Program Console.WriteLine("✓ API is ready"); Console.WriteLine(); - await RunSingleTileDownloadTest(httpClient); + await TileTests.RunSingleTileDownloadTest(httpClient); - await RunRegionProcessingTest(httpClient); + await RegionTests.RunRegionProcessingTest_200m_Zoom18(httpClient); + + await RegionTests.RunRegionProcessingTest_400m_Zoom17(httpClient); + + await RegionTests.RunRegionProcessingTest_500m_Zoom18(httpClient); Console.WriteLine(); Console.WriteLine("========================="); @@ -73,256 +69,4 @@ class Program throw new Exception("API did not become ready in time"); } - - static async Task RunSingleTileDownloadTest(HttpClient httpClient) - { - Console.WriteLine("Test: Download Single Tile at Coordinates 47.461747, 37.647063"); - Console.WriteLine("------------------------------------------------------------------"); - - const double latitude = 47.461747; - const double longitude = 37.647063; - const int zoomLevel = 18; - - Console.WriteLine($"Downloading tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}"); - - var request = new DownloadTileRequest - { - Latitude = latitude, - Longitude = longitude, - ZoomLevel = zoomLevel - }; - - var response = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request); - - if (!response.IsSuccessStatusCode) - { - var errorContent = await response.Content.ReadAsStringAsync(); - throw new Exception($"API returned error status {response.StatusCode}: {errorContent}"); - } - - var tile = await response.Content.ReadFromJsonAsync(JsonOptions); - - if (tile == null) - { - throw new Exception("No tile data returned from API"); - } - - Console.WriteLine(); - Console.WriteLine("Tile Details:"); - Console.WriteLine($" ID: {tile.Id}"); - Console.WriteLine($" Zoom Level: {tile.ZoomLevel}"); - Console.WriteLine($" Latitude: {tile.Latitude}"); - Console.WriteLine($" Longitude: {tile.Longitude}"); - Console.WriteLine($" Tile Size (meters): {tile.TileSizeMeters:F2}"); - Console.WriteLine($" Tile Size (pixels): {tile.TileSizePixels}"); - Console.WriteLine($" Image Type: {tile.ImageType}"); - Console.WriteLine($" Maps Version: {tile.MapsVersion}"); - Console.WriteLine($" File Path: {tile.FilePath}"); - Console.WriteLine($" Created At: {tile.CreatedAt:yyyy-MM-dd HH:mm:ss}"); - - if (tile.ZoomLevel != zoomLevel) - { - throw new Exception($"Expected zoom level {zoomLevel}, got {tile.ZoomLevel}"); - } - - if (string.IsNullOrEmpty(tile.FilePath)) - { - throw new Exception("File path is empty"); - } - - if (tile.TileSizePixels != 256) - { - throw new Exception($"Expected tile size 256 pixels, got {tile.TileSizePixels}"); - } - - if (tile.ImageType != "jpg") - { - throw new Exception($"Expected image type 'jpg', got '{tile.ImageType}'"); - } - - Console.WriteLine(); - Console.WriteLine("✓ Tile downloaded successfully"); - Console.WriteLine("✓ Tile metadata validated"); - Console.WriteLine(); - Console.WriteLine("Testing tile reuse (downloading same tile again)..."); - - var response2 = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request); - - if (!response2.IsSuccessStatusCode) - { - var errorContent = await response2.Content.ReadAsStringAsync(); - throw new Exception($"Second download failed with status {response2.StatusCode}: {errorContent}"); - } - - var tile2 = await response2.Content.ReadFromJsonAsync(JsonOptions); - - if (tile2 == null) - { - throw new Exception("No tile data returned from second download"); - } - - Console.WriteLine($"✓ Second download returned tile ID: {tile2.Id}"); - Console.WriteLine("✓ Tile reuse functionality working"); - Console.WriteLine(); - Console.WriteLine("Single Tile Download Test: PASSED"); - } - - static async Task RunRegionProcessingTest(HttpClient httpClient) - { - Console.WriteLine(); - Console.WriteLine("Test: Region Processing at Coordinates 47.461747, 37.647063"); - Console.WriteLine("------------------------------------------------------------------"); - - const double latitude = 47.461747; - const double longitude = 37.647063; - const double sizeMeters = 200; - const int zoomLevel = 18; - - var regionId = Guid.NewGuid(); - - Console.WriteLine($"Requesting region: ID={regionId}"); - Console.WriteLine($" Coordinates: ({latitude}, {longitude})"); - Console.WriteLine($" Size: {sizeMeters}m"); - Console.WriteLine($" Zoom Level: {zoomLevel}"); - Console.WriteLine(); - - var requestRegion = new RequestRegionRequest - { - Id = regionId, - Latitude = latitude, - Longitude = longitude, - SizeMeters = sizeMeters, - ZoomLevel = zoomLevel - }; - - var requestResponse = await httpClient.PostAsJsonAsync("/api/satellite/request", requestRegion); - - if (!requestResponse.IsSuccessStatusCode) - { - var errorContent = await requestResponse.Content.ReadAsStringAsync(); - throw new Exception($"Region request failed with status {requestResponse.StatusCode}: {errorContent}"); - } - - var initialStatus = await requestResponse.Content.ReadFromJsonAsync(JsonOptions); - - if (initialStatus == null) - { - throw new Exception("No status returned from region request"); - } - - Console.WriteLine($"✓ Region queued successfully"); - Console.WriteLine($" Initial Status: {initialStatus.Status}"); - Console.WriteLine(); - - Console.WriteLine("Polling for region status updates..."); - RegionStatusResponse? finalStatus = null; - int maxAttempts = 30; - - for (int i = 0; i < maxAttempts; i++) - { - await Task.Delay(1000); - - var statusResponse = await httpClient.GetAsync($"/api/satellite/region/{regionId}"); - - if (!statusResponse.IsSuccessStatusCode) - { - var errorContent = await statusResponse.Content.ReadAsStringAsync(); - throw new Exception($"Status check failed with status {statusResponse.StatusCode}: {errorContent}"); - } - - var status = await statusResponse.Content.ReadFromJsonAsync(JsonOptions); - - if (status == null) - { - throw new Exception("No status returned"); - } - - Console.WriteLine($" Attempt {i + 1}: Status = {status.Status}"); - - if (status.Status == "completed" || status.Status == "failed") - { - finalStatus = status; - break; - } - } - - if (finalStatus == null) - { - throw new Exception("Region processing did not complete in time"); - } - - Console.WriteLine(); - Console.WriteLine("Region Processing Results:"); - Console.WriteLine($" Status: {finalStatus.Status}"); - Console.WriteLine($" Tiles Downloaded: {finalStatus.TilesDownloaded}"); - Console.WriteLine($" Tiles Reused: {finalStatus.TilesReused}"); - Console.WriteLine($" CSV File: {finalStatus.CsvFilePath}"); - Console.WriteLine($" Summary File: {finalStatus.SummaryFilePath}"); - Console.WriteLine($" Created At: {finalStatus.CreatedAt:yyyy-MM-dd HH:mm:ss}"); - Console.WriteLine($" Updated At: {finalStatus.UpdatedAt:yyyy-MM-dd HH:mm:ss}"); - - if (finalStatus.Status != "completed") - { - throw new Exception($"Expected status 'completed', got '{finalStatus.Status}'"); - } - - if (string.IsNullOrEmpty(finalStatus.CsvFilePath)) - { - throw new Exception("CSV file path is empty"); - } - - if (string.IsNullOrEmpty(finalStatus.SummaryFilePath)) - { - throw new Exception("Summary file path is empty"); - } - - Console.WriteLine(); - Console.WriteLine("✓ Region processed successfully"); - Console.WriteLine("✓ CSV and summary files created"); - Console.WriteLine(); - Console.WriteLine("Region Processing Test: PASSED"); - } -} - -public record DownloadTileRequest -{ - public double Latitude { get; set; } - public double Longitude { get; set; } - public int ZoomLevel { get; set; } -} - -public record DownloadTileResponse -{ - public Guid Id { get; set; } - public int ZoomLevel { get; set; } - public double Latitude { get; set; } - public double Longitude { get; set; } - public double TileSizeMeters { get; set; } - public int TileSizePixels { get; set; } - public string ImageType { get; set; } = string.Empty; - public string? MapsVersion { get; set; } - public string FilePath { get; set; } = string.Empty; - public DateTime CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } -} - -public record RequestRegionRequest -{ - public Guid Id { get; set; } - public double Latitude { get; set; } - public double Longitude { get; set; } - public double SizeMeters { get; set; } - public int ZoomLevel { get; set; } -} - -public record RegionStatusResponse -{ - public Guid Id { get; set; } - public string Status { get; set; } = string.Empty; - public string? CsvFilePath { get; set; } - public string? SummaryFilePath { get; set; } - public int TilesDownloaded { get; set; } - public int TilesReused { get; set; } - public DateTime CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } } diff --git a/SatelliteProvider.IntegrationTests/RegionTests.cs b/SatelliteProvider.IntegrationTests/RegionTests.cs new file mode 100644 index 0000000..165371f --- /dev/null +++ b/SatelliteProvider.IntegrationTests/RegionTests.cs @@ -0,0 +1,174 @@ +using System.Net.Http.Json; +using System.Text.Json; + +namespace SatelliteProvider.IntegrationTests; + +public static class RegionTests +{ + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + public static async Task RunRegionProcessingTest_200m_Zoom18(HttpClient httpClient) + { + Console.WriteLine(); + Console.WriteLine("Test: Region Processing 200m at Zoom 18"); + Console.WriteLine("------------------------------------------------------------------"); + + const double latitude = 47.461747; + const double longitude = 37.647063; + const double sizeMeters = 200; + const int zoomLevel = 18; + + await RunRegionProcessingTest(httpClient, latitude, longitude, sizeMeters, zoomLevel); + + Console.WriteLine(); + Console.WriteLine("Region Processing Test (200m, Zoom 18): PASSED"); + } + + public static async Task RunRegionProcessingTest_400m_Zoom17(HttpClient httpClient) + { + Console.WriteLine(); + Console.WriteLine("Test: Region Processing 400m at Zoom 17"); + Console.WriteLine("------------------------------------------------------------------"); + + const double latitude = 47.461747; + const double longitude = 37.647063; + const double sizeMeters = 400; + const int zoomLevel = 17; + + await RunRegionProcessingTest(httpClient, latitude, longitude, sizeMeters, zoomLevel); + + Console.WriteLine(); + Console.WriteLine("Region Processing Test (400m, Zoom 17): PASSED"); + } + + public static async Task RunRegionProcessingTest_500m_Zoom18(HttpClient httpClient) + { + Console.WriteLine(); + Console.WriteLine("Test: Region Processing 500m at Zoom 18"); + Console.WriteLine("------------------------------------------------------------------"); + + const double latitude = 47.461747; + const double longitude = 37.647063; + const double sizeMeters = 500; + const int zoomLevel = 18; + + await RunRegionProcessingTest(httpClient, latitude, longitude, sizeMeters, zoomLevel); + + Console.WriteLine(); + Console.WriteLine("Region Processing Test (500m, Zoom 18): PASSED"); + } + + private static async Task RunRegionProcessingTest( + HttpClient httpClient, + double latitude, + double longitude, + double sizeMeters, + int zoomLevel) + { + var regionId = Guid.NewGuid(); + + Console.WriteLine($"Requesting region: ID={regionId}"); + Console.WriteLine($" Coordinates: ({latitude}, {longitude})"); + Console.WriteLine($" Size: {sizeMeters}m"); + Console.WriteLine($" Zoom Level: {zoomLevel}"); + Console.WriteLine(); + + var requestRegion = new RequestRegionRequest + { + Id = regionId, + Latitude = latitude, + Longitude = longitude, + SizeMeters = sizeMeters, + ZoomLevel = zoomLevel + }; + + var requestResponse = await httpClient.PostAsJsonAsync("/api/satellite/request", requestRegion); + + if (!requestResponse.IsSuccessStatusCode) + { + var errorContent = await requestResponse.Content.ReadAsStringAsync(); + throw new Exception($"Region request failed with status {requestResponse.StatusCode}: {errorContent}"); + } + + var initialStatus = await requestResponse.Content.ReadFromJsonAsync(JsonOptions); + + if (initialStatus == null) + { + throw new Exception("No status returned from region request"); + } + + Console.WriteLine($"✓ Region queued successfully"); + Console.WriteLine($" Initial Status: {initialStatus.Status}"); + Console.WriteLine(); + + Console.WriteLine("Polling for region status updates..."); + RegionStatusResponse? finalStatus = null; + int maxAttempts = 30; + + for (int i = 0; i < maxAttempts; i++) + { + await Task.Delay(1000); + + var statusResponse = await httpClient.GetAsync($"/api/satellite/region/{regionId}"); + + if (!statusResponse.IsSuccessStatusCode) + { + var errorContent = await statusResponse.Content.ReadAsStringAsync(); + throw new Exception($"Status check failed with status {statusResponse.StatusCode}: {errorContent}"); + } + + var status = await statusResponse.Content.ReadFromJsonAsync(JsonOptions); + + if (status == null) + { + throw new Exception("No status returned"); + } + + Console.WriteLine($" Attempt {i + 1}: Status = {status.Status}"); + + if (status.Status == "completed" || status.Status == "failed") + { + finalStatus = status; + break; + } + } + + if (finalStatus == null) + { + throw new Exception("Region processing did not complete in time"); + } + + Console.WriteLine(); + Console.WriteLine("Region Processing Results:"); + Console.WriteLine($" Status: {finalStatus.Status}"); + Console.WriteLine($" Tiles Downloaded: {finalStatus.TilesDownloaded}"); + Console.WriteLine($" Tiles Reused: {finalStatus.TilesReused}"); + Console.WriteLine($" CSV File: {finalStatus.CsvFilePath}"); + Console.WriteLine($" Summary File: {finalStatus.SummaryFilePath}"); + Console.WriteLine($" Created At: {finalStatus.CreatedAt:yyyy-MM-dd HH:mm:ss}"); + Console.WriteLine($" Updated At: {finalStatus.UpdatedAt:yyyy-MM-dd HH:mm:ss}"); + + if (finalStatus.Status != "completed") + { + throw new Exception($"Expected status 'completed', got '{finalStatus.Status}'"); + } + + if (string.IsNullOrEmpty(finalStatus.CsvFilePath)) + { + throw new Exception("CSV file path is empty"); + } + + if (string.IsNullOrEmpty(finalStatus.SummaryFilePath)) + { + throw new Exception("Summary file path is empty"); + } + + Console.WriteLine(); + Console.WriteLine("✓ Region processed successfully"); + Console.WriteLine("✓ CSV and summary files created"); + } +} + diff --git a/SatelliteProvider.IntegrationTests/TileTests.cs b/SatelliteProvider.IntegrationTests/TileTests.cs new file mode 100644 index 0000000..9ec4278 --- /dev/null +++ b/SatelliteProvider.IntegrationTests/TileTests.cs @@ -0,0 +1,106 @@ +using System.Net.Http.Json; +using System.Text.Json; + +namespace SatelliteProvider.IntegrationTests; + +public static class TileTests +{ + private static readonly JsonSerializerOptions JsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + public static async Task RunSingleTileDownloadTest(HttpClient httpClient) + { + Console.WriteLine("Test: Download Single Tile at Coordinates 47.461747, 37.647063"); + Console.WriteLine("------------------------------------------------------------------"); + + const double latitude = 47.461747; + const double longitude = 37.647063; + const int zoomLevel = 18; + + Console.WriteLine($"Downloading tile at coordinates ({latitude}, {longitude}) with zoom level {zoomLevel}"); + + var request = new DownloadTileRequest + { + Latitude = latitude, + Longitude = longitude, + ZoomLevel = zoomLevel + }; + + var response = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request); + + if (!response.IsSuccessStatusCode) + { + var errorContent = await response.Content.ReadAsStringAsync(); + throw new Exception($"API returned error status {response.StatusCode}: {errorContent}"); + } + + var tile = await response.Content.ReadFromJsonAsync(JsonOptions); + + if (tile == null) + { + throw new Exception("No tile data returned from API"); + } + + Console.WriteLine(); + Console.WriteLine("Tile Details:"); + Console.WriteLine($" ID: {tile.Id}"); + Console.WriteLine($" Zoom Level: {tile.ZoomLevel}"); + Console.WriteLine($" Latitude: {tile.Latitude}"); + Console.WriteLine($" Longitude: {tile.Longitude}"); + Console.WriteLine($" Tile Size (meters): {tile.TileSizeMeters:F2}"); + Console.WriteLine($" Tile Size (pixels): {tile.TileSizePixels}"); + Console.WriteLine($" Image Type: {tile.ImageType}"); + Console.WriteLine($" Maps Version: {tile.MapsVersion}"); + Console.WriteLine($" File Path: {tile.FilePath}"); + Console.WriteLine($" Created At: {tile.CreatedAt:yyyy-MM-dd HH:mm:ss}"); + + if (tile.ZoomLevel != zoomLevel) + { + throw new Exception($"Expected zoom level {zoomLevel}, got {tile.ZoomLevel}"); + } + + if (string.IsNullOrEmpty(tile.FilePath)) + { + throw new Exception("File path is empty"); + } + + if (tile.TileSizePixels != 256) + { + throw new Exception($"Expected tile size 256 pixels, got {tile.TileSizePixels}"); + } + + if (tile.ImageType != "jpg") + { + throw new Exception($"Expected image type 'jpg', got '{tile.ImageType}'"); + } + + Console.WriteLine(); + Console.WriteLine("✓ Tile downloaded successfully"); + Console.WriteLine("✓ Tile metadata validated"); + Console.WriteLine(); + Console.WriteLine("Testing tile reuse (downloading same tile again)..."); + + var response2 = await httpClient.PostAsJsonAsync("/api/satellite/tiles/download", request); + + if (!response2.IsSuccessStatusCode) + { + var errorContent = await response2.Content.ReadAsStringAsync(); + throw new Exception($"Second download failed with status {response2.StatusCode}: {errorContent}"); + } + + var tile2 = await response2.Content.ReadFromJsonAsync(JsonOptions); + + if (tile2 == null) + { + throw new Exception("No tile data returned from second download"); + } + + Console.WriteLine($"✓ Second download returned tile ID: {tile2.Id}"); + Console.WriteLine("✓ Tile reuse functionality working"); + Console.WriteLine(); + Console.WriteLine("Single Tile Download Test: PASSED"); + } +} +