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 10:01:45 UTC

[camel] branch test-pgevent created (now 1055d644a46)

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

acosentino pushed a change to branch test-pgevent
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 1055d644a46 Tests: Fix mockito tests for Camel-PgEvent

This branch includes the following new commits:

     new 1055d644a46 Tests: Fix mockito tests for Camel-PgEvent

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: Tests: Fix mockito tests for Camel-PgEvent

Posted by ac...@apache.org.
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 <an...@gmail.com>
AuthorDate: Mon Oct 9 12:00:52 2023 +0200

    Tests: Fix mockito tests for Camel-PgEvent
    
    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);