MailEndpointComponent extends AbstractEndpointComponent { @Override protected Endpoint createEndpoint(String resourcePath, Map<String, String> parameters, TestContext context) { MailClient client = new MailClient(); if (resourcePath.contains(":")) { StringTokenizer tok = new StringTokenizer(resourcePath, ":"); client.getEndpointConfiguration().setHost(tok.nextToken()); if (tok.hasMoreTokens()) { client.getEndpointConfiguration().setPort(Integer.valueOf(tok.nextToken())); } } else { client.getEndpointConfiguration().setHost(resourcePath); } enrichEndpointConfiguration(client.getEndpointConfiguration(), parameters, context); return client; } MailEndpointComponent();   }
@Test public void testCreateClientEndpoint() throws Exception { MailEndpointComponent component = new MailEndpointComponent(); Endpoint endpoint = component.createEndpoint("smtp: Assert.assertEquals(endpoint.getClass(), MailClient.class); Assert.assertEquals(((MailClient)endpoint).getEndpointConfiguration().getHost(), "localhost"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getPort(), 22000); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getTimeout(), 5000L); endpoint = component.createEndpoint("mail:localhost:25000", context); Assert.assertEquals(endpoint.getClass(), MailClient.class); Assert.assertEquals(((MailClient)endpoint).getEndpointConfiguration().getHost(), "localhost"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getPort(), 25000); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getTimeout(), 5000L); endpoint = component.createEndpoint("mail:localhost", context); Assert.assertEquals(endpoint.getClass(), MailClient.class); Assert.assertEquals(((MailClient)endpoint).getEndpointConfiguration().getHost(), "localhost"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getPort(), -1); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getTimeout(), 5000L); }
@Test public void testCreateClientEndpointWithParameters() throws Exception { MailEndpointComponent component = new MailEndpointComponent(); reset(referenceResolver); when(referenceResolver.isResolvable("myMarshaller")).thenReturn(true); when(referenceResolver.resolve("myMarshaller", MailMarshaller.class)).thenReturn(marshaller); Endpoint endpoint = component.createEndpoint("smtp: Assert.assertEquals(endpoint.getClass(), MailClient.class); Assert.assertEquals(((MailClient)endpoint).getEndpointConfiguration().getHost(), "localhost"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getPort(), -1); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getUsername(), "foo"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getPassword(), "1234"); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getMarshaller(), marshaller); Assert.assertEquals(((MailClient) endpoint).getEndpointConfiguration().getTimeout(), 10000L); }