This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 3857936 PubNub native support
3857936 is described below
commit 3857936f35d8ecd17135abc2367d6a779a1960d2
Author: James Netherton <[email protected]>
AuthorDate: Tue Feb 9 07:15:46 2021 +0000
PubNub native support
Fixes #1944
---
.../ROOT/pages/reference/extensions/pubnub.adoc | 14 +-
.../ROOT/partials/reference/components/pubnub.adoc | 6 +-
extensions-jvm/pom.xml | 1 -
.../pubnub/deployment/PubnubProcessor.java | 47 ------
.../component/pubnub/it/PubnubResource.java | 51 ------
extensions/pom.xml | 1 +
.../pubnub/deployment/pom.xml | 4 +
.../pubnub/deployment/PubnubProcessor.java | 70 ++++++++
{extensions-jvm => extensions}/pubnub/pom.xml | 1 -
.../pubnub/runtime/pom.xml | 5 +
.../main/resources/META-INF/quarkus-extension.yaml | 3 +-
integration-tests/pom.xml | 1 +
integration-tests/pubnub/README.adoc | 22 +++
.../pubnub}/pom.xml | 76 ++++++++-
.../component/pubnub/it/PubnubResource.java | 174 +++++++++++++++++++
.../quarkus/component/pubnub/it/PubnubRoutes.java | 26 +--
.../quarkus/component/pubnub/it/PubnubIT.java | 16 +-
.../quarkus/component/pubnub/it/PubnubTest.java | 188 +++++++++++++++++++++
.../component/pubnub/it/PubnubTestResource.java | 65 +++++++
tooling/scripts/test-categories.yaml | 1 +
20 files changed, 634 insertions(+), 138 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/pubnub.adoc
b/docs/modules/ROOT/pages/reference/extensions/pubnub.adoc
index a6ccbc6..938a421 100644
--- a/docs/modules/ROOT/pages/reference/extensions/pubnub.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/pubnub.adoc
@@ -3,15 +3,15 @@
= PubNub
:page-aliases: extensions/pubnub.adoc
:cq-artifact-id: camel-quarkus-pubnub
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-description: Send and receive messages to/from PubNub data stream network
for connected devices.
:cq-deprecated: false
:cq-jvm-since: 1.0.0
-:cq-native-since: n/a
+:cq-native-since: 1.7.0
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.0.0##
[.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native
since##[.badge-supported]##1.7.0##
Send and receive messages to/from PubNub data stream network for connected
devices.
@@ -32,3 +32,9 @@ Please refer to the above link for usage and configuration
details.
----
Check the xref:user-guide/index.adoc[User guide] for more information about
writing Camel Quarkus applications.
+
+== SSL in native mode
+
+This extension auto-enables SSL support in native mode. Hence you do not need
to add
+`quarkus.ssl.native=true` to your `application.properties` yourself. See also
+https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide].
diff --git a/docs/modules/ROOT/partials/reference/components/pubnub.adoc
b/docs/modules/ROOT/partials/reference/components/pubnub.adoc
index 9fec5f8..4fb82ab 100644
--- a/docs/modules/ROOT/partials/reference/components/pubnub.adoc
+++ b/docs/modules/ROOT/partials/reference/components/pubnub.adoc
@@ -2,11 +2,11 @@
// This file was generated by
camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-pubnub
:cq-artifact-id-base: pubnub
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.0.0
-:cq-native-since: n/a
+:cq-native-since: 1.7.0
:cq-camel-part-name: pubnub
:cq-camel-part-title: PubNub
:cq-camel-part-description: Send and receive messages to/from PubNub data
stream network for connected devices.
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index eea6159..d323038 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -101,7 +101,6 @@
<module>ognl</module>
<module>openstack</module>
<module>printer</module>
- <module>pubnub</module>
<module>pulsar</module>
<module>quickfix</module>
<module>redis</module>
diff --git
a/extensions-jvm/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
b/extensions-jvm/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
deleted file mode 100644
index 3613364..0000000
---
a/extensions-jvm/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.quarkus.component.pubnub.deployment;
-
-import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
-import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
-import org.jboss.logging.Logger;
-
-class PubnubProcessor {
- private static final Logger LOG = Logger.getLogger(PubnubProcessor.class);
-
- private static final String FEATURE = "camel-pubnub";
-
- @BuildStep
- FeatureBuildItem feature() {
- return new FeatureBuildItem(FEATURE);
- }
-
- /**
- * Remove this once this extension starts supporting the native mode.
- */
- @BuildStep(onlyIf = NativeBuild.class)
- @Record(value = ExecutionTime.RUNTIME_INIT)
- void warnJvmInNative(JvmOnlyRecorder recorder) {
- JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
- recorder.warnJvmInNative(FEATURE); // warn at runtime
- }
-
-}
diff --git
a/extensions-jvm/pubnub/integration-test/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
b/extensions-jvm/pubnub/integration-test/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
deleted file mode 100644
index e1ed7de..0000000
---
a/extensions-jvm/pubnub/integration-test/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.quarkus.component.pubnub.it;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.camel.CamelContext;
-import org.jboss.logging.Logger;
-
-@Path("/pubnub")
-@ApplicationScoped
-public class PubnubResource {
-
- private static final Logger LOG = Logger.getLogger(PubnubResource.class);
-
- private static final String COMPONENT_PUBNUB = "pubnub";
- @Inject
- CamelContext context;
-
- @Path("/load/component/pubnub")
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response loadComponentPubnub() throws Exception {
- /* This is an autogenerated test */
- if (context.getComponent(COMPONENT_PUBNUB) != null) {
- return Response.ok().build();
- }
- LOG.warnf("Could not load [%s] from the Camel context",
COMPONENT_PUBNUB);
- return Response.status(500, COMPONENT_PUBNUB + " could not be loaded
from the Camel context").build();
- }
-}
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 1492e91..b1ead03 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -186,6 +186,7 @@
<module>pgevent</module>
<module>platform-http</module>
<module>protobuf</module>
+ <module>pubnub</module>
<module>quartz</module>
<module>qute</module>
<module>rabbitmq</module>
diff --git a/extensions-jvm/pubnub/deployment/pom.xml
b/extensions/pubnub/deployment/pom.xml
similarity index 93%
rename from extensions-jvm/pubnub/deployment/pom.xml
rename to extensions/pubnub/deployment/pom.xml
index 5875f31..ccc183e 100644
--- a/extensions-jvm/pubnub/deployment/pom.xml
+++ b/extensions/pubnub/deployment/pom.xml
@@ -36,6 +36,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-support-retrofit-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-pubnub</artifactId>
</dependency>
</dependencies>
diff --git
a/extensions/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
b/extensions/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
new file mode 100644
index 0000000..c056025
--- /dev/null
+++
b/extensions/pubnub/deployment/src/main/java/org/apache/camel/quarkus/component/pubnub/deployment/PubnubProcessor.java
@@ -0,0 +1,70 @@
+/*
+ * 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.quarkus.component.pubnub.deployment;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
+import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
+import
io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.jboss.jandex.IndexView;
+
+class PubnubProcessor {
+ private static final String FEATURE = "camel-pubnub";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ IndexDependencyBuildItem indexDependencies() {
+ return new IndexDependencyBuildItem("com.pubnub", "pubnub-gson");
+ }
+
+ @BuildStep
+ ExtensionSslNativeSupportBuildItem activateSslNativeSupport() {
+ return new ExtensionSslNativeSupportBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem
combinedIndex) {
+ IndexView index = combinedIndex.getIndex();
+ String[] reflectiveClasses = index.getKnownClasses()
+ .stream()
+ .map(classInfo -> classInfo.name().toString())
+ .filter(name -> name.startsWith("com.pubnub.api.models"))
+ .toArray(String[]::new);
+
+ return new ReflectiveClassBuildItem(false, true, reflectiveClasses);
+ }
+
+ @BuildStep
+ void
registerProxyInterfaces(BuildProducer<NativeImageProxyDefinitionBuildItem>
proxyDefinitions,
+ CombinedIndexBuildItem combinedIndex) {
+ IndexView index = combinedIndex.getIndex();
+ index.getKnownClasses()
+ .stream()
+ .map(classInfo -> classInfo.name().toString())
+ .filter(name -> name.startsWith("com.pubnub.api.services"))
+ .map(NativeImageProxyDefinitionBuildItem::new)
+ .forEach(proxyDefinitions::produce);
+ }
+}
diff --git a/extensions-jvm/pubnub/pom.xml b/extensions/pubnub/pom.xml
similarity index 97%
rename from extensions-jvm/pubnub/pom.xml
rename to extensions/pubnub/pom.xml
index c81c268..f68efeb 100644
--- a/extensions-jvm/pubnub/pom.xml
+++ b/extensions/pubnub/pom.xml
@@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/pubnub/runtime/pom.xml
b/extensions/pubnub/runtime/pom.xml
similarity index 94%
rename from extensions-jvm/pubnub/runtime/pom.xml
rename to extensions/pubnub/runtime/pom.xml
index f8f2917..2bebdd8 100644
--- a/extensions-jvm/pubnub/runtime/pom.xml
+++ b/extensions/pubnub/runtime/pom.xml
@@ -31,6 +31,7 @@
<properties>
<camel.quarkus.jvmSince>1.0.0</camel.quarkus.jvmSince>
+ <camel.quarkus.nativeSince>1.7.0</camel.quarkus.nativeSince>
</properties>
<dependencyManagement>
@@ -51,6 +52,10 @@
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-support-retrofit</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pubnub</artifactId>
</dependency>
diff --git
a/extensions-jvm/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
b/extensions/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from
extensions-jvm/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to
extensions/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index fbd010a..e04e596 100644
---
a/extensions-jvm/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++
b/extensions/pubnub/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
name: "Camel PubNub"
description: "Send and receive messages to/from PubNub data stream network for
connected devices"
metadata:
- unlisted: true
guide:
"https://camel.apache.org/camel-quarkus/latest/reference/extensions/pubnub.html"
categories:
- "integration"
status:
- - "preview"
+ - "stable"
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index f38780d..05c5ba1 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -159,6 +159,7 @@
<module>platform-http</module>
<module>platform-http-engine</module>
<module>protobuf</module>
+ <module>pubnub</module>
<module>quartz</module>
<module>qute</module>
<module>rabbitmq</module>
diff --git a/integration-tests/pubnub/README.adoc
b/integration-tests/pubnub/README.adoc
new file mode 100644
index 0000000..a4ed393
--- /dev/null
+++ b/integration-tests/pubnub/README.adoc
@@ -0,0 +1,22 @@
+== Camel Quarkus PubNub Integration Tests
+
+By default the PubNub integration tests use WireMock to stub the API
interactions.
+
+To run the `camel-quarkus-pubnub` integration tests against the real API, you
must first create a PubNub account https://dashboard.pubnub.com/signup.
+
+Then find your [test credentials] and set the following environment variables:
+
+[source,shell]
+----
+export PUBNUB_PUBLISH_KEY=your-publish-key
+export PUBNUB_SUBSCRIBE_KEY=your-subscribe-key
+export PUBNUB_SECRET_KEY=your-secret-key
+----
+
+If the WireMock stub recordings need updating, edit the `stubFor` blocks
within the test case. You can capture recordings and run tests with either:
+
+System property `-Dwiremock.record=true`
+
+Or
+
+Set environment variable `WIREMOCK_RECORD=true`
diff --git a/extensions-jvm/pubnub/integration-test/pom.xml
b/integration-tests/pubnub/pom.xml
similarity index 50%
rename from extensions-jvm/pubnub/integration-test/pom.xml
rename to integration-tests/pubnub/pom.xml
index 3340647..57df718 100644
--- a/extensions-jvm/pubnub/integration-test/pom.xml
+++ b/integration-tests/pubnub/pom.xml
@@ -21,21 +21,28 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-build-parent-it</artifactId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.7.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>
- <artifactId>camel-quarkus-pubnub-integration-test</artifactId>
- <name>Camel Quarkus :: PubNub :: Integration Test</name>
+ <artifactId>camel-quarkus-integration-test-pubnub</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: PubNub</name>
<description>Integration tests for Camel Quarkus PubNub
extension</description>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-pubnub</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-seda</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
@@ -51,10 +58,28 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-wiremock-support</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- The following dependencies guarantee that this module is built
after them. You can update them by running `mvn process-resources -Pformat -N`
from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-pubnub-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
@@ -66,6 +91,49 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-seda-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
diff --git
a/integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
b/integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
new file mode 100644
index 0000000..5f55113
--- /dev/null
+++
b/integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubResource.java
@@ -0,0 +1,174 @@
+/*
+ * 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.quarkus.component.pubnub.it;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import com.pubnub.api.PNConfiguration;
+import com.pubnub.api.PubNub;
+import com.pubnub.api.enums.PNReconnectionPolicy;
+import com.pubnub.api.models.consumer.history.PNHistoryItemResult;
+import com.pubnub.api.models.consumer.presence.PNGetStateResult;
+import com.pubnub.api.models.consumer.presence.PNHereNowResult;
+import com.pubnub.api.models.consumer.pubsub.PNMessageResult;
+import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.pubnub.PubNubConstants;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+@Path("/pubnub")
+public class PubnubResource {
+
+ @ConfigProperty(name = "pubnub.publish.key")
+ String publishKey;
+
+ @ConfigProperty(name = "pubnub.subscribe.key")
+ String subscribeKey;
+
+ @ConfigProperty(name = "pubnub.secret.key")
+ String secretKey;
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Inject
+ ConsumerTemplate consumerTemplate;
+
+ @Inject
+ CamelContext context;
+
+ @Path("/publish/{channel}")
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ public Response publish(@PathParam("channel") String channel, String
message) throws Exception {
+ if (channel.equals("test")) {
+ context.getRouteController().startRoute("subscriber-route");
+ }
+ producerTemplate.sendBodyAndHeader("direct:publish", message,
PubNubConstants.CHANNEL, channel);
+ return Response.created(new URI("https://camel.apache.org")).build();
+ }
+
+ @Path("/subscribe")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String subscribe() throws Exception {
+ try {
+ PNMessageResult result =
consumerTemplate.receiveBody("seda:messages", 10000, PNMessageResult.class);
+ return result.getMessage().getAsString();
+ } finally {
+ context.getRouteController().stopRoute("subscriber-route");
+ }
+ }
+
+ @Path("/fire")
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ public String fire(String message) throws Exception {
+ Exchange exchange =
producerTemplate.request("pubnub:test-fire?pubNub=#pubNub&operation=fire",
+ ex -> ex.getMessage().setBody(message));
+ return exchange.getMessage().getHeader(PubNubConstants.TIMETOKEN,
String.class);
+ }
+
+ @Path("/presence")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String presence() throws Exception {
+ try {
+ context.getRouteController().startRoute("presence-route");
+
+ PNPresenceEventResult result =
consumerTemplate.receiveBody("seda:presence", 10000,
PNPresenceEventResult.class);
+ return result.getChannel();
+ } finally {
+ context.getRouteController().stopRoute("presence-route");
+
+ }
+ }
+
+ @Path("/state")
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ public void setState() throws Exception {
+ Map<String, String> state = new HashMap<>();
+ state.put("test-state-key", "test-state-value");
+
producerTemplate.requestBodyAndHeader("pubnub:test-state?pubNub=#pubNub",
state, PubNubConstants.OPERATION, "SETSTATE");
+ }
+
+ @Path("/state")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getState() throws Exception {
+ PNGetStateResult result =
producerTemplate.requestBodyAndHeader("pubnub:test-state?pubNub=#pubNub", null,
+ PubNubConstants.OPERATION, "GETSTATE", PNGetStateResult.class);
+ return
result.getStateByUUID().get("test-state").getAsJsonObject().get("test-state-key").getAsString();
+ }
+
+ @Path("/history")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ @SuppressWarnings("unchecked")
+ public int history() throws Exception {
+ List<PNHistoryItemResult> result =
producerTemplate.requestBodyAndHeader("pubnub:test-history?pubNub=#pubNub",
null,
+ PubNubConstants.OPERATION, "GETHISTORY", List.class);
+ return result.size();
+ }
+
+ @Path("/herenow")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ @SuppressWarnings("unchecked")
+ public int herenow() throws Exception {
+ PNHereNowResult result =
producerTemplate.requestBodyAndHeader("pubnub:test-herenow?pubNub=#pubNub",
null,
+ PubNubConstants.OPERATION, "HERENOW", PNHereNowResult.class);
+ return result.getTotalChannels();
+ }
+
+ @javax.enterprise.inject.Produces
+ @Singleton
+ @Named
+ public PubNub pubNub() {
+ PNConfiguration configuration = new PNConfiguration();
+ configuration.setPublishKey(publishKey);
+ configuration.setSubscribeKey(subscribeKey);
+ configuration.setSecretKey(secretKey);
+
+ String url = System.getProperty("pubnub.url");
+ if (url != null) {
+ configuration.setOrigin(url);
+ configuration.setSecure(false);
+ configuration.setReconnectionPolicy(PNReconnectionPolicy.LINEAR);
+ }
+
+ return new PubNub(configuration);
+ }
+}
diff --git
a/extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
b/integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubRoutes.java
similarity index 61%
copy from
extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
copy to
integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubRoutes.java
index dc4bfbf..c1171ba 100644
---
a/extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
+++
b/integration-tests/pubnub/src/main/java/org/apache/camel/quarkus/component/pubnub/it/PubnubRoutes.java
@@ -16,19 +16,21 @@
*/
package org.apache.camel.quarkus.component.pubnub.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import org.apache.camel.builder.RouteBuilder;
-@QuarkusTest
-class PubnubTest {
+public class PubnubRoutes extends RouteBuilder {
- @Test
- public void loadComponentPubnub() {
- /* A simple autogenerated test */
- RestAssured.get("/pubnub/load/component/pubnub")
- .then()
- .statusCode(200);
- }
+ @Override
+ public void configure() throws Exception {
+ from("direct:publish")
+ .to("pubnub:overridden?pubNub=#pubNub");
+
+ from("pubnub:test?pubNub=#pubNub").id("subscriber-route")
+ .autoStartup(false)
+ .to("seda:messages");
+
from("pubnub:test?pubnub=#pubNub&withPresence=true").id("presence-route")
+ .autoStartup(false)
+ .to("seda:presence");
+ }
}
diff --git
a/extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubIT.java
similarity index 70%
rename from
extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
rename to
integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubIT.java
index dc4bfbf..56966e5 100644
---
a/extensions-jvm/pubnub/integration-test/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
+++
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubIT.java
@@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.pubnub.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.test.junit.NativeImageTest;
-@QuarkusTest
-class PubnubTest {
-
- @Test
- public void loadComponentPubnub() {
- /* A simple autogenerated test */
- RestAssured.get("/pubnub/load/component/pubnub")
- .then()
- .statusCode(200);
- }
+@NativeImageTest
+class PubnubIT extends PubnubTest {
}
diff --git
a/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
new file mode 100644
index 0000000..97afb28
--- /dev/null
+++
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.quarkus.component.pubnub.it;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.apache.camel.quarkus.test.wiremock.MockServer;
+import org.junit.jupiter.api.Test;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.matchesPattern;
+
+@QuarkusTest
+@QuarkusTestResource(PubnubTestResource.class)
+class PubnubTest {
+
+ @MockServer
+ WireMockServer server;
+
+ @Test
+ public void testPublishSubscribeShouldReturnSameMessage() {
+ String message = "Test PubNub publish";
+
+ if (server != null) {
+ server.stubFor(post(urlPathMatching("/publish/(.*)/(.*)/0/test/0"))
+
.willReturn(aResponse().withStatus(200).withBody("[1,\"Sent\",\"14598111595318003\"]")));
+
+ server.stubFor(get(urlPathMatching("/v2/subscribe/(.*)/(.*)/0"))
+ .willReturn(aResponse()
+ .withBody(
+
"{\"t\":{\"t\":\"14607577960932487\",\"r\":1},\"m\":[{\"a\":\"4\",\"f\":0,\"i\":\"Publisher-A\",\"p\":{\"t\":\"14607577960925503\",\"r\":1},\"o\":"
+ +
"{\"t\":\"14737141991877032\",\"r\":2},\"k\":\"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\","
+ + "\"c\":\"test\",\"d\":\"" +
message + "\",\"b\":\"test\"}]}")));
+
+
server.stubFor(get(urlPathMatching("/v2/presence/sub-key/(.*)/channel/test/heartbeat"))
+ .willReturn(aResponse().withBody("{\"status\": 200,
\"message\": \"OK\", \"service\": \"Presence\"}")));
+
+
server.stubFor(get(urlPathMatching("/v2/presence/sub-key/(.*)/channel/test/leave"))
+ .willReturn(aResponse().withBody("{\"status\": 200,
\"message\": \"OK\", \"service\": \"Presence\"}")));
+ }
+
+ // Publish message
+ RestAssured.given()
+ .body(message)
+ .post("/pubnub/publish/test")
+ .then()
+ .statusCode(201);
+
+ // Subscribe and consume the message
+ RestAssured.get("/pubnub/subscribe")
+ .then()
+ .statusCode(200)
+ .body(is(message));
+ }
+
+ @Test
+ public void testPubNubFire() {
+ String message = "Test PubNub fire";
+
+ if (server != null) {
+
server.stubFor(get(urlPathMatching("/publish/(.*)/(.*)/0/(.*)/0/%22Test%20PubNub%20fire%22"))
+
.willReturn(aResponse().withBody("[1,\"Sent\",\"14598111595318003\"]")));
+ }
+
+ RestAssured.given()
+ .body(message)
+ .post("/pubnub/fire")
+ .then()
+ .statusCode(200)
+ .body(matchesPattern("[0-9]+"));
+ }
+
+ @Test
+ public void testPubNubPresence() {
+ if (server != null) {
+ server.stubFor(get(urlPathMatching("/v2/subscribe/(.*)/(.*)/0"))
+ .willReturn(aResponse()
+ .withBody(
+
"{\"t\":{\"t\":\"16127893527303416\",\"r\":12},\"m\":[{\"a\":\"4\",\"f\":0,\"p\":{\"t\":\"16127893527306385\","
+ +
"\"r\":12},\"k\":\"sub-c-b14e2458-66d0-11eb-b373-323c3659f3c9\",\"c\":\"test-pnpres\","
+ +
"\"u\":{\"pn_action\":\"join\",\"pn_uuid\":\"pn-cd0e849f-71ec-4006-a989-c0cc7d1b37a5\","
+ +
"\"pn_timestamp\":1612789352,\"pn_occupancy\":1,\"pn_ispresence\":1,\"pn_channel\":\"test\"},"
+ +
"\"d\":{\"action\":\"join\",\"uuid\":\"pn-cd0e849f-71ec-4006-a989-c0cc7d1b37a5\",\"timestamp\":1612789352,\"occupancy\":1},"
+ + "\"b\":\"test-pnpres\"}]}\n")));
+
+
server.stubFor(get(urlPathMatching("/v2/presence/sub-key/(.*)/channel/test/leave"))
+ .willReturn(aResponse().withBody("{\"status\": 200,
\"message\": \"OK\", \"service\": \"Presence\"}")));
+ }
+
+ RestAssured.given()
+ .get("/pubnub/presence")
+ .then()
+ .statusCode(200)
+ .body(is("test"));
+ }
+
+ @Test
+ public void testPubNubState() {
+ if (server != null) {
+
server.stubFor(get(urlPathMatching("/v2/presence/sub-key/(.*)/channel/(.*)/uuid/myuuid/data"))
+ .willReturn(aResponse().withBody(
+ "{\"status\": 200, \"message\": \"OK\",
\"payload\": {\"test-state-key\": \"test-state-value\"}, \"service\":
\"Presence\"}")));
+
+
server.stubFor(get(urlPathMatching("/v2/presence/sub-key/(.*)/channel/(.*)/uuid/(.*)"))
+ .willReturn(aResponse().withBody(
+ "{\"status\": 200, \"message\": \"OK\",
\"payload\": {\"test-state-key\": \"test-state-value\"}, "
+ + "\"uuid\":
\"pn-a2b8fef1-5c4f-4f26-b71b-0065eede6ad7\", \"channel\": \"test-state\",
\"service\": \"Presence\"}")));
+ }
+
+ RestAssured.given()
+ .post("/pubnub/state")
+ .then()
+ .statusCode(204);
+
+ RestAssured.given()
+ .get("/pubnub/state")
+ .then()
+ .statusCode(200)
+ .body(is("test-state-value"));
+ }
+
+ @Test
+ public void testPubNubHistory() {
+ if (server != null) {
+ server.stubFor(post(urlPathMatching("/publish/(.*)/(.*)/0/(.*)/0"))
+
.willReturn(aResponse().withStatus(200).withBody("[1,\"Sent\",\"14598111595318003\"]")));
+
+
server.stubFor(get(urlPathMatching("/v2/history/sub-key/(.*)/channel/(.*)"))
+ .willReturn(aResponse().withBody("[[\"Test PubNub
history\"],16124441622202741,16127935855440082]")));
+ }
+
+ RestAssured.given()
+ .body("Test PubNub history")
+ .post("/pubnub/publish/test-history")
+ .then()
+ .statusCode(201);
+
+ RestAssured.given()
+ .get("/pubnub/history")
+ .then()
+ .statusCode(200)
+ .body(matchesPattern("^[1-9][0-9]*$"));
+ }
+
+ @Test
+ public void testPubNubHereNow() {
+ if (server != null) {
+ server.stubFor(post(urlPathMatching("/publish/(.*)/(.*)/0/(.*)/0"))
+
.willReturn(aResponse().withStatus(200).withBody("[1,\"Sent\",\"14598111595318003\"]")));
+
+
server.stubFor(get(urlPathMatching("/v2/presence/sub_key/(.*)/channel/(.*)"))
+ .willReturn(aResponse().withBody(
+ "{\"status\": 200, \"message\": \"OK\",
\"occupancy\": 0, \"uuids\": [], \"service\": \"Presence\"}")));
+ }
+
+ RestAssured.given()
+ .body("Test PubNub Here Now")
+ .post("/pubnub/publish/test-herenow")
+ .then()
+ .statusCode(201);
+
+ RestAssured.given()
+ .get("/pubnub/herenow")
+ .then()
+ .statusCode(200)
+ .body(matchesPattern("^[1-9][0-9]*$"));
+ }
+}
diff --git
a/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTestResource.java
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTestResource.java
new file mode 100644
index 0000000..addcc24
--- /dev/null
+++
b/integration-tests/pubnub/src/test/java/org/apache/camel/quarkus/component/pubnub/it/PubnubTestResource.java
@@ -0,0 +1,65 @@
+/*
+ * 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.quarkus.component.pubnub.it;
+
+import java.util.Map;
+
+import
org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager;
+import org.apache.camel.util.CollectionHelper;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+
+public class PubnubTestResource extends WireMockTestResourceLifecycleManager {
+
+ private static final String PUBNUB_BASE_URL = "https://ps.pndsn.com";
+ private static final String PUBNUB_ENV_PUBLISH_KEY = "PUBNUB_PUBLISH_KEY";
+ private static final String PUBNUB_ENV_SUBSCRIBE_KEY =
"PUBNUB_SUBSCRIBE_KEY";
+ private static final String PUBNUB_ENV_SECRET_KEY = "PUBNUB_SECRET_KEY";
+
+ @Override
+ public Map<String, String> start() {
+ Map<String, String> properties = super.start();
+ String wireMockUrl = properties.get("wiremock.url");
+ if (wireMockUrl != null) {
+ properties.put("pubnub.url", wireMockUrl.replace("http://", "") +
"/");
+
+ // This is purposely stubbed here before the PubNub consumer
starts up
+ server.stubFor(get(urlPathMatching("/v2/subscribe/(.*)/(.*)/0"))
+
.willReturn(aResponse().withBody("{\"t\":{\"t\":\"16127970351113041\",\"r\":12},\"m\":[]}")));
+ }
+
+ return CollectionHelper.mergeMaps(properties, CollectionHelper.mapOf(
+ "pubnub.publish.key", envOrDefault(PUBNUB_ENV_PUBLISH_KEY,
"test-publish-key"),
+ "pubnub.subscribe.key", envOrDefault(PUBNUB_ENV_SUBSCRIBE_KEY,
"test-subscribe-key"),
+ "pubnub.secret.key", envOrDefault(PUBNUB_ENV_SECRET_KEY,
"test-secret-key")));
+ }
+
+ @Override
+ protected String getRecordTargetBaseUrl() {
+ return PUBNUB_BASE_URL;
+ }
+
+ @Override
+ protected boolean isMockingEnabled() {
+ return !envVarsPresent(
+ PUBNUB_ENV_PUBLISH_KEY,
+ PUBNUB_ENV_SUBSCRIBE_KEY,
+ PUBNUB_ENV_SECRET_KEY);
+ }
+}
diff --git a/tooling/scripts/test-categories.yaml
b/tooling/scripts/test-categories.yaml
index d6982a2..f4a42c0 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -36,6 +36,7 @@ cloud:
- google-bigquery
- google-pubsub
- grpc
+ - pubnub
- protobuf
- smallrye-reactive-messaging
core-main-validation: