JmsEndpointComponent extends AbstractEndpointComponent { @Override protected Endpoint createEndpoint(String resourcePath, Map<String, String> parameters, TestContext context) { JmsEndpoint endpoint; if (resourcePath.startsWith("sync:")) { endpoint = new JmsSyncEndpoint(); } else { endpoint = new JmsEndpoint(); } if (resourcePath.contains("topic:")) { endpoint.getEndpointConfiguration().setPubSubDomain(true); } if (resourcePath.indexOf(':') > 0) { endpoint.getEndpointConfiguration().setDestinationName(resourcePath.substring(resourcePath.lastIndexOf(':') + 1)); } else { endpoint.getEndpointConfiguration().setDestinationName(resourcePath); } if (context.getReferenceResolver() != null && context.getReferenceResolver().isResolvable("connectionFactory")) { endpoint.getEndpointConfiguration().setConnectionFactory(context.getReferenceResolver().resolve("connectionFactory", ConnectionFactory.class)); } enrichEndpointConfiguration(endpoint.getEndpointConfiguration(), parameters, context); return endpoint; } JmsEndpointComponent();   }
@Test public void testCreateQueueEndpoint() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("connectionFactory")).thenReturn(true); when(referenceResolver.resolve("connectionFactory", ConnectionFactory.class)).thenReturn(connectionFactory); Endpoint endpoint = component.createEndpoint("jms:queuename", context); Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class); Assert.assertEquals(((JmsEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "queuename"); Assert.assertFalse(((JmsEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory(), connectionFactory); Assert.assertNull(((JmsEndpoint) endpoint).getEndpointConfiguration().getDestination()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateTopicEndpoint() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("connectionFactory")).thenReturn(true); when(referenceResolver.resolve("connectionFactory", ConnectionFactory.class)).thenReturn(connectionFactory); Endpoint endpoint = component.createEndpoint("jms:topic:topicname", context); Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class); Assert.assertEquals(((JmsEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "topicname"); Assert.assertTrue(((JmsEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory(), connectionFactory); Assert.assertNull(((JmsEndpoint) endpoint).getEndpointConfiguration().getDestination()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateSyncQueueEndpoint() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("connectionFactory")).thenReturn(false); Endpoint endpoint = component.createEndpoint("jms:sync:queuename", context); Assert.assertEquals(endpoint.getClass(), JmsSyncEndpoint.class); Assert.assertEquals(((JmsSyncEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "queuename"); Assert.assertFalse(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertNull(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory()); Assert.assertNull(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getDestination()); }
@Test public void testCreateEndpointWithParameters() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("connectionFactory")).thenReturn(false); when(referenceResolver.isResolvable("specialConnectionFactory")).thenReturn(true); when(referenceResolver.resolve("specialConnectionFactory", ConnectionFactory.class)).thenReturn(connectionFactory); Endpoint endpoint = component.createEndpoint("jms:queuename?connectionFactory=specialConnectionFactory&timeout=10000", context); Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class); Assert.assertEquals(((JmsEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "queuename"); Assert.assertFalse(((JmsEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory(), connectionFactory); Assert.assertNull(((JmsEndpoint) endpoint).getEndpointConfiguration().getDestination()); Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }
@Test public void testCreateEndpointWithNullParameters() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); Endpoint endpoint = component.createEndpoint("jms:queuename?destination", context); Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class); Assert.assertEquals(((JmsEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "queuename"); Assert.assertFalse(((JmsEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertNull(((JmsEndpoint) endpoint).getEndpointConfiguration().getDestination()); }
@Test public void testCreateSyncEndpointWithParameters() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("connectionFactory")).thenReturn(false); when(referenceResolver.isResolvable("specialConnectionFactory")).thenReturn(true); when(referenceResolver.resolve("specialConnectionFactory", ConnectionFactory.class)).thenReturn(connectionFactory); when(referenceResolver.isResolvable("myReplyDestination")).thenReturn(true); when(referenceResolver.resolve("myReplyDestination", Destination.class)).thenReturn(replyDestination); Endpoint endpoint = component.createEndpoint("jms:sync:queuename?connectionFactory=specialConnectionFactory&pollingInterval=100&replyDestination=myReplyDestination", context); Assert.assertEquals(endpoint.getClass(), JmsSyncEndpoint.class); Assert.assertEquals(((JmsSyncEndpoint)endpoint).getEndpointConfiguration().getDestinationName(), "queuename"); Assert.assertFalse(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain()); Assert.assertEquals(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory(), connectionFactory); Assert.assertNull(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getDestination()); Assert.assertEquals(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getReplyDestination(), replyDestination); Assert.assertEquals(((JmsSyncEndpoint) endpoint).getEndpointConfiguration().getPollingInterval(), 100L); }
@Test public void testInvalidEndpointUri() throws Exception { JmsEndpointComponent component = new JmsEndpointComponent(); try { reset(referenceResolver); component.createEndpoint("jms:queuename?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()); } }