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

davsclaus pushed a commit to branch exchange-factory
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 53930f287e0a2491baa5569a1882169bd805d318
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Feb 23 07:04:14 2021 +0100

    CAMEL-16222: PooledExchangeFactory experiment
---
 .../mail/MailConsumerAuthenticatorTest.java        |  9 +++++++
 .../apache/camel/pgevent/PgEventConsumerTest.java  | 30 +++++++++++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConsumerAuthenticatorTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConsumerAuthenticatorTest.java
index e4ea961..c4f18a7 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConsumerAuthenticatorTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConsumerAuthenticatorTest.java
@@ -23,12 +23,15 @@ import javax.mail.MessagingException;
 import javax.mail.PasswordAuthentication;
 import javax.mail.Session;
 
+import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.Processor;
+import org.apache.camel.spi.ExchangeFactory;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 /**
@@ -51,8 +54,11 @@ public class MailConsumerAuthenticatorTest {
 
         JavaMailSender sender = Mockito.mock(JavaMailSender.class);
         Processor processor = Mockito.mock(Processor.class);
+        ExtendedCamelContext ecc = Mockito.mock(ExtendedCamelContext.class);
+        ExchangeFactory ef = Mockito.mock(ExchangeFactory.class);
 
         MailEndpoint endpoint = new MailEndpoint();
+        endpoint.setCamelContext(ecc);
         MailConfiguration configuration = new MailConfiguration();
         configuration.setAuthenticator(authenticator);
         configuration.configureProtocol(protocol);
@@ -65,6 +71,9 @@ public class MailConsumerAuthenticatorTest {
         Session session = Session.getDefaultInstance(props, authenticator);
 
         when(sender.getSession()).thenReturn(session);
+        when(ecc.adapt(ExtendedCamelContext.class)).thenReturn(ecc);
+        when(ecc.getExchangeFactory()).thenReturn(ef);
+        when(ef.newExchangeFactory(any())).thenReturn(ef);
 
         MailConsumer consumer = new MailConsumer(endpoint, processor, sender);
         try {
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 82ff432..196de5a 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
@@ -20,16 +20,19 @@ import java.sql.PreparedStatement;
 
 import com.impossibl.postgres.api.jdbc.PGConnection;
 import com.impossibl.postgres.jdbc.PGDataSource;
-import org.apache.camel.Exchange;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.ExtendedExchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.component.pgevent.PgEventConsumer;
 import org.apache.camel.component.pgevent.PgEventEndpoint;
+import org.apache.camel.spi.ExchangeFactory;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -44,7 +47,13 @@ public class PgEventConsumerTest {
         PreparedStatement statement = mock(PreparedStatement.class);
         PgEventEndpoint endpoint = mock(PgEventEndpoint.class);
         Processor processor = mock(Processor.class);
+        ExtendedCamelContext ecc = mock(ExtendedCamelContext.class);
+        ExchangeFactory ef = mock(ExchangeFactory.class);
 
+        when(endpoint.getCamelContext()).thenReturn(ecc);
+        when(ecc.adapt(ExtendedCamelContext.class)).thenReturn(ecc);
+        when(ecc.getExchangeFactory()).thenReturn(ef);
+        when(ef.newExchangeFactory(any())).thenReturn(ef);
         when(endpoint.getDatasource()).thenReturn(dataSource);
         when(dataSource.getConnection()).thenReturn(connection);
         when(connection.prepareStatement("LISTEN 
camel")).thenReturn(statement);
@@ -64,7 +73,13 @@ public class PgEventConsumerTest {
         PreparedStatement statement = mock(PreparedStatement.class);
         PgEventEndpoint endpoint = mock(PgEventEndpoint.class);
         Processor processor = mock(Processor.class);
+        ExtendedCamelContext ecc = mock(ExtendedCamelContext.class);
+        ExchangeFactory ef = mock(ExchangeFactory.class);
 
+        when(endpoint.getCamelContext()).thenReturn(ecc);
+        when(ecc.adapt(ExtendedCamelContext.class)).thenReturn(ecc);
+        when(ecc.getExchangeFactory()).thenReturn(ef);
+        when(ef.newExchangeFactory(any())).thenReturn(ef);
         when(endpoint.getDatasource()).thenReturn(dataSource);
         when(dataSource.getConnection()).thenReturn(connection);
         when(connection.prepareStatement("LISTEN 
camel")).thenReturn(statement);
@@ -84,10 +99,17 @@ public class PgEventConsumerTest {
     public void testPgEventNotification() throws Exception {
         PgEventEndpoint endpoint = mock(PgEventEndpoint.class);
         Processor processor = mock(Processor.class);
-        Exchange exchange = mock(Exchange.class);
+        ExtendedExchange exchange = mock(ExtendedExchange.class);
         Message message = mock(Message.class);
-
-        when(endpoint.createExchange()).thenReturn(exchange);
+        ExtendedCamelContext ecc = mock(ExtendedCamelContext.class);
+        ExchangeFactory ef = mock(ExchangeFactory.class);
+
+        when(endpoint.getCamelContext()).thenReturn(ecc);
+        when(ecc.adapt(ExtendedCamelContext.class)).thenReturn(ecc);
+        when(ecc.getExchangeFactory()).thenReturn(ef);
+        when(ef.newExchangeFactory(any())).thenReturn(ef);
+        when(ef.create(endpoint, false)).thenReturn(exchange);
+        when(exchange.adapt(ExtendedExchange.class)).thenReturn(exchange);
         when(exchange.getIn()).thenReturn(message);
 
         PgEventConsumer consumer = new PgEventConsumer(endpoint, processor);

Reply via email to