|
| 1 | +using Newtonsoft.Json; |
| 2 | +using NUnit.Framework; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.IO; |
| 6 | +using System.Linq; |
| 7 | +using System.Reflection; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | + |
| 11 | +namespace Nest.Tests.Unit.Core.Map |
| 12 | +{ |
| 13 | + class GetMappingSerializationTests : BaseJsonTests |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// Verify that we can serialize/deserialize a populated root mapping. |
| 17 | + /// If we can round trip a full root mapping, we're in a pretty good place. |
| 18 | + /// </summary> |
| 19 | + [Test] |
| 20 | + public void CanDeserializeRootMapping() |
| 21 | + { |
| 22 | + var rootMapping = new RootObjectMapping() |
| 23 | + { |
| 24 | + AllFieldMapping = new AllFieldMapping() |
| 25 | + { |
| 26 | + Enabled = true, |
| 27 | + IndexAnalyzer = "index_analyzer" |
| 28 | + }, |
| 29 | + SourceFieldMappingDescriptor = new SourceFieldMapping() |
| 30 | + { |
| 31 | + Compress = false, |
| 32 | + Excludes = new[] { "excluded" } |
| 33 | + }, |
| 34 | + RoutingFieldMapping = new RoutingFieldMapping() |
| 35 | + { |
| 36 | + Path = "routing_path" |
| 37 | + }, |
| 38 | + SizeFieldMapping = new SizeFieldMapping() |
| 39 | + { |
| 40 | + Enabled = true, |
| 41 | + }, |
| 42 | + TtlFieldMappingDescriptor = new TtlFieldMapping() |
| 43 | + { |
| 44 | + Enabled = true, |
| 45 | + }, |
| 46 | + IdFieldMappingDescriptor = new IdFieldMapping() |
| 47 | + { |
| 48 | + Index = "not_analyzed", |
| 49 | + Store = false, |
| 50 | + Path = "id_field", |
| 51 | + }, |
| 52 | + TimestampFieldMapping = new TimestampFieldMapping() |
| 53 | + { |
| 54 | + Enabled = true, |
| 55 | + Format = "YYY-MM-dd", |
| 56 | + Path = "the_timestamp", |
| 57 | + }, |
| 58 | + IndexFieldMapping = new IndexFieldMapping() |
| 59 | + { |
| 60 | + Enabled = true, |
| 61 | + }, |
| 62 | + AnalyzerFieldMapping = new AnalyzerFieldMapping() |
| 63 | + { |
| 64 | + Path = "index_path", |
| 65 | + }, |
| 66 | + BoostFieldMapping = new BoostFieldMapping() |
| 67 | + { |
| 68 | + Name = "boost", |
| 69 | + NullValue = 2.0, |
| 70 | + }, |
| 71 | + Parent = new ParentTypeMapping() |
| 72 | + { |
| 73 | + Type = "type" |
| 74 | + }, |
| 75 | + TypeFieldMappingDescriptor = new TypeFieldMapping() |
| 76 | + { |
| 77 | + Index = NonStringIndexOption.NotAnalyzed, |
| 78 | + Store = false, |
| 79 | + } |
| 80 | + }; |
| 81 | + var json = TestElasticClient.Serialize(rootMapping); |
| 82 | + |
| 83 | + var mapping = TestElasticClient.Deserialize<RootObjectMapping>(json); |
| 84 | + TestElasticClient.Serialize(mapping).JsonEquals(json); |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Verify that we can serialize/deserialize an empty root mapping. One of the |
| 89 | + /// failure modes of serialization/deserialization is handling data that's not there. |
| 90 | + /// </summary> |
| 91 | + [Test] |
| 92 | + public void CanDeserializeEmptyRootMapping() |
| 93 | + { |
| 94 | + var rootMapping = new RootObjectMapping() |
| 95 | + { |
| 96 | + }; |
| 97 | + var json = TestElasticClient.Serialize(rootMapping); |
| 98 | + |
| 99 | + var mapping = TestElasticClient.Deserialize<RootObjectMapping>(json); |
| 100 | + TestElasticClient.Serialize(mapping).JsonEquals(json); |
| 101 | + } |
| 102 | + |
| 103 | + } |
| 104 | +} |
0 commit comments