For IntelliJ IDEA,
Android Studio or Eclipse



public static SSLSocket createSSLSocket(String certDistinguishedName, boolean wantAuth, boolean needAuth) throws IOException { JMXPrincipal principal = new JMXPrincipal(certDistinguishedName); X509Certificate cert = new StubX509Certificate(principal); StubSSLSession sslSession = new StubSSLSession(cert); StubSSLSocket sslSocket = new StubSSLSocket(sslSession); sslSocket.setWantClientAuth(wantAuth); sslSocket.setNeedClientAuth(needAuth); return sslSocket; } }
private void createAndBindTransportServer(boolean wantClientAuth, boolean needClientAuth, String options) throws IOException { sslServerSocket = new StubSSLServerSocket(); StubSSLSocketFactory socketFactory = new StubSSLSocketFactory(sslServerSocket); try { sslTransportServer = new SslTransportServer(null, new URI("ssl://localhost:61616?" + options), socketFactory); } catch (Exception e) { fail("Unable to create SslTransportServer."); } sslTransportServer.setWantClientAuth(wantClientAuth); sslTransportServer.setNeedClientAuth(needClientAuth); sslTransportServer.bind(); }
private void testValidTypeOfServiceValue(int val) { try { int typeOfService = QualityOfServiceUtils.getToS(val); assertEquals("Incorrect Type of Services value returned for " + val + ".", val, typeOfService); } catch (IllegalArgumentException e) { fail("IllegalArgumentException thrown for valid Type of Service " + "value " + val + "."); } }
private void singleTest(int i, String options) throws IOException { final boolean wantClientAuth = getWantClientAuth(i); final boolean needClientAuth = getNeedClientAuth(i); final int expectedWantStatus = (needClientAuth? StubSSLServerSocket.UNTOUCHED: wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED); final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED ); createAndBindTransportServer(wantClientAuth, needClientAuth, options); assertEquals("Created ServerSocket did not have correct wantClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth, expectedWantStatus, sslServerSocket.getWantClientAuthStatus()); assertEquals("Created ServerSocket did not have correct needClientAuth status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + needClientAuth, expectedNeedStatus, sslServerSocket.getNeedClientAuthStatus()); }
public void testInvalidTypeOfServiceOptionDoesNotWork() throws Exception { int[] invalidOptions = {-2, -1, 256, 257}; for (int opt : invalidOptions) { testInvalidOptionsDoNotWork(TOS + opt, ""); } }
@Override protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException { TcpTransportServer result = new TcpTransportServer(this, location, serverSocketFactory); result.setAllowLinkStealing(true); return result; }
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException { SocketTst sockTst; sockTst = new SocketTst(host, port, localAddress, localPort, this.rnd); sockTst.startBagot(); return sockTst.getSocket(); }
public void setNeedClientAuth(boolean arg0) { this.needClientAuthStatus = arg0 ? TRUE : FALSE; if (session != null) { this.session.setIsVerified(arg0); } }
/** * @param socket * @param format * @param detectedTransportFactory * @return */ protected TcpTransport createTransport(Socket socket, WireFormat format, TcpTransportFactory detectedTransportFactory, InitBuffer initBuffer) throws IOException { return new TcpTransport(format, socket, initBuffer); }
@Override public void onFrame(MQTTFrame mqttFrame) { transport.doConsume(mqttFrame); } };
/** * @return pretty print of this */ public String toString() { return "" + getBindLocation(); } }
private void testValidDiffServName(String name, int expected) { int dscp = -1; try { dscp = QualityOfServiceUtils.getDSCP(name); } catch (IllegalArgumentException e) { fail("IllegalArgumentException thrown for valid Differentiated " + " Services name: " + name); } // Make sure it adjusted for any system ECN values. assertEquals("Incorrect Differentiated Services Code Point " + dscp + " returned for name " + name + ".", ECN | (expected << 2), dscp); }
@Override public Socket createSocket(String host, int port) throws IOException { SocketTst sockTst; sockTst = new SocketTst(host, port, this.rnd); sockTst.startBagot(); return sockTst.getSocket(); }