20
20
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
21
21
import static org .assertj .core .api .Assertions .assertThatNoException ;
22
22
23
- import java .util .Collection ;
24
23
import java .util .Collections ;
25
24
import java .util .HashMap ;
26
25
import java .util .Map ;
27
- import java .util .Set ;
28
26
27
+ import org .apache .pulsar .client .admin .PulsarAdmin ;
29
28
import org .apache .pulsar .client .api .CompressionType ;
30
29
import org .apache .pulsar .client .api .ConsumerCryptoFailureAction ;
31
30
import org .apache .pulsar .client .api .DeadLetterPolicy ;
42
41
import org .apache .pulsar .client .impl .conf .ConfigurationDataUtils ;
43
42
import org .apache .pulsar .client .impl .conf .ConsumerConfigurationData ;
44
43
import org .apache .pulsar .client .impl .conf .ProducerConfigurationData ;
44
+ import org .assertj .core .api .InstanceOfAssertFactories ;
45
45
import org .junit .jupiter .api .Nested ;
46
46
import org .junit .jupiter .api .Test ;
47
47
@@ -79,7 +79,6 @@ class ClientPropertiesTests {
79
79
private final String authToken = "1234" ;
80
80
81
81
@ Test
82
- @ SuppressWarnings ("unchecked" )
83
82
void clientProperties () {
84
83
Map <String , String > props = new HashMap <>();
85
84
props .put ("spring.pulsar.client.service-url" , "my-service-url" );
@@ -141,9 +140,13 @@ void clientProperties() {
141
140
.containsEntry ("tlsTrustStorePath" , "my-trust-store-path" )
142
141
.containsEntry ("tlsTrustStorePassword" , "my-trust-store-password" )
143
142
.hasEntrySatisfying ("tlsCiphers" ,
144
- t -> assertThat (((Set <String >) t )).containsExactly ("my-tls-cipher" ))
143
+ ciphers -> assertThat (ciphers )
144
+ .asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
145
+ .containsExactly ("my-tls-cipher" ))
145
146
.hasEntrySatisfying ("tlsProtocols" ,
146
- t -> assertThat (((Set <String >) t )).containsExactly ("my-tls-protocol" ))
147
+ protocols -> assertThat (protocols )
148
+ .asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
149
+ .containsExactly ("my-tls-protocol" ))
147
150
.containsEntry ("statsIntervalSeconds" , 6L ).containsEntry ("concurrentLookupRequest" , 7 )
148
151
.containsEntry ("maxLookupRequest" , 8 ).containsEntry ("maxLookupRedirects" , 9 )
149
152
.containsEntry ("maxNumberOfRejectedRequestPerConnection" , 10 )
@@ -210,6 +213,45 @@ class AdminPropertiesTests {
210
213
211
214
private final String authToken = "1234" ;
212
215
216
+ @ Test
217
+ void adminProperties () {
218
+ Map <String , String > props = new HashMap <>();
219
+ props .put ("spring.pulsar.administration.service-url" , "my-service-url" );
220
+ props .put ("spring.pulsar.administration.tls-hostname-verification-enable" , "true" );
221
+ props .put ("spring.pulsar.administration.tls-trust-certs-file-path" , "my-trust-certs-file-path" );
222
+ props .put ("spring.pulsar.administration.tls-allow-insecure-connection" , "true" );
223
+ props .put ("spring.pulsar.administration.use-key-store-tls" , "true" );
224
+ props .put ("spring.pulsar.administration.ssl-provider" , "my-ssl-provider" );
225
+ props .put ("spring.pulsar.administration.tls-trust-store-type" , "my-trust-store-type" );
226
+ props .put ("spring.pulsar.administration.tls-trust-store-path" , "my-trust-store-path" );
227
+ props .put ("spring.pulsar.administration.tls-trust-store-password" , "my-trust-store-password" );
228
+ props .put ("spring.pulsar.administration.tls-ciphers[0]" , "my-tls-cipher" );
229
+ props .put ("spring.pulsar.administration.tls-protocols[0]" , "my-tls-protocol" );
230
+
231
+ bind (props );
232
+ Map <String , Object > adminProps = properties .buildAdminProperties ();
233
+
234
+ // Verify that the props can be loaded in a ClientBuilder
235
+ assertThatNoException ().isThrownBy (() -> PulsarAdmin .builder ().loadConf (adminProps ));
236
+
237
+ assertThat (adminProps ).containsEntry ("serviceUrl" , "my-service-url" )
238
+ .containsEntry ("tlsHostnameVerificationEnable" , true )
239
+ .containsEntry ("tlsTrustCertsFilePath" , "my-trust-certs-file-path" )
240
+ .containsEntry ("tlsAllowInsecureConnection" , true ).containsEntry ("useKeyStoreTls" , true )
241
+ .containsEntry ("sslProvider" , "my-ssl-provider" )
242
+ .containsEntry ("tlsTrustStoreType" , "my-trust-store-type" )
243
+ .containsEntry ("tlsTrustStorePath" , "my-trust-store-path" )
244
+ .containsEntry ("tlsTrustStorePassword" , "my-trust-store-password" )
245
+ .hasEntrySatisfying ("tlsCiphers" ,
246
+ ciphers -> assertThat (ciphers )
247
+ .asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
248
+ .containsExactly ("my-tls-cipher" ))
249
+ .hasEntrySatisfying ("tlsProtocols" ,
250
+ protocols -> assertThat (protocols )
251
+ .asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
252
+ .containsExactly ("my-tls-protocol" ));
253
+ }
254
+
213
255
@ Test
214
256
void authenticationUsingAuthParamsString () {
215
257
Map <String , String > props = new HashMap <>();
@@ -254,7 +296,6 @@ void authenticationNotAllowedUsingBothAuthParamsStringAndAuthenticationMap() {
254
296
class ProducerPropertiesTests {
255
297
256
298
@ Test
257
- @ SuppressWarnings ("unchecked" )
258
299
void producerProperties () {
259
300
Map <String , String > props = new HashMap <>();
260
301
props .put ("spring.pulsar.producer.topic-name" , "my-topic" );
@@ -298,12 +339,14 @@ void producerProperties() {
298
339
.containsEntry ("batchingMaxMessages" , 7 ).containsEntry ("batchingMaxBytes" , 8 )
299
340
.containsEntry ("batchingEnabled" , false ).containsEntry ("chunkingEnabled" , true )
300
341
.hasEntrySatisfying ("encryptionKeys" ,
301
- keys -> assertThat (((Set <String >) keys )).containsExactly ("my-key" ))
342
+ keys -> assertThat (keys ).asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
343
+ .containsExactly ("my-key" ))
302
344
.containsEntry ("compressionType" , CompressionType .LZ4 ).containsEntry ("initialSequenceId" , 9L )
303
345
.containsEntry ("accessMode" , ProducerAccessMode .Exclusive )
304
- .containsEntry ("lazyStartPartitionedProducers" , true )
305
- .hasEntrySatisfying ("properties" , properties -> assertThat (((Map <String , String >) properties ))
306
- .containsEntry ("my-prop" , "my-prop-value" ));
346
+ .containsEntry ("lazyStartPartitionedProducers" , true ).hasEntrySatisfying ("properties" ,
347
+ properties -> assertThat (properties )
348
+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , String .class ))
349
+ .containsEntry ("my-prop" , "my-prop-value" ));
307
350
}
308
351
309
352
}
@@ -312,7 +355,6 @@ void producerProperties() {
312
355
class ConsumerPropertiesTests {
313
356
314
357
@ Test
315
- @ SuppressWarnings ("unchecked" )
316
358
void consumerProperties () {
317
359
Map <String , String > props = new HashMap <>();
318
360
props .put ("spring.pulsar.consumer.topics[0]" , "my-topic" );
@@ -361,12 +403,16 @@ void consumerProperties() {
361
403
362
404
assertThat (consumerProps )
363
405
.hasEntrySatisfying ("topicNames" ,
364
- n -> assertThat ((Collection <String >) n ).containsExactly ("my-topic" ))
406
+ topics -> assertThat (topics )
407
+ .asInstanceOf (InstanceOfAssertFactories .collection (String .class ))
408
+ .containsExactly ("my-topic" ))
365
409
.hasEntrySatisfying ("topicsPattern" , p -> assertThat (p .toString ()).isEqualTo ("my-pattern" ))
366
410
.containsEntry ("subscriptionName" , "my-subscription" )
367
411
.containsEntry ("subscriptionType" , SubscriptionType .Shared )
368
412
.hasEntrySatisfying ("subscriptionProperties" ,
369
- p -> assertThat ((Map <String , String >) p ).containsEntry ("my-sub-prop" , "my-sub-prop-value" ))
413
+ properties -> assertThat (properties )
414
+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , String .class ))
415
+ .containsEntry ("my-sub-prop" , "my-sub-prop-value" ))
370
416
.containsEntry ("subscriptionMode" , SubscriptionMode .NonDurable )
371
417
.containsEntry ("receiverQueueSize" , 1 ).containsEntry ("acknowledgementsGroupTimeMicros" , 2_000_000L )
372
418
.containsEntry ("negativeAckRedeliveryDelayMicros" , 3_000_000L )
@@ -375,7 +421,9 @@ void consumerProperties() {
375
421
.containsEntry ("tickDurationMillis" , 7_000L ).containsEntry ("priorityLevel" , 8 )
376
422
.containsEntry ("cryptoFailureAction" , ConsumerCryptoFailureAction .DISCARD )
377
423
.hasEntrySatisfying ("properties" ,
378
- p -> assertThat ((Map <String , String >) p ).containsEntry ("my-prop" , "my-prop-value" ))
424
+ properties -> assertThat (properties )
425
+ .asInstanceOf (InstanceOfAssertFactories .map (String .class , String .class ))
426
+ .containsEntry ("my-prop" , "my-prop-value" ))
379
427
.containsEntry ("readCompacted" , true )
380
428
.containsEntry ("subscriptionInitialPosition" , SubscriptionInitialPosition .Earliest )
381
429
.containsEntry ("patternAutoDiscoveryPeriod" , 9 )
0 commit comments