This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch test-pgevent in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1055d644a46dcee1e3f3a23ec3638f37f704c7a7 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Oct 9 12:00:52 2023 +0200 Tests: Fix mockito tests for Camel-PgEvent Signed-off-by: Andrea Cosentino <[email protected]> --- .../java/org/apache/camel/pgevent/PgEventConsumerTest.java | 7 +++---- .../java/org/apache/camel/pgevent/PgEventProducerTest.java | 11 ++++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventConsumerTest.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventConsumerTest.java index cce3b75600c..6fad950412e 100644 --- a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventConsumerTest.java +++ b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventConsumerTest.java @@ -57,8 +57,7 @@ public class PgEventConsumerTest { when(camelContext.getCamelContextExtension()).thenReturn(ecc); when(ecc.getExchangeFactory()).thenReturn(ef); when(ef.newExchangeFactory(any())).thenReturn(ef); - when(endpoint.getDatasource()).thenReturn(dataSource); - when(dataSource.getConnection()).thenReturn(connection); + when(endpoint.initJdbc()).thenReturn(connection); when(connection.prepareStatement("LISTEN camel")).thenReturn(statement); when(endpoint.getChannel()).thenReturn("camel"); @@ -84,8 +83,8 @@ public class PgEventConsumerTest { when(camelContext.getCamelContextExtension()).thenReturn(ecc); when(ecc.getExchangeFactory()).thenReturn(ef); when(ef.newExchangeFactory(any())).thenReturn(ef); - when(endpoint.getDatasource()).thenReturn(dataSource); - when(dataSource.getConnection()).thenReturn(connection); + when(endpoint.initJdbc()).thenReturn(connection); + when(connection.prepareStatement("LISTEN camel")).thenReturn(statement); when(connection.prepareStatement("LISTEN camel")).thenReturn(statement); when(endpoint.getChannel()).thenReturn("camel"); when(connection.prepareStatement("UNLISTEN camel")).thenReturn(statement); diff --git a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventProducerTest.java b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventProducerTest.java index 6cf0301bb20..d5ad387f15a 100644 --- a/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventProducerTest.java +++ b/components/camel-pgevent/src/test/java/org/apache/camel/pgevent/PgEventProducerTest.java @@ -61,8 +61,7 @@ public class PgEventProducerTest { @Test public void testPgEventProducerStop() throws Exception { - when(endpoint.getDatasource()).thenReturn(dataSource); - when(dataSource.getConnection()).thenReturn(connection); + when(endpoint.initJdbc()).thenReturn(connection); PgEventProducer producer = new PgEventProducer(endpoint); producer.start(); @@ -74,8 +73,7 @@ public class PgEventProducerTest { @Test public void testPgEventProducerProcessDbThrowsInvalidStateException() throws Exception { - when(endpoint.getDatasource()).thenReturn(dataSource); - when(dataSource.getConnection()).thenReturn(connection); + when(endpoint.initJdbc()).thenReturn(connection); when(connection.isClosed()).thenThrow(new SQLException("DB problem occurred")); PgEventProducer producer = new PgEventProducer(endpoint); @@ -88,13 +86,14 @@ public class PgEventProducerTest { public void testPgEventProducerProcessDbConnectionClosed() throws Exception { PGConnection connectionNew = mock(PGConnection.class); + when(endpoint.initJdbc()).thenReturn(connection); when(endpoint.getDatasource()).thenReturn(dataSource); when(dataSource.getConnection()).thenReturn(connection, connectionNew); when(connection.isClosed()).thenReturn(true); when(exchange.getIn()).thenReturn(message); when(message.getBody(String.class)).thenReturn("pgevent"); when(endpoint.getChannel()).thenReturn("camel"); - when(connectionNew.prepareStatement("NOTIFY camel, 'pgevent'")).thenReturn(statement); + when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(statement); PgEventProducer producer = new PgEventProducer(endpoint); producer.start(); @@ -107,6 +106,7 @@ public class PgEventProducerTest { public void testPgEventProducerProcessServerMinimumVersionMatched() throws Exception { CallableStatement statement = mock(CallableStatement.class); + when(endpoint.initJdbc()).thenReturn(connection); when(endpoint.getDatasource()).thenReturn(dataSource); when(connection.isClosed()).thenReturn(false); when(dataSource.getConnection()).thenReturn(connection); @@ -125,6 +125,7 @@ public class PgEventProducerTest { @Test public void testPgEventProducerProcessServerMinimumVersionNotMatched() throws Exception { + when(endpoint.initJdbc()).thenReturn(connection); when(endpoint.getDatasource()).thenReturn(dataSource); when(connection.isClosed()).thenReturn(false); when(dataSource.getConnection()).thenReturn(connection);
