Skip to content

Commit

Permalink
Add checkConf&Returns into RoutingCF.addTargetCF
Browse files Browse the repository at this point in the history
When only `AbstractRoutingConnectionFactory.addTargetConnectionFactory()` is used, 
the `AbstractRoutingConnectionFactory.afterPropertiesSet()` throw an `java.lang.IllegalArgumentException: At least one target factory (or default) is required` 
because the property `confirms` is `null` (the method `addTargetConnectionFactory` doesn't call `checkConfirmsAndReturns` that fill this field).

* add `checkConfirmsAndReturns` into the  `AbstractRoutingConnectionFactory .addTargetConnectionFactory()`
* using `assertThatNoException()` instead of `catch/fail`

**Cherry-pick to `2.4.x` & `2.3.x`**
  • Loading branch information
LeonardoFerreiraa authored Mar 15, 2022
1 parent a1aba73 commit d5e7c3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,7 @@
* @author Artem Bilan
* @author Josh Chappelle
* @author Gary Russell
* @author Leonardo Ferreira
* @since 1.3
*/
public abstract class AbstractRoutingConnectionFactory implements ConnectionFactory, RoutingConnectionFactory,
Expand Down Expand Up @@ -238,6 +239,8 @@ protected void addTargetConnectionFactory(Object key, ConnectionFactory connecti
for (ConnectionListener listener : this.connectionListeners) {
connectionFactory.addConnectionListener(listener);
}

checkConfirmsAndReturns(connectionFactory);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.amqp.rabbit.connection;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -51,6 +52,7 @@
* @author Artem Bilan
* @author Josh Chappelle
* @author Gary Russell
* @author Leonardo Ferreira
* @since 1.3
*/
public class RoutingConnectionFactoryTests {
Expand Down Expand Up @@ -323,4 +325,19 @@ protected synchronized void redeclareElementsIfNecessary() {
assertThat(SimpleResourceHolder.unbind(connectionFactory)).isEqualTo("foo");
}

@Test
void afterPropertiesSetShouldNotThrowAnyExceptionAfterAddTargetConnectionFactory() throws Exception {
AbstractRoutingConnectionFactory routingFactory = new AbstractRoutingConnectionFactory() {
@Override
protected Object determineCurrentLookupKey() {
return null;
}
};

routingFactory.addTargetConnectionFactory("1", Mockito.mock(ConnectionFactory.class));

assertThatNoException()
.isThrownBy(routingFactory::afterPropertiesSet);
}

}

0 comments on commit d5e7c3f

Please sign in to comment.