Skip to content

Commit 8023035

Browse files
committed
Test Updates
1 parent 1c0774d commit 8023035

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

src/test/scala/com/sfxcode/nosql/mongo/TestDatabase.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.sfxcode.nosql.mongo
22

33
import com.sfxcode.nosql.mongo.database.DatabaseProvider
44
import com.sfxcode.nosql.mongo.model._
5+
import com.sfxcode.nosql.mongo.operation.CrudObserver
56
import org.mongodb.scala._
67

78
object TestDatabase extends ObservableImplicits {
@@ -23,15 +24,15 @@ object TestDatabase extends ObservableImplicits {
2324

2425
class BookDocumentDAO extends MongoDAO[Document](database, "books")
2526

26-
object LineDAO extends MongoDAO[Line](database, "lines")
27+
object LineDAO extends MongoDAO[Line](database, "lines") with CrudObserver[Line]
2728

2829
object PersonDAO extends MongoDAO[Person](database, "person")
2930

3031
PersonDAO.dropResult()
3132

3233
val persons: List[Person] = Person.personList
3334

34-
PersonDAO.insertValuesResult(persons)
35+
PersonDAO.insertManyResult(persons)
3536

3637
def printDatabaseStatus(): Unit = {
3738
printDebugValues("Database Status", "%s rows for collection person found".format(PersonDAO.countResult()))

src/test/scala/com/sfxcode/nosql/mongo/demo/tour/QuickTour.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object QuickTour extends App {
1010

1111
val line = Line(1, "default", 3, Position(1, 3), Position(3, 7))
1212

13-
LineDAO.insert(line)
13+
LineDAO.insertOneResult(line)
1414

1515
printDebugValues("LineDAO.findAll", LineDAO.find())
1616

src/test/scala/com/sfxcode/nosql/mongo/demo/tour/TestTour.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object TestTour extends App {
2222

2323
assert(BookDAO.count().headResult() == 0)
2424

25-
BookDAO.insert(scalaBook)
25+
BookDAO.insertOneResult(scalaBook)
2626

2727
val books: List[Book] = BookDAO.find().resultList()
2828

src/test/scala/com/sfxcode/nosql/mongo/operation/AggregationSpec.scala

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
package com.sfxcode.nosql.mongo.operation
22

3-
import com.sfxcode.nosql.mongo._
4-
import com.sfxcode.nosql.mongo.Sort._
3+
// #agg_imports
54
import com.sfxcode.nosql.mongo.Field._
5+
import com.sfxcode.nosql.mongo.Filter._
6+
import com.sfxcode.nosql.mongo.Sort._
7+
import com.sfxcode.nosql.mongo._
8+
// #agg_imports
69

710
import com.sfxcode.nosql.mongo.TestDatabase._
8-
911
import org.mongodb.scala.bson.conversions.Bson
1012
import org.mongodb.scala.model.Aggregates.{ filter, group, sort }
11-
import org.mongodb.scala.model.Filters.equal
12-
13+
import org.mongodb.scala.model.Filters.{ and, equal }
1314
import org.specs2.mutable.{ Before, Specification }
1415

1516
class AggregationSpec extends Specification with Before {
1617

1718
sequential
1819

19-
val groupStage: Bson = group(Map("age" -> "$age"), sumField("balance"), firstField("age"))
20+
// #agg_stages
21+
val filterStage: Bson = filter(and(
22+
equal("gender", "female"),
23+
notNullFilter("balance")))
2024

21-
val filterStage: Bson = filter(equal("gender", "female"))
25+
val groupStage: Bson = group(
26+
Map("age" -> "$age"),
27+
sumField("balance"), firstField("age"))
2228

2329
val sortStage: Bson = sort(sortByKey("age"))
30+
// #agg_stages
2431

2532
"Search" should {
2633

@@ -35,15 +42,18 @@ class AggregationSpec extends Specification with Before {
3542
}
3643

3744
"support aggregation filter and group" in {
38-
45+
// #agg_execute
3946
val aggregator = List(filterStage, groupStage, sortStage)
4047

4148
val aggregated = PersonDAO.Raw.findAggregated(aggregator).resultList()
4249

50+
// #agg_execute
51+
4352
aggregated.size must be equalTo 21
4453

54+
// #agg_convert
4555
val list: List[Map[String, Any]] = aggregated
46-
56+
// #agg_convert
4757
list.foreach(m => println(m("age") + " -> " + m("balance")))
4858

4959
list.head("age") must be equalTo 20

src/test/scala/com/sfxcode/nosql/mongo/operation/BaseSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class BaseSpec extends Specification with BeforeAll {
1313
"Base Operations" should {
1414

1515
"count collection size in" in {
16-
BookDAO.insertResult(Book.scalaBook())
16+
BookDAO.insertOneResult(Book.scalaBook())
1717

1818
BookDAO.countResult() must be equalTo 1
1919

2020
val scalaBook = Book(Some(2), "Programming In Scala", 852, Author("Martin Odersky"), List(2, 4, 10))
2121

22-
BookDAO.insertResult(scalaBook)
22+
BookDAO.insertOneResult(scalaBook)
2323

2424
BookDAO.countResult() must be equalTo 2
2525

src/test/scala/com/sfxcode/nosql/mongo/operation/CrudSpec.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class CrudSpec extends Specification {
1313

1414
"create Documents in" in {
1515
LineDAO.dropResult()
16-
LineDAO.insertResult(Line.line())
16+
LineDAO.insertOneResult(Line.line())
1717
LineDAO.countResult() must be equalTo 1
1818

1919
}
2020

2121
"update Doduments" in {
2222
LineDAO.dropResult()
23-
LineDAO.insertResult(Line.line())
23+
LineDAO.insertOneResult(Line.line())
2424
LineDAO.countResult() must be equalTo 1
2525

2626
val line = LineDAO.find().headResult()
2727

2828
line.name must be equalTo "default"
2929

3030
line.name = "test"
31-
LineDAO.updateResult(line)
31+
LineDAO.replaceOneResult(line)
3232

3333
val line2 = LineDAO.find().headResult()
3434
line2.name must be equalTo "test"
@@ -37,10 +37,10 @@ class CrudSpec extends Specification {
3737

3838
"delete Documents in" in {
3939
LineDAO.dropResult()
40-
LineDAO.insertResult(Line.line(2))
40+
LineDAO.insertOneResult(Line.line(2))
4141
LineDAO.countResult() must be equalTo 1
4242
val line = LineDAO.find(Map("id" -> 2)).headResult()
43-
LineDAO.deleteByValueResult(line)
43+
LineDAO.deleteOneResult(line)
4444
LineDAO.countResult() must be equalTo 0
4545

4646
}

src/test/scala/com/sfxcode/nosql/mongo/operation/SearchSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.sfxcode.nosql.mongo.operation
22

33
import com.sfxcode.nosql.mongo.TestDatabase._
44
import com.sfxcode.nosql.mongo._
5+
import com.sfxcode.nosql.mongo.Sort._
56
import com.sfxcode.nosql.mongo.model.Person
67
import org.specs2.mutable.{ Before, Specification }
78

@@ -58,7 +59,7 @@ class SearchSpec extends Specification with Before {
5859

5960
"support findOne with Filter" in {
6061

61-
val females = PersonDAO.find(Map("gender" -> "female")).resultList()
62+
val females = PersonDAO.find(Map("gender" -> "female"), sortByKey("name")).resultList()
6263

6364
females.size must be equalTo 98
6465

src/test/scala/com/sfxcode/nosql/mongo/relation/RelationDemoDatabase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object RelationDemoDatabase {
1919
NodeDAO.parentRelation.removeFromCache(parentId)
2020
NodeDAO.childrenRelation.removeFromCache(node.id)
2121
val newNode = copy(parentId = node.id)
22-
NodeDAO.updateResult(newNode)
22+
NodeDAO.replaceOneResult(newNode)
2323
}
2424

2525
def children: List[Node] = {

src/test/scala/com/sfxcode/nosql/mongo/relation/RelationSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class RelationSpec extends Specification with Before {
5858

5959
val personList = Person.personList.take(10)
6060
personList.foreach(person => {
61-
UserDAO.insertResult(User(person.id, person.name, person.guid))
62-
LoginDAO.insertResult(Login(person.guid, person.email, person.email.reverse))
61+
UserDAO.insertOneResult(User(person.id, person.name, person.guid))
62+
LoginDAO.insertOneResult(Login(person.guid, person.email, person.email.reverse))
6363
person.friends.foreach(f => {
64-
FriendDAO.insertResult(Friend((person.id + 11) * (f.id + 3), f.name, person.id))
64+
FriendDAO.insertOneResult(Friend((person.id + 11) * (f.id + 3), f.name, person.id))
6565
})
6666
})
6767

0 commit comments

Comments
 (0)