use of javax.net.SocketFactory in project java-apns by notnoop.
the class ApnsFeedbackConnectionTest method feedbackWithClosedSocket.
/** Check error recover **/
@Test
public void feedbackWithClosedSocket() {
SocketFactory sf = mockClosedThenOpenSocket(null, simpleStream, true, 1);
ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
connection.DELAY_IN_MS = 0;
checkParsedSimple(connection.getInactiveDevices());
}
use of javax.net.SocketFactory in project robovm by robovm.
the class MySocketFactory method test_createSocket_05.
/**
* javax.net.SocketFactory#createSocket(String host, int port,
* InetAddress localHost, int localPort)
*/
public final void test_createSocket_05() 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, InetAddress.getLocalHost(), 0);
assertNotNull(s);
assertTrue("1: Failed to create socket", s.getPort() == sport);
try {
sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), 0);
fail("UnknownHostException wasn't thrown");
} catch (UnknownHostException expected) {
}
for (int i = 0; i < invalidPorts.length; i++) {
try {
sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i], InetAddress.getLocalHost(), 0);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
try {
sf.createSocket(InetAddress.getLocalHost().getHostName(), sport, InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
}
try {
sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 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.
public final void test_createSocket() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
Socket s = sf.createSocket();
assertNotNull(s);
assertEquals(-1, s.getLocalPort());
assertEquals(0, s.getPort());
MySocketFactory msf = new MySocketFactory();
try {
msf.createSocket();
fail("No expected SocketException");
} catch (SocketException expected) {
}
}
use of javax.net.SocketFactory in project robovm by robovm.
the class MySocketFactory method test_createSocket_InetAddressIInetAddressI.
public final void test_createSocket_InetAddressIInetAddressI() 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, InetAddress.getLocalHost(), 0);
assertNotNull(s);
assertTrue("1: Failed to create socket", s.getPort() == sport);
int portNumber = s.getLocalPort();
for (int i = 0; i < invalidPorts.length; i++) {
try {
sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i], InetAddress.getLocalHost(), portNumber);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
try {
sf.createSocket(InetAddress.getLocalHost(), sport, InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
} catch (IllegalArgumentException expected) {
}
}
try {
sf.createSocket(InetAddress.getLocalHost(), sport, InetAddress.getLocalHost(), portNumber);
fail("IOException wasn't thrown");
} catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
f.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
fail("IOException wasn't thrown ...");
} catch (IOException expected) {
}
}
use of javax.net.SocketFactory in project robovm by robovm.
the class MySocketFactory method test_getDefault.
/**
* javax.net.SocketFactory#getDefault()
*/
public final void test_getDefault() {
SocketFactory sf = SocketFactory.getDefault();
Socket s;
try {
s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8082);
s.close();
} catch (IOException e) {
}
try {
s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 8082);
s.close();
} catch (IOException e) {
}
try {
s = sf.createSocket(InetAddress.getLocalHost(), 8081);
s.close();
} catch (IOException e) {
}
try {
s = sf.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
s.close();
} catch (IOException e) {
}
}
Aggregations