@@ -151,7 +151,7 @@ public void shouldExitIfFromBeginningAndOffset() {
151
151
}
152
152
153
153
@ Test
154
- public void shouldParseValidSimpleConsumerValidConfigWithStringOffset () throws Exception {
154
+ public void shouldParseValidSimpleConsumerValidConfigWithStringOffsetDeprecated () throws Exception {
155
155
String [] args = new String []{
156
156
"--bootstrap-server" , "localhost:9092" ,
157
157
"--topic" , "test" ,
@@ -171,6 +171,27 @@ public void shouldParseValidSimpleConsumerValidConfigWithStringOffset() throws E
171
171
assertFalse (((DefaultMessageFormatter ) config .formatter ()).printValue ());
172
172
}
173
173
174
+ @ Test
175
+ public void shouldParseValidSimpleConsumerValidConfigWithStringOffset () throws Exception {
176
+ String [] args = new String []{
177
+ "--bootstrap-server" , "localhost:9092" ,
178
+ "--topic" , "test" ,
179
+ "--partition" , "0" ,
180
+ "--offset" , "LatEst" ,
181
+ "--formatter-property" , "print.value=false"
182
+ };
183
+
184
+ ConsoleConsumerOptions config = new ConsoleConsumerOptions (args );
185
+
186
+ assertEquals ("localhost:9092" , config .bootstrapServer ());
187
+ assertEquals ("test" , config .topicArg ().orElse ("" ));
188
+ assertTrue (config .partitionArg ().isPresent ());
189
+ assertEquals (0 , config .partitionArg ().getAsInt ());
190
+ assertEquals (-1 , config .offsetArg ());
191
+ assertFalse (config .fromBeginning ());
192
+ assertFalse (((DefaultMessageFormatter ) config .formatter ()).printValue ());
193
+ }
194
+
174
195
@ Test
175
196
public void shouldParseValidConsumerConfigWithAutoOffsetResetLatestDeprecated () throws IOException {
176
197
String [] args = new String []{
@@ -355,7 +376,7 @@ public void groupIdsProvidedInDifferentPlacesMustMatchDeprecated() throws IOExce
355
376
}
356
377
357
378
@ Test
358
- public void testCustomPropertyShouldBePassedToConfigureMethod () throws Exception {
379
+ public void testCustomPropertyShouldBePassedToConfigureMethodDeprecated () throws Exception {
359
380
String [] args = new String []{
360
381
"--bootstrap-server" , "localhost:9092" ,
361
382
"--topic" , "test" ,
@@ -378,7 +399,30 @@ public void testCustomPropertyShouldBePassedToConfigureMethod() throws Exception
378
399
}
379
400
380
401
@ Test
381
- public void testCustomConfigShouldBePassedToConfigureMethod () throws Exception {
402
+ public void testCustomPropertyShouldBePassedToConfigureMethod () throws Exception {
403
+ String [] args = new String []{
404
+ "--bootstrap-server" , "localhost:9092" ,
405
+ "--topic" , "test" ,
406
+ "--formatter-property" , "print.key=true" ,
407
+ "--formatter-property" , "key.deserializer=org.apache.kafka.test.MockDeserializer" ,
408
+ "--formatter-property" , "key.deserializer.my-props=abc"
409
+ };
410
+
411
+ ConsoleConsumerOptions config = new ConsoleConsumerOptions (args );
412
+
413
+ assertInstanceOf (DefaultMessageFormatter .class , config .formatter ());
414
+ assertTrue (config .formatterArgs ().containsKey ("key.deserializer.my-props" ));
415
+ DefaultMessageFormatter formatter = (DefaultMessageFormatter ) config .formatter ();
416
+ assertTrue (formatter .keyDeserializer ().isPresent ());
417
+ assertInstanceOf (MockDeserializer .class , formatter .keyDeserializer ().get ());
418
+ MockDeserializer keyDeserializer = (MockDeserializer ) formatter .keyDeserializer ().get ();
419
+ assertEquals (1 , keyDeserializer .configs .size ());
420
+ assertEquals ("abc" , keyDeserializer .configs .get ("my-props" ));
421
+ assertTrue (keyDeserializer .isKey );
422
+ }
423
+
424
+ @ Test
425
+ public void testCustomConfigShouldBePassedToConfigureMethodDeprecated () throws Exception {
382
426
Map <String , String > configs = new HashMap <>();
383
427
configs .put ("key.deserializer.my-props" , "abc" );
384
428
configs .put ("print.key" , "false" );
@@ -404,6 +448,33 @@ public void testCustomConfigShouldBePassedToConfigureMethod() throws Exception {
404
448
assertTrue (keyDeserializer .isKey );
405
449
}
406
450
451
+ @ Test
452
+ public void testCustomConfigShouldBePassedToConfigureMethod () throws Exception {
453
+ Map <String , String > configs = new HashMap <>();
454
+ configs .put ("key.deserializer.my-props" , "abc" );
455
+ configs .put ("print.key" , "false" );
456
+ File propsFile = ToolsTestUtils .tempPropertiesFile (configs );
457
+ String [] args = new String []{
458
+ "--bootstrap-server" , "localhost:9092" ,
459
+ "--topic" , "test" ,
460
+ "--formatter-property" , "print.key=true" ,
461
+ "--formatter-property" , "key.deserializer=org.apache.kafka.test.MockDeserializer" ,
462
+ "--formatter-config" , propsFile .getAbsolutePath ()
463
+ };
464
+
465
+ ConsoleConsumerOptions config = new ConsoleConsumerOptions (args );
466
+
467
+ assertInstanceOf (DefaultMessageFormatter .class , config .formatter ());
468
+ assertTrue (config .formatterArgs ().containsKey ("key.deserializer.my-props" ));
469
+ DefaultMessageFormatter formatter = (DefaultMessageFormatter ) config .formatter ();
470
+ assertTrue (formatter .keyDeserializer ().isPresent ());
471
+ assertInstanceOf (MockDeserializer .class , formatter .keyDeserializer ().get ());
472
+ MockDeserializer keyDeserializer = (MockDeserializer ) formatter .keyDeserializer ().get ();
473
+ assertEquals (1 , keyDeserializer .configs .size ());
474
+ assertEquals ("abc" , keyDeserializer .configs .get ("my-props" ));
475
+ assertTrue (keyDeserializer .isKey );
476
+ }
477
+
407
478
@ Test
408
479
public void shouldParseGroupIdFromBeginningGivenTogether () throws IOException {
409
480
// Start from earliest
0 commit comments