Skip to content

Commit 7d54eda

Browse files
committed
Fix tests
1 parent 0b07c02 commit 7d54eda

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.amqp;
18+
19+
import javax.net.ssl.TrustManager;
20+
21+
import com.rabbitmq.client.NullTrustManager;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
25+
import org.springframework.boot.junit.runner.classpath.ClassPathOverrides;
26+
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Compatibility tests for RabbitMQ with amqp-client 4.0.x
32+
*
33+
* @author Stephane Nicoll
34+
*/
35+
@RunWith(ModifiedClassPathRunner.class)
36+
@ClassPathOverrides("com.rabbitmq:amqp-client:4.0.3")
37+
public class RabbitAutoConfigurationCompatibilityTests
38+
extends RabbitAutoConfigurationTests {
39+
40+
@Test
41+
public void enableSslWithValidateServerCertificateFalse() {
42+
load(TestConfiguration.class, "spring.rabbitmq.ssl.enabled:true",
43+
"spring.rabbitmq.ssl.validateServerCertificate=false");
44+
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
45+
TrustManager trustManager = getTrustManager(rabbitConnectionFactory);
46+
assertThat(trustManager).isInstanceOf(NullTrustManager.class);
47+
}
48+
49+
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.rabbitmq.client.Address;
2424
import com.rabbitmq.client.NullTrustManager;
25+
import com.rabbitmq.client.TrustEverythingTrustManager;
2526
import org.aopalliance.aop.Advice;
2627
import org.junit.After;
2728
import org.junit.Rule;
@@ -66,8 +67,6 @@
6667
*
6768
* @author Greg Turnquist
6869
* @author Stephane Nicoll
69-
* @author Gary Russell
70-
* @author Stephane Nicoll
7170
*/
7271
public class RabbitAutoConfigurationTests {
7372

@@ -438,7 +437,7 @@ public void enableSslWithValidateServerCertificateFalse() throws Exception {
438437
"spring.rabbitmq.ssl.validateServerCertificate=false");
439438
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory();
440439
TrustManager trustManager = getTrustManager(rabbitConnectionFactory);
441-
assertThat(trustManager).isInstanceOf(NullTrustManager.class);
440+
assertThat(trustManager).isInstanceOf(TrustEverythingTrustManager.class);
442441
}
443442

444443
@Test
@@ -449,7 +448,7 @@ public void enableSslWithValidateServerCertificateDefault() throws Exception {
449448
assertThat(trustManager).isNotInstanceOf(NullTrustManager.class);
450449
}
451450

452-
private TrustManager getTrustManager(
451+
protected TrustManager getTrustManager(
453452
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory) {
454453
Object sslContext = ReflectionTestUtils.getField(rabbitConnectionFactory,
455454
"sslContext");
@@ -461,7 +460,7 @@ private TrustManager getTrustManager(
461460
return (TrustManager) trustManager;
462461
}
463462

464-
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory() {
463+
protected com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory() {
465464
CachingConnectionFactory connectionFactory = this.context
466465
.getBean(CachingConnectionFactory.class);
467466
return (com.rabbitmq.client.ConnectionFactory) new DirectFieldAccessor(
@@ -475,7 +474,7 @@ private boolean getMandatory(RabbitTemplate rabbitTemplate) {
475474
return expression.getValue();
476475
}
477476

478-
private void load(Class<?> config, String... environment) {
477+
protected void load(Class<?> config, String... environment) {
479478
load(new Class<?>[] { config }, environment);
480479
}
481480

0 commit comments

Comments
 (0)