Exemplo n.º 1
0
  @Test
  public void testResolveJmsEndpoint() throws Exception {
    reset(applicationContext);

    expect(applicationContext.getBeansOfType(EndpointComponent.class))
        .andReturn(Collections.<String, EndpointComponent>emptyMap())
        .once();
    expect(applicationContext.containsBean("connectionFactory")).andReturn(true).once();
    expect(applicationContext.getBean("connectionFactory", ConnectionFactory.class))
        .andReturn(EasyMock.createMock(ConnectionFactory.class))
        .once();

    replay(applicationContext);

    TestContext context = new TestContext();
    context.setApplicationContext(applicationContext);

    DefaultEndpointFactory factory = new DefaultEndpointFactory();
    Endpoint endpoint = factory.create("jms:Sample.Queue.Name", context);

    Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class);
    Assert.assertEquals(
        ((JmsEndpoint) endpoint).getEndpointConfiguration().getDestinationName(),
        "Sample.Queue.Name");

    verify(applicationContext);
  }
Exemplo n.º 2
0
  @Test
  public void testCreateQueueEndpoint() throws Exception {
    JmsEndpointComponent component = new JmsEndpointComponent();

    reset(applicationContext);
    expect(applicationContext.containsBean("connectionFactory")).andReturn(true).once();
    expect(applicationContext.getBean("connectionFactory", ConnectionFactory.class))
        .andReturn(connectionFactory)
        .once();
    replay(applicationContext);

    Endpoint endpoint = component.createEndpoint("jms:queuename", context);

    Assert.assertEquals(endpoint.getClass(), JmsEndpoint.class);

    Assert.assertEquals(
        ((JmsEndpoint) endpoint).getEndpointConfiguration().getDestinationName(), "queuename");
    Assert.assertEquals(
        ((JmsEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain(), false);
    Assert.assertEquals(
        ((JmsEndpoint) endpoint).getEndpointConfiguration().getConnectionFactory(),
        connectionFactory);
    Assert.assertNull(((JmsEndpoint) endpoint).getEndpointConfiguration().getDestination());
    Assert.assertEquals(((JmsEndpoint) endpoint).getEndpointConfiguration().getTimeout(), 5000L);

    verify(applicationContext);
  }
Exemplo n.º 3
0
  @Test
  public void testCreateSyncEndpointWithParameters() throws Exception {
    JmsEndpointComponent component = new JmsEndpointComponent();

    reset(applicationContext);
    expect(applicationContext.containsBean("connectionFactory")).andReturn(false).once();
    expect(applicationContext.containsBean("specialConnectionFactory")).andReturn(true).once();
    expect(applicationContext.getBean("specialConnectionFactory"))
        .andReturn(connectionFactory)
        .once();
    expect(applicationContext.containsBean("myReplyDestination")).andReturn(true).once();
    expect(applicationContext.getBean("myReplyDestination")).andReturn(replyDestination).once();
    replay(applicationContext);

    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.assertEquals(
        ((JmsSyncEndpoint) endpoint).getEndpointConfiguration().isPubSubDomain(), false);
    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);

    verify(applicationContext);
  }
 /**
  * Simple log helper to give logs a common prefix.
  *
  * @param ctx the context.
  * @param endpoint the endpoint.
  * @return a prefix string for logs.
  */
 protected static String logIdent(final ChannelHandlerContext ctx, final Endpoint endpoint) {
   return "[" + ctx.channel().remoteAddress() + "][" + endpoint.getClass().getSimpleName() + "]: ";
 }