Source:
<code>public void testHandshakeTimeoutWithValueSet() throws Exception { <START> JMSServerManager jmsServer; <END> FileConfiguration fc = new FileConfiguration(); FileJMSConfiguration fileConfiguration = new FileJMSConfiguration(); FileDeploymentManager deploymentManager = new FileDeploymentManager("server-start-stop-config1.xml"); deploymentManager.addDeployable(fc); deploymentManager.addDeployable(fileConfiguration); deploymentManager.readConfiguration(); ActiveMQJAASSecurityManager sm = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration()); ActiveMQServer server = addServer(new ActiveMQServerImpl(fc, sm)); server.start(); jmsServer = new JMSServerManagerImpl(server, fileConfiguration); TransportConfiguration tc = jmsServer.getActiveMQServer().getConfiguration().getAcceptorConfigurations().iterator().next(); String host = (String) tc.getParams().get(TransportConstants.HOST_PROP_NAME); String port = (String) tc.getParams().get(TransportConstants.PORT_PROP_NAME); int handshakeTimeout = Integer.parseInt(tc.getParams().get(TransportConstants.HANDSHAKE_TIMEOUT).toString()); jmsServer.setRegistry(null); assertEquals(5, handshakeTimeout); NettyTransport transport = NettyTransportFactory.createTransport(new URI("tcp://" + host + ":" + port)); transport.setTransportListener(new NettyTransportListener() { @Override public void onData(ByteBuf incoming) { } @Override public void onTransportClosed() { } @Override public void onTransportError(Throwable cause) { } }); try { transport.connect(); assertTrue("Connection should be closed now", Wait.waitFor(() -> !transport.isConnected(), TimeUnit.SECONDS.toMillis(handshakeTimeout + 1))); } finally { transport.close(); tearDown(); } }</code><technical_language>JMSServerManager is deprecated in new tests. Check out "embedded-simple" example for programmatically instantiate a broker a configuration file</technical_language>

Target:
public void testHandshakeTimeoutWithValueSet() throws Exception { SecurityConfiguration securityConfig = new SecurityConfiguration(); securityConfig.addUser("guest", "guest"); securityConfig.addRole("guest", "guest"); securityConfig.setDefaultUser("guest"); ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig); ActiveMQServer server = ActiveMQServers.newActiveMQServer("server-start-stop-config1.xml", null, securityManager); server.start(); TransportConfiguration tc = server.getConfiguration().getAcceptorConfigurations().iterator().next(); String host = (String) tc.getParams().get(TransportConstants.HOST_PROP_NAME); String port = (String) tc.getParams().get(TransportConstants.PORT_PROP_NAME); int handshakeTimeout = Integer.parseInt(tc.getParams().get(TransportConstants.HANDSHAKE_TIMEOUT).toString()); assertEquals(5, handshakeTimeout); NettyTransport transport = NettyTransportFactory.createTransport(new URI("tcp://" + host + ":" + port)); transport.setTransportListener(new NettyTransportListener() { @Override public void onData(ByteBuf incoming) { } @Override public void onTransportClosed() { } @Override public void onTransportError(Throwable cause) { } }); try { transport.connect(); assertTrue("Connection should be closed now", Wait.waitFor(() -> !transport.isConnected(), TimeUnit.SECONDS.toMillis(handshakeTimeout + 1))); } finally { transport.close(); server.stop(); } }