Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
package software.amazon.smithy.protocoltests.traits.eventstream;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
Expand Down Expand Up @@ -137,7 +139,7 @@ public Optional<String> getBodyMediaType() {
* @return Returns an optional binary representation of the entire event.
*/
public Optional<byte[]> getBytes() {
return Optional.of(bytes);
return Optional.ofNullable(bytes);
}

/**
Expand Down Expand Up @@ -185,6 +187,37 @@ public static Builder builder() {
return new Builder();
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Event)) {
return false;
}
Event event = (Event) o;
return type == event.type && Objects.equals(params, event.params)
&& Objects.equals(headers, event.headers)
&& Objects.equals(forbidHeaders, event.forbidHeaders)
&& Objects.equals(requireHeaders, event.requireHeaders)
&& Objects.equals(body, event.body)
&& Objects.equals(bodyMediaType, event.bodyMediaType)
&& Objects.deepEquals(bytes, event.bytes)
&& Objects.equals(vendorParams, event.vendorParams)
&& Objects.equals(vendorParamsShape, event.vendorParamsShape);
}

@Override
public int hashCode() {
return Objects.hash(type,
params,
headers,
forbidHeaders,
requireHeaders,
body,
bodyMediaType,
Arrays.hashCode(bytes),
vendorParams,
vendorParamsShape);
}

/**
* Builder used to create {@link Event}.
*/
Expand Down Expand Up @@ -244,7 +277,11 @@ public Builder bodyMediaType(String bodyMediaType) {
}

public Builder bytes(String bytes) {
this.bytes = Base64.getDecoder().decode(bytes.getBytes(StandardCharsets.UTF_8));
if (bytes == null) {
this.bytes = null;
} else {
this.bytes = Base64.getDecoder().decode(bytes.getBytes(StandardCharsets.UTF_8));
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package software.amazon.smithy.protocoltests.traits.eventstream;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
Expand Down Expand Up @@ -195,6 +196,45 @@ public static Builder builder() {
return new Builder();
}

@Override
public boolean equals(Object o) {
if (!(o instanceof EventStreamTestCase)) {
return false;
}
EventStreamTestCase that = (EventStreamTestCase) o;
return Objects.equals(id, that.id) && Objects.equals(protocol, that.protocol)
&& Objects.equals(initialRequestParams, that.initialRequestParams)
&& Objects.equals(initialRequest, that.initialRequest)
&& Objects.equals(initialRequestShape, that.initialRequestShape)
&& Objects.equals(initialResponseParams, that.initialResponseParams)
&& Objects.equals(initialResponse, that.initialResponse)
&& Objects.equals(initialResponseShape, that.initialResponseShape)
&& Objects.equals(events, that.events)
&& Objects.equals(expectation, that.expectation)
&& Objects.equals(vendorParams, that.vendorParams)
&& Objects.equals(vendorParamsShape, that.vendorParamsShape)
&& Objects.equals(documentation, that.documentation)
&& appliesTo == that.appliesTo;
}

@Override
public int hashCode() {
return Objects.hash(id,
protocol,
initialRequestParams,
initialRequest,
initialRequestShape,
initialResponseParams,
initialResponse,
initialResponseShape,
events,
expectation,
vendorParams,
vendorParamsShape,
documentation,
appliesTo);
}

/**
* Builder used to create {@link EventStreamTestCase}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.node.ArrayNode;
Expand Down Expand Up @@ -58,6 +59,20 @@ public List<EventStreamTestCase> getTestCasesFor(AppliesTo appliesTo) {
.collect(Collectors.toList());
}

@Override
public boolean equals(Object o) {
if (!(o instanceof EventStreamTestsTrait)) {
return false;
}
EventStreamTestsTrait that = (EventStreamTestsTrait) o;
return Objects.equals(testCases, that.testCases);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), testCases);
}

@Override
protected Node createNode() {
NodeMapper mapper = new NodeMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.protocoltests.traits.eventstream;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.node.NodeMapper;

public class EventTest {
@Test
public void testReserializeEventWithoutBytes() {
NodeMapper mapper = new NodeMapper();
Event expected = Event.builder()
.type(EventType.REQUEST)
.build();
Event actual = mapper.deserialize(mapper.serialize(expected), Event.class);
assertEquals(expected, actual);
}
}
Loading