-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathTemplateTests.cs
109 lines (93 loc) · 3.79 KB
/
TemplateTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using FluentAssertions;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;
namespace Nest.Tests.Integration.Template
{
[TestFixture]
public class TemplateTests : IntegrationTests
{
[Test]
public void SimplePutAndGet()
{
this._client.DeleteTemplate("put-template-with-settings");
var putResponse = this._client.PutTemplate("put-template-with-settings", t => t
.Template("donotinfluencothertests-*")
.Order(42)
);
Assert.IsTrue(putResponse.Acknowledged);
var templateResponse = this._client.GetTemplate("put-template-with-settings");
templateResponse.Should().NotBeNull();
templateResponse.IsValid.Should().BeTrue();
templateResponse.TemplateMapping.Should().NotBeNull();
templateResponse.TemplateMapping.Mappings.Should().NotBeNull();
var settings = templateResponse.TemplateMapping.Settings;
templateResponse.TemplateMapping.Order.Should().Be(42);
settings.Should().NotBeNull();
}
[Test]
public void PutTemplateWithSettings()
{
this._client.DeleteTemplate("put-template-with-settings");
var putResponse = this._client.PutTemplate("put-template-with-settings", t=>t
.Template("donotinfluencothertests-*")
.Settings(s=>s
.Add("index.number_of_shards", 3)
.Add("index.number_of_replicas", 2)
)
);
Assert.IsTrue(putResponse.Acknowledged);
var templateResponse = this._client.GetTemplate("put-template-with-settings");
templateResponse.Should().NotBeNull();
templateResponse.IsValid.Should().BeTrue();
templateResponse.TemplateMapping.Should().NotBeNull();
templateResponse.TemplateMapping.Mappings.Should().NotBeNull();
var settings = templateResponse.TemplateMapping.Settings;
settings.Should().NotBeNull();
Assert.AreEqual("3", settings["index.number_of_shards"]);
Assert.AreEqual("2", settings["index.number_of_replicas"]);
}
[Test]
public void PutTemplateWithMappings()
{
this._client.DeleteTemplate("put-template-with-mappings");
var putResponse = this._client.PutTemplate("put-template-with-mappings",t => t
.Template("donotinfluencothertests")
.AddMapping<ElasticsearchProject>(s=>s
.AllField(a=>a.Enabled(false))
)
);
Assert.IsTrue(putResponse.Acknowledged);
var templateResponse = this._client.GetTemplate("put-template-with-mappings");
templateResponse.Should().NotBeNull();
templateResponse.IsValid.Should().BeTrue();
templateResponse.TemplateMapping.Should().NotBeNull();
templateResponse.TemplateMapping.Mappings.Should().NotBeNull().And.NotBeEmpty();
var mappings = templateResponse.TemplateMapping.Mappings;
Assert.IsTrue(mappings.ContainsKey("elasticsearchprojects"), "put-template-with-mappings template should have a `mytype` mapping");
Assert.NotNull(mappings["elasticsearchprojects"].AllFieldMapping, "`mytype` mapping should contain the _all field mapping");
Assert.AreEqual(false, mappings["elasticsearchprojects"].AllFieldMapping._Enabled, "_all { enabled } should be set to false");
}
[Test]
public void PutTemplateWithWarmers()
{
this._client.DeleteTemplate("put-template-with-warmers");
var putResponse = this._client.PutTemplate("put-template-with-warmers", t => t
.Template("donotinfluencothertests2")
.AddWarmer<ElasticsearchProject>(w => w
.WarmerName("matchall")
.Type("elasticsearchprojects")
.Search(s=>s
.MatchAll()
)
)
);
Assert.IsTrue(putResponse.Acknowledged);
var templateResponse = this._client.GetTemplate("put-template-with-warmers");
templateResponse.Should().NotBeNull();
templateResponse.IsValid.Should().BeTrue();
templateResponse.TemplateMapping.Should().NotBeNull();
//possible elasticsearch bug https://github.com/elasticsearch/elasticsearch/issues/2868
//templateResponse.TemplateMapping.Warmers.Should().NotBeNull().And.NotBeEmpty();
}
}
}