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 2018/07/23 11:29:40 UTC
[camel] 02/02: Camel-Nats: Add Auth Token test
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 e979ad4515e09cdcde08d6fa7dc1979d537d729a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Jul 23 13:26:00 2018 +0200
Camel-Nats: Add Auth Token test
---
.../nats/NatsAuthTokenConsumerLoadTest.java | 59 ++++++++++++++++++++++
.../component/nats/NatsAuthTokenProducerTest.java | 39 ++++++++++++++
.../component/nats/NatsAuthTokenTestSupport.java | 53 +++++++++++++++++++
3 files changed, 151 insertions(+)
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenConsumerLoadTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenConsumerLoadTest.java
new file mode 100644
index 0000000..55493be
--- /dev/null
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenConsumerLoadTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.nats;
+
+import java.io.IOException;
+import java.util.concurrent.TimeoutException;
+
+import io.nats.client.Connection;
+import io.nats.client.Nats;
+import io.nats.client.Options;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class NatsAuthTokenConsumerLoadTest extends NatsAuthTokenTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ protected MockEndpoint mockResultEndpoint;
+
+ @Test
+ public void testLoadConsumer() throws InterruptedException, IOException, TimeoutException {
+ mockResultEndpoint.setExpectedMessageCount(100);
+ Options options = new Options.Builder().server("nats://" + getNatsUrl()).build();
+ Connection connection = Nats.connect(options);
+
+ for (int i = 0; i < 100; i++) {
+ connection.publish("test", ("test" + i).getBytes());
+ }
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("nats://" + getNatsUrl() + "?topic=test").to(mockResultEndpoint);
+ }
+ };
+ }
+
+}
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenProducerTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenProducerTest.java
new file mode 100644
index 0000000..1a9e11a
--- /dev/null
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenProducerTest.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.nats;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NatsAuthTokenProducerTest extends NatsAuthTestSupport {
+
+ @Test
+ public void sendTest() throws Exception {
+
+ template.sendBody("direct:send", "pippo");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:send").to("nats://" + getNatsUrl() + "?topic=test");
+ }
+ };
+ }
+}
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java
new file mode 100644
index 0000000..1e482cc
--- /dev/null
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.nats;
+
+import org.apache.camel.test.testcontainers.ContainerAwareTestSupport;
+import org.apache.camel.test.testcontainers.Wait;
+import org.testcontainers.containers.GenericContainer;
+
+public class NatsAuthTokenTestSupport extends ContainerAwareTestSupport {
+
+ public static final String CONTAINER_IMAGE = "nats:1.2.0";
+ public static final String CONTAINER_NAME = "nats-auth-token";
+ public static final String TOKEN = "!admin23456";
+
+ @Override
+ protected GenericContainer<?> createContainer() {
+ return natsContainer();
+ }
+
+ public static GenericContainer natsContainer() {
+ return new GenericContainer(CONTAINER_IMAGE)
+ .withNetworkAliases(CONTAINER_NAME)
+ .waitingFor(Wait.forLogMessageContaining("Server is ready", 1))
+ .withCommand(
+ "-DV",
+ "-auth",
+ TOKEN
+ );
+ }
+
+ public String getNatsUrl() {
+ return String.format(
+ "%s@%s:%d",
+ TOKEN,
+ getContainerHost(CONTAINER_NAME),
+ getContainerPort(CONTAINER_NAME, 4222)
+ );
+ }
+}