-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix StartBasicLicense API integration tests
This commit fixes the StartBasicLicense integration tests. Introduce custom JsonFormatter to handle the structure of StartBasicLicenseFeatureAcknowledgements
- Loading branch information
Showing
3 changed files
with
66 additions
and
33 deletions.
There are no files selected for viewing
71 changes: 60 additions & 11 deletions
71
src/Nest/XPack/License/StartBasicLicense/StartBasicLicenseResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 6 additions & 9 deletions
15
src/Tests/Tests/XPack/License/StartBasicLicense/StartBasicLicenseApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters