This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9fd14ca78e3d34c2b3f11af5ef050f5b630edafa Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Aug 24 13:16:41 2021 +0200 CAMEL-16392 - Added some tests --- .../integration/PulsarConsumerInURIClientIT.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java new file mode 100644 index 0000000..c82f4bc --- /dev/null +++ b/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarConsumerInURIClientIT.java @@ -0,0 +1,85 @@ +/* + * 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.pulsar.integration; + +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.pulsar.PulsarComponent; +import org.apache.camel.component.pulsar.utils.AutoConfiguration; +import org.apache.camel.spi.Registry; +import org.apache.camel.support.SimpleRegistry; +import org.apache.pulsar.client.api.Producer; +import org.apache.pulsar.client.api.PulsarClient; +import org.apache.pulsar.client.api.PulsarClientException; +import org.apache.pulsar.client.api.Schema; +import org.apache.pulsar.client.impl.ClientBuilderImpl; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +public class PulsarConsumerInURIClientIT extends PulsarITSupport { + + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarConsumerInURIClientIT.class); + + private static final String TOPIC_URI = "persistent://public/default/camel-topic"; + private static final String PRODUCER = "camel-producer-1"; + private static final String URI_ENDPOINT = "pulsar:" + TOPIC_URI + "?numberOfConsumers=1&subscriptionType=Exclusive" + + "&subscriptionName=camel-subscription&consumerQueueSize=1&consumerName=camel-consumer&serviceUrl=" + service.getPulsarBrokerUrl(); + + @EndpointInject("mock:result") + private MockEndpoint to; + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + Processor processor = new Processor() { + @Override + public void process(final Exchange exchange) { + LOGGER.info("Processing message {}", exchange.getIn().getBody()); + } + }; + + @Override + public void configure() { + from(URI_ENDPOINT).to(to).process(processor); + } + }; + } + + private PulsarClient givenPulsarClient() throws PulsarClientException { + return new ClientBuilderImpl().serviceUrl(getPulsarBrokerUrl()).ioThreads(1).listenerThreads(1).build(); + } + + @Test + public void testAMessageToClusterIsConsumed() throws Exception { + to.expectedMessageCount(1); + + Producer<String> producer + = givenPulsarClient().newProducer(Schema.STRING).producerName(PRODUCER).topic(TOPIC_URI).create(); + + producer.send("Hello World!"); + + MockEndpoint.assertIsSatisfied(10, TimeUnit.SECONDS, to); + } +}