Back to Repositories

Validating AMQP Settings Configuration in Conductor-OSS

This test suite validates the AMQP settings configuration in Conductor’s AMQP integration. It ensures proper handling of AMQP exchange and queue parameters, focusing on URI parsing and configuration validation for RabbitMQ connections.

Test Coverage Overview

The test suite provides comprehensive coverage of AMQP settings configuration.

Key areas tested include:
  • Exchange configuration parsing from URI strings
  • Queue configuration validation
  • Default configuration handling
  • Parameter validation for delivery modes
Integration points focus on RabbitMQ connection factory defaults and AMQP protocol specifications.

Implementation Analysis

The testing approach uses JUnit 4 with Mockito for mocking dependencies. Tests validate the AMQPSettings class’s ability to parse and validate configuration from URI strings.

Key patterns include:
  • Mock-based configuration setup
  • URI parameter parsing validation
  • Exception handling verification

Technical Details

Testing tools and configuration:
  • JUnit 4 test framework
  • Mockito mocking framework
  • RabbitMQ client library
  • AMQP protocol configuration
  • Mock AMQPEventQueueProperties for configuration

Best Practices Demonstrated

The test suite demonstrates several testing best practices:

  • Proper test setup using @Before annotation
  • Clear test method naming conventions
  • Thorough validation of configuration parameters
  • Exception testing for invalid inputs
  • Isolation of test cases

conductor-oss/conductor

amqp/src/test/java/com/netflix/conductor/contribs/queue/amqp/AMQPSettingsTest.java

            
/*
 * Copyright 2023 Conductor Authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.netflix.conductor.contribs.queue.amqp;

import java.time.Duration;

import org.junit.Before;
import org.junit.Test;

import com.netflix.conductor.contribs.queue.amqp.config.AMQPEventQueueProperties;
import com.netflix.conductor.contribs.queue.amqp.util.AMQPSettings;

import com.rabbitmq.client.AMQP.PROTOCOL;
import com.rabbitmq.client.ConnectionFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AMQPSettingsTest {

    private AMQPEventQueueProperties properties;

    @Before
    public void setUp() {
        properties = mock(AMQPEventQueueProperties.class);
        when(properties.getBatchSize()).thenReturn(1);
        when(properties.getPollTimeDuration()).thenReturn(Duration.ofMillis(100));
        when(properties.getHosts()).thenReturn(ConnectionFactory.DEFAULT_HOST);
        when(properties.getUsername()).thenReturn(ConnectionFactory.DEFAULT_USER);
        when(properties.getPassword()).thenReturn(ConnectionFactory.DEFAULT_PASS);
        when(properties.getVirtualHost()).thenReturn(ConnectionFactory.DEFAULT_VHOST);
        when(properties.getPort()).thenReturn(PROTOCOL.PORT);
        when(properties.getConnectionTimeoutInMilliSecs()).thenReturn(60000);
        when(properties.isUseNio()).thenReturn(false);
        when(properties.isDurable()).thenReturn(true);
        when(properties.isExclusive()).thenReturn(false);
        when(properties.isAutoDelete()).thenReturn(false);
        when(properties.getContentType()).thenReturn("application/json");
        when(properties.getContentEncoding()).thenReturn("UTF-8");
        when(properties.getExchangeType()).thenReturn("topic");
        when(properties.getDeliveryMode()).thenReturn(2);
        when(properties.isUseExchange()).thenReturn(true);
    }

    @Test
    public void testAMQPSettings_exchange_fromuri_defaultconfig() {
        String exchangestring =
                "amqp_exchange:myExchangeName?exchangeType=topic&routingKey=test&deliveryMode=2";
        AMQPSettings settings = new AMQPSettings(properties);
        settings.fromURI(exchangestring);
        assertEquals("topic", settings.getExchangeType());
        assertEquals("test", settings.getRoutingKey());
        assertEquals("myExchangeName", settings.getQueueOrExchangeName());
    }

    @Test
    public void testAMQPSettings_queue_fromuri_defaultconfig() {
        String exchangestring =
                "amqp_queue:myQueueName?deliveryMode=2&durable=false&autoDelete=true&exclusive=true";
        AMQPSettings settings = new AMQPSettings(properties);
        settings.fromURI(exchangestring);
        assertFalse(settings.isDurable());
        assertTrue(settings.isExclusive());
        assertTrue(settings.autoDelete());
        assertEquals(2, settings.getDeliveryMode());
        assertEquals("myQueueName", settings.getQueueOrExchangeName());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testAMQPSettings_exchange_fromuri_wrongdeliverymode() {
        String exchangestring =
                "amqp_exchange:myExchangeName?exchangeType=topic&routingKey=test&deliveryMode=3";
        AMQPSettings settings = new AMQPSettings(properties);
        settings.fromURI(exchangestring);
    }
}