/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.codehaus.activemq.transport;

import junit.framework.TestCase;
import org.codehaus.activemq.io.impl.DefaultWireFormat;
import org.codehaus.activemq.transport.vm.VmTransportChannel;

import javax.jms.JMSException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @version $Revision: 1.5 $
 */
public class TransportChannelProviderTest extends TestCase {
    public void testVmChannelWithProperties() throws Exception {
        TransportChannel channel = createChannel("vm://localhost:0?asyncSend=true&sendCapacity=100&receiveCapacity=20");
        assertTrue(channel instanceof VmTransportChannel);

        VmTransportChannel vmChannel = (VmTransportChannel) channel;
        assertEquals("sendCapacity", 100, vmChannel.getSendCapacity());
        assertEquals("receiveCapacity", 20, vmChannel.getReceiveCapacity());
        assertEquals("asyncSend", true, vmChannel.isAsyncSend());
        vmChannel.start();
        assertTrue("has send channel", vmChannel.getSendChannel() != null);
        assertTrue("has receive channel", vmChannel.getReceiveChannel() != null);
        vmChannel.stop();

        vmChannel = (VmTransportChannel) createChannel("vm://localhost?receiveCapacity=20");
        vmChannel.start();
        assertTrue("has no send channel", vmChannel.getSendChannel() == null);
        assertTrue("has receive channel", vmChannel.getReceiveChannel() == null);
        vmChannel.stop();
    }

    protected TransportChannel createChannel(String uri) throws JMSException, URISyntaxException {
        return TransportChannelProvider.create(new DefaultWireFormat(), new URI(uri));
    }
}
