Search in sources :

Example 1 with ConnectionFactory

use of org.springframework.amqp.rabbit.connection.ConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RabbitConnectionFactoryCreatorTest method cloudRabbitCreationWithUri.

@Test
public void cloudRabbitCreationWithUri() throws Exception {
    String userinfo = String.format("%s:%s", TEST_USERNAME, TEST_PASSWORD);
    URI uri = new URI("amqp", userinfo, TEST_HOST, TEST_PORT, "/" + TEST_VH, null, null);
    AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", uri.toString());
    ConnectionFactory connector = testCreator.create(serviceInfo, null);
    assertConnectorPropertiesMatchUri(connector, serviceInfo.getUri());
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) URI(java.net.URI) AmqpServiceInfo(org.springframework.cloud.service.common.AmqpServiceInfo) Test(org.junit.Test)

Example 2 with ConnectionFactory

use of org.springframework.amqp.rabbit.connection.ConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RabbitConnectionFactoryCreatorTest method assertConnectorPropertiesMatchUri.

private void assertConnectorPropertiesMatchUri(ConnectionFactory connector, String uriString) throws Exception {
    assertNotNull(connector);
    URI uri = new URI(uriString);
    assertEquals(uri.getHost(), connector.getHost());
    assertEquals(uri.getPort(), connector.getPort());
    com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = (com.rabbitmq.client.ConnectionFactory) ReflectionTestUtils.getField(connector, "rabbitConnectionFactory");
    String[] userInfo = uri.getRawUserInfo().split(":");
    assertEquals(userInfo[0], ReflectionTestUtils.getField(rabbitConnectionFactory, "username"));
    assertEquals(userInfo[1], ReflectionTestUtils.getField(rabbitConnectionFactory, "password"));
    assertTrue(uri.getPath().endsWith(connector.getVirtualHost()));
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) URI(java.net.URI)

Example 3 with ConnectionFactory

use of org.springframework.amqp.rabbit.connection.ConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RabbitConnectionFactoryCreatorTest method cloudRabbitCreationWithUris.

@Test
public void cloudRabbitCreationWithUris() throws Exception {
    String userinfo = String.format("%s:%s", TEST_USERNAME, TEST_PASSWORD);
    URI uri = new URI("amqp", userinfo, "0.0.0.0", 0, "/" + TEST_VH, null, null);
    URI uri1 = new URI("amqp", userinfo, TEST_HOST, TEST_PORT, "/" + TEST_VH, null, null);
    URI uri2 = new URI("amqp", userinfo, TEST_HOST2, TEST_PORT2, "/" + TEST_VH, null, null);
    List<String> uris = Arrays.asList(uri1.toString(), uri2.toString());
    AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", uri.toString(), null, uris, null);
    ConnectionFactory connector = testCreator.create(serviceInfo, null);
    assertConnectorPropertiesMatchUri(connector, uri1.toString());
    assertConnectorPropertiesMatchHosts(connector, uris);
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) URI(java.net.URI) AmqpServiceInfo(org.springframework.cloud.service.common.AmqpServiceInfo) Test(org.junit.Test)

Example 4 with ConnectionFactory

use of org.springframework.amqp.rabbit.connection.ConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RabbitConnectionFactoryConfigWithServiceConfig method cloudRabbitConnectionFactoryWithConfig.

@Test
public void cloudRabbitConnectionFactoryWithConfig() {
    ApplicationContext testContext = getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service"));
    ConnectionFactory connector = testContext.getBean("connectionFactoryWithConfig", getConnectorType());
    RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, -1, -1);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) Test(org.junit.Test)

Example 5 with ConnectionFactory

use of org.springframework.amqp.rabbit.connection.ConnectionFactory in project spring-cloud-connectors by spring-cloud.

the class RabbitConnectionFactoryXmlConfigTest method cloudRabbitConnectionFactoryWithConfigurationAndProperties.

@Test
public void cloudRabbitConnectionFactoryWithConfigurationAndProperties() {
    ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));
    ConnectionFactory connector = testContext.getBean("service-channelCacheSize200-properties", getConnectorType());
    RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 5, 10);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) Test(org.junit.Test)

Aggregations

ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)11 Test (org.junit.Test)10 ApplicationContext (org.springframework.context.ApplicationContext)6 URI (java.net.URI)3 AmqpServiceInfo (org.springframework.cloud.service.common.AmqpServiceInfo)3 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1