-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protocol traits now list the traits that protocol implementations must understand in order to successfully implement the protocol. This provides the ability to better ensure correctness of protocol implementations as protocols evolve.
- Loading branch information
Showing
5 changed files
with
195 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
37 changes: 37 additions & 0 deletions
37
...-model/src/test/java/software/amazon/smithy/model/traits/ProtocolDefinitionTraitTest.java
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package software.amazon.smithy.model.traits; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.model.node.ArrayNode; | ||
import software.amazon.smithy.model.node.Node; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
|
||
public class ProtocolDefinitionTraitTest { | ||
@Test | ||
public void loadsTrait() { | ||
TraitFactory provider = TraitFactory.createServiceFactory(); | ||
ArrayNode values = Node.fromStrings( | ||
JsonNameTrait.ID.toString(), | ||
XmlNameTrait.ID.toString()); | ||
Node node = Node.objectNode().withMember("traits", values); | ||
Optional<Trait> trait = provider.createTrait( | ||
ShapeId.from("smithy.api#protocolDefinition"), | ||
ShapeId.from("ns.qux#foo"), | ||
node); | ||
|
||
assertTrue(trait.isPresent()); | ||
assertThat(trait.get(), instanceOf(ProtocolDefinitionTrait.class)); | ||
ProtocolDefinitionTrait protocolDefinitionTrait = (ProtocolDefinitionTrait) trait.get(); | ||
assertThat(protocolDefinitionTrait.getTraits(), containsInAnyOrder( | ||
JsonNameTrait.ID, XmlNameTrait.ID)); | ||
assertThat(protocolDefinitionTrait.toNode(), equalTo(node)); | ||
assertThat(protocolDefinitionTrait.toBuilder().build(), equalTo(protocolDefinitionTrait)); | ||
} | ||
} |