Skip to content

Commit

Permalink
Serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Aug 7, 2023
1 parent e6a896c commit bda405a
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(apiKeyName);
out.writeOptionalBoolean(ownedByAuthenticatedUser);
out.writeBoolean(randomBoolean());
out.writeBoolean(randomBoolean());
}
}

Expand Down Expand Up @@ -143,6 +144,7 @@ public void testSerialization() throws IOException {
.apiKeyId(apiKeyId)
.ownedByAuthenticatedUser(true)
.withLimitedBy(randomBoolean())
.activeOnly(randomBoolean())
.build();
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
Expand All @@ -157,17 +159,46 @@ public void testSerialization() throws IOException {
assertThat(requestFromInputStream.ownedByAuthenticatedUser(), is(true));
// old version so the default for `withLimitedBy` is false
assertThat(requestFromInputStream.withLimitedBy(), is(false));
// old version so the default for `activeOnly` is false
assertThat(requestFromInputStream.activeOnly(), is(false));
}
{
final GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.builder().apiKeyId(apiKeyId).withLimitedBy(randomBoolean()).build();
final GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.builder()
.apiKeyId(apiKeyId)
.ownedByAuthenticatedUser(randomBoolean())
.withLimitedBy(randomBoolean())
.activeOnly(randomBoolean())
.build();
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
TransportVersion beforeActiveOnly = TransportVersion.V_8_500_051;
out.setTransportVersion(randomVersionBetween(random(), TransportVersion.V_8_5_0, beforeActiveOnly));
getApiKeyRequest.writeTo(out);

InputStreamStreamInput inputStreamStreamInput = new InputStreamStreamInput(new ByteArrayInputStream(outBuffer.toByteArray()));
inputStreamStreamInput.setTransportVersion(randomVersionBetween(random(), TransportVersion.V_8_5_0, beforeActiveOnly));
GetApiKeyRequest requestFromInputStream = new GetApiKeyRequest(inputStreamStreamInput);

assertThat(requestFromInputStream.getApiKeyId(), equalTo(getApiKeyRequest.getApiKeyId()));
assertThat(requestFromInputStream.ownedByAuthenticatedUser(), is(getApiKeyRequest.ownedByAuthenticatedUser()));
assertThat(requestFromInputStream.withLimitedBy(), is(getApiKeyRequest.withLimitedBy()));
// old version so the default for `activeOnly` is false
assertThat(requestFromInputStream.activeOnly(), is(false));
}
{
final GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.builder()
.apiKeyId(apiKeyId)
.withLimitedBy(randomBoolean())
.activeOnly(randomBoolean())
.build();
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
out.setTransportVersion(randomVersionBetween(random(), TransportVersion.V_8_5_0, TransportVersion.current()));
out.setTransportVersion(randomVersionBetween(random(), TransportVersion.V_8_500_052, TransportVersion.current()));
getApiKeyRequest.writeTo(out);

InputStreamStreamInput inputStreamStreamInput = new InputStreamStreamInput(new ByteArrayInputStream(outBuffer.toByteArray()));
inputStreamStreamInput.setTransportVersion(
randomVersionBetween(random(), TransportVersion.V_8_5_0, TransportVersion.current())
randomVersionBetween(random(), TransportVersion.V_8_500_052, TransportVersion.current())
);
GetApiKeyRequest requestFromInputStream = new GetApiKeyRequest(inputStreamStreamInput);

Expand Down

0 comments on commit bda405a

Please sign in to comment.