Skip to content

Commit

Permalink
Fix StartBasicLicense API integration tests
Browse files Browse the repository at this point in the history
This commit fixes the StartBasicLicense integration tests.
Introduce custom JsonFormatter to handle the structure of
StartBasicLicenseFeatureAcknowledgements
  • Loading branch information
russcam committed Mar 27, 2019
1 parent b909ac4 commit 61f5545
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,45 +1,94 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization;
using Elasticsearch.Net;

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<string, string[]>
{
internal StartBasicLicenseFeatureAcknowledgements(IDictionary<string, string[]> dictionary)
: base(dictionary) { }

[DataMember(Name = "message")]
public string Message { get; internal set; }
}

internal class StartBasicLicenseFeatureAcknowledgementsFormatter : IJsonFormatter<StartBasicLicenseFeatureAcknowledgements>
{
private static readonly ArrayFormatter<string> StringArrayFormatter = new ArrayFormatter<string>();

public StartBasicLicenseFeatureAcknowledgements Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
if (reader.ReadIsNull())
return null;

var count = 0;
string message = null;
var dict = new Dictionary<string, string[]>();
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();
}
}
}
13 changes: 0 additions & 13 deletions src/Tests/Tests.Core/Xunit/SkipOnTeamCityAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <summary>
/// Indicates a test that is failing due to a change not related to request/response structure changes
/// <pre>Warrants deeper investigation preferably as a separate PR</pre>
/// </summary>
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;
}
}
Original file line number Diff line number Diff line change
@@ -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<BasicLicenseCluster, IStartBasicLicenseResponse, IStartBasicLicenseRequest, StartBasicLicenseDescriptor, StartBasicLicenseRequest>
public class StartBasicLicenseInvalidApiTests
: ApiIntegrationTestBase<XPackCluster, IStartBasicLicenseResponse, IStartBasicLicenseRequest, StartBasicLicenseDescriptor,
StartBasicLicenseRequest>
{
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;
Expand Down

0 comments on commit 61f5545

Please sign in to comment.