From 5264aa72f2b6010642f20f97f116405dcc0ed39d Mon Sep 17 00:00:00 2001 From: Santiago Pericas-Geertsen Date: Thu, 6 Jun 2024 11:06:57 -0400 Subject: [PATCH] Restores unit tests in MP gRPC module. Signed-off-by: Santiago Pericas-Geertsen --- microprofile/grpc/server/pom.xml | 5 ++ .../grpc/server/GrpcServerImpl.java | 7 +-- .../microprofile/grpc/server/EchoService.java | 47 +++++++++++++++++++ .../grpc/server/EchoServiceTest.java | 35 ++++++++++++++ .../grpc/server/GrpcServiceBuilderTest.java | 13 ++--- .../grpc/server/StubMarshaller.java | 7 ++- .../grpc/server/src/test/proto/echo.proto | 30 ++++++++++++ ...> io.helidon.grpc.core.MarshallerSupplier} | 0 ...croprofile.grpc.server.spi.GrpcMpExtension | 17 ------- 9 files changed, 129 insertions(+), 32 deletions(-) create mode 100644 microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoService.java create mode 100644 microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoServiceTest.java create mode 100644 microprofile/grpc/server/src/test/proto/echo.proto rename microprofile/grpc/server/src/test/resources/META-INF/services/{io.helidon.grpc.server.MarshallerSupplier => io.helidon.grpc.core.MarshallerSupplier} (100%) delete mode 100644 microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.microprofile.grpc.server.spi.GrpcMpExtension diff --git a/microprofile/grpc/server/pom.xml b/microprofile/grpc/server/pom.xml index f820c8aeddb..ebf165bcf89 100644 --- a/microprofile/grpc/server/pom.xml +++ b/microprofile/grpc/server/pom.xml @@ -76,6 +76,11 @@ org.slf4j slf4j-jdk14 + + io.helidon.microprofile.testing + helidon-microprofile-testing-junit5 + test + org.junit.jupiter junit-jupiter-api diff --git a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerImpl.java b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerImpl.java index c0a88b852f5..3aa7a151e7b 100644 --- a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerImpl.java +++ b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerImpl.java @@ -16,6 +16,7 @@ package io.helidon.microprofile.grpc.server; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import io.helidon.common.context.Context; @@ -47,17 +48,17 @@ public Context context() { @Override public CompletionStage start() { - return null; + return CompletableFuture.completedFuture(null); } @Override public CompletionStage whenShutdown() { - return null; + return CompletableFuture.completedFuture(null); } @Override public CompletionStage shutdown() { - return null; + return CompletableFuture.completedFuture(null); } @Override diff --git a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoService.java b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoService.java new file mode 100644 index 00000000000..0180267b819 --- /dev/null +++ b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoService.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.microprofile.grpc.server; + +import io.grpc.stub.StreamObserver; +import io.helidon.grpc.server.test.Echo.EchoRequest; +import io.helidon.grpc.server.test.Echo.EchoResponse; +import io.helidon.microprofile.grpc.core.Grpc; +import io.helidon.microprofile.grpc.core.Unary; +import jakarta.enterprise.context.ApplicationScoped; + +import static io.helidon.grpc.core.ResponseHelper.complete; + +/** + * A simple test gRPC echo service. + */ +@Grpc +@ApplicationScoped +public class EchoService { + + /** + * Echo the message back to the caller. + * + * @param request the echo request containing the message to echo + * @param observer the call response + */ + @Unary + public void echo(EchoRequest request, StreamObserver observer) { + String message = request.getMessage(); + EchoResponse response = EchoResponse.newBuilder().setMessage(message).build(); + complete(observer, response); + } +} diff --git a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoServiceTest.java b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoServiceTest.java new file mode 100644 index 00000000000..9c88a54fe88 --- /dev/null +++ b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/EchoServiceTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.microprofile.grpc.server; + +import io.helidon.microprofile.testing.junit5.AddExtension; +import io.helidon.microprofile.testing.junit5.HelidonTest; +import jakarta.enterprise.inject.spi.CDI; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +@HelidonTest +@AddExtension(GrpcServerCdiExtension.class) +class EchoServiceTest { + + @Test + void test() { + assertThat(CDI.current(), is(notNullValue())); + } +} diff --git a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilderTest.java b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilderTest.java index 66216e01dd8..2548d3d1346 100644 --- a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilderTest.java +++ b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilderTest.java @@ -20,22 +20,20 @@ import java.util.List; import java.util.Map; -import io.helidon.webserver.grpc.MethodDescriptor; -import io.helidon.webserver.grpc.ServiceDescriptor; -import io.helidon.microprofile.grpc.core.Grpc; -import io.helidon.microprofile.grpc.core.GrpcMarshaller; -import io.helidon.microprofile.grpc.core.GrpcMethod; - import io.grpc.Metadata; import io.grpc.ServerCall; import io.grpc.ServerCallHandler; import io.grpc.stub.StreamObserver; +import io.helidon.microprofile.grpc.core.Grpc; +import io.helidon.microprofile.grpc.core.GrpcMarshaller; +import io.helidon.microprofile.grpc.core.GrpcMethod; +import io.helidon.webserver.grpc.MethodDescriptor; +import io.helidon.webserver.grpc.ServiceDescriptor; import jakarta.enterprise.inject.Instance; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Singleton; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Disabled; import org.mockito.ArgumentCaptor; import static org.hamcrest.CoreMatchers.is; @@ -47,7 +45,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@Disabled public class GrpcServiceBuilderTest { private BeanManager beanManager; diff --git a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/StubMarshaller.java b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/StubMarshaller.java index 43a4c6c572e..a20f296d99d 100644 --- a/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/StubMarshaller.java +++ b/microprofile/grpc/server/src/test/java/io/helidon/microprofile/grpc/server/StubMarshaller.java @@ -29,8 +29,7 @@ * This marshaller will not actually work and should not * be used as a real marshaller. */ -public class StubMarshaller - implements MethodDescriptor.Marshaller { +public class StubMarshaller implements MethodDescriptor.Marshaller { @Override public InputStream stream(T value) { @@ -43,8 +42,8 @@ public T parse(InputStream stream) { } @Named("stub") - public static class Supplier - implements MarshallerSupplier { + public static class Supplier implements MarshallerSupplier { + @Override public MethodDescriptor.Marshaller get(Class clazz) { return new StubMarshaller<>(); diff --git a/microprofile/grpc/server/src/test/proto/echo.proto b/microprofile/grpc/server/src/test/proto/echo.proto new file mode 100644 index 00000000000..739b442d005 --- /dev/null +++ b/microprofile/grpc/server/src/test/proto/echo.proto @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; +option java_package = "io.helidon.grpc.server.test"; + +service EchoService { + rpc Echo (EchoRequest) returns (EchoResponse) {} +} + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; +} diff --git a/microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.grpc.server.MarshallerSupplier b/microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.grpc.core.MarshallerSupplier similarity index 100% rename from microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.grpc.server.MarshallerSupplier rename to microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.grpc.core.MarshallerSupplier diff --git a/microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.microprofile.grpc.server.spi.GrpcMpExtension b/microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.microprofile.grpc.server.spi.GrpcMpExtension deleted file mode 100644 index b1e27c19138..00000000000 --- a/microprofile/grpc/server/src/test/resources/META-INF/services/io.helidon.microprofile.grpc.server.spi.GrpcMpExtension +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright (c) 2019, 2024 Oracle and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -io.helidon.microprofile.grpc.server.GrpcServerCdiExtensionIT$ExtensionTwo \ No newline at end of file