From 61f5545a2d8f77d28f590a5ae34e38bdb023de3b Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Wed, 27 Mar 2019 13:36:33 +1000 Subject: [PATCH] Fix StartBasicLicense API integration tests This commit fixes the StartBasicLicense integration tests. Introduce custom JsonFormatter to handle the structure of StartBasicLicenseFeatureAcknowledgements --- .../StartBasicLicenseResponse.cs | 71 ++++++++++++++++--- .../Xunit/SkipOnTeamCityAttribute.cs | 13 ---- .../StartBasicLicenseApiTests.cs | 15 ++-- 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src/Nest/XPack/License/StartBasicLicense/StartBasicLicenseResponse.cs b/src/Nest/XPack/License/StartBasicLicense/StartBasicLicenseResponse.cs index 34ff71b8ec8..2adfd66b127 100644 --- a/src/Nest/XPack/License/StartBasicLicense/StartBasicLicenseResponse.cs +++ b/src/Nest/XPack/License/StartBasicLicense/StartBasicLicenseResponse.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.ObjectModel; -using System.IO; using System.Runtime.Serialization; using Elasticsearch.Net; @@ -9,30 +7,29 @@ namespace Nest { public interface IStartBasicLicenseResponse : IAcknowledgedResponse { + [DataMember(Name = "acknowledge")] + StartBasicLicenseFeatureAcknowledgements Acknowledge { get; } + [DataMember(Name = "basic_was_started")] bool BasicWasStarted { get; } [DataMember(Name = "error_message")] string ErrorMessage { get; } - - [DataMember(Name = "acknowledge")] - StartBasicLicenseFeatureAcknowledgements Acknowledge { get; } } public class StartBasicLicenseResponse : AcknowledgedResponseBase, IStartBasicLicenseResponse { - //TODO: make this the default on base class for 7.0 ? - public override bool IsValid => base.IsValid && Acknowledged; + public StartBasicLicenseFeatureAcknowledgements Acknowledge { get; internal set; } public bool BasicWasStarted { get; internal set; } public string ErrorMessage { get; internal set; } - public StartBasicLicenseFeatureAcknowledgements Acknowledge { get; internal set; } + //TODO: make this the default on base class for 7.0 ? + public override bool IsValid => base.IsValid && Acknowledged; } - // TODO this might need a new formatter - //[JsonFormatter(typeof(StartBasicLicenseFeatureAcknowledgementsJsonConverter))] + [JsonFormatter(typeof(StartBasicLicenseFeatureAcknowledgementsFormatter))] public class StartBasicLicenseFeatureAcknowledgements : ReadOnlyDictionary { internal StartBasicLicenseFeatureAcknowledgements(IDictionary dictionary) @@ -40,6 +37,58 @@ internal StartBasicLicenseFeatureAcknowledgements(IDictionary [DataMember(Name = "message")] public string Message { get; internal set; } + } + + internal class StartBasicLicenseFeatureAcknowledgementsFormatter : IJsonFormatter + { + private static readonly ArrayFormatter StringArrayFormatter = new ArrayFormatter(); + + public StartBasicLicenseFeatureAcknowledgements Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) + { + if (reader.ReadIsNull()) + return null; + + var count = 0; + string message = null; + var dict = new Dictionary(); + while (reader.ReadIsInObject(ref count)) + { + var propertyName = reader.ReadPropertyName(); + if (propertyName == "message") + message = reader.ReadString(); + else + dict.Add(propertyName, StringArrayFormatter.Deserialize(ref reader, formatterResolver)); + } + + return new StartBasicLicenseFeatureAcknowledgements(dict) { Message = message }; + } + + public void Serialize(ref JsonWriter writer, StartBasicLicenseFeatureAcknowledgements value, IJsonFormatterResolver formatterResolver) + { + if (value == null) + { + writer.WriteNull(); + return; + } + + writer.WriteBeginObject(); + var count = 0; + if (!string.IsNullOrEmpty(value.Message)) + { + writer.WritePropertyName("message"); + writer.WriteString(value.Message); + count++; + } + foreach (var kv in value) + { + if (count > 0) + writer.WriteValueSeparator(); + writer.WritePropertyName(kv.Key); + StringArrayFormatter.Serialize(ref writer, kv.Value, formatterResolver); + count++; + } + writer.WriteEndObject(); + } } } diff --git a/src/Tests/Tests.Core/Xunit/SkipOnTeamCityAttribute.cs b/src/Tests/Tests.Core/Xunit/SkipOnTeamCityAttribute.cs index 2ffd827f62a..d5108bd4c4a 100644 --- a/src/Tests/Tests.Core/Xunit/SkipOnTeamCityAttribute.cs +++ b/src/Tests/Tests.Core/Xunit/SkipOnTeamCityAttribute.cs @@ -25,17 +25,4 @@ public class BlockedByIssueAttribute : SkipTestAttributeBase private string Url { get; } } - - //TODO 7.0: this attribute and all its usages have to be scrubbed before we can do a 7.x release - /// - /// Indicates a test that is failing due to a change not related to request/response structure changes - ///
Warrants deeper investigation preferably as a separate PR
- ///
- public class SkipNonStructuralChangeAttribute : SkipTestAttributeBase - { - public override string Reason => $"Tests is failing due to change not related to a structural change in request/response"; - - //only skip non structural changes when running integration tests, we do want the unit tests to be green for these in the interim. - public override bool Skip => TestConfiguration.Instance.RunIntegrationTests; - } } diff --git a/src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs b/src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs index 2a7da450d69..7f13497ad46 100644 --- a/src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs +++ b/src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs @@ -1,24 +1,21 @@ -using Elastic.Xunit.XunitPlumbing; +using System; +using Elastic.Xunit.XunitPlumbing; using Elasticsearch.Net; using FluentAssertions; using Nest; using Tests.Core.ManagedElasticsearch.Clusters; -using Tests.Core.Xunit; using Tests.Framework; using Tests.Framework.Integration; using static Elasticsearch.Net.HttpMethod; namespace Tests.XPack.License.StartBasicLicense { - public class BasicLicenseCluster : ClientTestClusterBase { } - - // TODO: cluster starts with a basic license now, investigate further - [SkipNonStructuralChange] [SkipVersion("<6.5.0", "")] - public class StartBasicLicenseApiTests - : ApiIntegrationTestBase + public class StartBasicLicenseInvalidApiTests + : ApiIntegrationTestBase { - public StartBasicLicenseApiTests(BasicLicenseCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + public StartBasicLicenseInvalidApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { } protected override bool ExpectIsValid => false; protected override int ExpectStatusCode => 200;