|
| 1 | +using FluentAssertions; |
| 2 | +using Nest; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using Tests.Framework; |
| 9 | +using Tests.Framework.Integration; |
| 10 | +using Tests.Framework.MockData; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace Tests.Ingest |
| 14 | +{ |
| 15 | + [Collection(IntegrationContext.Indexing)] |
| 16 | + public class PipelineCrudTests |
| 17 | + : CrudTestBase<IPutPipelineResponse, IGetPipelineResponse, IPutPipelineResponse, IDeletePipelineResponse> |
| 18 | + { |
| 19 | + public PipelineCrudTests(IndexingCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 20 | + |
| 21 | + protected override LazyResponses Create() => Calls<PutPipelineDescriptor, PutPipelineRequest, IPutPipelineRequest, IPutPipelineResponse>( |
| 22 | + CreateInitializer, |
| 23 | + CreateFluent, |
| 24 | + fluent: (s, c, f) => c.PutPipeline(s, f), |
| 25 | + fluentAsync: (s, c, f) => c.PutPipelineAsync(s, f), |
| 26 | + request: (s, c, r) => c.PutPipeline(r), |
| 27 | + requestAsync: (s, c, r) => c.PutPipelineAsync(r) |
| 28 | + ); |
| 29 | + |
| 30 | + protected override void ExpectAfterCreate(IGetPipelineResponse response) |
| 31 | + { |
| 32 | + response.Pipelines.Should().NotBeNull().And.HaveCount(1); |
| 33 | + |
| 34 | + var pipeline = response.Pipelines.First(); |
| 35 | + pipeline.Config.Should().NotBeNull(); |
| 36 | + pipeline.Id.Should().NotBeNullOrEmpty(); |
| 37 | + |
| 38 | + var processors = pipeline.Config.Processors; |
| 39 | + processors.Should().NotBeNull().And.HaveCount(2); |
| 40 | + |
| 41 | + var uppercase = processors.Where(p => p.Name == "uppercase").FirstOrDefault() as UppercaseProcessor; |
| 42 | + uppercase.Should().NotBeNull(); |
| 43 | + uppercase.Field.Should().NotBeNull(); |
| 44 | + |
| 45 | + var set = processors.Where(p => p.Name == "set").FirstOrDefault() as SetProcessor; |
| 46 | + set.Should().NotBeNull(); |
| 47 | + set.Field.Should().NotBeNull(); |
| 48 | + set.Value.Should().NotBeNull(); |
| 49 | + } |
| 50 | + |
| 51 | + protected PutPipelineRequest CreateInitializer(string pipelineId) => new PutPipelineRequest(pipelineId) |
| 52 | + { |
| 53 | + Description = "Project Pipeline", |
| 54 | + Processors = new IProcessor[] |
| 55 | + { |
| 56 | + new UppercaseProcessor |
| 57 | + { |
| 58 | + Field = Infer.Field<Project>(p => p.State) |
| 59 | + }, |
| 60 | + new SetProcessor |
| 61 | + { |
| 62 | + Field = Infer.Field<Project>(p => p.NumberOfCommits), |
| 63 | + Value = 0 |
| 64 | + } |
| 65 | + } |
| 66 | + }; |
| 67 | + |
| 68 | + protected IPutPipelineRequest CreateFluent(string pipelineId, PutPipelineDescriptor d) => d |
| 69 | + .Description("Project Pipeline") |
| 70 | + .Processors(ps => ps |
| 71 | + .Uppercase<Project>(u => u |
| 72 | + .Field(p => p.State) |
| 73 | + ) |
| 74 | + .Set<Project>(s => s |
| 75 | + .Field(p => p.NumberOfCommits) |
| 76 | + .Value(0) |
| 77 | + ) |
| 78 | + ); |
| 79 | + |
| 80 | + protected override LazyResponses Read() => Calls<GetPipelineDescriptor, GetPipelineRequest, IGetPipelineRequest, IGetPipelineResponse>( |
| 81 | + GetInitializer, |
| 82 | + GetFluent, |
| 83 | + fluent: (s, c, f) => c.GetPipeline(s, f), |
| 84 | + fluentAsync: (s, c, f) => c.GetPipelineAsync(s, f), |
| 85 | + request: (s, c, r) => c.GetPipeline(r), |
| 86 | + requestAsync: (s, c, r) => c.GetPipelineAsync(r) |
| 87 | + ); |
| 88 | + |
| 89 | + protected GetPipelineRequest GetInitializer(string pipelineId) => new GetPipelineRequest(pipelineId); |
| 90 | + |
| 91 | + protected IGetPipelineRequest GetFluent(string pipelineId, GetPipelineDescriptor d) => d; |
| 92 | + |
| 93 | + protected override LazyResponses Update() => Calls<PutPipelineDescriptor, PutPipelineRequest, IPutPipelineRequest, IPutPipelineResponse>( |
| 94 | + UpdateInitializer, |
| 95 | + UpdateFluent, |
| 96 | + fluent: (s, c, f) => c.PutPipeline(s, f), |
| 97 | + fluentAsync: (s, c, f) => c.PutPipelineAsync(s, f), |
| 98 | + request: (s, c, r) => c.PutPipeline(r), |
| 99 | + requestAsync: (s, c, r) => c.PutPipelineAsync(r) |
| 100 | + ); |
| 101 | + |
| 102 | + protected PutPipelineRequest UpdateInitializer(string pipelineId) => new PutPipelineRequest(pipelineId) |
| 103 | + { |
| 104 | + Description = "Project Pipeline (updated)", |
| 105 | + Processors = new IProcessor[] |
| 106 | + { |
| 107 | + new UppercaseProcessor |
| 108 | + { |
| 109 | + Field = Infer.Field<Project>(p => p.State) |
| 110 | + }, |
| 111 | + new SetProcessor |
| 112 | + { |
| 113 | + Field = Infer.Field<Project>(p => p.NumberOfCommits), |
| 114 | + Value = 500 |
| 115 | + }, |
| 116 | + new RenameProcessor |
| 117 | + { |
| 118 | + Field = Infer.Field<Project>(p => p.LeadDeveloper), |
| 119 | + TargetField = "techLead" |
| 120 | + } |
| 121 | + } |
| 122 | + }; |
| 123 | + |
| 124 | + protected IPutPipelineRequest UpdateFluent(string pipelineId, PutPipelineDescriptor d) => d |
| 125 | + .Description("Project Pipeline (updated)") |
| 126 | + .Processors(ps => ps |
| 127 | + .Uppercase<Project>(u => u |
| 128 | + .Field(p => p.State) |
| 129 | + ) |
| 130 | + .Set<Project>(s => s |
| 131 | + .Field(p => p.NumberOfCommits) |
| 132 | + .Value(500) |
| 133 | + ) |
| 134 | + .Rename<Project>(s => s |
| 135 | + .Field(p => p.LeadDeveloper) |
| 136 | + .TargetField("techLead") |
| 137 | + ) |
| 138 | + ); |
| 139 | + |
| 140 | + protected override void ExpectAfterUpdate(IGetPipelineResponse response) |
| 141 | + { |
| 142 | + response.Pipelines.Should().NotBeNull().And.HaveCount(1); |
| 143 | + |
| 144 | + var pipeline = response.Pipelines.First(); |
| 145 | + pipeline.Config.Should().NotBeNull(); |
| 146 | + pipeline.Id.Should().NotBeNullOrEmpty(); |
| 147 | + |
| 148 | + var processors = pipeline.Config.Processors; |
| 149 | + processors.Should().NotBeNull().And.HaveCount(3); |
| 150 | + |
| 151 | + var uppercase = processors.Where(p => p.Name == "uppercase").FirstOrDefault() as UppercaseProcessor; |
| 152 | + uppercase.Should().NotBeNull(); |
| 153 | + uppercase.Field.Should().NotBeNull(); |
| 154 | + |
| 155 | + var set = processors.Where(p => p.Name == "set").FirstOrDefault() as SetProcessor; |
| 156 | + set.Should().NotBeNull(); |
| 157 | + set.Field.Should().NotBeNull(); |
| 158 | + set.Value.Should().NotBeNull(); |
| 159 | + |
| 160 | + var rename = processors.Where(p => p.Name == "rename").FirstOrDefault() as RenameProcessor; |
| 161 | + rename.Should().NotBeNull(); |
| 162 | + rename.Field.Should().NotBeNull(); |
| 163 | + rename.TargetField.Should().NotBeNull(); |
| 164 | + } |
| 165 | + |
| 166 | + protected override LazyResponses Delete() => Calls<DeletePipelineDescriptor, DeletePipelineRequest, IDeletePipelineRequest, IDeletePipelineResponse>( |
| 167 | + DeleteInitializer, |
| 168 | + DeleteFluent, |
| 169 | + fluent: (s, c, f) => c.DeletePipeline(s, f), |
| 170 | + fluentAsync: (s, c, f) => c.DeletePipelineAsync(s, f), |
| 171 | + request: (s, c, r) => c.DeletePipeline(r), |
| 172 | + requestAsync: (s, c, r) => c.DeletePipelineAsync(r) |
| 173 | + ); |
| 174 | + |
| 175 | + protected DeletePipelineRequest DeleteInitializer(string pipelineId) => new DeletePipelineRequest(pipelineId); |
| 176 | + |
| 177 | + protected IDeletePipelineRequest DeleteFluent(string pipelineId, DeletePipelineDescriptor d) => d; |
| 178 | + } |
| 179 | +} |
0 commit comments