File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
module/spring-boot-amqp/src
main/java/org/springframework/boot/amqp/health
test/java/org/springframework/boot/amqp/health Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
5252
5353 private @ Nullable String getVersion () {
5454 return this .rabbitTemplate .execute ((channel ) -> {
55- Object version = channel .getConnection ().getServerProperties ().get ("version" );
55+ Object version = channel .getConnection ().getServerProperties ().getOrDefault ("version" , "unknown " );
5656 Assert .state (version != null , "'version' must not be null" );
5757 return version .toString ();
5858 });
Original file line number Diff line number Diff line change @@ -70,6 +70,17 @@ void healthWhenConnectionSucceedsShouldReturnUpWithVersion() {
7070 assertThat (health .getDetails ()).containsEntry ("version" , "123" );
7171 }
7272
73+ @ Test
74+ void healthWhenVersionIsMissingShouldReturnUpWithUnknownVersion () {
75+ givenTemplateExecutionWillInvokeCallback ();
76+ Connection connection = mock (Connection .class );
77+ given (this .channel .getConnection ()).willReturn (connection );
78+ given (connection .getServerProperties ()).willReturn (Collections .emptyMap ());
79+ Health health = new RabbitHealthIndicator (this .rabbitTemplate ).health ();
80+ assertThat (health .getStatus ()).isEqualTo (Status .UP );
81+ assertThat (health .getDetails ()).containsEntry ("version" , "unknown" );
82+ }
83+
7384 @ Test
7485 void healthWhenConnectionFailsShouldReturnDown () {
7586 givenTemplateExecutionWillInvokeCallback ();
You can’t perform that action at this time.
0 commit comments