protected void setUp() throws Exception {
		HandlerForTests.setupLogging();
        
        if(bufFactory == null) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put(FactoryCreator.KEY_IS_DIRECT, false);
            FactoryCreator creator = FactoryCreator.createFactory(null);
            bufFactory = creator.createBufferFactory(map);          
        }
        mockSunsChannel = MockObjectFactory.createMock(SocketChannel.class);
        mockSunsChannel.addIgnore("isBlocking");
        mockSunsChannel.addIgnore("getSelectableChannel");
        mockSunsChannel.setDefaultReturnValue("isBlocking", false);
        mockSunsChannel.addReturnValue("connect", true);

        mockSelect = MockObjectFactory.createMock(Select.class);
        mockSelect.addIgnore("isRunning");
        mockSelect.addIgnore("getThread");
        mockSelect.addIgnore("setRunning");
        mockSelect.setDefaultReturnValue("isRunning", true);
        mockSelect.setDefaultReturnValue("isWantShutdown", false);

        mockWriteHandler = MockObjectFactory.createMock(OperationCallback.class);
        mockRegListener = MockObjectFactory.createMock(ChannelRegistrationListener.class);
        MockObject mockChannels = MockObjectFactory.createMock(ChannelsFactory.class);
        MockObject mockSelectorProv = MockObjectFactory.createMock(SelectorProviderFactory.class);

        ChannelServiceFactory basic = ChannelServiceFactory.createFactory(null);

        Map<String, Object> props2 = new HashMap<String, Object>();
        props2.put(ChannelServiceFactory.KEY_IMPLEMENTATION_CLASS, ChannelServiceFactory.VAL_EXCEPTION_CHANNEL_MGR);
        props2.put(ChannelServiceFactory.KEY_CHILD_CHANNELMGR_FACTORY, basic);
        factory = ChannelServiceFactory.createFactory(props2);   
        
		Map<String, Object> p = new HashMap<String, Object>();
        p.put(ChannelManager.KEY_ID, "[client]");
        p.put(ChannelManager.KEY_BUFFER_FACTORY, bufFactory);
        p.put("mock.channelsFactory", mockChannels);
        p.put("mock.selectorProvider", mockSelectorProv);            
        chanMgr = factory.createChannelManager(p);
        
        mockSelectorProv.addReturnValue("provider", mockSelect);
		chanMgr.start();
		CalledMethod m = mockSelect.expect("startPollingThread");
		listener = (SelectorListener)m.getAllParams()[0];
		
		mockHandler = MockObjectFactory.createMock(DataListener.class);
		mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
		//mockConnect = MockObjectFactory.createMock(ConnectCallback.class);
        
        mockChannels.addReturnValue("open", mockSunsChannel);
		client1 = chanMgr.createTCPChannel("ClientChannel", null);	
        mockSunsChannel.expect("configureBlocking");
        
	}