use of javax.net.SocketFactory in project robovm by robovm.
the class MySocketFactory method test_createSocket_StringI.
public final void test_createSocket_StringI() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE };
Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport);
assertNotNull(s);
assertTrue("Failed to create socket", s.getPort() == sport);
try {
sf.createSocket("bla-bla", sport);
fail("UnknownHostException wasn't thrown");
} catch (UnknownHostException expected) {
}
for (int i = 0; i < invalidPorts.length; i++) {
try {
sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
}
try {
sf.createSocket(InetAddress.getLocalHost().getHostName(), s.getLocalPort());
fail("IOException wasn't thrown");
} catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
f.createSocket(InetAddress.getLocalHost().getHostName(), 8082);
fail("IOException wasn't thrown ...");
} catch (IOException expected) {
}
}
use of javax.net.SocketFactory in project robovm by robovm.
the class MySocketFactory method test_createSocket_InetAddressI.
public final void test_createSocket_InetAddressI() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE };
Socket s = sf.createSocket(InetAddress.getLocalHost(), sport);
assertNotNull(s);
assertTrue("Failed to create socket", s.getPort() == sport);
for (int i = 0; i < invalidPorts.length; i++) {
try {
sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
}
try {
sf.createSocket(InetAddress.getLocalHost(), s.getLocalPort());
fail("IOException wasn't thrown");
} catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
f.createSocket(InetAddress.getLocalHost(), 8081);
fail("IOException wasn't thrown ...");
} catch (IOException expected) {
}
}
use of javax.net.SocketFactory in project robovm by robovm.
the class SSLSocketFactoryTest method test_Constructor.
/**
* javax.net.ssl.SSLSocketFactory#SSLSocketFactory()
*/
public void test_Constructor() {
try {
SocketFactory sf = SSLSocketFactory.getDefault();
assertTrue(sf instanceof SSLSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
use of javax.net.SocketFactory in project robovm by robovm.
the class SSLSocketFactoryTest method test_SSLSocketFactory_getDefault.
public void test_SSLSocketFactory_getDefault() {
SocketFactory sf = SSLSocketFactory.getDefault();
assertNotNull(sf);
assertTrue(SSLSocketFactory.class.isAssignableFrom(sf.getClass()));
}
use of javax.net.SocketFactory in project robovm by robovm.
the class SSLContextTest method test_SSLContext_getSocketFactory.
public void test_SSLContext_getSocketFactory() throws Exception {
for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
SSLContext.getInstance(protocol).getSocketFactory();
} else {
try {
SSLContext.getInstance(protocol).getSocketFactory();
fail();
} catch (IllegalStateException expected) {
}
}
SSLContext sslContext = SSLContext.getInstance(protocol);
if (!protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
sslContext.init(null, null, null);
}
SocketFactory sf = sslContext.getSocketFactory();
assertNotNull(sf);
assertTrue(SSLSocketFactory.class.isAssignableFrom(sf.getClass()));
}
}
Aggregations