GrpcUtil { public static String checkAuthority(String authority) { URI uri = authorityToUri(authority); checkArgument(uri.getHost() != null, "No host in authority '%s'", authority); checkArgument(uri.getUserInfo() == null, "Userinfo must not be present on authority: '%s'", authority); return authority; } private  GrpcUtil(); static Status httpStatusToGrpcStatus(int httpStatusCode); static boolean isGrpcContentType(String contentType); static String getGrpcUserAgent(String transportName,
                                        @Nullable String applicationUserAgent); static URI authorityToUri(String authority); static String checkAuthority(String authority); static String authorityFromHostAndPort(String host, int port); static String getLogId(WithLogId subject); static final Metadata.Key<Long> TIMEOUT_KEY; static final Metadata.Key<String> MESSAGE_ENCODING_KEY; static final Metadata.Key<String> MESSAGE_ACCEPT_ENCODING_KEY; static final Metadata.Key<String> CONTENT_TYPE_KEY; static final Metadata.Key<String> USER_AGENT_KEY; static final int DEFAULT_PORT_PLAINTEXT; static final int DEFAULT_PORT_SSL; static final String CONTENT_TYPE_GRPC; static final String HTTP_METHOD; static final String TE_TRAILERS; static final String TIMEOUT; static final String MESSAGE_ENCODING; static final String MESSAGE_ACCEPT_ENCODING; static final int DEFAULT_MAX_MESSAGE_SIZE; static final int DEFAULT_MAX_HEADER_LIST_SIZE; static final Splitter ACCEPT_ENCODING_SPLITER; static final Joiner ACCEPT_ENCODING_JOINER; static final Resource<ExecutorService> SHARED_CHANNEL_EXECUTOR; static final Resource<ScheduledExecutorService> TIMER_SERVICE; }
@Test public void checkAuthority_failsOnNull() { thrown.expect(NullPointerException.class); GrpcUtil.checkAuthority(null); }
@Test public void checkAuthority_succeedsOnHostAndPort() { String actual = GrpcUtil.checkAuthority("valid:1234"); assertEquals("valid:1234", actual); }
@Test public void checkAuthority_succeedsOnHost() { String actual = GrpcUtil.checkAuthority("valid"); assertEquals("valid", actual); }
@Test public void checkAuthority_succeedsOnIpV6() { String actual = GrpcUtil.checkAuthority("[::1]"); assertEquals("[::1]", actual); }
@Test public void checkAuthority_failsOnInvalidAuthority() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Invalid authority"); GrpcUtil.checkAuthority("[ : : 1]"); }
@Test public void checkAuthority_failsOnInvalidHost() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("No host in authority"); GrpcUtil.checkAuthority("bad_host"); }
@Test public void checkAuthority_userInfoNotAllowed() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Userinfo"); GrpcUtil.checkAuthority("foo@valid"); }