You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/05/24 14:53:45 UTC
[incubator-plc4x] 02/02: added a manual test for apache camel
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit f50b046a10993ccb828bf1edc7173f4d3e6cae6c
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu May 24 16:53:39 2018 +0200
added a manual test for apache camel
---
integrations/apache-camel/pom.xml | 6 ++
.../java/org/apache/plc4x/camel/ManualTest.java | 87 ++++++++++++++++++++++
2 files changed, 93 insertions(+)
diff --git a/integrations/apache-camel/pom.xml b/integrations/apache-camel/pom.xml
index 4702340..792b059 100644
--- a/integrations/apache-camel/pom.xml
+++ b/integrations/apache-camel/pom.xml
@@ -87,6 +87,12 @@
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-protocol-ads</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<dependencyManagement>
diff --git a/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/ManualTest.java b/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/ManualTest.java
new file mode 100644
index 0000000..1ded42a
--- /dev/null
+++ b/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/ManualTest.java
@@ -0,0 +1,87 @@
+/*
+ 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.plc4x.camel;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.apache.camel.main.MainListenerSupport;
+import org.apache.camel.main.MainSupport;
+
+import java.util.Date;
+
+public class ManualTest {
+
+ private Main main;
+
+ public static void main(String[] args) throws Exception {
+ ManualTest example = new ManualTest();
+ example.boot();
+ }
+
+ public void boot() throws Exception {
+ // create a Main instance
+ main = new Main();
+ // bind MyBean into the registry
+ main.bind("foo", new MyBean());
+ // add routes
+ main.addRouteBuilder(new MyRouteBuilder());
+ // add event listener
+ main.addMainListener(new Events());
+ // set the properties from a file
+ main.setPropertyPlaceholderLocations("example.properties");
+ // run until you terminate the JVM
+ System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
+ main.run();
+ }
+
+ private static class MyRouteBuilder extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("plc4x:ads:tcp://10.10.64.40/10.10.64.40.1.1:851/10.10.56.23.1.1:30000?dataType=java.lang.Integer&address=Allgemein_S2.Station")
+ .process(new Processor() {
+ public void process(Exchange exchange) {
+ System.out.println("Invoked timer at " + new Date());
+ }
+ })
+ .bean("foo")
+ .log("Received ${body}");
+ }
+ }
+
+ public static class MyBean {
+ public void callMe() {
+ System.out.println("MyBean.callMe method has been called");
+ }
+ }
+
+ public static class Events extends MainListenerSupport {
+
+ @Override
+ public void afterStart(MainSupport main) {
+ System.out.println("MainExample with Camel is now started!");
+ }
+
+ @Override
+ public void beforeStop(MainSupport main) {
+ System.out.println("MainExample with Camel is now being stopped!");
+ }
+ }
+}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.