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

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

commit 8862694d78698ae6914f80fc9c76d4ed90fdf0b2
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Mon Jul 29 13:18:10 2019 +0200

    Camel-Mail: Use BindToRegistry annotation wherever possible
---
 .../component/mail/MailCustomMailSenderTest.java   | 11 ++++-------
 .../MailIdempotentRepositoryDuplicateTest.java     |  9 ++-------
 .../mail/MailIdempotentRepositoryTest.java         |  9 ++-------
 .../component/mail/MailPostProcessActionTest.java  | 12 +++---------
 .../camel/component/mail/MailSearchTermTest.java   | 11 ++++-------
 .../mail/MailSearchTermUriConfigBeanTest.java      |  9 ++++-----
 .../camel/component/mail/MailSortTermTest.java     | 21 ++++++++++++---------
 .../component/mail/MailSortTermThreeTest.java      | 22 ++++++++++++----------
 .../camel/component/mail/MailSortTermTwoTest.java  | 21 ++++++++++++---------
 .../component/mail/MailUsingCustomSessionTest.java | 12 +++---------
 .../SslContextParametersMailRouteTest.java         | 18 +++++-------------
 11 files changed, 63 insertions(+), 92 deletions(-)

diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
index d31fecb..6b057ce 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCustomMailSenderTest.java
@@ -22,6 +22,7 @@ import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -29,13 +30,9 @@ import org.junit.Test;
 public class MailCustomMailSenderTest extends CamelTestSupport {
 
     private static boolean sent;
-
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("mySender", new MySender());
-        return jndi;
-    }
+    
+    @BindToRegistry("mySender")
+    private MySender sender = new MySender();
 
     @Test
     public void testSendWithCustomMailSender() throws Exception {
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryDuplicateTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryDuplicateTest.java
index 2f615c9..024de5b 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryDuplicateTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryDuplicateTest.java
@@ -20,6 +20,7 @@ import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -34,16 +35,10 @@ import org.jvnet.mock_javamail.Mailbox;
  */
 public class MailIdempotentRepositoryDuplicateTest extends CamelTestSupport {
 
+       @BindToRegistry("myRepo")
     MemoryIdempotentRepository myRepo = new MemoryIdempotentRepository();
 
     @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("myRepo", myRepo);
-        return jndi;
-    }
-
-    @Override
     @Before
     public void setUp() throws Exception {
         // lets assume this ID is already done
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryTest.java
index 1cea1f6..19ed520 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailIdempotentRepositoryTest.java
@@ -20,6 +20,7 @@ import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -34,16 +35,10 @@ import org.jvnet.mock_javamail.Mailbox;
  */
 public class MailIdempotentRepositoryTest extends CamelTestSupport {
 
+       @BindToRegistry("myRepo")
     private MemoryIdempotentRepository myRepo = new 
MemoryIdempotentRepository();
 
     @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("myRepo", myRepo);
-        return jndi;
-    }
-
-    @Override
     @Before
     public void setUp() throws Exception {
         prepareMailbox();
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailPostProcessActionTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailPostProcessActionTest.java
index 8b0b703..623f548 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailPostProcessActionTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailPostProcessActionTest.java
@@ -20,6 +20,7 @@ import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -36,23 +37,16 @@ import org.slf4j.LoggerFactory;
 public class MailPostProcessActionTest extends CamelTestSupport {
     private static final Logger LOG = 
LoggerFactory.getLogger(MailPostProcessActionTest.class);
 
-    private TestPostProcessAction action;
+    @BindToRegistry("postProcessAction")
+    private TestPostProcessAction action = new TestPostProcessAction();
 
     @Override
     @Before
     public void setUp() throws Exception {
         prepareMailbox();
-        action = new TestPostProcessAction();
         super.setUp();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("postProcessAction", action);
-        return jndi;
-    }
-
     @Test
     public void testActionCalled() throws Exception {
         Mailbox mailbox = Mailbox.get("bill@localhost");
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermTest.java
index d6b9245..6147b15 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermTest.java
@@ -22,6 +22,7 @@ import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.mail.search.SearchTerm;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -34,6 +35,9 @@ import static 
org.apache.camel.component.mail.SearchTermBuilder.Op;
 
 public class MailSearchTermTest extends CamelTestSupport {
 
+       @BindToRegistry("myTerm")
+       private SearchTerm term = createSearchTerm();
+       
     @Override
     @Before
     public void setUp() throws Exception {
@@ -49,13 +53,6 @@ public class MailSearchTermTest extends CamelTestSupport {
         return build.build();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("myTerm", createSearchTerm());
-        return jndi;
-    }
-
     @Test
     public void testSearchTerm() throws Exception {
         Mailbox mailbox = Mailbox.get("bill@localhost");
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java
index 033dece..e78eb34 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSearchTermUriConfigBeanTest.java
@@ -16,19 +16,18 @@
  */
 package org.apache.camel.component.mail;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 
 public class MailSearchTermUriConfigBeanTest extends 
MailSearchTermUriConfigTest {
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
+    @BindToRegistry("mySearchTerm")
+    public SimpleSearchTerm addSearchTerm() throws Exception {
         SimpleSearchTerm mySearchTerm = new SimpleSearchTerm();
         mySearchTerm.setSubjectOrBody("Camel");
 
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("mySearchTerm", mySearchTerm);
-        return jndi;
+        return mySearchTerm;
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java
index 52e00e5..11ecf1f 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java
@@ -21,8 +21,11 @@ import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
+import javax.mail.search.SearchTerm;
 
 import com.sun.mail.imap.SortTerm;
+
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -36,6 +39,15 @@ import org.jvnet.mock_javamail.Mailbox;
  * SortUtilTest.
  */
 public class MailSortTermTest extends CamelTestSupport {
+       
+       @BindToRegistry("sortAscendingDate")
+       private SortTerm[] termAscDate = new SortTerm[]{SortTerm.DATE};
+       
+    @BindToRegistry("sortDescendingDate")
+    private SortTerm[] termDescDate = new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE};
+    
+    @BindToRegistry("searchTerm")
+    private SearchTerm searchTerm = new 
SearchTermBuilder().subject("Camel").build();
 
     @Override
     @Before
@@ -44,15 +56,6 @@ public class MailSortTermTest extends CamelTestSupport {
         super.setUp();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("sortAscendingDate", new SortTerm[]{SortTerm.DATE});
-        jndi.bind("sortDescendingDate", new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE});
-        jndi.bind("searchTerm", new 
SearchTermBuilder().subject("Camel").build());
-        return jndi;
-    }
-
     @Test
     public void testSortTerm() throws Exception {
         Mailbox mailbox = Mailbox.get("bill@localhost");
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeTest.java
index b46e86f..133927c 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermThreeTest.java
@@ -21,8 +21,11 @@ import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
+import javax.mail.search.SearchTerm;
 
 import com.sun.mail.imap.SortTerm;
+
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -36,7 +39,15 @@ import org.jvnet.mock_javamail.Mailbox;
  * SortUtilTest.
  */
 public class MailSortTermThreeTest extends CamelTestSupport {
-
+       
+    @BindToRegistry("sortAscendingDate")
+    private SortTerm[] termAscDate = new SortTerm[]{SortTerm.DATE};
+    
+@BindToRegistry("sortDescendingDate")
+private SortTerm[] termDescDate = new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE};
+
+@BindToRegistry("searchTerm")
+private SearchTerm searchTerm = new 
SearchTermBuilder().subject("Camel").build();
     @Override
     @Before
     public void setUp() throws Exception {
@@ -44,15 +55,6 @@ public class MailSortTermThreeTest extends CamelTestSupport {
         super.setUp();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("sortAscendingDate", new SortTerm[]{SortTerm.DATE});
-        jndi.bind("sortDescendingDate", new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE});
-        jndi.bind("searchTerm", new 
SearchTermBuilder().subject("Camel").build());
-        return jndi;
-    }
-
     @Test
     public void testSortTerm() throws Exception {
         Mailbox mailbox = Mailbox.get("bill@localhost");
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoTest.java
index 6631325..17f85a2 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTwoTest.java
@@ -21,8 +21,11 @@ import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.Store;
 import javax.mail.internet.MimeMessage;
+import javax.mail.search.SearchTerm;
 
 import com.sun.mail.imap.SortTerm;
+
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
@@ -37,6 +40,15 @@ import org.jvnet.mock_javamail.Mailbox;
  */
 public class MailSortTermTwoTest extends CamelTestSupport {
 
+    @BindToRegistry("sortAscendingDate")
+    private SortTerm[] termAscDate = new SortTerm[]{SortTerm.DATE};
+    
+@BindToRegistry("sortDescendingDate")
+private SortTerm[] termDescDate = new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE};
+
+@BindToRegistry("searchTerm")
+private SearchTerm searchTerm = new 
SearchTermBuilder().subject("Camel").build();
+
     @Override
     @Before
     public void setUp() throws Exception {
@@ -44,15 +56,6 @@ public class MailSortTermTwoTest extends CamelTestSupport {
         super.setUp();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("sortAscendingDate", new SortTerm[]{SortTerm.DATE});
-        jndi.bind("sortDescendingDate", new SortTerm[]{SortTerm.REVERSE, 
SortTerm.DATE});
-        jndi.bind("searchTerm", new 
SearchTermBuilder().subject("Camel").build());
-        return jndi;
-    }
-
     @Test
     public void testSortTerm() throws Exception {
         Mailbox mailbox = Mailbox.get("bill@localhost");
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingCustomSessionTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingCustomSessionTest.java
index 6aab62e..d437b01 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingCustomSessionTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailUsingCustomSessionTest.java
@@ -23,6 +23,7 @@ import java.util.Properties;
 import javax.mail.Message;
 import javax.mail.Session;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -34,7 +35,8 @@ import org.jvnet.mock_javamail.Mailbox;
 
 public class MailUsingCustomSessionTest extends CamelTestSupport {
 
-    private Session mailSession;
+       @BindToRegistry("myCustomMailSession")
+    private Session mailSession = Session.getInstance(new Properties());
 
     @Before
     public void setUp() throws Exception {
@@ -42,14 +44,6 @@ public class MailUsingCustomSessionTest extends 
CamelTestSupport {
         Mailbox.clearAll();
     }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry registry = super.createRegistry();
-        mailSession = Session.getInstance(new Properties());
-        registry.bind("myCustomMailSession", mailSession);
-        return registry;
-    }
-
     @Test
     public void testEndpointConfigurationWithCustomSession() {
         // Verify that the mail session bound to the bean registry is 
identical to the session tied to the endpoint configuration
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java
index b1aff6d..2924a19 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java
@@ -21,11 +21,13 @@ import java.util.Map;
 
 import javax.net.ssl.SSLHandshakeException;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mail.MailTestHelper;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.support.jsse.SSLContextParameters;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -44,6 +46,9 @@ public class SslContextParametersMailRouteTest extends 
CamelTestSupport {
     private String smtpHost = "smtp.gmail.com";
     private String password = "PASSWORD";
     
+    @BindToRegistry("sslContextParameters")
+    private SSLContextParameters params = 
MailTestHelper.createSslContextParameters();
+    
     @Test
     public void testSendAndReceiveMails() throws Exception {
         
@@ -105,19 +110,6 @@ public class SslContextParametersMailRouteTest extends 
CamelTestSupport {
         }
     }
     
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry reg = super.createRegistry();
-        
-        addSslContextParametersToRegistry(reg);
-    
-        return reg;
-    }
-    
-    protected void addSslContextParametersToRegistry(JndiRegistry registry) {
-        registry.bind("sslContextParameters", 
MailTestHelper.createSslContextParameters());
-    }
-    
     /**
      * Stop Camel startup.
      */

Reply via email to