From e5ec5c926fe3378bfab92c6df2f056056c2e0f37 Mon Sep 17 00:00:00 2001 From: Yash Mewada Date: Mon, 26 Jan 2026 10:23:52 -0800 Subject: [PATCH 1/3] Fix protocol initialization for AwsRestJson1Protocol --- .../server/restjson/AwsRestJson1Protocol.java | 7 +- .../AwsRestJson1ProtocolProvider.java | 2 +- .../restjson/AwsRestJson1ProtocolTest.java | 226 ++++++++++++++++++ .../smithy/java/core/schema/Schema.java | 2 +- .../harness/ProtocolTestProtocolProvider.java | 2 +- .../java/server/core/ProtocolResolver.java | 2 +- .../server/core/ServerProtocolProvider.java | 2 +- .../rpcv2/RpcV2CborProtocolProvider.java | 4 +- .../server/rpcv2/RpcV2CborProtocolTest.java | 189 +++++++++++++++ 9 files changed, 428 insertions(+), 8 deletions(-) create mode 100644 aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java create mode 100644 server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java diff --git a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java index 786b69707..4cec5f3f8 100644 --- a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java +++ b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java @@ -53,9 +53,14 @@ final class AwsRestJson1Protocol extends ServerProtocol { var httpMethodToMatchers = new HashMap>>(); for (Service service : services) { for (var operation : service.getAllOperations()) { + // Only process operations with HTTP trait. var httpTrait = operation.getApiOperation() .schema() - .expectTrait(TraitKey.HTTP_TRAIT); + .getTrait(TraitKey.HTTP_TRAIT); + if (httpTrait == null) { + continue; + } + String method = httpTrait.getMethod(); String pattern = httpTrait .getUri() diff --git a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolProvider.java b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolProvider.java index 55da044d1..536dd846c 100644 --- a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolProvider.java +++ b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolProvider.java @@ -24,7 +24,7 @@ public ShapeId getProtocolId() { } @Override - public int priority() { + public int precision() { return 0; } } diff --git a/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java b/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java new file mode 100644 index 000000000..75e10ef7d --- /dev/null +++ b/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java @@ -0,0 +1,226 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.aws.server.restjson; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import java.util.List; +import org.junit.jupiter.api.Test; +import software.amazon.smithy.aws.traits.protocols.RestJson1Trait; +import software.amazon.smithy.java.core.schema.ApiOperation; +import software.amazon.smithy.java.core.schema.ApiService; +import software.amazon.smithy.java.core.schema.Schema; +import software.amazon.smithy.java.core.schema.SchemaIndex; +import software.amazon.smithy.java.core.schema.SerializableStruct; +import software.amazon.smithy.java.core.schema.ShapeBuilder; +import software.amazon.smithy.java.core.serde.ShapeDeserializer; +import software.amazon.smithy.java.core.serde.ShapeSerializer; +import software.amazon.smithy.java.core.serde.TypeRegistry; +import software.amazon.smithy.java.server.Operation; +import software.amazon.smithy.java.server.Service; +import software.amazon.smithy.model.pattern.UriPattern; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.HttpTrait; + +public class AwsRestJson1ProtocolTest { + + @Test + void shouldInitializeWithHttpOperations() { + Service service = createServiceWithHttpOperations(); + assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); + } + + @Test + void shouldHandleOperationsWithoutHttpTraits() { + Service service = createServiceWithoutHttpOperations(); + assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); + } + + @Test + void shouldHandleMixedOperations() { + Service service = createServiceWithMixedOperations(); + AwsRestJson1Protocol protocol = assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); + assertThat(protocol, notNullValue()); + } + + @Test + void shouldHandleEmptyService() { + Service service = createEmptyService(); + assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); + } + + @Test + void shouldHandleMultipleServices() { + Service httpService = createServiceWithHttpOperations(); + Service nonHttpService = createServiceWithoutHttpOperations(); + assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(httpService, nonHttpService))); + } + + @Test + void shouldReturnCorrectProtocolId() { + Service service = createServiceWithHttpOperations(); + AwsRestJson1Protocol protocol = new AwsRestJson1Protocol(List.of(service)); + assertThat(protocol.getProtocolId(), equalTo(RestJson1Trait.ID)); + } + + private Service createServiceWithHttpOperations() { + Operation getOp = createOperationWithHttpTrait("GetItem", "GET", "/items/{id}"); + Operation postOp = createOperationWithHttpTrait("CreateItem", "POST", "/items"); + return new TestService(List.of(getOp, postOp)); + } + + private Service createServiceWithoutHttpOperations() { + Operation rpcOp = createOperationWithoutHttpTrait("RpcOperation"); + return new TestService(List.of(rpcOp)); + } + + private Service createServiceWithMixedOperations() { + Operation httpOp = createOperationWithHttpTrait("GetItem", "GET", "/items/{id}"); + Operation nonHttpOp = createOperationWithoutHttpTrait("RpcOperation"); + return new TestService(List.of(httpOp, nonHttpOp)); + } + + private Service createEmptyService() { + return new TestService(List.of()); + } + + private Operation createOperationWithHttpTrait(String name, String method, String uri) { + HttpTrait httpTrait = HttpTrait.builder() + .method(method) + .uri(UriPattern.parse(uri)) + .build(); + Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name), httpTrait).build(); + return Operation.of(name, + (input, ctx) -> new TestOutput(), + new TestApiOperation(operationSchema), + new TestService(List.of())); + } + + private Operation createOperationWithoutHttpTrait(String name) { + Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name)).build(); + return Operation.of(name, + (input, ctx) -> new TestOutput(), + new TestApiOperation(operationSchema), + new TestService(List.of())); + } + + private static class TestService implements Service { + private final List> operations; + + TestService(List> operations) { + this.operations = operations; + } + + @Override + public Operation getOperation(String operationName) { + throw new UnsupportedOperationException(); + } + + @Override + public List> getAllOperations() { + return operations; + } + + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestService")).build(); + } + + @Override + public TypeRegistry typeRegistry() { + return TypeRegistry.builder().build(); + } + + @Override + public SchemaIndex schemaIndex() { + throw new UnsupportedOperationException(); + } + } + + private static class TestApiOperation implements ApiOperation { + private final Schema operationSchema; + + TestApiOperation(Schema operationSchema) { + this.operationSchema = operationSchema; + } + + @Override + public ShapeBuilder inputBuilder() { + return new TestBuilder(); + } + + @Override + public ShapeBuilder outputBuilder() { + return new TestBuilder(); + } + + @Override + public Schema schema() { + return operationSchema; + } + + @Override + public Schema inputSchema() { + return Schema.structureBuilder(ShapeId.from("test#TestInput")).build(); + } + + @Override + public Schema outputSchema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + + @Override + public TypeRegistry errorRegistry() { + return TypeRegistry.builder().build(); + } + + @Override + public List effectiveAuthSchemes() { + return List.of(); + } + + @Override + public ApiService service() { + return () -> Schema.structureBuilder(ShapeId.from("test#TestService")).build(); + } + } + + private static class TestOutput implements SerializableStruct { + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + + @Override + public void serializeMembers(ShapeSerializer serializer) {} + + @Override + public T getMemberValue(Schema member) { + return null; + } + } + + private static class TestBuilder implements ShapeBuilder { + @Override + public TestOutput build() { + return new TestOutput(); + } + + @Override + public ShapeBuilder deserialize(ShapeDeserializer decoder) { + return this; + } + + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + } +} diff --git a/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java b/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java index e09aead78..f52af6228 100644 --- a/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java +++ b/core/src/main/java/software/amazon/smithy/java/core/schema/Schema.java @@ -387,7 +387,7 @@ public final boolean hasTrait(TraitKey trait) { public final T expectTrait(TraitKey trait) { var t = getTrait(trait); if (t == null) { - throw new NoSuchElementException("Expected trait not found: " + trait.getClass().getName()); + throw new NoSuchElementException("Expected trait not found: " + trait.traitClass().getName()); } return t; } diff --git a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestProtocolProvider.java b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestProtocolProvider.java index 195d23de1..6f4721500 100644 --- a/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestProtocolProvider.java +++ b/protocol-test-harness/src/main/java/software/amazon/smithy/java/protocoltests/harness/ProtocolTestProtocolProvider.java @@ -35,7 +35,7 @@ public ShapeId getProtocolId() { } @Override - public int priority() { + public int precision() { return Integer.MAX_VALUE; } diff --git a/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ProtocolResolver.java b/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ProtocolResolver.java index 5866057fa..80a18ea9b 100644 --- a/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ProtocolResolver.java +++ b/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ProtocolResolver.java @@ -26,7 +26,7 @@ public final class ProtocolResolver { public ProtocolResolver(ServiceMatcher serviceMatcher) { serverProtocolHandlers = SERVER_PROTOCOL_HANDLERS.values() .stream() - .sorted(Comparator.comparing(ServerProtocolProvider::priority).reversed()) + .sorted(Comparator.comparing(ServerProtocolProvider::precision)) .map(p -> p.provideProtocolHandler(serviceMatcher.getAllServices())) .toList(); this.serviceMatcher = serviceMatcher; diff --git a/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ServerProtocolProvider.java b/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ServerProtocolProvider.java index dc8e59450..6924a836b 100644 --- a/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ServerProtocolProvider.java +++ b/server/server-core/src/main/java/software/amazon/smithy/java/server/core/ServerProtocolProvider.java @@ -15,5 +15,5 @@ public interface ServerProtocolProvider { ShapeId getProtocolId(); - int priority(); + int precision(); } diff --git a/server/server-rpcv2-cbor/src/main/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolProvider.java b/server/server-rpcv2-cbor/src/main/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolProvider.java index 8045479fa..3c1d1192c 100644 --- a/server/server-rpcv2-cbor/src/main/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolProvider.java +++ b/server/server-rpcv2-cbor/src/main/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolProvider.java @@ -24,7 +24,7 @@ public ShapeId getProtocolId() { } @Override - public int priority() { - return 1; + public int precision() { + return 0; } } diff --git a/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java b/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java new file mode 100644 index 000000000..543f6fa72 --- /dev/null +++ b/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java @@ -0,0 +1,189 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.java.server.rpcv2; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import java.util.List; +import org.junit.jupiter.api.Test; +import software.amazon.smithy.java.core.schema.ApiOperation; +import software.amazon.smithy.java.core.schema.ApiService; +import software.amazon.smithy.java.core.schema.Schema; +import software.amazon.smithy.java.core.schema.SchemaIndex; +import software.amazon.smithy.java.core.schema.SerializableStruct; +import software.amazon.smithy.java.core.schema.ShapeBuilder; +import software.amazon.smithy.java.core.serde.ShapeDeserializer; +import software.amazon.smithy.java.core.serde.ShapeSerializer; +import software.amazon.smithy.java.core.serde.TypeRegistry; +import software.amazon.smithy.java.server.Operation; +import software.amazon.smithy.java.server.Service; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.protocol.traits.Rpcv2CborTrait; + +public class RpcV2CborProtocolTest { + + @Test + void shouldInitializeWithAnyOperations() { + Service service = createServiceWithOperations(); + assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service))); + } + + @Test + void shouldHandleEmptyService() { + Service service = createEmptyService(); + assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service))); + } + + @Test + void shouldHandleMultipleServices() { + Service service1 = createServiceWithOperations(); + Service service2 = createEmptyService(); + RpcV2CborProtocol protocol = assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service1, service2))); + assertThat(protocol, notNullValue()); + } + + @Test + void shouldReturnCorrectProtocolId() { + Service service = createServiceWithOperations(); + RpcV2CborProtocol protocol = new RpcV2CborProtocol(List.of(service)); + assertThat(protocol.getProtocolId(), equalTo(Rpcv2CborTrait.ID)); + } + + private Service createServiceWithOperations() { + Operation op1 = createOperation("Operation1"); + Operation op2 = createOperation("Operation2"); + return new TestService(List.of(op1, op2)); + } + + private Service createEmptyService() { + return new TestService(List.of()); + } + + private Operation createOperation(String name) { + Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name)).build(); + return Operation.of(name, + (input, ctx) -> new TestOutput(), + new TestApiOperation(operationSchema), + new TestService(List.of())); + } + + private static class TestService implements Service { + private final List> operations; + + TestService(List> operations) { + this.operations = operations; + } + + @Override + public Operation getOperation(String operationName) { + throw new UnsupportedOperationException(); + } + + @Override + public List> getAllOperations() { + return operations; + } + + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestService")).build(); + } + + @Override + public TypeRegistry typeRegistry() { + return TypeRegistry.builder().build(); + } + + @Override + public SchemaIndex schemaIndex() { + throw new UnsupportedOperationException(); + } + } + + private static class TestApiOperation implements ApiOperation { + private final Schema operationSchema; + + TestApiOperation(Schema operationSchema) { + this.operationSchema = operationSchema; + } + + @Override + public ShapeBuilder inputBuilder() { + return new TestBuilder(); + } + + @Override + public ShapeBuilder outputBuilder() { + return new TestBuilder(); + } + + @Override + public Schema schema() { + return operationSchema; + } + + @Override + public Schema inputSchema() { + return Schema.structureBuilder(ShapeId.from("test#TestInput")).build(); + } + + @Override + public Schema outputSchema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + + @Override + public TypeRegistry errorRegistry() { + return TypeRegistry.builder().build(); + } + + @Override + public List effectiveAuthSchemes() { + return List.of(); + } + + @Override + public ApiService service() { + return () -> Schema.structureBuilder(ShapeId.from("test#TestService")).build(); + } + } + + private static class TestOutput implements SerializableStruct { + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + + @Override + public void serializeMembers(ShapeSerializer serializer) {} + + @Override + public T getMemberValue(Schema member) { + return null; + } + } + + private static class TestBuilder implements ShapeBuilder { + @Override + public TestOutput build() { + return new TestOutput(); + } + + @Override + public ShapeBuilder deserialize(ShapeDeserializer decoder) { + return this; + } + + @Override + public Schema schema() { + return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); + } + } +} From d044d0060e79be1a27eccf67ca38ab170ac734bf Mon Sep 17 00:00:00 2001 From: Yash Mewada Date: Tue, 27 Jan 2026 11:44:24 -0800 Subject: [PATCH 2/3] Remove tautological protocol tests per review feedback --- .../restjson/AwsRestJson1ProtocolTest.java | 226 ------------------ .../server/rpcv2/RpcV2CborProtocolTest.java | 189 --------------- 2 files changed, 415 deletions(-) delete mode 100644 aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java delete mode 100644 server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java diff --git a/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java b/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java deleted file mode 100644 index 75e10ef7d..000000000 --- a/aws/server/aws-server-restjson/src/test/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1ProtocolTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.aws.server.restjson; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import java.util.List; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.aws.traits.protocols.RestJson1Trait; -import software.amazon.smithy.java.core.schema.ApiOperation; -import software.amazon.smithy.java.core.schema.ApiService; -import software.amazon.smithy.java.core.schema.Schema; -import software.amazon.smithy.java.core.schema.SchemaIndex; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.schema.ShapeBuilder; -import software.amazon.smithy.java.core.serde.ShapeDeserializer; -import software.amazon.smithy.java.core.serde.ShapeSerializer; -import software.amazon.smithy.java.core.serde.TypeRegistry; -import software.amazon.smithy.java.server.Operation; -import software.amazon.smithy.java.server.Service; -import software.amazon.smithy.model.pattern.UriPattern; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.traits.HttpTrait; - -public class AwsRestJson1ProtocolTest { - - @Test - void shouldInitializeWithHttpOperations() { - Service service = createServiceWithHttpOperations(); - assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); - } - - @Test - void shouldHandleOperationsWithoutHttpTraits() { - Service service = createServiceWithoutHttpOperations(); - assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); - } - - @Test - void shouldHandleMixedOperations() { - Service service = createServiceWithMixedOperations(); - AwsRestJson1Protocol protocol = assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); - assertThat(protocol, notNullValue()); - } - - @Test - void shouldHandleEmptyService() { - Service service = createEmptyService(); - assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(service))); - } - - @Test - void shouldHandleMultipleServices() { - Service httpService = createServiceWithHttpOperations(); - Service nonHttpService = createServiceWithoutHttpOperations(); - assertDoesNotThrow(() -> new AwsRestJson1Protocol(List.of(httpService, nonHttpService))); - } - - @Test - void shouldReturnCorrectProtocolId() { - Service service = createServiceWithHttpOperations(); - AwsRestJson1Protocol protocol = new AwsRestJson1Protocol(List.of(service)); - assertThat(protocol.getProtocolId(), equalTo(RestJson1Trait.ID)); - } - - private Service createServiceWithHttpOperations() { - Operation getOp = createOperationWithHttpTrait("GetItem", "GET", "/items/{id}"); - Operation postOp = createOperationWithHttpTrait("CreateItem", "POST", "/items"); - return new TestService(List.of(getOp, postOp)); - } - - private Service createServiceWithoutHttpOperations() { - Operation rpcOp = createOperationWithoutHttpTrait("RpcOperation"); - return new TestService(List.of(rpcOp)); - } - - private Service createServiceWithMixedOperations() { - Operation httpOp = createOperationWithHttpTrait("GetItem", "GET", "/items/{id}"); - Operation nonHttpOp = createOperationWithoutHttpTrait("RpcOperation"); - return new TestService(List.of(httpOp, nonHttpOp)); - } - - private Service createEmptyService() { - return new TestService(List.of()); - } - - private Operation createOperationWithHttpTrait(String name, String method, String uri) { - HttpTrait httpTrait = HttpTrait.builder() - .method(method) - .uri(UriPattern.parse(uri)) - .build(); - Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name), httpTrait).build(); - return Operation.of(name, - (input, ctx) -> new TestOutput(), - new TestApiOperation(operationSchema), - new TestService(List.of())); - } - - private Operation createOperationWithoutHttpTrait(String name) { - Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name)).build(); - return Operation.of(name, - (input, ctx) -> new TestOutput(), - new TestApiOperation(operationSchema), - new TestService(List.of())); - } - - private static class TestService implements Service { - private final List> operations; - - TestService(List> operations) { - this.operations = operations; - } - - @Override - public Operation getOperation(String operationName) { - throw new UnsupportedOperationException(); - } - - @Override - public List> getAllOperations() { - return operations; - } - - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestService")).build(); - } - - @Override - public TypeRegistry typeRegistry() { - return TypeRegistry.builder().build(); - } - - @Override - public SchemaIndex schemaIndex() { - throw new UnsupportedOperationException(); - } - } - - private static class TestApiOperation implements ApiOperation { - private final Schema operationSchema; - - TestApiOperation(Schema operationSchema) { - this.operationSchema = operationSchema; - } - - @Override - public ShapeBuilder inputBuilder() { - return new TestBuilder(); - } - - @Override - public ShapeBuilder outputBuilder() { - return new TestBuilder(); - } - - @Override - public Schema schema() { - return operationSchema; - } - - @Override - public Schema inputSchema() { - return Schema.structureBuilder(ShapeId.from("test#TestInput")).build(); - } - - @Override - public Schema outputSchema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - - @Override - public TypeRegistry errorRegistry() { - return TypeRegistry.builder().build(); - } - - @Override - public List effectiveAuthSchemes() { - return List.of(); - } - - @Override - public ApiService service() { - return () -> Schema.structureBuilder(ShapeId.from("test#TestService")).build(); - } - } - - private static class TestOutput implements SerializableStruct { - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - - @Override - public void serializeMembers(ShapeSerializer serializer) {} - - @Override - public T getMemberValue(Schema member) { - return null; - } - } - - private static class TestBuilder implements ShapeBuilder { - @Override - public TestOutput build() { - return new TestOutput(); - } - - @Override - public ShapeBuilder deserialize(ShapeDeserializer decoder) { - return this; - } - - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - } -} diff --git a/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java b/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java deleted file mode 100644 index 543f6fa72..000000000 --- a/server/server-rpcv2-cbor/src/test/java/software/amazon/smithy/java/server/rpcv2/RpcV2CborProtocolTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.java.server.rpcv2; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import java.util.List; -import org.junit.jupiter.api.Test; -import software.amazon.smithy.java.core.schema.ApiOperation; -import software.amazon.smithy.java.core.schema.ApiService; -import software.amazon.smithy.java.core.schema.Schema; -import software.amazon.smithy.java.core.schema.SchemaIndex; -import software.amazon.smithy.java.core.schema.SerializableStruct; -import software.amazon.smithy.java.core.schema.ShapeBuilder; -import software.amazon.smithy.java.core.serde.ShapeDeserializer; -import software.amazon.smithy.java.core.serde.ShapeSerializer; -import software.amazon.smithy.java.core.serde.TypeRegistry; -import software.amazon.smithy.java.server.Operation; -import software.amazon.smithy.java.server.Service; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.protocol.traits.Rpcv2CborTrait; - -public class RpcV2CborProtocolTest { - - @Test - void shouldInitializeWithAnyOperations() { - Service service = createServiceWithOperations(); - assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service))); - } - - @Test - void shouldHandleEmptyService() { - Service service = createEmptyService(); - assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service))); - } - - @Test - void shouldHandleMultipleServices() { - Service service1 = createServiceWithOperations(); - Service service2 = createEmptyService(); - RpcV2CborProtocol protocol = assertDoesNotThrow(() -> new RpcV2CborProtocol(List.of(service1, service2))); - assertThat(protocol, notNullValue()); - } - - @Test - void shouldReturnCorrectProtocolId() { - Service service = createServiceWithOperations(); - RpcV2CborProtocol protocol = new RpcV2CborProtocol(List.of(service)); - assertThat(protocol.getProtocolId(), equalTo(Rpcv2CborTrait.ID)); - } - - private Service createServiceWithOperations() { - Operation op1 = createOperation("Operation1"); - Operation op2 = createOperation("Operation2"); - return new TestService(List.of(op1, op2)); - } - - private Service createEmptyService() { - return new TestService(List.of()); - } - - private Operation createOperation(String name) { - Schema operationSchema = Schema.structureBuilder(ShapeId.from("test#" + name)).build(); - return Operation.of(name, - (input, ctx) -> new TestOutput(), - new TestApiOperation(operationSchema), - new TestService(List.of())); - } - - private static class TestService implements Service { - private final List> operations; - - TestService(List> operations) { - this.operations = operations; - } - - @Override - public Operation getOperation(String operationName) { - throw new UnsupportedOperationException(); - } - - @Override - public List> getAllOperations() { - return operations; - } - - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestService")).build(); - } - - @Override - public TypeRegistry typeRegistry() { - return TypeRegistry.builder().build(); - } - - @Override - public SchemaIndex schemaIndex() { - throw new UnsupportedOperationException(); - } - } - - private static class TestApiOperation implements ApiOperation { - private final Schema operationSchema; - - TestApiOperation(Schema operationSchema) { - this.operationSchema = operationSchema; - } - - @Override - public ShapeBuilder inputBuilder() { - return new TestBuilder(); - } - - @Override - public ShapeBuilder outputBuilder() { - return new TestBuilder(); - } - - @Override - public Schema schema() { - return operationSchema; - } - - @Override - public Schema inputSchema() { - return Schema.structureBuilder(ShapeId.from("test#TestInput")).build(); - } - - @Override - public Schema outputSchema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - - @Override - public TypeRegistry errorRegistry() { - return TypeRegistry.builder().build(); - } - - @Override - public List effectiveAuthSchemes() { - return List.of(); - } - - @Override - public ApiService service() { - return () -> Schema.structureBuilder(ShapeId.from("test#TestService")).build(); - } - } - - private static class TestOutput implements SerializableStruct { - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - - @Override - public void serializeMembers(ShapeSerializer serializer) {} - - @Override - public T getMemberValue(Schema member) { - return null; - } - } - - private static class TestBuilder implements ShapeBuilder { - @Override - public TestOutput build() { - return new TestOutput(); - } - - @Override - public ShapeBuilder deserialize(ShapeDeserializer decoder) { - return this; - } - - @Override - public Schema schema() { - return Schema.structureBuilder(ShapeId.from("test#TestOutput")).build(); - } - } -} From 309445209a4e120f2f953902d151d95783294376 Mon Sep 17 00:00:00 2001 From: Yash Mewada <128434488+yasmewad@users.noreply.github.com> Date: Wed, 28 Jan 2026 10:42:45 -0800 Subject: [PATCH 3/3] Update aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java Co-authored-by: Manuel Sugawara --- .../smithy/java/aws/server/restjson/AwsRestJson1Protocol.java | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java index 4cec5f3f8..0b465ff51 100644 --- a/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java +++ b/aws/server/aws-server-restjson/src/main/java/software/amazon/smithy/java/aws/server/restjson/AwsRestJson1Protocol.java @@ -60,7 +60,6 @@ final class AwsRestJson1Protocol extends ServerProtocol { if (httpTrait == null) { continue; } - String method = httpTrait.getMethod(); String pattern = httpTrait .getUri()