VertxEndpointComponent extends AbstractEndpointComponent { @Override protected Endpoint createEndpoint(String resourcePath, Map<String, String> parameters, TestContext context) { VertxEndpoint endpoint; if (resourcePath.startsWith("sync:")) { endpoint = new VertxSyncEndpoint(); } else { endpoint = new VertxEndpoint(); } if (resourcePath.contains("pubSub:")) { endpoint.getEndpointConfiguration().setPubSubDomain(true); } if (resourcePath.indexOf(':') > 0) { endpoint.getEndpointConfiguration().setAddress(resourcePath.substring(resourcePath.lastIndexOf(':') + 1)); } else { endpoint.getEndpointConfiguration().setAddress(resourcePath); } if (parameters.containsKey(VERTX_INSTANCE_FACTORY)) { String vertFactoryBean = parameters.remove(VERTX_INSTANCE_FACTORY); if (context.getReferenceResolver() != null) { endpoint.setVertxInstanceFactory(context.getReferenceResolver().resolve(vertFactoryBean, VertxInstanceFactory.class)); } else { log.warn("Unable to set custom Vert.x instance factory as Spring application context is not accessible!"); } } else { if (context.getReferenceResolver() != null && context.getReferenceResolver().isResolvable(VERTX_INSTANCE_FACTORY)) { endpoint.setVertxInstanceFactory(context.getReferenceResolver().resolve(VERTX_INSTANCE_FACTORY, VertxInstanceFactory.class)); } else { log.warn("Unable to set default Vert.x instance factory as Spring application context is not accessible or default factory bean is not available!"); } } enrichEndpointConfiguration(endpoint.getEndpointConfiguration(), parameters, context); return endpoint; } VertxEndpointComponent();  static final String VERTX_INSTANCE_FACTORY; }
@Test public void testCreateEndpoint() throws Exception { VertxEndpointComponent component = new VertxEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("vertxInstanceFactory")).thenReturn(true); when(referenceResolver.resolve("vertxInstanceFactory", VertxInstanceFactory.class)).thenReturn(instanceFactory); Endpoint endpoint = component.createEndpoint("vertx:news", context); Assert.assertEquals(endpoint.getClass(), VertxEndpoint.class); Assert.assertEquals(((VertxEndpoint)endpoint).getEndpointConfiguration().getAddress(), "news"); Assert.assertFalse(((VertxEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((VertxEndpoint) endpoint).getVertxInstanceFactory(), instanceFactory); Assert.assertEquals(((VertxEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); endpoint = component.createEndpoint("eventbus:news-feed", context); Assert.assertEquals(endpoint.getClass(), VertxEndpoint.class); Assert.assertEquals(((VertxEndpoint)endpoint).getEndpointConfiguration().getAddress(), "news-feed"); Assert.assertFalse(((VertxEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((VertxEndpoint) endpoint).getVertxInstanceFactory(), instanceFactory); Assert.assertEquals(((VertxEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateEndpointWithParameters() throws Exception { VertxEndpointComponent component = new VertxEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("vertxInstanceFactory")).thenReturn(true); when(referenceResolver.resolve("vertxInstanceFactory", VertxInstanceFactory.class)).thenReturn(instanceFactory); Endpoint endpoint = component.createEndpoint("vertx:news-feed?port=10105&timeout=10000&pubSubDomain=true", context); Assert.assertEquals(endpoint.getClass(), VertxEndpoint.class); Assert.assertEquals(((VertxEndpoint)endpoint).getEndpointConfiguration().getAddress(), "news-feed"); Assert.assertEquals(((VertxEndpoint)endpoint).getEndpointConfiguration().getPort(), 10105); Assert.assertTrue(((VertxEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((VertxEndpoint) endpoint).getVertxInstanceFactory(), instanceFactory); Assert.assertEquals(((VertxEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }
@Test public void testCreateEndpointCustomInstanceFactory() throws Exception { VertxEndpointComponent component = new VertxEndpointComponent(); reset(referenceResolver); when(referenceResolver.resolve("vertxFactory", VertxInstanceFactory.class)).thenReturn(instanceFactory); Endpoint endpoint = component.createEndpoint("vertx:news?vertxInstanceFactory=vertxFactory", context); Assert.assertEquals(endpoint.getClass(), VertxEndpoint.class); Assert.assertEquals(((VertxEndpoint)endpoint).getEndpointConfiguration().getAddress(), "news"); Assert.assertFalse(((VertxEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((VertxEndpoint) endpoint).getVertxInstanceFactory(), instanceFactory); Assert.assertEquals(((VertxEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testInvalidEndpointUri() throws Exception { VertxEndpointComponent component = new VertxEndpointComponent(); try { reset(referenceResolver); component.createEndpoint("vertx:news?param1=&param2=value2", context); Assert.fail("Missing exception due to invalid endpoint uri"); } catch (CitrusRuntimeException e) { Assert.assertTrue(e.getMessage().startsWith("Unable to find parameter"), e.getMessage()); } }