Skip to content

Commit

Permalink
Fix tests for the server issue #8
Browse files Browse the repository at this point in the history
--Fix j-unit tests for mongospectodo

-Kyle
  • Loading branch information
fossx229 committed Feb 25, 2018
1 parent 0290a96 commit fb051d1
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions server/src/test/java/umm3601/mongotest/MongoSpecTodo.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,42 @@ public void justCategoryAndStausNoIdSortedByCategory() {
assertNull("First should not have '_id'", docs.get(0).get("_id"));
}

//come back to this test later


// @Test
// public void categoryCounts() {
// AggregateIterable<Document> documents
// = todoDocuments.aggregate(
// Arrays.asList(
// /*
// * Groups data by the "category" field, and then counts
// * the number of documents with each given category.
// * This creates a new "constructed document" that
// * has "category" as it's "_id", and the count as the
// * "categoryCount" field.
// */
// Aggregates.group("$category",
// Accumulators.sum("categoryCount", 1)),
// Aggregates.sort(Sorts.ascending("_id"))
// )
// );
// List<Document> docs = intoList(documents);
// assertEquals("Should be two distinct ages", 2, docs.size());
// assertEquals(docs.get(0).get("_id"), 25);
// assertEquals(docs.get(0).get("ageCount"), 1);
// assertEquals(docs.get(1).get("_id"), 37);
// assertEquals(docs.get(1).get("ageCount"), 2);
// }



@Test
public void categoryCounts() {
AggregateIterable<Document> documents
= todoDocuments.aggregate(
Arrays.asList(
/*
* Groups data by the "category" field, and then counts
* the number of documents with each given category.
* This creates a new "constructed document" that
has "category" as it's "_id", and the count as the
* "categoryCount" field. *
*/
Aggregates.group("$category",
Accumulators.sum("categoryCount", 1)),
Aggregates.sort(Sorts.ascending("_id"))
)
);





List<Document> docs = intoList(documents);

assertEquals("Should be two distinct documents", 2, docs.size());

assertEquals(docs.get(0).get("categoryCount"), 2);

assertEquals(docs.get(1).get("categoryCount"), 1);
assertEquals(docs.get(0).get("_id"), "homework");

assertEquals(docs.get(1).get("_id"), "software design");
}



Expand Down

0 comments on commit fb051d1

Please sign in to comment.