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 9364ce0d1c6dbe1fd8605817cad4bfeeec3e2c9b Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Jul 23 11:49:00 2018 +0200 CAMEL-12670 - Camel-Nats: add authentication example --- .../camel/component/nats/NatsConfiguration.java | 2 +- .../camel/component/nats/NatsAuthProducerTest.java | 39 +++++++++++++++ .../camel/component/nats/NatsAuthTestSupport.java | 57 ++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java index 4ecc74095..9e1d018f 100644 --- a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java +++ b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java @@ -26,6 +26,7 @@ import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.spi.UriPath; +import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.jsse.SSLContextParameters; @UriParams @@ -75,7 +76,6 @@ public class NatsConfiguration { private boolean secure; @UriParam(label = "security") private SSLContextParameters sslContextParameters; - /** * URLs to one or more NAT servers. Use comma to separate URLs when * specifying multiple servers. diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthProducerTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthProducerTest.java new file mode 100644 index 0000000..c6c822d --- /dev/null +++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthProducerTest.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 NatsAuthProducerTest 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/NatsAuthTestSupport.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java new file mode 100644 index 0000000..45856b5 --- /dev/null +++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java @@ -0,0 +1,57 @@ +/** + * 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 NatsAuthTestSupport extends ContainerAwareTestSupport { + + public static final String CONTAINER_IMAGE = "nats:1.2.0"; + public static final String CONTAINER_NAME = "nats-auth"; + public static final String USERNAME = "admin"; + public static final String PASSWORD = "password"; + + @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", + "--user", + USERNAME, + "--pass", + PASSWORD + ); + } + + public String getNatsUrl() { + return String.format( + "%s:%s@%s:%d", + USERNAME, + PASSWORD, + getContainerHost(CONTAINER_NAME), + getContainerPort(CONTAINER_NAME, 4222) + ); + } +}