Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding a dao package and some simple trait that parallels the way I w…

…ould do this in Java.

The DAO package just has a simple "findAll()" funciton in its trait and the one implementing class is all just stubbed out right now, but this might be a good starting point for the kind of DAO functionality I'll want to write for this data loader.
  • Loading branch information...
commit f39aa0b3f8bfe9a1279e7ca83afe0892db0dfaba 1 parent 6bd7148
@tvaughan77 authored
View
16 mag_art_dl/src/main/scala/vaughan/dao/ArticleDAO.scala
@@ -0,0 +1,16 @@
+package vaughan.dao
+
+import vaughan.model.Article
+
+/**
+ * A DAO for Article objects
+ *
+ */
+trait ArticleDAO {
+
+ /**
+ * @return All articles from the underlying data source
+ */
+ def findAll(): List[Article]
+
+}
View
34 mag_art_dl/src/main/scala/vaughan/dao/ArticleMongoDAO.scala
@@ -0,0 +1,34 @@
+package vaughan.dao
+
+import vaughan.model.Article
+
+/**
+ * <p>A Mongo-backed DAO for Article objects</p>
+ * @author tom.vaughan
+ */
+object ArticleMongoDAO extends ArticleDAO {
+
+ val format = new java.text.SimpleDateFormat("yyyy-MM-dd")
+
+ val mockArticle1 = new Article("Cruising World",
+ format.parse("2012-02-01"),
+ 23,
+ "How to foo your bar",
+ "Describes what foos are best in bolstering your bar",
+ "",
+ List("foo","bar"))
+
+
+ val mockArticle2 = new Article("Sailing World",
+ format.parse("2011-12-15"),
+ 7,
+ "Lorem Ipsum",
+ "Whatever description you want goes here",
+ "These are my notes for this artcle",
+ List("bar","baz"))
+
+
+ def findAll(): List[Article] = {
+ List(mockArticle1, mockArticle2)
+ }
+}
View
16 mag_art_dl/src/test/scala/vaughan/dao/ArticleMongoDBSuite.scala
@@ -0,0 +1,16 @@
+package vaughan.dao
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.FunSuite
+import org.junit.Assert._
+import java.text.SimpleDateFormat
+
+
+@RunWith(classOf[JUnitRunner])
+class ArticleMongoDBSuite extends FunSuite {
+
+ test("Find all returns a couple mock articles") {
+ assertEquals(2, ArticleMongoDAO.findAll().size)
+ }
+}
View
1  mag_art_dl/src/test/scala/vaughan/model/ArticleSuite.scala
@@ -22,5 +22,6 @@ class ArticleSuite extends FunSuite {
"",
List("foo","bar"))
assertNotNull(myArticle)
+ assertEquals(2, myArticle.categories.size)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.