
package org.apache.camel.component.cxf.transport;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.cxf.HelloService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CamelJBIClientProxyTest {
    private HelloService proxy;
    private ClassPathXmlApplicationContext applicationContext;
    
    @Before
    public void setUp() {
        // setup service
        applicationContext = new ClassPathXmlApplicationContext(new String[]{"/org/apache/camel/component/cxf/transport/CamelJBIClientProxy.xml"});
        applicationContext.start();
        proxy = (HelloService) applicationContext.getBean("client");
        assertNotNull("The proxy should not be null.", proxy);
    }
    
    
    @Test
    public void testCallFromProxy() throws Exception {
        // The echo parameter will be ignore, since the service has the fix response
        String response = proxy.echo("Hello World!");
        assertEquals("Get a wrong response ", "echo Hello World!", response);
    }
    
    @Test
    public void testCallFromCamel() throws Exception {
        // get camel context
        CamelContext context = (CamelContext) applicationContext.getBean("conduit_context");
        ProducerTemplate producer = context.createProducerTemplate();
        // The echo parameter will be ignore, since the service has the fix response
        String response = producer.requestBody("direct://jbiStart", "Hello World!", String.class);
        assertEquals("Get a wrong response ", "echo Hello World!", response);
    }
    
    @After
    public void tearDown() {
        if (applicationContext != null) {
            applicationContext.stop();
        }
    }
    
    
    

}
