/** 
 * 
 * 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.spring;

import junit.framework.TestCase;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import javax.jms.JMSException;

/**
 * @version $Revision: 1.1 $
 */
public class SpringTest extends TestCase {

    public void testSenderWithSpringXml() throws Exception {
        String config = "org/codehaus/activemq/spring/spring.xml";
        assertSenderConfig(config);
    }

    public void testSenderWithSpringXmlAndQueue() throws Exception {
        String config = "org/codehaus/activemq/spring/spring-queue.xml";
        assertSenderConfig(config);
    }

    public void testSenderWithSpringXmlUsingJNDI() throws Exception {
        String config = "org/codehaus/activemq/spring/spring-jndi.xml";
        assertSenderConfig(config);
    }

    public void testSenderWithSpringXmlEmbeddedBrokerConfiguredViaXml() throws Exception {
        String config = "org/codehaus/activemq/spring/spring-embedded.xml";
        assertSenderConfig(config);
    }

    protected void assertSenderConfig(String config) throws JMSException {
        XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(config));

        SpringConsumer consumer = (SpringConsumer) factory.getBean("consumer");
        assertTrue("Found a valid consumer", consumer != null);

        consumer.start();

        SpringProducer producer = (SpringProducer) factory.getBean("producer");
        assertTrue("Found a valid producer", producer != null);

        producer.start();
        producer.stop();
        factory.destroySingletons();
    }


}
