|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Elasticsearch.Net; |
| 4 | +using Nest; |
| 5 | +using Tests.Framework; |
| 6 | +using Tests.Framework.Integration; |
| 7 | +using Tests.Framework.ManagedElasticsearch.Clusters; |
| 8 | + |
| 9 | +namespace Tests.Mapping.Types |
| 10 | +{ |
| 11 | + public abstract class SingleMappingPropertyTestsBase |
| 12 | + : ApiIntegrationTestBase<WritableCluster, IPutIndexTemplateResponse, IPutIndexTemplateRequest, PutIndexTemplateDescriptor, PutIndexTemplateRequest> |
| 13 | + { |
| 14 | + protected SingleMappingPropertyTestsBase(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 15 | + |
| 16 | + protected override LazyResponses ClientUsage() => Calls( |
| 17 | + fluent: (client, f) => client.PutIndexTemplate(CallIsolatedValue, f), |
| 18 | + fluentAsync: (client, f) => client.PutIndexTemplateAsync(CallIsolatedValue, f), |
| 19 | + request: (client, r) => client.PutIndexTemplate(r), |
| 20 | + requestAsync: (client, r) => client.PutIndexTemplateAsync(r) |
| 21 | + ); |
| 22 | + |
| 23 | + protected override HttpMethod HttpMethod => HttpMethod.PUT; |
| 24 | + protected override string UrlPath => $"/_template/{CallIsolatedValue}?create=false"; |
| 25 | + protected override bool SupportsDeserialization => false; |
| 26 | + protected override bool ExpectIsValid => true; |
| 27 | + protected override int ExpectStatusCode => 200; |
| 28 | + |
| 29 | + protected override object ExpectJson => new |
| 30 | + { |
| 31 | + order = 1, |
| 32 | + template = "nestx-*", |
| 33 | + settings = new Dictionary<string, object> { { "index.number_of_shards", 1 } }, |
| 34 | + mappings = new |
| 35 | + { |
| 36 | + _default_ = new |
| 37 | + { |
| 38 | + dynamic_templates = new object[] |
| 39 | + { |
| 40 | + new |
| 41 | + { |
| 42 | + @base = new |
| 43 | + { |
| 44 | + match = "*", |
| 45 | + match_mapping_type = "*", |
| 46 | + mapping = this.SingleMappingJson |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + protected abstract object SingleMappingJson { get; } |
| 55 | + |
| 56 | + protected override PutIndexTemplateDescriptor NewDescriptor() => new PutIndexTemplateDescriptor(CallIsolatedValue); |
| 57 | + protected override Func<PutIndexTemplateDescriptor, IPutIndexTemplateRequest> Fluent => d => d |
| 58 | + .Order(1) |
| 59 | + .Template("nestx-*") |
| 60 | + .Create(false) |
| 61 | + .Settings(p=>p.NumberOfShards(1)) |
| 62 | + .Mappings(m => m |
| 63 | + .Map("_default_", tm => tm |
| 64 | + .DynamicTemplates(t => t |
| 65 | + .DynamicTemplate("base", dt => dt |
| 66 | + .Match("*") |
| 67 | + .MatchMappingType("*") |
| 68 | + .Mapping(FluentSingleMapping) |
| 69 | + ) |
| 70 | + ) |
| 71 | + ) |
| 72 | + ); |
| 73 | + |
| 74 | + protected abstract Func<SingleMappingDescriptor<object>, IProperty> FluentSingleMapping { get; } |
| 75 | + protected abstract IProperty InitializerSingleMapping { get; } |
| 76 | + |
| 77 | + protected override PutIndexTemplateRequest Initializer => new PutIndexTemplateRequest(CallIsolatedValue) |
| 78 | + { |
| 79 | + Order = 1, |
| 80 | + Template = "nestx-*", |
| 81 | + Create = false, |
| 82 | + Settings = new Nest.IndexSettings |
| 83 | + { |
| 84 | + NumberOfShards = 1 |
| 85 | + }, |
| 86 | + Mappings = new Mappings |
| 87 | + { |
| 88 | + { "_default_", new TypeMapping |
| 89 | + { |
| 90 | + DynamicTemplates = new DynamicTemplateContainer |
| 91 | + { |
| 92 | + { "base", new DynamicTemplate |
| 93 | + { |
| 94 | + Match = "*", |
| 95 | + MatchMappingType = "*", |
| 96 | + Mapping = InitializerSingleMapping |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + }; |
| 104 | + } |
| 105 | +} |
0 commit comments