diff options
author | Bansal, Nitin (nb121v) <nitin.bansal@amdocs.com> | 2018-11-16 13:36:30 -0500 |
---|---|---|
committer | Bansal, Nitin (nb121v) <nitin.bansal@amdocs.com> | 2018-11-16 13:40:25 -0500 |
commit | f2daa751f0c6e838316aa90f6a25ed267c8c6d48 (patch) | |
tree | b32ddd95cab8e57dceb66b73bb3a76cdda003c9c /event-client-rabbitmq/src/test/java/org/onap | |
parent | 898e060c37c2e7734a025dff9db1f733c9e4580f (diff) |
support SSL in rabbit mq in event client lib
Issue-ID: AAI-1929
Change-Id: I5912b0814e4b565942e32c5ed6d5094b45040c33
Signed-off-by: Bansal, Nitin (nb121v) <nitin.bansal@amdocs.com>
Diffstat (limited to 'event-client-rabbitmq/src/test/java/org/onap')
2 files changed, 68 insertions, 57 deletions
diff --git a/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqConsumer.java b/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqConsumer.java index df4c54b..79f9914 100644 --- a/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqConsumer.java +++ b/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqConsumer.java @@ -65,10 +65,33 @@ public class TestRabbitMqConsumer { BuiltinExchangeType topicEx = BuiltinExchangeType.TOPIC; TimeUnit unit = TimeUnit.MILLISECONDS; Map<String, Integer> hostPortMap = new HashMap<String, Integer>(); + + RabbitMqClientConfig config1 = new RabbitMqClientConfig(); + RabbitMqClientConfig config2 = new RabbitMqClientConfig(); + RabbitMqClientConfig config3 = new RabbitMqClientConfig(); + @Before public void init() throws Exception { - RabbitMqEventConsumer.setConnectionFactory(mockConnectionFactory); + RabbitMqUtils.setConnectionFactory(mockConnectionFactory); + + config1.setHosts("host1:1234"); + config1.setUsername("user"); + config1.setPassword("secret"); + config1.setExchangeName("my-exchange"); + config1.setQueue("my-queue"); + + config2.setHosts("host1:1234"); + config2.setUsername("user"); + config2.setPassword("secret"); + config2.setExchangeName("my-exchange"); + config2.setExchangeType(BuiltinExchangeType.DIRECT.name()); + config2.setQueue("my-queue"); + + config3.setHosts("host1:1234,host2:5678"); + config3.setUsername("user"); + config3.setPassword("secret"); + config3.setQueue("my-queue"); } @Test @@ -77,11 +100,9 @@ public class TestRabbitMqConsumer { Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); Mockito.when(mockChannel.basicConsume(Mockito.any(), Mockito.anyBoolean(), Mockito.any(Consumer.class))).thenReturn(Mockito.anyString()); - new RabbitMqEventConsumer("hosts", 0, "userName", "password", "exchangeName", "queueName"); - new RabbitMqEventConsumer("hosts", 0, "userName", "password", BuiltinExchangeType.DIRECT.name(), "exchangeName", "queueName"); - new RabbitMqEventConsumer(hostPortMap, "userName", "password", "exchangeName", "queueName"); - new RabbitMqEventConsumer(hostPortMap, "userName", "password", BuiltinExchangeType.DIRECT.name(), "exchangeName", "queueName"); - new RabbitMqEventConsumer("hosts", 0, "userName", "password", "queue"); + new RabbitMqEventConsumer(config1); + new RabbitMqEventConsumer(config2); + new RabbitMqEventConsumer(config3); } @Test @@ -90,7 +111,7 @@ public class TestRabbitMqConsumer { Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); Mockito.when(mockChannel.basicConsume(Mockito.any(), Mockito.anyBoolean(), Mockito.any(Consumer.class))).thenReturn(Mockito.anyString()); - RabbitMqEventConsumer consumer = new RabbitMqEventConsumer("hosts", 0, "userName", "password", "exchangeName", "queueName"); + RabbitMqEventConsumer consumer = new RabbitMqEventConsumer(config1); consumer.consume(); consumer.consumeWithOffsets(); consumer.consumeAndCommit(); @@ -103,7 +124,7 @@ public class TestRabbitMqConsumer { Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); Mockito.when(mockChannel.basicConsume(Mockito.any(), Mockito.anyBoolean(), Mockito.any(Consumer.class))).thenReturn(Mockito.anyString()); - RabbitMqEventConsumer consumer = new RabbitMqEventConsumer("hosts", 0, "userName", "password", "exchangeName", "queueName"); + RabbitMqEventConsumer consumer = new RabbitMqEventConsumer(config1); consumer.commitOffsets(); consumer.commitOffsets(0L); consumer.close(); @@ -118,7 +139,7 @@ public class TestRabbitMqConsumer { List<MessageWithOffset> records = buildTestMessages(2); mqueue = new ArrayBlockingQueue<>(2); mqueue.addAll(records); - RabbitMqEventConsumer consumer = new RabbitMqEventConsumer("hosts", 0, "userName", "password", "exchangeName", "queueName"); + RabbitMqEventConsumer consumer = new RabbitMqEventConsumer(config1); consumer.setMessageQueue(mqueue); consumer.consumeAndCommit(); consumer.close(); @@ -133,7 +154,7 @@ public class TestRabbitMqConsumer { List<MessageWithOffset> records = buildTestMessages(2); mqueue = new ArrayBlockingQueue<>(2); mqueue.addAll(records); - RabbitMqEventConsumer consumer = new RabbitMqEventConsumer("hosts", 0, "userName", "password", "exchangeName", "queueName"); + RabbitMqEventConsumer consumer = new RabbitMqEventConsumer(config1); consumer.setMessageQueue(mqueue); consumer.consumeWithOffsets(); consumer.commitOffsets(); diff --git a/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqPublisher.java b/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqPublisher.java index e41126f..54384ed 100644 --- a/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqPublisher.java +++ b/event-client-rabbitmq/src/test/java/org/onap/aai/event/client/TestRabbitMqPublisher.java @@ -55,69 +55,59 @@ public class TestRabbitMqPublisher { BuiltinExchangeType topicEx = BuiltinExchangeType.TOPIC; Map<String, Integer> hostPortMap = new HashMap<String, Integer>(); + RabbitMqClientConfig config1 = new RabbitMqClientConfig(); + RabbitMqClientConfig config2 = new RabbitMqClientConfig(); + RabbitMqClientConfig config3 = new RabbitMqClientConfig(); @Before public void init() throws Exception { - RabbitMqEventPublisher.setConnectionFactory(mockConnectionFactory); + RabbitMqUtils.setConnectionFactory(mockConnectionFactory); + + config1.setHosts("host1:1234"); + config1.setUsername("user"); + config1.setPassword("secret"); + config1.setExchangeName("my-exchange"); + + config2.setHosts("host1:1234"); + config2.setUsername("user"); + config2.setPassword("secret"); + config2.setExchangeName("my-exchange"); + config2.setExchangeType(BuiltinExchangeType.DIRECT.name()); } @Test public void testConstructors() throws Exception { - Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); - Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); - Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); - new RabbitMqEventPublisher("hosts", 0, "userName", "password", "exchangeName"); - new RabbitMqEventPublisher("hosts", 0, "userName", "password", BuiltinExchangeType.DIRECT.name(), "exchangeName"); - new RabbitMqEventPublisher(hostPortMap, "userName", "password", "exchangeName"); - new RabbitMqEventPublisher(hostPortMap, "userName", "password", BuiltinExchangeType.DIRECT.name(), "exchangeName"); - new RabbitMqEventPublisher("hosts", 0, "userName", "password", "queueName",new HashMap<String, Object>()); + Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); + Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); + Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); + new RabbitMqEventPublisher(config1); + new RabbitMqEventPublisher(config2); } - + @Test public void publishSynchronous() throws Exception { - Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); - Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); - Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); - RabbitMqEventPublisher publisher = new RabbitMqEventPublisher("hosts", 0, "userName", "password", "exchangeName"); - publisher.sendSync(""); - publisher.sendSync(Arrays.asList("")); - publisher.sendSync("key", ""); + Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); + Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); + Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); + RabbitMqEventPublisher publisher = new RabbitMqEventPublisher(config1); + publisher.sendSync(""); + publisher.sendSync(Arrays.asList("")); + publisher.sendSync("key", ""); publisher.sendSync("key", Arrays.asList("")); publisher.close(); } @Test public void publishAsynchronous() throws Exception { - Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); - Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); - Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); - RabbitMqEventPublisher publisher = new RabbitMqEventPublisher("hosts", 0, "userName", "password", "exchangeName"); - publisher.sendAsync(""); - publisher.sendAsync(Arrays.asList("")); - publisher.sendAsync("key", ""); - publisher.sendAsync("key", Arrays.asList("")); - publisher.close(); - } - @Test(expected = UnsupportedOperationException.class) - public void UnsupportedMessageTest() throws Exception { - Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); - Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); - Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); - RabbitMqEventPublisher publisher = new RabbitMqEventPublisher("hosts", 0, "userName", "password", "queueName",new HashMap<String, Object>()); - publisher.sendSync("key", ""); - publisher.sendSync("key", Arrays.asList("")); - publisher.close(); - } - - @Test(expected = UnsupportedOperationException.class) - public void UnSupportedMultiMessageTests() throws Exception { - Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); - Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); - Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); - RabbitMqEventPublisher publisher = new RabbitMqEventPublisher("hosts", 0, "userName", "password", "queueName",new HashMap<String, Object>()); - publisher.sendSync("key", Arrays.asList("")); - publisher.close(); + Mockito.when(mockConnectionFactory.newConnection(Mockito.anyListOf(Address.class))).thenReturn(mockConnection); + Mockito.when(mockConnection.createChannel()).thenReturn(mockChannel); + Mockito.when(mockChannel.exchangeDeclare(Mockito.any(), Mockito.eq(topicEx), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyMap())).thenReturn(mockDeclareOK); + RabbitMqEventPublisher publisher = new RabbitMqEventPublisher(config1); + publisher.sendAsync(""); + publisher.sendAsync(Arrays.asList("")); + publisher.sendAsync("key", ""); + publisher.sendAsync("key", Arrays.asList("")); + publisher.close(); } - } |