4
4
using Tests . Framework ;
5
5
using Tests . Framework . Integration ;
6
6
using Xunit ;
7
+ using Tests . Framework . MockData ;
8
+ using FluentAssertions ;
9
+ using System . Linq ;
7
10
8
11
namespace Tests . Ingest . SimulatePipeline
9
12
{
10
13
[ Collection ( IntegrationContext . ReadOnly ) ]
11
- public class SimulatePipelineApiTests : ApiTestBase < ISimulatePipelineResponse , ISimulatePipelineRequest , SimulatePipelineDescriptor , SimulatePipelineRequest >
14
+ public class SimulatePipelineApiTests
15
+ : ApiIntegrationTestBase < ISimulatePipelineResponse , ISimulatePipelineRequest , SimulatePipelineDescriptor , SimulatePipelineRequest >
12
16
{
13
17
public SimulatePipelineApiTests ( ReadOnlyCluster cluster , EndpointUsage usage ) : base ( cluster , usage ) { }
14
18
@@ -22,19 +26,215 @@ protected override LazyResponses ClientUsage() => Calls(
22
26
) ;
23
27
24
28
protected override HttpMethod HttpMethod => HttpMethod . POST ;
25
- protected override string UrlPath => $ "/_ingest/pipeline/{ _id } /_simulate";
26
-
29
+ protected override string UrlPath => $ "/_ingest/pipeline/_simulate";
30
+ protected override int ExpectStatusCode => 200 ;
31
+ protected override bool ExpectIsValid => true ;
27
32
protected override bool SupportsDeserialization => false ;
28
33
29
34
protected override object ExpectJson { get ; } = new
30
35
{
36
+ pipeline = new
37
+ {
38
+ description = "pipeline simulation" ,
39
+ processors = new object [ ]
40
+ {
41
+ new
42
+ {
43
+ set = new
44
+ {
45
+ field = "name" ,
46
+ value = "buzz"
47
+ }
48
+ } ,
49
+ new
50
+ {
51
+ append = new
52
+ {
53
+ field = "colors" ,
54
+ value = new [ ] { "blue" , "black" }
55
+ }
56
+ } ,
57
+ new
58
+ {
59
+ uppercase = new
60
+ {
61
+ field = "name"
62
+ }
63
+ }
64
+ }
65
+ } ,
66
+ docs = new object [ ]
67
+ {
68
+ new
69
+ {
70
+ _index = "project" ,
71
+ _type = "project" ,
72
+ _id = Project . Instance . Name ,
73
+ _source = Project . Instance
74
+ } ,
75
+ new
76
+ {
77
+ _index = "otherindex" ,
78
+ _type = "othertype" ,
79
+ _id = "otherid" ,
80
+ _source = Project . Instance
81
+ } ,
82
+ new
83
+ {
84
+ _index = "otherindex" ,
85
+ _type = "anotherType" ,
86
+ _id = "2" ,
87
+ _source = new { id = "2" , colors = new [ ] { "red" } }
88
+ }
89
+ }
31
90
} ;
32
91
92
+ protected override void ExpectResponse ( ISimulatePipelineResponse response )
93
+ {
94
+ response . IsValid . Should ( ) . BeTrue ( ) ;
95
+ response . Documents . Should ( ) . NotBeNull ( ) . And . HaveCount ( 3 ) ;
96
+
97
+ var simulation = response . Documents . Where ( d => d . Document . Id == Project . Instance . Name ) . FirstOrDefault ( ) ;
98
+ simulation . Should ( ) . NotBeNull ( ) ;
99
+ simulation . Document . Ingest . Should ( ) . NotBeNull ( ) ;
100
+ simulation . Document . Ingest . Timestamp . Should ( ) . NotBe ( default ( DateTime ) ) ;
101
+ var project = simulation . Document . Source . As < Project > ( ) ;
102
+ project . Should ( ) . NotBeNull ( ) ;
103
+ project . Name . Should ( ) . Be ( "BUZZ" ) ;
104
+
105
+ simulation = response . Documents . Where ( d => d . Document . Id == "otherid" ) . FirstOrDefault ( ) ;
106
+ simulation . Should ( ) . NotBeNull ( ) ;
107
+ simulation . Document . Ingest . Should ( ) . NotBeNull ( ) ;
108
+ simulation . Document . Ingest . Timestamp . Should ( ) . NotBe ( default ( DateTime ) ) ;
109
+ project = simulation . Document . Source . As < Project > ( ) ;
110
+ project . Name . Should ( ) . Be ( "BUZZ" ) ;
111
+
112
+ simulation = response . Documents . Where ( d => d . Document . Id == "2" ) . FirstOrDefault ( ) ;
113
+ simulation . Document . Ingest . Should ( ) . NotBeNull ( ) ;
114
+ simulation . Document . Ingest . Timestamp . Should ( ) . NotBe ( default ( DateTime ) ) ;
115
+ var anotherType = simulation . Document . Source . As < AnotherType > ( ) ;
116
+ anotherType . Should ( ) . NotBeNull ( ) ;
117
+ anotherType . Colors . Should ( ) . BeEquivalentTo ( new string [ ] { "red" , "blue" , "black" } ) ;
118
+ }
119
+
120
+ public class AnotherType
121
+ {
122
+ public string Id { get ; set ; }
123
+ public string [ ] Colors { get ; set ; }
124
+ }
125
+
33
126
protected override Func < SimulatePipelineDescriptor , ISimulatePipelineRequest > Fluent => d => d
34
- . Id ( _id ) ;
127
+ . Pipeline ( pl => pl
128
+ . Description ( "pipeline simulation" )
129
+ . Processors ( ps => ps
130
+ . Set < Project > ( s => s
131
+ . Field ( p => p . Name )
132
+ . Value ( "buzz" )
133
+ )
134
+ . Append < AnotherType > ( a => a
135
+ . Field ( p => p . Colors )
136
+ . Value ( "blue" , "black" )
137
+ )
138
+ . Uppercase < Project > ( u => u
139
+ . Field ( p => p . Name )
140
+ )
141
+ )
142
+ )
143
+ . Documents ( ds => ds
144
+ . Document ( doc => doc
145
+ . Source ( Project . Instance )
146
+ )
147
+ . Document ( doc => doc
148
+ . Source ( Project . Instance )
149
+ . Index ( "otherindex" )
150
+ . Type ( "othertype" )
151
+ . Id ( "otherid" )
152
+ )
153
+ . Document ( doc => doc
154
+ . Index ( "otherindex" )
155
+ . Type ( "anotherType" )
156
+ . Source ( new AnotherType { Id = "2" , Colors = new string [ ] { "red" } } )
157
+ )
158
+ ) ;
35
159
36
- protected override SimulatePipelineRequest Initializer => new SimulatePipelineRequest ( _id )
160
+ protected override SimulatePipelineRequest Initializer => new SimulatePipelineRequest
37
161
{
162
+ Pipeline = new Pipeline
163
+ {
164
+ Description = "pipeline simulation" ,
165
+ Processors = new IProcessor [ ]
166
+ {
167
+ new SetProcessor
168
+ {
169
+ Field = "name" ,
170
+ Value = "buzz"
171
+ } ,
172
+ new AppendProcessor
173
+ {
174
+ Field = "colors" ,
175
+ Value = new [ ] { "blue" , "black" }
176
+ } ,
177
+ new UppercaseProcessor
178
+ {
179
+ Field = "name"
180
+ }
181
+ }
182
+ } ,
183
+ Documents = new SimulatePipelineDocument [ ]
184
+ {
185
+ new SimulatePipelineDocument
186
+ {
187
+ Source = Project . Instance
188
+ } ,
189
+ new SimulatePipelineDocument
190
+ {
191
+ Source = Project . Instance ,
192
+ Index = "otherindex" ,
193
+ Type = "othertype" ,
194
+ Id = "otherid"
195
+ } ,
196
+ new SimulatePipelineDocument
197
+ {
198
+ Index = "otherindex" ,
199
+ Type = "anotherType" ,
200
+ Source = new AnotherType { Id = "2" , Colors = new [ ] { "red" } }
201
+ }
202
+ }
38
203
} ;
39
204
}
205
+
206
+ [ Collection ( IntegrationContext . ReadOnly ) ]
207
+ public class SimulatePipelineVerboseApiTests : SimulatePipelineApiTests
208
+ {
209
+ public SimulatePipelineVerboseApiTests ( ReadOnlyCluster cluster , EndpointUsage usage ) : base ( cluster , usage ) { }
210
+
211
+ protected override string UrlPath => $ "/_ingest/pipeline/_simulate?verbose=true";
212
+
213
+ protected override void ExpectResponse ( ISimulatePipelineResponse response )
214
+ {
215
+ response . IsValid . Should ( ) . BeTrue ( ) ;
216
+ response . Documents . Count . Should ( ) . Be ( 3 ) ;
217
+ foreach ( var doc in response . Documents )
218
+ {
219
+ doc . ProcessorResults . Should ( ) . NotBeNull ( ) ;
220
+ foreach ( var result in doc . ProcessorResults )
221
+ {
222
+ result . Document . Should ( ) . NotBeNull ( ) ;
223
+ result . Document . Ingest . Should ( ) . NotBeNull ( ) ;
224
+ }
225
+ }
226
+ }
227
+
228
+ protected override Func < SimulatePipelineDescriptor , ISimulatePipelineRequest > Fluent => f => base . Fluent ( f . Verbose ( ) ) ;
229
+
230
+ protected override SimulatePipelineRequest Initializer
231
+ {
232
+ get
233
+ {
234
+ var initializer = base . Initializer ;
235
+ initializer . Verbose = true ;
236
+ return initializer ;
237
+ }
238
+ }
239
+ }
40
240
}
0 commit comments