You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/01/14 03:26:50 UTC
svn commit: r1058840 - in /camel/trunk/tests/camel-itest-osgi: pom.xml
src/test/java/org/apache/camel/itest/osgi/syslog/
src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java
Author: ningjiang
Date: Fri Jan 14 02:26:50 2011
New Revision: 1058840
URL: http://svn.apache.org/viewvc?rev=1058840&view=rev
Log:
Added the SyslogTest with thanks to joed
Added:
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java (with props)
Modified:
camel/trunk/tests/camel-itest-osgi/pom.xml
Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1058840&r1=1058839&r2=1058840&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Fri Jan 14 02:26:50 2011
@@ -134,6 +134,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-syslog</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-rss</artifactId>
<scope>test</scope>
</dependency>
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java?rev=1058840&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java Fri Jan 14 02:26:50 2011
@@ -0,0 +1,120 @@
+/**
+ * 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.itest.osgi.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+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.syslog.Rfc3164SyslogDataFormat;
+import org.apache.camel.component.syslog.SyslogMessage;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.apache.camel.spi.DataFormat;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
+@RunWith(JUnit4TestRunner.class)
+public class SyslogTest extends OSGiIntegrationTestSupport {
+
+ private final int serverPort = 10514;
+ private final int messageCount = 1;
+ private final String message =
+ "<165>Aug 4 05:34:00 mymachine myproc[10]: %% It's\n time to make the do-nuts. %% Ingredients: Mix=OK, Jelly=OK #\n"
+ + " Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + " Conveyer1=OK, Conveyer2=OK # %%";
+
+ @Test
+ public void testSendingRawUDP() throws IOException, InterruptedException {
+
+ MockEndpoint mock = getMockEndpoint("mock:syslogReceiver");
+ MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
+ mock.expectedMessageCount(1);
+ mock2.expectedMessageCount(1);
+ mock2.expectedBodiesReceived(message);
+ DatagramSocket ds = new DatagramSocket();
+
+ DatagramSocket socket = new DatagramSocket();
+ try {
+ InetAddress address = InetAddress.getByName("127.0.0.1");
+ for (int i = 0; i < messageCount; i++) {
+
+ byte[] data = message.getBytes();
+
+ DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+ socket.send(packet);
+ Thread.sleep(100);
+ }
+ } finally {
+ socket.close();
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
+ //context.setTracing(true);
+ DataFormat syslogDataFormat = new Rfc3164SyslogDataFormat();
+
+ // we setup a Syslog listener on a random port.
+ from("mina:udp://127.0.0.1:" + serverPort).unmarshal(syslogDataFormat).process(new Processor() {
+ public void process(Exchange ex) {
+ assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
+ }
+ }).to("mock:syslogReceiver").
+ marshal(syslogDataFormat).to("mock:syslogReceiver2");
+ }
+ };
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ Option[] options = options(
+
+ // install the spring dm profile
+ profile("spring.dm").version("1.2.0"),
+ // this is how you set the default log level when using pax logging (logProfile)
+ org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // using the features to install the camel components
+ scanFeatures(getCamelKarafFeatureUrl(), "camel-core", "camel-test", "camel-mina", "camel-syslog"),
+
+ workingDirectory("target/paxrunner/"),
+
+ felix(), equinox());
+
+ return options;
+ }
+}
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/syslog/SyslogTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date