Преглед на файлове

Updated json test to output exact text required. Updated db test to output ints not floats.

sksamuel преди 11 години
родител
ревизия
bf47fef88a
променени са 2 файла, в които са добавени 9 реда и са изтрити 7 реда
  1. 1 1
      scruffy/src/main/scala/scruffy/examples/Test1Endpoint.scala
  2. 8 6
      scruffy/src/main/scala/scruffy/examples/Test2Endpoint.scala

+ 1 - 1
scruffy/src/main/scala/scruffy/examples/Test1Endpoint.scala

@@ -6,7 +6,7 @@ import com.sksamuel.scruffy.EndpointProvider
 class Test1Endpoint extends EndpointProvider {
 
   get("json").complete {
-    req => json(Message("Hello World"))
+    req => json(Message("Hello, World!"))
   }
 }
 

+ 8 - 6
scruffy/src/main/scala/scruffy/examples/Test2Endpoint.scala

@@ -7,20 +7,22 @@ import com.sksamuel.scruffy.EndpointProvider
 class Test2Endpoint(hostname: String) extends EndpointProvider {
 
   val connection = MongoConnection(hostname, 27017)
-  val collection = connection.getDB("world").getCollection("world")
+  val collection = connection.getDB("hello_world").getCollection("world")
 
   val random = new scala.util.Random(System.currentTimeMillis)
   val fields = DBObject("_id" -> true, "randomNumber" -> true)
 
-  // uncomment to populate
-  // for ( k <- 1 to 10000 )
-  //   collection.save(DBObject("_id" -> k, "id" -> k, "randomNumber" -> random.nextInt(10000)))
+  //uncomment to populate
+  for ( k <- 1 to 10000 )
+    collection.save(DBObject("_id" -> k, "id" -> k, "randomNumber" -> random.nextInt(10000).toDouble))
 
   get("db").json {
     req =>
       val id = random.nextInt(10000)
-      collection.findOne(DBObject("_id" -> id), fields)
+      val dbo = collection.findOne(DBObject("_id" -> id), fields)
+      val randomNumber = Math.round(dbo.get("randomNumber").toString.toFloat)
+      Output(id, randomNumber)
   }
 }
 
-
+case class Output(_id: Int, randomNumber: Int)