Skip to content

Commit

Permalink
Make GenericDAO actually generic. (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcoperez authored Mar 3, 2017
1 parent 2158028 commit 7f942aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
*/
package com.stratio.common.utils.components.dao

import com.stratio.common.utils.components.config.ConfigComponent
import com.stratio.common.utils.components.logger.LoggerComponent
import com.stratio.common.utils.components.repository.impl.ZookeeperRepositoryComponent
import org.json4s.{Formats, DefaultFormats}
import com.stratio.common.utils.components.repository.RepositoryComponent
import org.json4s.{DefaultFormats, Formats}
import org.json4s.jackson.Serialization._

trait GenericDAOComponent[M <: AnyRef] extends DAOComponent[String, Array[Byte], M]
with ZookeeperRepositoryComponent {

self: ConfigComponent with LoggerComponent =>
trait GenericDAOComponent[M <: AnyRef] extends DAOComponent[String, Array[Byte], M] {
self: RepositoryComponent[String, Array[Byte]] =>

val dao: DAO = new GenericDAO()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.stratio.common.utils.integration
import com.stratio.common.utils.components.config.impl.TypesafeConfigComponent
import com.stratio.common.utils.components.dao.GenericDAOComponent
import com.stratio.common.utils.components.logger.impl.Slf4jLoggerComponent
import com.stratio.common.utils.components.repository.impl.ZookeeperRepositoryComponent
import org.apache.curator.test.TestingServer
import org.apache.curator.utils.CloseableUtils
import org.junit.runner.RunWith
Expand Down Expand Up @@ -55,30 +56,33 @@ class ZookeeperIntegrationTest extends WordSpec

"A dao component" should {

"save a dummy in ZK and get it" in new DummyDAOComponent {
dao.create("test1", new Dummy("value"))
val component = new DummyZookeeperDAOComponent
import component.dao

"save a dummy in ZK and get it" in {
dao.create("test1", Dummy("value"))
dao.get("test1") should be(Success(Some(Dummy("value"))))
}

"update the dummy in ZK and get it" in new DummyDAOComponent {
dao.update("test1", new Dummy("newValue"))
"update the dummy in ZK and get it" in {
dao.update("test1", Dummy("newValue"))
dao.get("test1") should be(Success(Some(Dummy("newValue"))))
}

"upser the dummy in ZK and get it" in new DummyDAOComponent {
dao.upsert("test1", new Dummy("newValue"))
"upser the dummy in ZK and get it" in {
dao.upsert("test1", Dummy("newValue"))
dao.get("test1") should be(Success(Some(Dummy("newValue"))))
dao.upsert("test1", new Dummy("newValue2"))
dao.upsert("test1", Dummy("newValue2"))
dao.get("test1") should be(Success(Some(Dummy("newValue2"))))
}

"delete the dummy in ZK and get it with a None result" in new DummyDAOComponent {
"delete the dummy in ZK and get it with a None result" in {
dao.delete("test1")
dao.exists("test1") should be (Success(false))
}

"save a dummy in ZK and delete all" in new DummyDAOComponent {
dao.create("test1", new Dummy("value"))
"save a dummy in ZK and delete all" in {
dao.create("test1", Dummy("value"))
dao.get("test1") should be(Success(Some(Dummy("value"))))
dao.deleteAll
dao.exists("test1") should be (Success(false))
Expand All @@ -87,10 +91,13 @@ class ZookeeperIntegrationTest extends WordSpec
}
}


trait DummyDAOComponent extends GenericDAOComponent[Dummy] with TypesafeConfigComponent with Slf4jLoggerComponent {
class DummyZookeeperDAOComponent extends GenericDAOComponent[Dummy]
with ZookeeperRepositoryComponent
with TypesafeConfigComponent
with Slf4jLoggerComponent {

override val dao : DAO = new GenericDAO(Option("dummy"))

}

case class Dummy(property: String) {}

0 comments on commit 7f942aa

Please sign in to comment.