You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/10/09 11:09:49 UTC

[camel] branch main updated: Tests: Fix mockito tests for Camel-PgEvent (#11671)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2446a80f69e Tests: Fix mockito tests for Camel-PgEvent (#11671)
2446a80f69e is described below

commit 2446a80f69e28249dd8a9e07e9c8c4d8574766ee
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Oct 9 13:09:39 2023 +0200

    Tests: Fix mockito tests for Camel-PgEvent (#11671)
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../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);