CamelEndpointComponent extends AbstractEndpointComponent { @Override protected Endpoint createEndpoint(String resourcePath, Map<String, String> parameters, TestContext context) { CamelEndpoint endpoint; if (resourcePath.startsWith("sync:")) { endpoint = new CamelSyncEndpoint(); endpoint.getEndpointConfiguration().setEndpointUri(resourcePath.substring("sync:".length()) + getParameterString(parameters, CamelSyncEndpointConfiguration.class)); } else { endpoint = new CamelEndpoint(); endpoint.getEndpointConfiguration().setEndpointUri(resourcePath + getParameterString(parameters, CamelEndpointConfiguration.class)); } if (context.getReferenceResolver() != null) { if (context.getReferenceResolver().resolveAll(CamelContext.class).size() == 1) { endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve(CamelContext.class)); } else if (context.getReferenceResolver().isResolvable("camelContext")) { endpoint.getEndpointConfiguration().setCamelContext(context.getReferenceResolver().resolve("camelContext", CamelContext.class)); } else { endpoint.getEndpointConfiguration().setCamelContext(new DefaultCamelContext()); } } enrichEndpointConfiguration(endpoint.getEndpointConfiguration(), getEndpointConfigurationParameters(parameters, endpoint.getEndpointConfiguration().getClass()), context); return endpoint; } CamelEndpointComponent();   }
@Test public void testCreateEndpoint() throws Exception { CamelEndpointComponent component = new CamelEndpointComponent(); reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(Collections.singletonMap("myCamelContext", camelContext)); when(referenceResolver.resolve(CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:direct:news", context); Assert.assertEquals(endpoint.getClass(), CamelEndpoint.class); Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "direct:news"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); endpoint = component.createEndpoint("camel:seda:news-feed", context); Assert.assertEquals(endpoint.getClass(), CamelEndpoint.class); Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "seda:news-feed"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateSyncEndpoint() throws Exception { CamelEndpointComponent component = new CamelEndpointComponent(); reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(Collections.singletonMap("myCamelContext", camelContext)); when(referenceResolver.resolve(CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:sync:direct:news", context); Assert.assertEquals(endpoint.getClass(), CamelSyncEndpoint.class); Assert.assertEquals(((CamelSyncEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "direct:news"); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); endpoint = component.createEndpoint("camel:sync:seda:news-feed", context); Assert.assertEquals(endpoint.getClass(), CamelSyncEndpoint.class); Assert.assertEquals(((CamelSyncEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "seda:news-feed"); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelSyncEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateEndpointWithParameters() throws Exception { CamelEndpointComponent component = new CamelEndpointComponent(); Map<String, CamelContext> camelContextMap = new HashMap<String, CamelContext>(); camelContextMap.put("someCamelContext", Mockito.mock(CamelContext.class)); camelContextMap.put("myCamelContext", camelContext); reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(camelContextMap); when(referenceResolver.isResolvable("camelContext")).thenReturn(false); when(referenceResolver.isResolvable("myCamelContext")).thenReturn(true); when(referenceResolver.resolve("myCamelContext", CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:direct:news-feed?timeout=10000&camelContext=myCamelContext", context); Assert.assertEquals(endpoint.getClass(), CamelEndpoint.class); Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "direct:news-feed"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }
@Test public void testCreateEndpointWithCamelParameters() throws Exception { CamelEndpointComponent component = new CamelEndpointComponent(); Map<String, CamelContext> camelContextMap = new HashMap<String, CamelContext>(); camelContextMap.put("someCamelContext", Mockito.mock(CamelContext.class)); camelContextMap.put("myCamelContext", camelContext); reset(referenceResolver); when(referenceResolver.resolveAll(CamelContext.class)).thenReturn(camelContextMap); when(referenceResolver.isResolvable("camelContext")).thenReturn(false); when(referenceResolver.isResolvable("myCamelContext")).thenReturn(true); when(referenceResolver.resolve("myCamelContext", CamelContext.class)).thenReturn(camelContext); Endpoint endpoint = component.createEndpoint("camel:controlbus:route?routeId=news&timeout=10000&camelContext=myCamelContext&action=stats", context); Assert.assertEquals(endpoint.getClass(), CamelEndpoint.class); Assert.assertEquals(((CamelEndpoint)endpoint).getEndpointConfiguration().getEndpointUri(), "controlbus:route?routeId=news&action=stats"); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getCamelContext(), camelContext); Assert.assertEquals(((CamelEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }