Search in sources :

Example 86 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class PropertyFileInitialisationTest method tlsNotEnabledIfNotConfigured.

@Test
public void tlsNotEnabledIfNotConfigured() {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    ConnectionFactoryConfigurator.load(connectionFactory, Collections.emptyMap(), "");
    verify(connectionFactory, never()).useSslProtocol(any(SSLContext.class));
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 87 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class PropertyFileInitialisationTest method propertyInitialisationFromFile.

@Test
public void propertyInitialisationFromFile() throws IOException {
    for (String propertyFileLocation : Arrays.asList("./src/test/resources/property-file-initialisation/configuration.properties", "classpath:/property-file-initialisation/configuration.properties")) {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.load(propertyFileLocation);
        checkConnectionFactory(connectionFactory);
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Test(org.junit.Test)

Example 88 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class PropertyFileInitialisationTest method tlsBasicSetupShouldSetDefaultTrustManagerWhenServerValidationIsEnabled.

@Test
public void tlsBasicSetupShouldSetDefaultTrustManagerWhenServerValidationIsEnabled() throws Exception {
    Map<String, String> configuration = new HashMap<>();
    configuration.put(ConnectionFactoryConfigurator.SSL_ENABLED, "true");
    configuration.put(ConnectionFactoryConfigurator.SSL_VALIDATE_SERVER_CERTIFICATE, "true");
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    ConnectionFactoryConfigurator.load(connectionFactory, configuration, "");
    verify(connectionFactory, never()).useSslProtocol(anyString());
    verify(connectionFactory, times(1)).useSslProtocol(any(SSLContext.class));
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 89 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class PropertyFileInitialisationTest method tlsBasicSetupShouldTrustEveryoneWhenServerValidationIsNotEnabled.

@Test
public void tlsBasicSetupShouldTrustEveryoneWhenServerValidationIsNotEnabled() throws Exception {
    String algorithm = ConnectionFactory.computeDefaultTlsProtocol(SSLContext.getDefault().getSupportedSSLParameters().getProtocols());
    Map<String, String> configuration = new HashMap<>();
    configuration.put(ConnectionFactoryConfigurator.SSL_ENABLED, "true");
    configuration.put(ConnectionFactoryConfigurator.SSL_VALIDATE_SERVER_CERTIFICATE, "false");
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    ConnectionFactoryConfigurator.load(connectionFactory, configuration, "");
    verify(connectionFactory, times(1)).useSslProtocol(algorithm);
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Test(org.junit.Test)

Example 90 with ConnectionFactory

use of com.rabbitmq.client.ConnectionFactory in project rabbitmq-java-client by rabbitmq.

the class PropertyFileInitialisationTest method tlsSslContextSetIfTlsEnabled.

@Test
public void tlsSslContextSetIfTlsEnabled() {
    AtomicBoolean sslProtocolSet = new AtomicBoolean(false);
    ConnectionFactory connectionFactory = new ConnectionFactory() {

        @Override
        public void useSslProtocol(SSLContext context) {
            sslProtocolSet.set(true);
            super.useSslProtocol(context);
        }
    };
    ConnectionFactoryConfigurator.load(connectionFactory, Collections.singletonMap(ConnectionFactoryConfigurator.SSL_ENABLED, "true"), "");
    assertThat(sslProtocolSet).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Aggregations

ConnectionFactory (com.rabbitmq.client.ConnectionFactory)188 Connection (com.rabbitmq.client.Connection)87 Test (org.junit.Test)73 Channel (com.rabbitmq.client.Channel)63 IOException (java.io.IOException)53 TimeoutException (java.util.concurrent.TimeoutException)23 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)11 Envelope (com.rabbitmq.client.Envelope)11 SSLContext (javax.net.ssl.SSLContext)11 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)9 HashMap (java.util.HashMap)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 AMQP (com.rabbitmq.client.AMQP)6 Consumer (com.rabbitmq.client.Consumer)6 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)6 AMQConnection (com.rabbitmq.client.impl.AMQConnection)6 Address (com.rabbitmq.client.Address)5 NioParams (com.rabbitmq.client.impl.nio.NioParams)4 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)4 Path (javax.ws.rs.Path)3