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-kafka-connector.git
The following commit(s) were added to refs/heads/master by this push:
new 00415db Adds a new manual integration test for SlackSource
new 08a0f76 Merge pull request #328 from orpiske/slack-source
00415db is described below
commit 00415db9eb75705da9bd7761c2fbe84269aa9ffa
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Jul 22 13:00:56 2020 +0200
Adds a new manual integration test for SlackSource
---
.../slack/source/CamelSlackPropertyFactory.java | 54 +++++++++++
.../slack/source/CamelSourceSlackITCase.java | 103 +++++++++++++++++++++
.../slack/source/SlackTransformer.java | 72 ++++++++++++++
3 files changed, 229 insertions(+)
diff --git
a/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSlackPropertyFactory.java
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSlackPropertyFactory.java
new file mode 100644
index 0000000..45ebcf0
--- /dev/null
+++
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSlackPropertyFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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.kafkaconnector.slack.source;
+
+import org.apache.camel.kafkaconnector.common.EndpointUrlBuilder;
+import org.apache.camel.kafkaconnector.common.SourceConnectorPropertyFactory;
+
+final class CamelSlackPropertyFactory extends
SourceConnectorPropertyFactory<CamelSlackPropertyFactory> {
+
+ private CamelSlackPropertyFactory() {
+ }
+
+ public CamelSlackPropertyFactory withChannel(String value) {
+ return setProperty("camel.source.path.channel", value);
+ }
+
+ public CamelSlackPropertyFactory withMaxResults(int value) {
+ return setProperty("camel.source.endpoint.maxResults", value);
+ }
+
+ public CamelSlackPropertyFactory withToken(String value) {
+ return setProperty("camel.source.endpoint.token", value);
+ }
+
+ public EndpointUrlBuilder<CamelSlackPropertyFactory> withUrl(String topic)
{
+ String queueUrl = String.format("slack://%s", topic);
+
+ return new EndpointUrlBuilder<>(this::withSourceUrl, queueUrl);
+ }
+
+ public static CamelSlackPropertyFactory basic() {
+ return new CamelSlackPropertyFactory()
+ .withName("CamelSlackSourceConnector")
+ .withTasksMax(1)
+
.withConnectorClass("org.apache.camel.kafkaconnector.slack.CamelSlackSourceConnector")
+
.withKeyConverterClass("org.apache.kafka.connect.storage.StringConverter")
+
.withValueConverterClass("org.apache.kafka.connect.storage.StringConverter");
+ }
+}
diff --git
a/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSourceSlackITCase.java
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSourceSlackITCase.java
new file mode 100644
index 0000000..14ee2c8
--- /dev/null
+++
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/CamelSourceSlackITCase.java
@@ -0,0 +1,103 @@
+/*
+ * 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.kafkaconnector.slack.source;
+
+import java.util.concurrent.ExecutionException;
+
+import org.apache.camel.kafkaconnector.common.AbstractKafkaTest;
+import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
+import org.apache.camel.kafkaconnector.common.clients.kafka.KafkaClient;
+import org.apache.camel.kafkaconnector.common.utils.TestUtils;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+@Testcontainers
+
+/*
+This test is disabled by default because requires manual steps.
+
+You need to set 3 system properties to run this test:
+ -Dit.test.slack.enable=true to enable the test
+ -Dit.test.slack.channel=#channel to inform the channel to send the message to
+ -Dit.test.slack.token=<token> The token is a string that starts with xoxb
+
+Preparing for the test. You need create a bot and give it the following scopes:
+channel:history, channels:read and incoming-webhook. The settings for these,
+along with the token can be found on the page OAuth & Permissions.
+*/
+
+@EnabledIfSystemProperty(named = "it.test.slack.enable", matches = "true")
+public class CamelSourceSlackITCase extends AbstractKafkaTest {
+ private static final Logger LOG =
LoggerFactory.getLogger(CamelSourceSlackITCase.class);
+ private String slackChannel = System.getProperty("it.test.slack.channel");
+ private String token = System.getProperty("it.test.slack.token");
+
+ private boolean received;
+
+ @Override
+ protected String[] getConnectorsInTest() {
+ return new String[]{"camel-slack-kafka-connector"};
+ }
+
+ private <T> boolean checkRecord(ConsumerRecord<String, T> record) {
+ LOG.debug("Received: {}", record.value());
+
+ if (record.value() instanceof String) {
+ LOG.debug("Received text: {}", record.value());
+ } else {
+ fail(String.format("Unexpected message type: %s",
record.value().getClass()));
+ }
+
+ received = true;
+
+ return false;
+ }
+
+ @Test
+ @Timeout(90)
+ public void testBasicSendReceive() throws ExecutionException,
InterruptedException {
+ String kafkaTopic = TestUtils.getDefaultTestTopic(this.getClass());
+ ConnectorPropertyFactory factory = CamelSlackPropertyFactory
+ .basic()
+ .withKafkaTopic(kafkaTopic)
+ .withChannel(slackChannel)
+ .withMaxResults(1)
+ .withToken(token)
+ .withTransformsConfig("SlackTransformer")
+ .withEntry("type",
"org.apache.camel.kafkaconnector.slack.source.SlackTransformer")
+ .end();
+
+ factory.log();
+ getKafkaConnectService().initializeConnectorBlocking(factory, 1);
+
+ LOG.debug("Creating the consumer ...");
+ KafkaClient<String, String> kafkaClient = new
KafkaClient<>(getKafkaService().getBootstrapServers());
+ kafkaClient.consume(kafkaTopic, this::checkRecord);
+ LOG.debug("Created the consumer ...");
+
+ assertTrue(received, "Didn't receive any messages");
+ }
+}
diff --git
a/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/SlackTransformer.java
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/SlackTransformer.java
new file mode 100644
index 0000000..cc144bd
--- /dev/null
+++
b/tests/itests-slack/src/test/java/org/apache/camel/kafkaconnector/slack/source/SlackTransformer.java
@@ -0,0 +1,72 @@
+/*
+ * 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.kafkaconnector.slack.source;
+
+import java.util.Map;
+
+import org.apache.camel.component.slack.helper.SlackMessage;
+import org.apache.camel.kafkaconnector.utils.SchemaHelper;
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.connect.connector.ConnectRecord;
+import org.apache.kafka.connect.transforms.Transformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SlackTransformer <R extends ConnectRecord<R>> implements
Transformation<R> {
+ public static final String FIELD_KEY_CONFIG = "key";
+ public static final ConfigDef CONFIG_DEF = new ConfigDef()
+ .define(FIELD_KEY_CONFIG, ConfigDef.Type.STRING, null,
ConfigDef.Importance.MEDIUM,
+ "Transforms String-based content from Kafka into a map");
+
+ private static final Logger LOG =
LoggerFactory.getLogger(SlackTransformer.class);
+
+ @Override
+ public R apply(R r) {
+ Object value = r.value();
+
+ if (r.value() instanceof SlackMessage) {
+ LOG.debug("Converting record from SlackMessage to text");
+ SlackMessage message = (SlackMessage) r.value();
+
+ LOG.debug("Received text: {}", message.getText());
+
+ return r.newRecord(r.topic(), r.kafkaPartition(), null, r.key(),
+ SchemaHelper.buildSchemaBuilderForType(message.getText()),
message.getText(), r.timestamp());
+
+ } else {
+ LOG.debug("Unexpected message type: {}", r.value().getClass());
+
+ return r;
+ }
+ }
+
+ @Override
+ public ConfigDef config() {
+ return CONFIG_DEF;
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void configure(Map<String, ?> map) {
+
+ }
+}