1
1
/*
2
- * Copyright 2018-2019 the original author or authors.
2
+ * Copyright 2018-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
24
24
import org .junit .jupiter .api .Test ;
25
25
26
+ import org .springframework .kafka .config .AbstractKafkaListenerEndpoint ;
26
27
import org .springframework .kafka .config .ConcurrentKafkaListenerContainerFactory ;
27
28
import org .springframework .kafka .core .ConsumerFactory ;
28
29
import org .springframework .kafka .listener .ConcurrentMessageListenerContainer ;
30
+ import org .springframework .kafka .listener .MessageListenerContainer ;
31
+ import org .springframework .kafka .listener .adapter .MessagingMessageListenerAdapter ;
32
+ import org .springframework .kafka .listener .adapter .RecordMessagingMessageListenerAdapter ;
33
+ import org .springframework .kafka .support .converter .MessageConverter ;
29
34
import org .springframework .kafka .test .utils .KafkaTestUtils ;
30
35
31
36
/**
36
41
public class ContainerFactoryTests {
37
42
38
43
@ Test
39
- public void testConfigContainer () {
44
+ void testConfigContainer () {
40
45
ConcurrentKafkaListenerContainerFactory <String , String > factory =
41
46
new ConcurrentKafkaListenerContainerFactory <>();
42
47
factory .setAutoStartup (false );
@@ -56,4 +61,33 @@ public void testConfigContainer() {
56
61
assertThat (customized ).isTrue ();
57
62
}
58
63
64
+ @ SuppressWarnings ("unchecked" )
65
+ @ Test
66
+ void clientIdAndGroupIdTransferred () {
67
+ ConcurrentKafkaListenerContainerFactory <String , String > factory =
68
+ new ConcurrentKafkaListenerContainerFactory <>();
69
+ factory .getContainerProperties ().setClientId ("myClientId" );
70
+ factory .getContainerProperties ().setGroupId ("myGroup" );
71
+ factory .setConsumerFactory (mock (ConsumerFactory .class ));
72
+ AbstractKafkaListenerEndpoint <String , String > endpoint = new AbstractKafkaListenerEndpoint <String , String >() {
73
+
74
+ @ Override
75
+ protected MessagingMessageListenerAdapter <String , String > createMessageListener (
76
+ MessageListenerContainer container , MessageConverter messageConverter ) {
77
+
78
+ RecordMessagingMessageListenerAdapter <String , String > adapter =
79
+ new RecordMessagingMessageListenerAdapter <String , String >(null , null );
80
+ return adapter ;
81
+ }
82
+
83
+ };
84
+ endpoint .setTopics ("test" );
85
+ endpoint .setClientIdPrefix ("" );
86
+ endpoint .setGroupId ("" );
87
+ ConcurrentMessageListenerContainer <String , String > container = factory .createListenerContainer (
88
+ endpoint );
89
+ assertThat (container .getContainerProperties ().getClientId ()).isEqualTo ("myClientId" );
90
+ assertThat (container .getContainerProperties ().getGroupId ()).isEqualTo ("myGroup" );
91
+ }
92
+
59
93
}
0 commit comments