|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using Elasticsearch.Net; |
| 4 | +using FluentAssertions; |
| 5 | +using Nest; |
| 6 | +using Tests.Core.Extensions; |
| 7 | +using Tests.Core.ManagedElasticsearch.Clusters; |
| 8 | +using Tests.Domain; |
| 9 | +using Tests.Framework; |
| 10 | +using Tests.Framework.Integration; |
| 11 | + |
| 12 | +namespace Tests.Mapping.Types.Core.GeoShape |
| 13 | +{ |
| 14 | + public class GeoShapeClusterMetadataApiTests : ApiIntegrationTestBase<WritableCluster, PutMappingResponse, IPutMappingRequest, PutMappingDescriptor<Project>, |
| 15 | + PutMappingRequest<Project>> |
| 16 | + { |
| 17 | + public GeoShapeClusterMetadataApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 18 | + |
| 19 | + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) |
| 20 | + { |
| 21 | + foreach (var index in values.Values) client.Indices.Create(index, CreateIndexSettings).ShouldBeValid(); |
| 22 | + var indices = Infer.Indices(values.Values.Select(i => (IndexName)i)); |
| 23 | + client.Cluster.Health(null, f => f.WaitForStatus(WaitForStatus.Yellow).Index(indices)) |
| 24 | + .ShouldBeValid(); |
| 25 | + } |
| 26 | + |
| 27 | + protected virtual ICreateIndexRequest CreateIndexSettings(CreateIndexDescriptor create) => create; |
| 28 | + |
| 29 | + protected override bool ExpectIsValid => true; |
| 30 | + protected override int ExpectStatusCode => 200; |
| 31 | + |
| 32 | + protected override Func<PutMappingDescriptor<Project>, IPutMappingRequest> Fluent => f => f |
| 33 | + .Index(CallIsolatedValue) |
| 34 | + .Properties(FluentProperties); |
| 35 | + |
| 36 | + private static Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => f => f |
| 37 | + .GeoShape(s => s |
| 38 | + .Name(p => p.Location) |
| 39 | + .Tree(GeoTree.Quadtree) |
| 40 | + .Orientation(GeoOrientation.ClockWise) |
| 41 | + .Strategy(GeoStrategy.Recursive) |
| 42 | + .TreeLevels(3) |
| 43 | + .PointsOnly() |
| 44 | + .DistanceErrorPercentage(1.0) |
| 45 | + .Coerce() |
| 46 | + ); |
| 47 | + |
| 48 | + private static IProperties InitializerProperties => new Properties |
| 49 | + { |
| 50 | + { |
| 51 | + "location", new GeoShapeProperty |
| 52 | + { |
| 53 | + Tree = GeoTree.Quadtree, |
| 54 | + Orientation = GeoOrientation.ClockWise, |
| 55 | + Strategy = GeoStrategy.Recursive, |
| 56 | + TreeLevels = 3, |
| 57 | + PointsOnly = true, |
| 58 | + DistanceErrorPercentage = 1.0, |
| 59 | + Coerce = true |
| 60 | + } |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + protected override HttpMethod HttpMethod => HttpMethod.PUT; |
| 65 | + |
| 66 | + protected override PutMappingRequest<Project> Initializer => new PutMappingRequest<Project>(CallIsolatedValue) |
| 67 | + { |
| 68 | + Properties = InitializerProperties |
| 69 | + }; |
| 70 | + |
| 71 | + protected override string UrlPath => $"/{CallIsolatedValue}/doc/_mapping"; |
| 72 | + |
| 73 | + protected override LazyResponses ClientUsage() => Calls( |
| 74 | + (client, f) => client.Map(f), |
| 75 | + (client, f) => client.MapAsync(f), |
| 76 | + (client, r) => client.Map(r), |
| 77 | + (client, r) => client.MapAsync(r) |
| 78 | + ); |
| 79 | + |
| 80 | + protected override void ExpectResponse(PutMappingResponse response) |
| 81 | + { |
| 82 | + // Ensure metadata can be deserialised |
| 83 | + var metadata = Client.Cluster.State(null, r => r.Metric(ClusterStateMetric.Metadata)); |
| 84 | + metadata.IsValid.Should().BeTrue(); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments