This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-examples.git
The following commit(s) were added to refs/heads/main by this push:
new d52a1b3c chore(pubnub): added examples
d52a1b3c is described below
commit d52a1b3c16bedaedc6751bd8e5dee8fe9862e2c7
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Oct 9 11:38:42 2025 +0200
chore(pubnub): added examples
They are taken "as is" from core code base [1] since we're cleaning from
there. The idea is to maintain these examples as utilities in the examples repo
instead.
[1]
https://github.com/apache/camel/tree/24e3fdbd40e0edd66cb2115f0710bd2e5d1b29db/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example
---
pom.xml | 1 +
pubnub/pom.xml | 101 +++++++++++++++++
.../pubnub/example/PubNubExampleConstants.java | 24 ++++
.../pubnub/example/PubNubGeoLocationExample.java | 56 ++++++++++
.../pubnub/example/PubNubPresenseExample.java | 44 ++++++++
.../pubnub/example/PubNubSensor2Example.html | 108 ++++++++++++++++++
.../pubnub/example/PubNubSensor2Example.java | 124 +++++++++++++++++++++
.../pubnub/example/PubNubSensorExample.java | 43 +++++++
.../pubnub/example/PubNubStateManualTest.java | 73 ++++++++++++
pubnub/src/test/resources/log4j2.properties | 28 +++++
10 files changed, 602 insertions(+)
diff --git a/pom.xml b/pom.xml
index 7f7416fb..0e109ea7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,6 +123,7 @@
<module>mongodb</module>
<module>netty-custom-correlation</module>
<module>quickfixj</module>
+ <module>pubnub</module>
<module>resume-api</module>
<module>routeloader</module>
<module>routetemplate</module>
diff --git a/pubnub/pom.xml b/pubnub/pom.xml
new file mode 100644
index 00000000..3ad063e4
--- /dev/null
+++ b/pubnub/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel.example</groupId>
+ <artifactId>camel-examples</artifactId>
+ <version>4.15.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-pubnub</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Example: PubNub</name>
+
+ <properties>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Add Camel BOM -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-bom</artifactId>
+ <version>${camel.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.pubnub</groupId>
+ <artifactId>pubnub-gson</artifactId>
+ <version>${pubnub-version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>${gson-version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-pubnub</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-main</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <version>${hamcrest-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.wiremock</groupId>
+ <artifactId>wiremock</artifactId>
+ <version>${wiremock-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubExampleConstants.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubExampleConstants.java
new file mode 100644
index 00000000..91c0eb25
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubExampleConstants.java
@@ -0,0 +1,24 @@
+/*
+ * 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.pubnub.example;
+
+public interface PubNubExampleConstants {
+ // replace subscribe+publish key with one obtained from PubNub.
+ // http://www.pubnub.com
+ String PUBNUB_SUBSCRIBE_KEY = "mysubkey";
+ String PUBNUB_PUBLISH_KEY = "mypubkey";
+}
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubGeoLocationExample.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubGeoLocationExample.java
new file mode 100644
index 00000000..1164c86f
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubGeoLocationExample.java
@@ -0,0 +1,56 @@
+/*
+ * 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.pubnub.example;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_PUBLISH_KEY;
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBE_KEY;
+
+/**
+ * Example of the use of GeoLocation Blocks
https://www.pubnub.com/blocks-catalog/geolocation/
+ */
+
+public final class PubNubGeoLocationExample {
+
+ private PubNubGeoLocationExample() {
+ }
+
+ public static void main(String[] args) throws Exception {
+ Main main = new Main();
+ main.configure().addRoutesBuilder(new GeoLocationRoute());
+ main.run();
+ }
+
+ static class GeoLocationRoute extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("timer:geotimer")
+ .process(exchange -> exchange.getIn().setBody(new
Foo("bar", "TEXT")))
+
.to("pubnub:eon-maps-geolocation-input?uuid=camel&operation=fire&publishKey=" +
PUBNUB_PUBLISH_KEY
+ + "&subscribeKey="
+ + PUBNUB_SUBSCRIBE_KEY);
+
+ from("pubnub:eon-map-geolocation-output?uuid=camel&subscribeKey="
+ PUBNUB_SUBSCRIBE_KEY)
+ .log("${body}");
+ }
+ }
+
+ record Foo(String foo, String text) {
+ }
+}
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
new file mode 100644
index 00000000..f0782898
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
@@ -0,0 +1,44 @@
+/*
+ * 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.pubnub.example;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBE_KEY;
+
+public final class PubNubPresenseExample {
+
+ private PubNubPresenseExample() {
+ }
+
+ public static void main(String[] args) throws Exception {
+ Main main = new Main();
+ main.configure().addRoutesBuilder(new PresensRoute());
+ main.run();
+ }
+
+ static class PresensRoute extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("pubnub:iot?uuid=camel&withPresence=true&subscribeKey=" +
PUBNUB_SUBSCRIBE_KEY)
+ .log("${body}")
+ .to("mock:result");
+ }
+ }
+
+}
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
new file mode 100644
index 00000000..87824b0b
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
@@ -0,0 +1,108 @@
+<!--
+
+ 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.
+
+-->
+<html>
+<head>
+
+<link rel="stylesheet" type="text/css"
href="https://pubnub.github.io/eon/v/eon/1.0.0/eon.css">
+<script
src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.6.0.min.js"></script>
+<script src="https://pubnub.github.io/eon/v/eon/1.0.0/eon.js"></script>
+
+
+<style>
+.c3-region-1 {
+ fill: #dd3333;
+ fill-opacity: 0.8
+}
+</style>
+
+</head>
+<body>
+ <div>
+ <div align="center">
+ <h1>Description</h1>
+ </div>
+ <br /> This is a example of PubNub EON charts displaying stream data
+ using the camel-pubnub component. <br /> To see live data you have
+ to:
+ <ul>
+ <li>Sign up for a PubNub acount</li>
+ <li>Replace 'mySubscriberKey' in this html with a subscriberkey
obtained from PubNub.</li>
+ <li>Update the constants PUBNUB_SUBSCRIBER_KEY and
PUBNUB_PUBLISHER_KEY in the class PubNubExampleConstants</li>
+ <li>Run the class PubNubSensor2Example</li>
+ <li>Open this html page in your web browser</li>
+ </ul>
+ </div>
+ <div id="chart"></div>
+<script>
+
+ var pubnub = new PubNub({
+ subscribeKey: 'mySubscriberKey'
+ });
+
+eon.chart({
+ channels: ["iot"],
+ generate: {
+ bindto: '#chart',
+ data: {
+ type:'spline',
+ colors: {
+ value0:'#ffaaaa',
+ value1:'#cc8888',
+ },
+ names: {
+ value0: "Temperature",
+ value1: "Humidity",
+ }
+ },
+ point: {
+ show: false
+ },
+ axis: {
+ x: {
+ type: 'timeseries',
+ tick: {
+ format: '%H:%m:%S'
+ }
+ },
+ y: {
+ label: {
+ text: 'Values',
+ position: 'outer-middle'
+ }
+ }
+ },
+ tooltip: {
+ show: false
+ }
+ },
+ history:false,
+ pubnub: pubnub,
+ limit: 100,
+ transform: function(m) {
+ return { eon: {
+ temperature: m.temperature,
+ humidity: m.humidity
+ }}
+ }
+
+});
+
+ </script>
+</body>
+</html>
\ No newline at end of file
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
new file mode 100644
index 00000000..76b2e37a
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
@@ -0,0 +1,124 @@
+/*
+ * 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.pubnub.example;
+
+import java.security.SecureRandom;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.pubnub.api.models.consumer.pubsub.PNMessageResult;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.pubnub.PubNubConstants;
+import org.apache.camel.main.Main;
+
+import static org.apache.camel.component.pubnub.PubNubConstants.OPERATION;
+import static org.apache.camel.component.pubnub.PubNubConstants.UUID;
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_PUBLISH_KEY;
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBE_KEY;
+
+public final class PubNubSensor2Example {
+
+ private PubNubSensor2Example() {
+ }
+
+ public static void main(String[] args) throws Exception {
+ Main main = new Main();
+ main.configure().addRoutesBuilder(new PubsubRoute());
+ main.configure().addRoutesBuilder(new
SimulatedDeviceEventGeneratorRoute());
+ main.run();
+ }
+
+ static class SimulatedDeviceEventGeneratorRoute extends RouteBuilder {
+ private final String deviceEP
+ = "pubnub:iot?uuid=device2&publishKey=" + PUBNUB_PUBLISH_KEY +
"&subscribeKey=" + PUBNUB_SUBSCRIBE_KEY;
+ private final String devicePrivateEP =
"pubnub:device2private?uuid=device2&publishKey=" + PUBNUB_PUBLISH_KEY
+ + "&subscribeKey=" +
PUBNUB_SUBSCRIBE_KEY;
+
+ @Override
+ public void configure() {
+ from("timer:device2").routeId("device-event-route")
+ .bean(PubNubSensor2Example.EventGeneratorBean.class,
"getRandomEvent('device2')")
+ .to(deviceEP);
+
+ from(devicePrivateEP)
+ .routeId("device-unicast-route")
+ .log("Message from master to device2 : ${body}");
+ }
+ }
+
+ static class PubsubRoute extends RouteBuilder {
+ private static String masterEP
+ = "pubnub:iot?uuid=master&subscribeKey=" +
PUBNUB_SUBSCRIBE_KEY + "&publishKey=" + PUBNUB_PUBLISH_KEY;
+ private static Map<String, String> devices = new ConcurrentHashMap<>();
+
+ @Override
+ public void configure() {
+ from(masterEP)
+ .routeId("master-route")
+
.bean(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class,
"doSomethingInteresting(${body})")
+ .log("${body} headers : ${headers}").to("mock:result");
+
+ //TODO Could remote control device to turn on/off sensor
measurement
+
from("timer:master?delay=15000&period=5000").routeId("unicast2device-route")
+ .setHeader(PubNubConstants.CHANNEL,
+
method(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class,
"getUnicastChannelOfDevice()"))
+ .setBody(constant("Hello device"))
+ .to(masterEP);
+ }
+
+ public static class DataProcessorBean {
+ @EndpointInject("pubnub:iot?uuid=master&subscribeKey=" +
PUBNUB_SUBSCRIBE_KEY)
+ private static ProducerTemplate template;
+
+ public static String getUnicastChannelOfDevice() {
+ // just get the first channel
+ return devices.values().iterator().next();
+ }
+
+ public static void doSomethingInteresting(PNMessageResult message)
{
+ String deviceUUID;
+ deviceUUID = message.getPublisher();
+ if (devices.get(deviceUUID) == null) {
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(OPERATION, "WHERENOW");
+ headers.put(UUID, deviceUUID);
+ @SuppressWarnings("unchecked")
+ java.util.List<String> channels = (java.util.List<String>)
template.requestBodyAndHeaders(null, headers);
+ devices.put(deviceUUID, channels.get(0));
+ }
+ }
+ }
+ }
+
+ record DeviceWeatherInfo(String device, int humidity, int temperature) {
+
+ private static SecureRandom rand = new SecureRandom();
+
+ public DeviceWeatherInfo(String device) {
+ this(device, rand.nextInt(100), rand.nextInt(40));
+ }
+ }
+
+ public static class EventGeneratorBean {
+ public static DeviceWeatherInfo getRandomEvent(String device) {
+ return new DeviceWeatherInfo(device);
+ }
+ }
+}
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
new file mode 100644
index 00000000..8b3fe0f7
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
@@ -0,0 +1,43 @@
+/*
+ * 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.pubnub.example;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBE_KEY;
+
+public final class PubNubSensorExample {
+
+ private PubNubSensorExample() {
+ }
+
+ public static void main(String[] args) throws Exception {
+ Main main = new Main();
+ main.configure().addRoutesBuilder(new SensorRoute());
+ main.run();
+ }
+
+ static class SensorRoute extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("pubnub:pubnub-sensor-network?uuid=camel&subscribeKey=" +
PUBNUB_SUBSCRIBE_KEY).log("${body}")
+ .to("mock:result");
+ }
+ }
+
+}
diff --git
a/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubStateManualTest.java
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubStateManualTest.java
new file mode 100644
index 00000000..b515cffa
--- /dev/null
+++
b/pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubStateManualTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.pubnub.example;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.pubnub.api.models.consumer.presence.PNGetStateResult;
+import com.pubnub.api.models.consumer.presence.PNSetStateResult;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.pubnub.PubNubConstants;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_PUBLISH_KEY;
+import static
org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBE_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@Disabled("Integration test that requires a pub/sub key to run")
+public class PubNubStateManualTest extends CamelTestSupport {
+
+ @Test
+ public void testStateChange() throws Exception {
+ Map<String, Object> myState = new HashMap<>();
+ myState.put("state", "online");
+ myState.put("name", "preben");
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(PubNubConstants.OPERATION, "SETSTATE");
+ PNSetStateResult response =
template.requestBodyAndHeaders("direct:publish", myState, headers,
PNSetStateResult.class);
+ assertNotNull(response);
+ assertNotNull(response.getState());
+ assertEquals("preben",
response.getState().getAsJsonObject().get("name").getAsString());
+
+ MockEndpoint.resetMocks(context);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ headers.clear();
+ headers.put(PubNubConstants.OPERATION, "GETSTATE");
+ PNGetStateResult getStateResult =
template.requestBodyAndHeader("direct:publish", null, PubNubConstants.OPERATION,
+ "GETSTATE", PNGetStateResult.class);
+ MockEndpoint.assertIsSatisfied(context);
+ assertEquals("preben",
getStateResult.getStateByUUID().get("iot").getAsJsonObject().get("name").getAsString());
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:publish")
+ .to("pubnub:iot?uuid=myuuid&publishKey=" +
PUBNUB_PUBLISH_KEY + "&subscribeKey=" + PUBNUB_SUBSCRIBE_KEY)
+ .to("mock:result");
+ }
+ };
+ }
+
+}
diff --git a/pubnub/src/test/resources/log4j2.properties
b/pubnub/src/test/resources/log4j2.properties
new file mode 100644
index 00000000..7a124d8a
--- /dev/null
+++ b/pubnub/src/test/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-pubnub-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file