@Test public void testCreateDestinationFromSpring() throws Exception { CxfEndpoint cxfEndpoint = context.getEndpoint("cxf:bean:serviceEndpoint", CxfEndpoint.class); CxfProducer producer = (CxfProducer)cxfEndpoint.createProducer(); assertNotNull("The producer should not be null", producer); producer.start(); CamelConduit conduit = (CamelConduit)producer.getClient().getConduit(); assertTrue("we should get SpringCamelContext here", conduit.getCamelContext() instanceof SpringCamelContext); assertEquals("The context id should be camel_conduit", "camel_conduit", conduit.getCamelContext().getName()); cxfEndpoint = context.getEndpoint("cxf:bean:routerEndpoint", CxfEndpoint.class); CxfConsumer consumer = (CxfConsumer)cxfEndpoint.createConsumer(new Processor() { public void process(Exchange exchange) throws Exception { // do nothing here } }); assertNotNull("The consumer should not be null", consumer); consumer.start(); CamelDestination destination = (CamelDestination)consumer.getServer().getDestination(); assertTrue("we should get SpringCamelContext here", destination.getCamelContext() instanceof SpringCamelContext); assertEquals("The context id should be camel_destination", "camel_destination", destination.getCamelContext().getName()); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "org/apache/camel/dataformat/jibx/SpringJibxConfigurationTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaLocationTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/jaxb/CamelJaxbTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
@Override public void doPreSetup() throws Exception { if (!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) { // tell camel-spring it should not trigger starting CamelContext, since we do that later // after we are finished setting up the unit test synchronized (lock) { SpringCamelContext.setNoStart(true); if (isCreateCamelContextPerClass()) { applicationContext = threadAppContext.get(); if (applicationContext == null) { applicationContext = createApplicationContext(); threadAppContext.set(applicationContext); } } else { applicationContext = createApplicationContext(); } assertNotNull(applicationContext, "Should have created a valid spring context"); SpringCamelContext.setNoStart(false); } } else { log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true."); } }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/xstream/SpringMarshalDomainObjectJSONTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "org/apache/camel/dataformat/xstream/SpringXStreamConfigurationTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/xstream/SpringMarshalListTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
protected CamelContext createCamelContext() throws Exception { setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "org/apache/camel/dataformat/xstream/SpringMarshalOmitFieldsTest.xml"); setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
public void testProxyWithTwoCamelContext() throws Exception { AbstractXmlApplicationContext applicationContext = createApplicationContext(); CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext); ISay proxy = applicationContext.getBean("sayProxy1", ISay.class); String rc = proxy.say(); assertEquals("context-1", rc); proxy = applicationContext.getBean("sayProxy2", ISay.class); rc = proxy.say(); assertEquals("context-2", rc); camelContext.stop(); IOHelper.close(applicationContext); }
public static CamelContext createSpringCamelContext(ContextTestSupport test, String classpathUri) throws Exception { test.setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(classpathUri); test.setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
public void testAutoStartupTrue() throws Exception { ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestTrue.xml"); SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next(); assertNotNull(camel.getName()); assertEquals(true, camel.isStarted()); assertEquals(Boolean.TRUE, camel.isAutoStartup()); assertEquals(1, camel.getRoutes().size()); // send a message to the route and see that it works MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); ProducerTemplate template = camel.createProducerTemplate(); template.start(); template.sendBody("direct:start", "Hello World"); template.stop(); mock.assertIsSatisfied(); }
public void testAutoStartupFalse() throws Exception { ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupFalseTest.xml"); SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next(); assertEquals(false, camel.getRouteStatus("foo").isStarted()); // now starting route manually camel.startRoute("foo"); assertEquals(true, camel.getRouteStatus("foo").isStarted()); // and now we can send a message to the route and see that it works MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); ProducerTemplate template = camel.createProducerTemplate(); template.start(); template.sendBody("direct:start", "Hello World"); template.stop(); mock.assertIsSatisfied(); }
public void testAutoStartupTrue() throws Exception { ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupTrueTest.xml"); SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next(); assertEquals(true, camel.getRouteStatus("bar").isStarted()); // and now we can send a message to the route and see that it works MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); ProducerTemplate template = camel.createProducerTemplate(); template.start(); template.sendBody("direct:start", "Hello World"); template.stop(); mock.assertIsSatisfied(); }
/** * Handles updating shutdown timeouts on Camel contexts based on {@link ShutdownTimeout}. * * @param context the initialized Spring context * @param testClass the test class being executed */ public static void handleShutdownTimeout(ConfigurableApplicationContext context, Class<?> testClass) throws Exception { final int shutdownTimeout; final TimeUnit shutdownTimeUnit; if (testClass.isAnnotationPresent(ShutdownTimeout.class)) { shutdownTimeout = testClass.getAnnotation(ShutdownTimeout.class).value(); shutdownTimeUnit = testClass.getAnnotation(ShutdownTimeout.class).timeUnit(); } else { shutdownTimeout = 10; shutdownTimeUnit = TimeUnit.SECONDS; } CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() { public void execute(String contextName, SpringCamelContext camelContext) throws Exception { LOGGER.info("Setting shutdown timeout to [{} {}] on CamelContext with name [{}].", new Object[]{shutdownTimeout, shutdownTimeUnit, contextName}); camelContext.getShutdownStrategy().setTimeout(shutdownTimeout); camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit); } }); }
/** * Handles auto-intercepting of endpoints with mocks based on {@link MockEndpointsAndSkip} and skipping the * original endpoint. * * @param context the initialized Spring context * @param testClass the test class being executed */ public static void handleMockEndpointsAndSkip(ConfigurableApplicationContext context, Class<?> testClass) throws Exception { if (testClass.isAnnotationPresent(MockEndpointsAndSkip.class)) { final String mockEndpoints = testClass.getAnnotation(MockEndpointsAndSkip.class).value(); CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() { public void execute(String contextName, SpringCamelContext camelContext) throws Exception { // resovle the property place holders of the mockEndpoints String mockEndpointsValue = camelContext.resolvePropertyPlaceholders(mockEndpoints); LOGGER.info("Enabling auto mocking and skipping of endpoints matching pattern [{}] on CamelContext with name [{}].", mockEndpointsValue, contextName); camelContext.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(mockEndpointsValue, true)); } }); } }
@Override public void doPreSetup() throws Exception { if (!"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"))) { // tell camel-spring it should not trigger starting CamelContext, since we do that later // after we are finished setting up the unit test synchronized (lock) { SpringCamelContext.setNoStart(true); if (isCreateCamelContextPerClass()) { applicationContext = threadAppContext.get(); if (applicationContext == null) { applicationContext = doCreateApplicationContext(); threadAppContext.set(applicationContext); } } else { applicationContext = doCreateApplicationContext(); } SpringCamelContext.setNoStart(false); } } else { log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true."); } }
/** * Performs the bulk of the Spring application context loading/customization. * * @param context the partially configured context. The context should have the bean definitions loaded, but nothing else. * @param testClass the test class being executed * @return the initialized (refreshed) Spring application context * * @throws Exception if there is an error during initialization/customization */ protected ApplicationContext loadContext(GenericApplicationContext context, Class<?> testClass) throws Exception { AnnotationConfigUtils.registerAnnotationConfigProcessors(context); // Pre CamelContext(s) instantiation setup handleDisableJmx(context, testClass); // Temporarily disable CamelContext start while the contexts are instantiated. SpringCamelContext.setNoStart(true); context.refresh(); context.registerShutdownHook(); // Turn CamelContext startup back on since the context's have now been instantiated. SpringCamelContext.setNoStart(false); // Post CamelContext(s) instantiation but pre CamelContext(s) start setup handleProvidesBreakpoint(context, testClass); handleShutdownTimeout(context, testClass); handleMockEndpoints(context, testClass); handleMockEndpointsAndSkip(context, testClass); handleUseOverridePropertiesWithPropertiesComponent(context, testClass); // CamelContext(s) startup handleCamelContextStartup(context, testClass); return context; }
/** * Handles updating shutdown timeouts on Camel contexts based on {@link ShutdownTimeout}. * * @param context the initialized Spring context * @param testClass the test class being executed */ protected void handleShutdownTimeout(GenericApplicationContext context, Class<?> testClass) throws Exception { final int shutdownTimeout; final TimeUnit shutdownTimeUnit; if (testClass.isAnnotationPresent(ShutdownTimeout.class)) { shutdownTimeout = testClass.getAnnotation(ShutdownTimeout.class).value(); shutdownTimeUnit = testClass.getAnnotation(ShutdownTimeout.class).timeUnit(); } else { shutdownTimeout = 10; shutdownTimeUnit = TimeUnit.SECONDS; } CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() { @Override public void execute(String contextName, SpringCamelContext camelContext) throws Exception { LOG.info("Setting shutdown timeout to [{} {}] on CamelContext with name [{}].", new Object[]{shutdownTimeout, shutdownTimeUnit, contextName}); camelContext.getShutdownStrategy().setTimeout(shutdownTimeout); camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit); } }); }
/** * Handles auto-intercepting of endpoints with mocks based on {@link MockEndpointsAndSkip} and skipping the * original endpoint. * * @param context the initialized Spring context * @param testClass the test class being executed */ protected void handleMockEndpointsAndSkip(GenericApplicationContext context, Class<?> testClass) throws Exception { if (testClass.isAnnotationPresent(MockEndpointsAndSkip.class)) { final String mockEndpoints = testClass.getAnnotation(MockEndpointsAndSkip.class).value(); CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() { @Override public void execute(String contextName, SpringCamelContext camelContext) throws Exception { // resovle the property place holders of the mockEndpoints String mockEndpointsValue = camelContext.resolvePropertyPlaceholders(mockEndpoints); LOG.info("Enabling auto mocking and skipping of endpoints matching pattern [{}] on CamelContext with name [{}].", mockEndpointsValue, contextName); camelContext.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(mockEndpointsValue, true)); } }); } }
@Override public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { Class<?> testClass = getTestClass(); if (logger.isDebugEnabled()) { logger.debug("Loading ApplicationContext for merged context configuration [{}].", mergedConfig); } // Pre CamelContext(s) instantiation setup CamelAnnotationsHandler.handleDisableJmx(null, testClass); try { SpringCamelContext.setNoStart(true); System.setProperty("skipStartingCamelContext", "true"); ConfigurableApplicationContext context = (ConfigurableApplicationContext) super.loadContext(mergedConfig); SpringCamelContext.setNoStart(false); System.clearProperty("skipStartingCamelContext"); return loadContext(context, testClass); } finally { cleanup(testClass); } }
public static CamelContext createSpringCamelContext(CamelTestSupport test, String classpathUri) throws Exception { test.setUseRouteBuilder(false); final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(classpathUri); test.setCamelContextService(new Service() { public void start() throws Exception { applicationContext.start(); } public void stop() throws Exception { applicationContext.stop(); } }); return SpringCamelContext.springCamelContext(applicationContext); }
public static void logContextOverview(SpringCamelContext camelContext){ //Display Current loaded Routes and Endpoints for Easy Debugging StringBuffer buffer = new StringBuffer(); buffer.append("\n####################################################"); buffer.append("\n############# Routing Overview #################"); buffer.append("\n####################################################"); List<Route> routes = camelContext.getRoutes(); for (Route route : routes) { DefaultRoute defaultRoute = (DefaultRoute) route; buffer.append("\n" + defaultRoute.getId()); buffer.append("\n " + defaultRoute.getConsumer().getEndpoint().getEndpointUri()+ " Status:" +defaultRoute.getStatus()); } buffer.append("\n####################################################"); buffer.append("\n############# Endpoint Overview #################"); buffer.append("\n####################################################"); Collection<Endpoint> endpoints = camelContext.getEndpoints(); for (Endpoint endpoint : endpoints) { buffer.append("\n" + endpoint.getEndpointKey() + " - " + endpoint.getEndpointUri()); } log.info(buffer); }
/** * Initializes the Spring {@link GenericApplicationContext} and returns all instances of {@link SpringCamelContext} beans. * * Note that {@link SpringCamelContext} instances are created in the <b>stopped</b> state. Starting the {@link SpringCamelContext} * is left to the caller. * * @return Unmodifiable list of {@link SpringCamelContext} instances * @throws Exception */ public List<SpringCamelContext> createSpringCamelContexts() throws Exception { if (applicationContext.isActive()) { throw new IllegalStateException("Unable to refresh Spring application context. Context is already initialized"); } SpringCamelContext.setNoStart(true); ProxyUtils.invokeProxied(new ProxiedAction() { @Override public void run() throws Exception { applicationContext.refresh(); } }, applicationContext.getClassLoader()); SpringCamelContext.setNoStart(false); return getSpringCamelContexts(); }
@Test public void testSpringJavaConfig() throws Exception { AnnotationConfigApplicationContext appctx = new AnnotationConfigApplicationContext(MyConfiguration.class); CamelContext camelctx = new SpringCamelContext(appctx); camelctx.addRoutes(appctx.getBean(RouteBuilder.class)); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.stop(); } }
@Test public void testSpringCxfEndpoint() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"org/apache/camel/component/cxf/CxfEndpointBeans.xml"}); CxfComponent cxfComponent = new CxfComponent(new SpringCamelContext(ctx)); CxfSpringEndpoint endpoint = (CxfSpringEndpoint)cxfComponent.createEndpoint("cxf://bean:serviceEndpoint"); assertEquals("Got the wrong endpoint address", endpoint.getAddress(), "http://localhost:" + port2 + "/CxfEndpointTest/helloworld"); assertEquals("Got the wrong endpont service class", endpoint.getServiceClass().getCanonicalName(), "org.apache.camel.component.cxf.HelloService"); }
@Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest1.xml"); context1 = SpringCamelContext.springCamelContext(applicationContext, false); context1.start(); template1 = context1.createProducerTemplate(); template1.start(); }
@Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext( "org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml"); context = SpringCamelContext.springCamelContext(applicationContext, false); context.start(); }
@Before public void setUp() throws Exception { applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml"); context2 = SpringCamelContext.springCamelContext(applicationContext, false); context2.start(); template2 = context2.createProducerTemplate(); template2.start(); }
private CamelContext createCamelContext(String[] options) throws Exception { Main main = new Main(); main.parseArguments(options); ApplicationContext applicationContext = main.createDefaultApplicationContext(); CamelContext context = SpringCamelContext.springCamelContext(applicationContext); return context; }
@Override protected CamelContext createCamelContext() throws Exception { applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class); CamelContext ctx = SpringCamelContext.springCamelContext(applicationContext); PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties"); ctx.addComponent("properties", pc); return ctx; }
protected SpringCamelContext createContext() { SpringCamelContext ctx = newCamelContext(); // only set the name if its explicit (Camel will auto assign name if none explicit set) if (!isImplicitId()) { ctx.setName(getId()); } return ctx; }
private EvaluationContext createEvaluationContext(Exchange exchange) { StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new RootObject(exchange)); if (exchange.getContext() instanceof SpringCamelContext) { // Support references (like @foo) in expressions to beans defined in the Registry/ApplicationContext ApplicationContext applicationContext = ((SpringCamelContext) exchange.getContext()).getApplicationContext(); evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext)); } return evaluationContext; }
public void testBeanRoutes() throws Exception { AbstractXmlApplicationContext applicationContext = createApplicationContext(); CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext); Invoker invoker = applicationContext.getBean("invokerProxy", Invoker.class); String response = invoker.invoke(new Bean.SubClass()); assertEquals("Hello from Sub", response); camelContext.stop(); IOHelper.close(applicationContext); }
public void testBeanRoutes() throws Exception { AbstractXmlApplicationContext applicationContext = createApplicationContext(); CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext); // START SNIPPET: invoke ISay proxy = applicationContext.getBean("sayProxy", ISay.class); String rc = proxy.say(); assertEquals("Hello", rc); // END SNIPPET: invoke camelContext.stop(); IOHelper.close(applicationContext); }
protected List<Route> getRoutesFromContext(String classpathConfigFile) { applicationContext = new ClassPathXmlApplicationContext(classpathConfigFile); SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next(); assertNotNull("No Camel Context in file: " + classpathConfigFile, context); List<Route> routes = context.getRoutes(); assertNotNull("No routes available for context: " + context.getName() + " in file: " + classpathConfigFile, routes); return routes; }
public void testEndpointConfiguration() throws Exception { SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next(); List<Route> list = context.getRoutes(); assertEquals("Number routes created" + list, 2, list.size()); for (Route route : list) { EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route); Channel channel = unwrapChannel(consumerRoute.getProcessor()); DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler()); RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy(); assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries()); assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff()); } }
public void testDefaultThreadPoolProfile() throws Exception { SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next(); ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile(); assertEquals(5, profile.getPoolSize().intValue()); assertEquals(15, profile.getMaxPoolSize().intValue()); assertEquals(25, profile.getKeepAliveTime().longValue()); assertEquals(250, profile.getMaxQueueSize().intValue()); assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue()); assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy()); }
public void testAutoStartup() throws Exception { applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml"); SpringCamelContext context = applicationContext.getBean("camel4", SpringCamelContext.class); assertFalse(context.isAutoStartup()); // there is 1 route but its not started assertEquals(1, context.getRoutes().size()); context = applicationContext.getBean("camel3", SpringCamelContext.class); assertTrue(context.isAutoStartup()); // there is 1 route but and its started assertEquals(1, context.getRoutes().size()); }
public void testCamelProxy() throws Exception { AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml"); MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class); String reply = sender.hello("World"); assertEquals("Hello World", reply); // test sending inOnly message MyProxySender anotherSender = ac.getBean("myAnotherProxySender", MyProxySender.class); SpringCamelContext context = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next(); MockEndpoint result = resolveMandatoryEndpoint(context, "mock:result", MockEndpoint.class); result.expectedBodiesReceived("Hello my friends!"); anotherSender.greeting("Hello my friends!"); result.assertIsSatisfied(); result.reset(); // test sending inOnly message with other sender MyProxySender myProxySenderWithCamelContextId = ac.getBean("myProxySenderWithCamelContextId", MyProxySender.class); result.expectedBodiesReceived("Hello my friends again!"); myProxySenderWithCamelContextId.greeting("Hello my friends again!"); result.assertIsSatisfied(); // we're done so let's properly close the application context IOHelper.close(ac); }