Add Camel tests just to be there in history
authorChristos KK Loverdos <loverdos@gmail.com>
Tue, 6 Dec 2011 13:09:16 +0000 (15:09 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Tue, 6 Dec 2011 13:09:16 +0000 (15:09 +0200)
logic/src/main/scala/gr/grnet/aquarium/rest/akka/service/CamelPingService.scala [new file with mode: 0644]
logic/src/test/scala/gr/grnet/aquarium/LogicTestsAssumptions.scala
logic/src/test/scala/gr/grnet/aquarium/PropertyNames.scala
logic/src/test/scala/gr/grnet/aquarium/rest/akka/service/CamelPingServiceTest.scala [new file with mode: 0644]

diff --git a/logic/src/main/scala/gr/grnet/aquarium/rest/akka/service/CamelPingService.scala b/logic/src/main/scala/gr/grnet/aquarium/rest/akka/service/CamelPingService.scala
new file mode 100644 (file)
index 0000000..c1b0352
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.rest.akka.service
+
+import akka.actor.Actor
+import akka.camel.Consumer
+import org.apache.camel.Message
+import scala.collection.JavaConversions._
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class CamelPingService(val host: String, val port: Int, path: String) extends Actor with Consumer {
+  def endpointUri = "jetty:http://%s:%s%s".format(host, port, path)
+
+  protected def receive = {
+    case message: Message =>
+      val theReply = "pong %s %s".format(System.currentTimeMillis(), message.getClass.getName)
+      println("++ MessageID: %s".format(message.getMessageId))
+      println("+++ HEADERS +++")
+      for((k, v) <- message.getHeaders) {
+        println("  %s -> %s".format(k, v))
+      }
+      println("--- HEADERS ---")
+      println("++ BODY: %s".format(message.getBody))
+      println("++ REPLY: %s".format(theReply))
+      self reply theReply
+
+    case message: AnyRef =>
+      val theReply = "pong %s %s".format(System.currentTimeMillis(), message.getClass.getName)
+      println("++ REPLY: %s".format(theReply))
+      self reply theReply
+  }
+}
\ No newline at end of file
index 95e01c6..decb959 100644 (file)
@@ -66,4 +66,5 @@ object LogicTestsAssumptions {
   val EnableMongoDBTests  = testPropertyTrue(PropertyNames.TestEnableMongoDB)
   val EnablePerfTests = testPropertyTrue(PropertyNames.TestEnablePerf)
   val EnableSprayTests = testPropertyTrue(PropertyNames.TestEnableSpray)
+  val EnableCamelTests = testPropertyTrue(PropertyNames.TestEnableSpray)
 }
\ No newline at end of file
index 05dca13..b23de47 100644 (file)
@@ -46,6 +46,7 @@ object PropertyNames {
   val TestEnableMongoDB  = "test.enable.mongodb"
   val TestEnablePerf     = "test.enable.perf"
   val TestEnableSpray    = "test.enable.spray"
+  val TestEnableCamel    = "test.enable.camel"
 
   // Test configuration files used
   val MongoDBConfFile  = "mongodb.conf.file"
diff --git a/logic/src/test/scala/gr/grnet/aquarium/rest/akka/service/CamelPingServiceTest.scala b/logic/src/test/scala/gr/grnet/aquarium/rest/akka/service/CamelPingServiceTest.scala
new file mode 100644 (file)
index 0000000..dda9454
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.rest.akka.service
+
+import org.junit.Test
+import org.junit.Assume._
+import akka.actor.{ActorRef, Actor}
+import akka.camel.{Producer, Consumer, CamelServiceManager}
+import org.apache.camel.Message
+import org.apache.camel.impl.DefaultMessage
+import gr.grnet.aquarium.LogicTestsAssumptions
+
+class CamelPingClient(val host: String, val port: Int, path: String) extends Actor with Producer {
+  def endpointUri = "jetty:http://%s:%s%s".format(host, port, path)
+}
+
+/**
+ * 
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class CamelPingServiceTest {
+  @Test
+  def testPing: Unit = {
+    assumeTrue(LogicTestsAssumptions.EnableCamelTests)
+    val client = Actor.actorOf(new CamelPingClient("localhost", 9090, "/ping")).start()
+
+    CamelServiceManager.startCamelService
+    CamelServiceManager.mandatoryService.awaitEndpointActivation(1) {
+      Actor.actorOf(new CamelPingService("localhost", 9090, "/ping")).start()
+    }
+
+    val msg = new DefaultMessage
+    msg.setHeader("Header1", "Value1")
+    msg.setHeader("Header2", "Value2")
+    msg.setBody("{ yes: \"yes\"}")
+    client ! msg
+
+    Thread sleep 30000
+    CamelServiceManager.stopCamelService
+  }
+}
\ No newline at end of file