Package io.grpc.internal.testing
Class TestUtils
java.lang.Object
io.grpc.internal.testing.TestUtils
Internal utility functions useful for writing tests.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd Conscrypt to the list of security providers, if it is available.static FileSaves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.static X509CertificateloadX509Cert(String fileName) Loads an X.509 certificate from the classpath resources in src/main/resources/certs.static SSLSocketFactorynewSslSocketFactoryForCa(Provider provider, File certChainFile) Creates an SSLSocketFactory which containscertChainFileas its only root certificate.static InetSocketAddresstestServerAddress(String host, int port) Creates a newInetSocketAddressthat overrides the host withTEST_SERVER_HOST.static InetSocketAddresstestServerAddress(InetSocketAddress originalSockAddr) Creates a newInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.static List<InetSocketAddress> testServerAddresses(InetSocketAddress... originalSockAddr) Creates a new list ofInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST.
-
Field Details
-
TEST_SERVER_HOST
- See Also:
-
conscryptInstallAttempted
private static boolean conscryptInstallAttempted
-
-
Constructor Details
-
TestUtils
private TestUtils()
-
-
Method Details
-
testServerAddress
Creates a newInetSocketAddressthat overrides the host withTEST_SERVER_HOST. -
testServerAddress
Creates a newInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST. -
testServerAddresses
Creates a new list ofInetSocketAddresson localhost that overrides the host withTEST_SERVER_HOST. -
loadCert
Saves 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:
IOException
-
loadX509Cert
public static X509Certificate loadX509Cert(String fileName) throws CertificateException, IOException Loads 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:
CertificateExceptionIOException
-
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 SSLSocketFactory newSslSocketFactoryForCa(Provider provider, File certChainFile) throws Exception Creates an SSLSocketFactory which containscertChainFileas its only root certificate.- Throws:
Exception
-