|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2020 Michael Zhang <[email protected]> |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 5 | + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 6 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 7 | + * permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 8 | + * |
| 9 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
| 10 | + * Software. |
| 11 | + * |
| 12 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 13 | + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 14 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 15 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 16 | + */ |
| 17 | + |
| 18 | +package net.devh.boot.grpc.server.serverfactory; |
| 19 | + |
| 20 | +import static java.util.Collections.emptyList; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import io.grpc.ServerBuilder; |
| 27 | +import io.grpc.netty.NettyServerBuilder; |
| 28 | +import io.grpc.protobuf.services.ProtoReflectionService; |
| 29 | +import io.grpc.reflection.v1alpha.ServerReflectionGrpc; |
| 30 | +import io.grpc.services.HealthStatusManager; |
| 31 | +import net.devh.boot.grpc.server.config.GrpcServerProperties; |
| 32 | +import net.devh.boot.grpc.server.service.GrpcServiceDefinition; |
| 33 | + |
| 34 | +/** |
| 35 | + * Tests for {@link AbstractGrpcServerFactory}. |
| 36 | + */ |
| 37 | +class AbstractGrpcServerFactoryTest { |
| 38 | + |
| 39 | + /** |
| 40 | + * Tests {@link AbstractGrpcServerFactory#configureServices(ServerBuilder)}. |
| 41 | + */ |
| 42 | + @Test |
| 43 | + void testConfigureServices() { |
| 44 | + final GrpcServerProperties properties = new GrpcServerProperties(); |
| 45 | + properties.setReflectionServiceEnabled(false); |
| 46 | + |
| 47 | + final NettyGrpcServerFactory serverFactory = new NettyGrpcServerFactory(properties, emptyList()); |
| 48 | + serverFactory.healthStatusManager = new HealthStatusManager(); |
| 49 | + |
| 50 | + serverFactory.addService(new GrpcServiceDefinition("test1", ProtoReflectionService.class, |
| 51 | + ProtoReflectionService.newInstance().bindService())); |
| 52 | + serverFactory.addService(new GrpcServiceDefinition("test2", ProtoReflectionService.class, |
| 53 | + ProtoReflectionService.newInstance().bindService())); |
| 54 | + |
| 55 | + final NettyServerBuilder serverBuilder = serverFactory.newServerBuilder(); |
| 56 | + |
| 57 | + assertEquals("Found duplicate service implementation: " + ServerReflectionGrpc.SERVICE_NAME, |
| 58 | + assertThrows(IllegalStateException.class, () -> serverFactory.configureServices(serverBuilder)) |
| 59 | + .getMessage()); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments