Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright 2018 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.internal;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 
     21 import com.google.common.testing.EqualsTester;
     22 import io.grpc.Attributes;
     23 import io.grpc.internal.ClientTransportFactory.ClientTransportOptions;
     24 import java.net.InetSocketAddress;
     25 import org.junit.Test;
     26 import org.junit.runner.RunWith;
     27 import org.junit.runners.JUnit4;
     28 
     29 @RunWith(JUnit4.class)
     30 public final class ClientTransportFactoryTest {
     31   private String authority = "testing123";
     32   private Attributes eagAttributes =
     33       Attributes.newBuilder().set(Attributes.Key.create("fake key"), "fake value").build();
     34   private String userAgent = "best-ua/3.14";
     35   private ProxyParameters proxyParameters =
     36       new ProxyParameters(new InetSocketAddress(0), null, null);
     37 
     38   @Test
     39   public void clientTransportOptions_init_checkNotNulls() {
     40     ClientTransportOptions cto = new ClientTransportOptions();
     41     assertThat(cto.getAuthority()).isNotNull();
     42     assertThat(cto.getEagAttributes()).isEqualTo(Attributes.EMPTY);
     43   }
     44 
     45   @Test
     46   public void clientTransportOptions_getsMatchSets() {
     47     ClientTransportOptions cto = new ClientTransportOptions()
     48         .setAuthority(authority)
     49         .setEagAttributes(eagAttributes)
     50         .setUserAgent(userAgent)
     51         .setProxyParameters(proxyParameters);
     52     assertThat(cto.getAuthority()).isEqualTo(authority);
     53     assertThat(cto.getEagAttributes()).isEqualTo(eagAttributes);
     54     assertThat(cto.getUserAgent()).isEqualTo(userAgent);
     55     assertThat(cto.getProxyParameters()).isSameAs(proxyParameters);
     56   }
     57 
     58   @Test
     59   public void clientTransportOptions_equals() {
     60     new EqualsTester()
     61         .addEqualityGroup(new ClientTransportOptions())
     62         .addEqualityGroup(
     63             new ClientTransportOptions()
     64               .setAuthority(authority),
     65             new ClientTransportOptions()
     66               .setAuthority(authority)
     67               .setEagAttributes(Attributes.EMPTY))
     68         .addEqualityGroup(
     69             new ClientTransportOptions()
     70               .setAuthority(authority)
     71               .setEagAttributes(eagAttributes))
     72         .addEqualityGroup(
     73             new ClientTransportOptions()
     74               .setAuthority(authority)
     75               .setEagAttributes(eagAttributes)
     76               .setUserAgent(userAgent))
     77         .addEqualityGroup(
     78             new ClientTransportOptions()
     79               .setAuthority(authority)
     80               .setEagAttributes(eagAttributes)
     81               .setUserAgent(userAgent)
     82               .setProxyParameters(proxyParameters),
     83             new ClientTransportOptions()
     84               .setAuthority(authority)
     85               .setEagAttributes(eagAttributes)
     86               .setUserAgent(userAgent)
     87               .setProxyParameters(proxyParameters))
     88         .testEquals();
     89   }
     90 }
     91