1 /* 2 * Copyright 2015 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.netty; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertSame; 21 import static org.junit.Assert.assertTrue; 22 import static org.junit.Assert.fail; 23 24 import io.grpc.InternalManagedChannelProvider; 25 import io.grpc.InternalServiceProviders; 26 import io.grpc.ManagedChannelProvider; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.junit.runners.JUnit4; 30 31 /** Unit tests for {@link NettyChannelProvider}. */ 32 @RunWith(JUnit4.class) 33 public class NettyChannelProviderTest { 34 private NettyChannelProvider provider = new NettyChannelProvider(); 35 36 @Test provided()37 public void provided() { 38 for (ManagedChannelProvider current 39 : InternalServiceProviders.getCandidatesViaServiceLoader( 40 ManagedChannelProvider.class, getClass().getClassLoader())) { 41 if (current instanceof NettyChannelProvider) { 42 return; 43 } 44 } 45 fail("ServiceLoader unable to load NettyChannelProvider"); 46 } 47 48 @Test providedHardCoded()49 public void providedHardCoded() { 50 for (ManagedChannelProvider current : InternalServiceProviders.getCandidatesViaHardCoded( 51 ManagedChannelProvider.class, InternalManagedChannelProvider.HARDCODED_CLASSES)) { 52 if (current instanceof NettyChannelProvider) { 53 return; 54 } 55 } 56 fail("Hard coded unable to load NettyChannelProvider"); 57 } 58 59 @Test basicMethods()60 public void basicMethods() { 61 assertTrue(provider.isAvailable()); 62 assertEquals(5, provider.priority()); 63 } 64 65 @Test builderIsANettyBuilder()66 public void builderIsANettyBuilder() { 67 assertSame(NettyChannelBuilder.class, provider.builderForAddress("localhost", 443).getClass()); 68 } 69 } 70