2929import org .junit .jupiter .api .Test ;
3030
3131import org .springframework .beans .factory .annotation .Autowired ;
32- import org .springframework .boot .pulsar .autoconfigure .PulsarAutoConfiguration ;
33- import org .springframework .boot .pulsar .autoconfigure .PulsarContainerFactoryCustomizer ;
3432import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
3533import org .springframework .context .annotation .Configuration ;
34+ import org .springframework .pulsar .listener .PulsarTxnTestsBase .TestPulsarContainerPropertiesCustomizer ;
3635import org .springframework .pulsar .annotation .EnablePulsar ;
3736import org .springframework .pulsar .annotation .PulsarListener ;
38- import org .springframework .pulsar .config .ConcurrentPulsarListenerContainerFactory ;
3937import org .springframework .pulsar .config .PulsarListenerEndpointRegistry ;
4038import org .springframework .pulsar .core .PulsarTemplate ;
4139import org .springframework .pulsar .listener .PulsarListenerTxnTests .BatchListenerWithCommit .BatchListenerWithCommitConfig ;
@@ -276,10 +274,8 @@ void throwsExceptionWhenTransactionsAreRequired() {
276274 assertThatIllegalStateException ().isThrownBy (() -> {
277275 var context = new AnnotationConfigApplicationContext ();
278276 context .register (TopLevelConfig .class , TransactionsDisabledOnListenerConfig .class );
279- context .registerBean (PulsarAutoConfiguration .class );
280- context .registerBean ("containerPropsRequiredCustomizer" , PulsarContainerFactoryCustomizer .class ,
281- () -> ((PulsarContainerFactoryCustomizer <ConcurrentPulsarListenerContainerFactory <?>>) (
282- cf ) -> cf .getContainerProperties ().transactions ().setRequired (true )));
277+ context .registerBean ("containerPropsRequiredCustomizer" , TestPulsarContainerPropertiesCustomizer .class ,
278+ () -> containerProps -> containerProps .transactions ().setRequired (true ));
283279 context .refresh ();
284280 }).withMessage ("Listener w/ id [%s] requested no transactions but txn are required" .formatted (LISTENER_ID ));
285281 }
@@ -288,10 +284,9 @@ void throwsExceptionWhenTransactionsAreRequired() {
288284 void disablesTransactionsWhenTransactionsAreNotRequired () {
289285 try (var context = new AnnotationConfigApplicationContext ()) {
290286 context .register (TopLevelConfig .class , TransactionsDisabledOnListenerConfig .class );
291- context .registerBean (PulsarAutoConfiguration .class );
292- context .registerBean ("containerPropsNotRequiredCustomizer" , PulsarContainerFactoryCustomizer .class ,
293- () -> ((PulsarContainerFactoryCustomizer <ConcurrentPulsarListenerContainerFactory <?>>) (
294- cf ) -> cf .getContainerProperties ().transactions ().setRequired (false )));
287+ context .registerBean ("containerPropsNotRequiredCustomizer" ,
288+ TestPulsarContainerPropertiesCustomizer .class ,
289+ () -> containerProps -> containerProps .transactions ().setRequired (false ));
295290 context .refresh ();
296291 var container = context .getBean (PulsarListenerEndpointRegistry .class ).getListenerContainer (LISTENER_ID );
297292 assertThat (container ).isNotNull ();
@@ -322,10 +317,8 @@ void ignoresSettingWhenNoTxnManagerAvailable() {
322317 assertThatException ().isThrownBy (() -> {
323318 var context = new AnnotationConfigApplicationContext ();
324319 context .register (TopLevelConfig .class , TransactionsEnabledOnListenerConfig .class );
325- context .registerBean (PulsarAutoConfiguration .class );
326- context .registerBean ("removeTxnManagerCustomizer" , PulsarContainerFactoryCustomizer .class ,
327- () -> ((PulsarContainerFactoryCustomizer <ConcurrentPulsarListenerContainerFactory <?>>) (
328- cf ) -> cf .getContainerProperties ().transactions ().setTransactionManager (null )));
320+ context .registerBean ("removeTxnManagerCustomizer" , TestPulsarContainerPropertiesCustomizer .class ,
321+ () -> containerProps -> containerProps .transactions ().setTransactionManager (null ));
329322 context .refresh ();
330323 })
331324 .withCauseInstanceOf (IllegalStateException .class )
@@ -337,10 +330,9 @@ void ignoresSettingWhenNoTxnManagerAvailable() {
337330 void enablesTransactionsWhenTxnManagerAvailable () {
338331 try (var context = new AnnotationConfigApplicationContext ()) {
339332 context .register (TopLevelConfig .class , TransactionsEnabledOnListenerConfig .class );
340- context .registerBean (PulsarAutoConfiguration .class );
341- context .registerBean ("containerPropsNotRequiredCustomizer" , PulsarContainerFactoryCustomizer .class ,
342- () -> ((PulsarContainerFactoryCustomizer <ConcurrentPulsarListenerContainerFactory <?>>) (
343- cf ) -> cf .getContainerProperties ().transactions ().setEnabled (false )));
333+ context .registerBean ("containerPropsNotRequiredCustomizer" ,
334+ TestPulsarContainerPropertiesCustomizer .class ,
335+ () -> containerProps -> containerProps .transactions ().setEnabled (false ));
344336 context .refresh ();
345337 var container = context .getBean (PulsarListenerEndpointRegistry .class ).getListenerContainer (LISTENER_ID );
346338 assertThat (container ).isNotNull ();
0 commit comments