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 2019/06/21 14:10:06 UTC

[camel] 01/02: Camel-Nats: Use BindToRegistry annotation where possible in tests

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 97bd6290eafc2e131398573bfb7d0298fe030140
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Jun 21 16:06:05 2019 +0200

    Camel-Nats: Use BindToRegistry annotation where possible in tests
---
 .../nats/NatsConsumerWithConnectionLoadTest.java   | 22 +++++++++-------------
 .../camel/component/nats/NatsProducerTLSTest.java  | 16 +++++++---------
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerWithConnectionLoadTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerWithConnectionLoadTest.java
index eccf3e2..c87ea8b 100644
--- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerWithConnectionLoadTest.java
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerWithConnectionLoadTest.java
@@ -24,10 +24,10 @@ import io.nats.client.Nats;
 import io.nats.client.Options;
 import io.nats.client.Options.Builder;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.JndiRegistry;
 import org.junit.Test;
 
 public class NatsConsumerWithConnectionLoadTest extends NatsTestSupport {
@@ -39,6 +39,14 @@ public class NatsConsumerWithConnectionLoadTest extends NatsTestSupport {
     protected MockEndpoint mockResultEndpoint1;
     
     private Connection connection;
+    
+    @BindToRegistry("connection")
+    public Connection connection() throws IllegalStateException, IOException, InterruptedException {
+        Builder options = new Options.Builder();
+        options.server("nats://" + getNatsUrl());
+        connection = Nats.connect(options.build());
+        return connection;
+    }
 
     @Test
     public void testLoadConsumer() throws InterruptedException, IOException, TimeoutException {
@@ -54,18 +62,6 @@ public class NatsConsumerWithConnectionLoadTest extends NatsTestSupport {
         mockResultEndpoint.assertIsSatisfied();
         mockResultEndpoint1.assertIsSatisfied();
     }
-    
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry registry = super.createRegistry();
-        
-        Builder options = new Options.Builder();
-        options.server("nats://" + getNatsUrl());
-        connection = Nats.connect(options.build());
-        registry.bind("connection", connection);
-        
-        return registry;
-    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsProducerTLSTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsProducerTLSTest.java
index a0b8774..f1d91dc 100644
--- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsProducerTLSTest.java
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsProducerTLSTest.java
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.component.nats;
 
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.support.jsse.KeyManagersParameters;
 import org.apache.camel.support.jsse.KeyStoreParameters;
 import org.apache.camel.support.jsse.SSLContextParameters;
@@ -31,20 +31,18 @@ import org.junit.Test;
  */
 @Ignore("Require a running Nats server")
 public class NatsProducerTLSTest extends CamelTestSupport {
-    
+   
+
+	@BindToRegistry("ssl")
+	SSLContextParameters ssl = createSSLContextParameters();
+
+	
     @Test
     public void sendTest() throws Exception {
         
         template.sendBody("direct:send", "pippo");
     }
     
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry registry = super.createRegistry();
-        registry.bind("ssl", createSSLContextParameters());
-        return registry;
-    }
-    
     private SSLContextParameters createSSLContextParameters() {
         SSLContextParameters sslContextParameters = new SSLContextParameters();