/data/test/scala/6fece33916d5900c7271d9e97e65fea980a85173BasicMongoTest.scala

https://github.com/aliostad/deep-learning-lang-detection · Scala · 65 lines · 54 code · 11 blank · 0 comment · 1 complexity · 9dde79009641777c40e4fe6a7a8366c3 MD5 · raw file

  1. package test.mongodb
  2. import com.mongodb.casbah.Imports._
  3. import org.scalatest.FeatureSpec
  4. class BasicMongoSpec extends FeatureSpec {
  5. var mongoDB: MongoCollection = _
  6. feature("Basic database operations") {
  7. scenario("a simple database is created") {
  8. val mongoClient = MongoClient()
  9. mongoDB = mongoClient("casbah_test")("test_data")
  10. assert(mongoDB.size === 0)
  11. }
  12. scenario("an entry is added to the database using DBObject mappings") {
  13. val newObj =
  14. MongoDBObject(
  15. "foo" -> "bar",
  16. "x" -> "y",
  17. "pie" -> 3.14,
  18. "spam" -> "eggs"
  19. )
  20. newObj += "coolfactor" -> (9001: java.lang.Integer)
  21. val oldLength = mongoDB.size
  22. mongoDB += newObj
  23. assert(mongoDB.size === oldLength + 1)
  24. }
  25. scenario("an entry is added to the database using builders") {
  26. val builder = MongoDBObject.newBuilder
  27. builder += "foo" -> "baz"
  28. builder += "x" -> "z"
  29. builder += "pie" -> 3.14
  30. builder += ("spam" -> "green", "something else" -> "something cool")
  31. val oldLength = mongoDB.size
  32. mongoDB += builder.result
  33. assert(mongoDB.size === oldLength + 1)
  34. }
  35. scenario("an entry with a unique field is queried from the database") {
  36. val foundItems = mongoDB.find(MongoDBObject("x" -> "y"))
  37. assert(foundItems.length === 1)
  38. }
  39. scenario("multiple entries with common fields are queried from the database") {
  40. val foundItems = mongoDB.find(MongoDBObject("pie" -> 3.14))
  41. assert(foundItems.length === 2)
  42. }
  43. scenario("one entry is removed from the database") {
  44. val oldLength = mongoDB.size
  45. for (entry <- mongoDB.find(MongoDBObject("x" -> "y")))
  46. mongoDB -= entry
  47. assert(mongoDB.size === oldLength - 1)
  48. }
  49. scenario("the simple database is deleted") {
  50. mongoDB.dropCollection()
  51. assert(mongoDB.size === 0)
  52. }
  53. }
  54. }