16
16
17
17
package org .springframework .boot .autoconfigure .kafka ;
18
18
19
+ import java .util .Map ;
20
+
21
+ import org .apache .kafka .common .config .SslConfigs ;
19
22
import org .junit .jupiter .api .Test ;
20
23
21
24
import org .springframework .boot .autoconfigure .kafka .KafkaProperties .Cleanup ;
22
25
import org .springframework .boot .autoconfigure .kafka .KafkaProperties .IsolationLevel ;
23
26
import org .springframework .boot .autoconfigure .kafka .KafkaProperties .Listener ;
27
+ import org .springframework .boot .context .properties .source .MutuallyExclusiveConfigurationPropertiesException ;
28
+ import org .springframework .core .io .ClassPathResource ;
24
29
import org .springframework .kafka .core .CleanupConfig ;
25
30
import org .springframework .kafka .listener .ContainerProperties ;
26
31
27
32
import static org .assertj .core .api .Assertions .assertThat ;
33
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
28
34
29
35
/**
30
36
* Tests for {@link KafkaProperties}.
31
37
*
32
38
* @author Stephane Nicoll
39
+ * @author Madhura Bhave
33
40
*/
34
41
class KafkaPropertiesTests {
35
42
@@ -52,6 +59,37 @@ void listenerDefaultValuesAreConsistent() {
52
59
assertThat (listenerProperties .isMissingTopicsFatal ()).isEqualTo (container .isMissingTopicsFatal ());
53
60
}
54
61
62
+ @ Test
63
+ void sslPemConfiguration () {
64
+ KafkaProperties properties = new KafkaProperties ();
65
+ properties .getSsl ().setKeyStoreKey ("-----BEGINkey" );
66
+ properties .getSsl ().setTrustStoreCertificates ("-----BEGINtrust" );
67
+ properties .getSsl ().setKeyStoreCertificateChain ("-----BEGINchain" );
68
+ Map <String , Object > consumerProperties = properties .buildConsumerProperties ();
69
+ assertThat (consumerProperties .get (SslConfigs .SSL_KEYSTORE_KEY_CONFIG )).isEqualTo ("-----BEGINkey" );
70
+ assertThat (consumerProperties .get (SslConfigs .SSL_TRUSTSTORE_CERTIFICATES_CONFIG )).isEqualTo ("-----BEGINtrust" );
71
+ assertThat (consumerProperties .get (SslConfigs .SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG ))
72
+ .isEqualTo ("-----BEGINchain" );
73
+ }
74
+
75
+ @ Test
76
+ void sslPropertiesWhenKeyStoreLocationAndKeySetShouldThrowException () {
77
+ KafkaProperties properties = new KafkaProperties ();
78
+ properties .getSsl ().setKeyStoreKey ("-----BEGIN" );
79
+ properties .getSsl ().setKeyStoreLocation (new ClassPathResource ("ksLoc" ));
80
+ assertThatExceptionOfType (MutuallyExclusiveConfigurationPropertiesException .class )
81
+ .isThrownBy (properties ::buildConsumerProperties );
82
+ }
83
+
84
+ @ Test
85
+ void sslPropertiesWhenTrustStoreLocationAndCertificatesSetShouldThrowException () {
86
+ KafkaProperties properties = new KafkaProperties ();
87
+ properties .getSsl ().setTrustStoreLocation (new ClassPathResource ("tsLoc" ));
88
+ properties .getSsl ().setTrustStoreCertificates ("-----BEGIN" );
89
+ assertThatExceptionOfType (MutuallyExclusiveConfigurationPropertiesException .class )
90
+ .isThrownBy (properties ::buildConsumerProperties );
91
+ }
92
+
55
93
@ Test
56
94
void cleanupConfigDefaultValuesAreConsistent () {
57
95
CleanupConfig cleanupConfig = new CleanupConfig ();
0 commit comments