log.debug("-----------------------------------------------------------------handler");
IScope testApp = context.resolveScope(appPath);
assertTrue("should have a handler", testApp.hasHandler());
log.debug("App: {}", testApp);
TestConnection conn = new TestConnection(host, "/junit", null);
Red5.setConnectionLocal(conn);
IClientRegistry reg = context.getClientRegistry();
IClient client = reg.newClient(null);
assertTrue("client should not be null", client != null);
log.debug("{}", client);
String key = "key";
String value = "value";
client.setAttribute(key, value);
assertTrue("attributes not working", client.getAttribute(key) == value);
conn.initialize(client);
if (conn.connect(testApp)) {
// give connect a moment to settle
Thread.sleep(100L);
assertTrue("Should have a scope", conn.getScope() != null);
assertTrue("app should have 1 client", ((Scope) testApp).getActiveClients() == 1);
assertTrue("host should have 1 client", testApp.getParent().getClients().size() == 1);
conn.close();
assertTrue("Should not be connected", !conn.isConnected());
assertTrue("app should have 0 client", ((Scope) testApp).getActiveClients() == 0);
assertTrue("host should have 0 client", testApp.getParent().getClients().size() == 0);
} else {
fail("Didnt connect");
}