Package io.grpc.internal.testing
Class TestUtils
- java.lang.Object
-
- io.grpc.internal.testing.TestUtils
-
public class TestUtils extends java.lang.ObjectInternal utility functions useful for writing tests.
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanconscryptInstallAttemptedstatic java.lang.StringTEST_SERVER_HOST
-
Constructor Summary
Constructors Modifier Constructor Description privateTestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidinstallConscryptIfAvailable()Add Conscrypt to the list of security providers, if it is available.static java.io.FileloadCert(java.lang.String name)Saves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.static java.security.cert.X509CertificateloadX509Cert(java.lang.String fileName)Loads an X.509 certificate from the classpath resources in src/main/resources/certs.static javax.net.ssl.SSLSocketFactorynewSslSocketFactoryForCa(java.security.Provider provider, java.io.File certChainFile)Creates an SSLSocketFactory which containscertChainFileas its only root certificate.static java.net.InetSocketAddresstestServerAddress(java.lang.String host, int port)Creates a newInetSocketAddressthat overrides the host withTEST_SERVER_HOST.static java.net.InetSocketAddresstestServerAddress(java.net.InetSocketAddress originalSockAddr)Creates a newInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.static java.util.List<java.net.InetSocketAddress>testServerAddresses(java.net.InetSocketAddress... originalSockAddr)Creates a new list ofInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.
-
-
-
Field Detail
-
TEST_SERVER_HOST
public static final java.lang.String TEST_SERVER_HOST
- See Also:
- Constant Field Values
-
conscryptInstallAttempted
private static boolean conscryptInstallAttempted
-
-
Method Detail
-
testServerAddress
public static java.net.InetSocketAddress testServerAddress(java.lang.String host, int port)Creates a newInetSocketAddressthat overrides the host withTEST_SERVER_HOST.
-
testServerAddress
public static java.net.InetSocketAddress testServerAddress(java.net.InetSocketAddress originalSockAddr)
Creates a newInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.
-
testServerAddresses
public static java.util.List<java.net.InetSocketAddress> testServerAddresses(java.net.InetSocketAddress... originalSockAddr)
Creates a new list ofInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.
-
loadCert
public static java.io.File loadCert(java.lang.String name) throws java.io.IOExceptionSaves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.- Parameters:
name- name of a file in src/main/resources/certs.- Throws:
java.io.IOException
-
loadX509Cert
public static java.security.cert.X509Certificate loadX509Cert(java.lang.String fileName) throws java.security.cert.CertificateException, java.io.IOExceptionLoads an X.509 certificate from the classpath resources in src/main/resources/certs.- Parameters:
fileName- name of a file in src/main/resources/certs.- Throws:
java.security.cert.CertificateExceptionjava.io.IOException
-
installConscryptIfAvailable
public static void installConscryptIfAvailable()
Add Conscrypt to the list of security providers, if it is available. If it appears to be available but fails to load, this method will throw an exception. Since the list of security providers is static, this method does nothing if the provider is not available or succeeded previously.
-
newSslSocketFactoryForCa
public static javax.net.ssl.SSLSocketFactory newSslSocketFactoryForCa(java.security.Provider provider, java.io.File certChainFile) throws java.lang.ExceptionCreates an SSLSocketFactory which containscertChainFileas its only root certificate.- Throws:
java.lang.Exception
-
-