6
6
7
7
import static org .junit .jupiter .api .Assertions .assertEquals ;
8
8
import static org .junit .jupiter .api .Assertions .assertThrows ;
9
- import static org .mockito .Mockito .mock ;
10
9
11
10
import com .fasterxml .jackson .databind .JsonNode ;
12
11
import com .fasterxml .jackson .databind .ObjectMapper ;
15
14
import io .airbyte .commons .jackson .MoreMappers ;
16
15
import io .airbyte .commons .json .Jsons ;
17
16
import io .airbyte .integrations .base .AirbyteStreamNameNamespacePair ;
17
+ import io .airbyte .integrations .base .FailureTrackingAirbyteMessageConsumer ;
18
18
import io .airbyte .integrations .destination .StandardNameTransformer ;
19
+ import io .airbyte .integrations .standardtest .destination .PerStreamStateMessageTest ;
19
20
import io .airbyte .protocol .models .AirbyteMessage ;
20
21
import io .airbyte .protocol .models .AirbyteRecordMessage ;
21
22
import io .airbyte .protocol .models .AirbyteStateMessage ;
30
31
import java .util .stream .Collectors ;
31
32
import java .util .stream .IntStream ;
32
33
import java .util .stream .Stream ;
34
+ import org .junit .jupiter .api .BeforeEach ;
33
35
import org .junit .jupiter .api .DisplayName ;
34
36
import org .junit .jupiter .api .Test ;
37
+ import org .junit .jupiter .api .extension .ExtendWith ;
35
38
import org .junit .jupiter .api .extension .ExtensionContext ;
36
39
import org .junit .jupiter .params .ParameterizedTest ;
37
40
import org .junit .jupiter .params .provider .Arguments ;
38
41
import org .junit .jupiter .params .provider .ArgumentsProvider ;
39
42
import org .junit .jupiter .params .provider .ArgumentsSource ;
43
+ import org .mockito .Mock ;
44
+ import org .mockito .junit .jupiter .MockitoExtension ;
40
45
41
46
@ DisplayName ("KafkaRecordConsumer" )
42
- public class KafkaRecordConsumerTest {
47
+ @ ExtendWith (MockitoExtension .class )
48
+ public class KafkaRecordConsumerTest extends PerStreamStateMessageTest {
43
49
44
50
private static final ObjectMapper mapper = MoreMappers .initMapper ();
45
51
private static final String TOPIC_NAME = "test.topic" ;
@@ -53,16 +59,27 @@ public class KafkaRecordConsumerTest {
53
59
Field .of ("id" , JsonSchemaType .NUMBER ),
54
60
Field .of ("name" , JsonSchemaType .STRING ))));
55
61
62
+ @ Mock
63
+ private Consumer <AirbyteMessage > outputRecordCollector ;
64
+
65
+ private KafkaRecordConsumer consumer ;
66
+
56
67
private static final StandardNameTransformer NAMING_RESOLVER = new StandardNameTransformer ();
57
68
69
+ @ BeforeEach
70
+ public void init () {
71
+ final KafkaDestinationConfig config = KafkaDestinationConfig .getKafkaDestinationConfig (getConfig (TOPIC_NAME ));
72
+ consumer = new KafkaRecordConsumer (config , CATALOG , outputRecordCollector , NAMING_RESOLVER );
73
+ }
74
+
58
75
@ ParameterizedTest
59
76
@ ArgumentsSource (TopicMapArgumentsProvider .class )
60
77
@ SuppressWarnings ("unchecked" )
61
78
public void testBuildTopicMap (final String topicPattern , final String expectedTopic ) {
62
79
final KafkaDestinationConfig config = KafkaDestinationConfig .getKafkaDestinationConfig (getConfig (topicPattern ));
63
- final KafkaRecordConsumer recordConsumer = new KafkaRecordConsumer (config , CATALOG , mock ( Consumer . class ) , NAMING_RESOLVER );
80
+ consumer = new KafkaRecordConsumer (config , CATALOG , outputRecordCollector , NAMING_RESOLVER );
64
81
65
- final Map <AirbyteStreamNameNamespacePair , String > topicMap = recordConsumer .buildTopicMap ();
82
+ final Map <AirbyteStreamNameNamespacePair , String > topicMap = consumer .buildTopicMap ();
66
83
assertEquals (1 , topicMap .size ());
67
84
68
85
final AirbyteStreamNameNamespacePair streamNameNamespacePair = new AirbyteStreamNameNamespacePair (STREAM_NAME , SCHEMA_NAME );
@@ -72,8 +89,6 @@ public void testBuildTopicMap(final String topicPattern, final String expectedTo
72
89
@ Test
73
90
@ SuppressWarnings ("unchecked" )
74
91
void testCannotConnectToBrokers () throws Exception {
75
- final KafkaDestinationConfig config = KafkaDestinationConfig .getKafkaDestinationConfig (getConfig (TOPIC_NAME ));
76
- final KafkaRecordConsumer consumer = new KafkaRecordConsumer (config , CATALOG , mock (Consumer .class ), NAMING_RESOLVER );
77
92
final List <AirbyteMessage > expectedRecords = getNRecords (10 );
78
93
79
94
consumer .start ();
@@ -133,6 +148,16 @@ private List<AirbyteMessage> getNRecords(final int n) {
133
148
134
149
}
135
150
151
+ @ Override
152
+ protected Consumer <AirbyteMessage > getMockedConsumer () {
153
+ return outputRecordCollector ;
154
+ }
155
+
156
+ @ Override
157
+ protected FailureTrackingAirbyteMessageConsumer getMessageConsumer () {
158
+ return consumer ;
159
+ }
160
+
136
161
public static class TopicMapArgumentsProvider implements ArgumentsProvider {
137
162
138
163
@ Override
0 commit comments