|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using Elasticsearch.Net; |
| 5 | +using FluentAssertions; |
| 6 | +using Nest; |
| 7 | +using Newtonsoft.Json.Linq; |
| 8 | +using Tests.Framework; |
| 9 | +using Tests.Framework.Integration; |
| 10 | +using Tests.Framework.MockData; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace Tests.Document.Single.Index |
| 14 | +{ |
| 15 | + [Collection(IntegrationContext.Indexing)] |
| 16 | + public class IndexIngestApiTests : |
| 17 | + ApiIntegrationTestBase<IIndexResponse, IIndexRequest<Project>, IndexDescriptor<Project>, IndexRequest<Project>> |
| 18 | + { |
| 19 | + private string PipelineId { get; } = "pipeline-" + Guid.NewGuid().ToString("N").Substring(0, 8); |
| 20 | + |
| 21 | + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) |
| 22 | + { |
| 23 | + client.PutPipeline(new PutPipelineRequest(this.PipelineId) |
| 24 | + { |
| 25 | + Description = "Index pipeline test", |
| 26 | + Processors = new List<IProcessor> |
| 27 | + { |
| 28 | + new RenameProcessor |
| 29 | + { |
| 30 | + TargetField = "lastSeen", |
| 31 | + Field = "lastActivity" |
| 32 | + } |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + private Project Document => new Project |
| 41 | + { |
| 42 | + State = StateOfBeing.Stable, |
| 43 | + Name = CallIsolatedValue, |
| 44 | + StartedOn = FixedDate, |
| 45 | + LastActivity = FixedDate, |
| 46 | + CuratedTags = new List<Tag> {new Tag {Name = "x", Added = FixedDate}}, |
| 47 | + }; |
| 48 | + |
| 49 | + public IndexIngestApiTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) |
| 50 | + { |
| 51 | + } |
| 52 | + |
| 53 | + protected override LazyResponses ClientUsage() => Calls( |
| 54 | + fluent: (client, f) => client.Index<Project>(this.Document, f), |
| 55 | + fluentAsync: (client, f) => client.IndexAsync<Project>(this.Document, f), |
| 56 | + request: (client, r) => client.Index(r), |
| 57 | + requestAsync: (client, r) => client.IndexAsync(r) |
| 58 | + ); |
| 59 | + |
| 60 | + protected override bool ExpectIsValid => true; |
| 61 | + protected override int ExpectStatusCode => 201; |
| 62 | + protected override HttpMethod HttpMethod => HttpMethod.PUT; |
| 63 | + |
| 64 | + protected override string UrlPath |
| 65 | + => $"/project/project/{CallIsolatedValue}?consistency=quorum&op_type=index&refresh=true&routing=route"; |
| 66 | + |
| 67 | + protected override bool SupportsDeserialization => false; |
| 68 | + |
| 69 | + protected override object ExpectJson => |
| 70 | + new |
| 71 | + { |
| 72 | + name = CallIsolatedValue, |
| 73 | + state = "Stable", |
| 74 | + startedOn = FixedDate, |
| 75 | + lastActivity = FixedDate, |
| 76 | + curatedTags = new[] {new {name = "x", added = FixedDate}}, |
| 77 | + }; |
| 78 | + |
| 79 | + protected override IndexDescriptor<Project> NewDescriptor() => new IndexDescriptor<Project>(this.Document); |
| 80 | + |
| 81 | + protected override Func<IndexDescriptor<Project>, IIndexRequest<Project>> Fluent => s => s |
| 82 | + .Consistency(Consistency.Quorum) |
| 83 | + .OpType(OpType.Index) |
| 84 | + .Refresh() |
| 85 | + .Pipeline(this.PipelineId) |
| 86 | + .Routing("route"); |
| 87 | + |
| 88 | + protected override IndexRequest<Project> Initializer => |
| 89 | + new IndexRequest<Project>(this.Document) |
| 90 | + { |
| 91 | + Refresh = true, |
| 92 | + OpType = OpType.Index, |
| 93 | + Consistency = Consistency.Quorum, |
| 94 | + Routing = "route", |
| 95 | + Pipeline = this.PipelineId |
| 96 | + }; |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | +} |
0 commit comments