From b9195e3a2b206bb65bf61b412371cf07858d5450 Mon Sep 17 00:00:00 2001 From: David Arroyo Cazorla Date: Wed, 21 Dec 2016 12:35:11 +0100 Subject: [PATCH] [DCS-231] DAO interface should not hide underlying exceptions (#50) --- .../utils/components/dao/DAOComponent.scala | 28 ++++---- .../repository/RepositoryComponent.scala | 22 +++--- .../impl/ZookeeperRepositoryComponent.scala | 65 ++++++++--------- .../common/utils/functional/TryUtils.scala | 31 +++++++++ .../components/dao/DaoComponentTest.scala | 12 ++-- .../repository/DummyRepositoryComponent.scala | 69 +++++++++---------- .../repository/RepositoryComponentTest.scala | 52 +++++++------- .../utils/functional/TryUtilsTest.scala | 42 +++++++++++ .../utils/integration/ZookeeperTest.scala | 18 ++--- 9 files changed, 212 insertions(+), 127 deletions(-) create mode 100644 src/main/scala/com/stratio/common/utils/functional/TryUtils.scala create mode 100644 src/test/scala/com/stratio/common/utils/functional/TryUtilsTest.scala diff --git a/src/main/scala/com/stratio/common/utils/components/dao/DAOComponent.scala b/src/main/scala/com/stratio/common/utils/components/dao/DAOComponent.scala index 06ce0a9..546d9d4 100644 --- a/src/main/scala/com/stratio/common/utils/components/dao/DAOComponent.scala +++ b/src/main/scala/com/stratio/common/utils/components/dao/DAOComponent.scala @@ -17,6 +17,8 @@ package com.stratio.common.utils.components.dao import com.stratio.common.utils.components.repository.RepositoryComponent +import scala.util.Try + trait DAOComponent[K, V, M] { self: RepositoryComponent[K, V] => @@ -24,31 +26,31 @@ trait DAOComponent[K, V, M] { trait DAO { - def get(id: K) (implicit manifest: Manifest[M]): Option[M] = - repository.get(entity, id).map(entity => fromVtoM(entity)) + def get(id: K) (implicit manifest: Manifest[M]): Try[Option[M]] = + repository.get(entity, id).map(_.map(entity => fromVtoM(entity))) - def getAll() (implicit manifest: Manifest[M]): List[M] = - repository.getAll(entity).map(fromVtoM(_)) + def getAll() (implicit manifest: Manifest[M]): Try[Seq[M]] = + repository.getAll(entity).map(_.map(fromVtoM)) - def count(): Long = + def count(): Try[Long] = repository.count(entity) - def exists(id: K): Boolean = + def exists(id: K): Try[Boolean] = repository.exists(entity, id) - def create(id: K, element: M) (implicit manifest: Manifest[M]): M = - fromVtoM(repository.create(entity, id, fromMtoV(element))) + def create(id: K, element: M) (implicit manifest: Manifest[M]): Try[M] = + repository.create(entity, id, fromMtoV(element)).map(fromVtoM) - def update(id: K, element: M) (implicit manifest: Manifest[M]): Unit = + def update(id: K, element: M) (implicit manifest: Manifest[M]): Try[Unit] = repository.update(entity, id, fromMtoV(element)) - def upsert(id: K, element: M) (implicit manifest: Manifest[M]): M = - fromVtoM(repository.upsert(entity, id, fromMtoV(element))) + def upsert(id: K, element: M) (implicit manifest: Manifest[M]): Try[M] = + repository.upsert(entity, id, fromMtoV(element)).map(fromVtoM) - def delete(id: K): Unit = + def delete(id: K): Try[Unit] = repository.delete(entity, id) - def deleteAll: Unit = + def deleteAll: Try[Unit] = repository.deleteAll(entity) def entity: String diff --git a/src/main/scala/com/stratio/common/utils/components/repository/RepositoryComponent.scala b/src/main/scala/com/stratio/common/utils/components/repository/RepositoryComponent.scala index 646a5cb..68b3b4e 100644 --- a/src/main/scala/com/stratio/common/utils/components/repository/RepositoryComponent.scala +++ b/src/main/scala/com/stratio/common/utils/components/repository/RepositoryComponent.scala @@ -15,30 +15,32 @@ */ package com.stratio.common.utils.components.repository +import scala.util.Try + trait RepositoryComponent[K, V] { val repository: Repository trait Repository { - def get(entity: String, id: K): Option[V] + def get(entity: String, id: K): Try[Option[V]] - def getAll(entity: String): List[V] + def getAll(entity: String): Try[Seq[V]] - def getNodes(entity: String): List[K] + def getNodes(entity: String): Try[Seq[K]] - def count(entity: String): Long + def count(entity: String): Try[Long] - def exists(entity: String, id: K): Boolean + def exists(entity: String, id: K): Try[Boolean] - def create(entity: String, id: K, element: V): V + def create(entity: String, id: K, element: V): Try[V] - def upsert(entity: String, id: K, element: V): V + def upsert(entity: String, id: K, element: V): Try[V] - def update(entity: String, id: K, element: V): Unit + def update(entity: String, id: K, element: V): Try[Unit] - def delete(entity: String, id: K): Unit + def delete(entity: String, id: K): Try[Unit] - def deleteAll(entity: String): Unit + def deleteAll(entity: String): Try[Unit] } } diff --git a/src/main/scala/com/stratio/common/utils/components/repository/impl/ZookeeperRepositoryComponent.scala b/src/main/scala/com/stratio/common/utils/components/repository/impl/ZookeeperRepositoryComponent.scala index 695a194..588df48 100644 --- a/src/main/scala/com/stratio/common/utils/components/repository/impl/ZookeeperRepositoryComponent.scala +++ b/src/main/scala/com/stratio/common/utils/components/repository/impl/ZookeeperRepositoryComponent.scala @@ -15,7 +15,6 @@ */ package com.stratio.common.utils.components.repository.impl -import java.util.NoSuchElementException import java.util.concurrent.ConcurrentHashMap import com.stratio.common.utils.components.config.ConfigComponent @@ -31,6 +30,8 @@ import org.json4s.jackson.Serialization.read import scala.collection.JavaConversions._ import scala.util.{Failure, Success, Try} import com.stratio.common.utils.components.repository.impl.ZookeeperRepositoryComponent._ +import com.stratio.common.utils.functional.TryUtils + trait ZookeeperRepositoryComponent extends RepositoryComponent[String, Array[Byte]] { self: ConfigComponent with LoggerComponent => @@ -42,67 +43,69 @@ trait ZookeeperRepositoryComponent extends RepositoryComponent[String, Array[Byt private def curatorClient: CuratorFramework = ZookeeperRepository.getInstance(getZookeeperConfig) - def get(entity: String, id: String): Option[Array[Byte]] = + def get(entity: String, id: String): Try[Option[Array[Byte]]] = Try(Option(curatorClient .getData - .forPath(s"/$entity/$id"))).getOrElse(None) + .forPath(s"/$entity/$id"))) + + def getAll(entity: String): Try[Seq[Array[Byte]]] = { - def getAll(entity: String): List[Array[Byte]] = Try(curatorClient .getChildren - .forPath(s"/$entity").map(get(entity, _).get).toList).getOrElse(List.empty[Array[Byte]]) + .forPath(s"/$entity")).flatMap(entityIds => + TryUtils.sequence(entityIds.map(get(entity, _).map(_.get))) + ) + } + - def getNodes(entity: String): List[String] = + def getNodes(entity: String): Try[Seq[String]] = Try(curatorClient .getChildren - .forPath(s"/$entity").toList).getOrElse(List.empty[String]) + .forPath(s"/$entity")) - def count(entity: String): Long = + def count(entity: String): Try[Long] = Try(curatorClient .getChildren - .forPath(s"/$entity").size.toLong).getOrElse(0L) + .forPath(s"/$entity").size.toLong) - def exists(entity: String, id: String): Boolean = + def exists(entity: String, id: String): Try[Boolean] = Try(Option(curatorClient .checkExists() .forPath(s"/$entity/$id")) - ).getOrElse(None).isDefined + ).map(_.isDefined) - def create(entity: String, id: String, element: Array[Byte]): Array[Byte] = { - Try(curatorClient - .create() - .creatingParentsIfNeeded() - .forPath(s"/$entity/$id", element)) + def create(entity: String, id: String, element: Array[Byte]): Try[Array[Byte]] = + Try( + curatorClient + .create() + .creatingParentsIfNeeded() + .forPath(s"/$entity/$id", element) + ).flatMap( _ => get(entity, id).map(_.get)) - get(entity, id) - .getOrElse(throw new NoSuchElementException(s"Something were wrong when retrieving element $id after create")) - } - def upsert(entity: String, id: String, element: Array[Byte]): Array[Byte] = - if (!exists(entity, id)) create(entity, id, element) - else { - update(entity, id, element) - get(entity, id) - .getOrElse(throw new NoSuchElementException(s"Something were wrong when retrieving element $id after create")) + def upsert(entity: String, id: String, element: Array[Byte]): Try[Array[Byte]] = + exists(entity, id).flatMap { + case false => create(entity, id, element) + case true => update(entity, id, element).flatMap(_ => get(entity, id).map(_.get)) } - def update(entity: String, id: String, element: Array[Byte]): Unit = + def update(entity: String, id: String, element: Array[Byte]): Try[Unit] = Try(curatorClient .setData() .forPath(s"/$entity/$id", element) - ).getOrElse(throw new ZookeeperRepositoryException(s"Something were wrong when updating element $id")) + ) - def delete(entity: String, id: String): Unit = + def delete(entity: String, id: String): Try[Unit] = Try(curatorClient .delete() .forPath(s"/$entity/$id") - ).getOrElse(throw new ZookeeperRepositoryException(s"Something were wrong when deleting element $id")) + ) - def deleteAll(entity: String): Unit = + def deleteAll(entity: String): Try[Unit] = Try(curatorClient .delete().deletingChildrenIfNeeded() .forPath(s"/$entity") - ).getOrElse(throw new ZookeeperRepositoryException(s"Something were wrong when deleting all")) + ) def getZookeeperConfig: Config = { config.getConfig(path.getOrElse(ConfigZookeeper)) diff --git a/src/main/scala/com/stratio/common/utils/functional/TryUtils.scala b/src/main/scala/com/stratio/common/utils/functional/TryUtils.scala new file mode 100644 index 0000000..bbff04f --- /dev/null +++ b/src/main/scala/com/stratio/common/utils/functional/TryUtils.scala @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Stratio (http://stratio.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.stratio.common.utils.functional + +import scala.util.{Failure, Success, Try} + +object TryUtils { + + def sequence[T](s: Seq[Try[T]]): Try[Seq[T]] = { + def recSequence(s: Seq[Try[T]], acc: Seq[T]): Try[Seq[T]] = + s.headOption map { + case Failure(cause) => Failure(cause) + case Success(v) => recSequence(s.tail, v +: acc) + } getOrElse Success(acc reverse) + recSequence(s, Seq.empty) + } + +} diff --git a/src/test/scala/com/stratio/common/utils/components/dao/DaoComponentTest.scala b/src/test/scala/com/stratio/common/utils/components/dao/DaoComponentTest.scala index 78a441d..50022ce 100644 --- a/src/test/scala/com/stratio/common/utils/components/dao/DaoComponentTest.scala +++ b/src/test/scala/com/stratio/common/utils/components/dao/DaoComponentTest.scala @@ -19,6 +19,8 @@ import com.stratio.common.utils.components.repository.DummyRepositoryComponent import org.json4s.DefaultFormats import org.scalatest.{Matchers, WordSpec} +import scala.util.{Success, Try} + class DaoComponentTest extends WordSpec with Matchers { trait DummyDAOComponentContext extends DummyDAOComponent { @@ -40,11 +42,11 @@ class DaoComponentTest extends WordSpec with Matchers { "check if a value exists" should { "return true if the value exists" in new DummyDAOComponentContext { - dao.exists("key1") should be(true) + dao.exists("key1") should matchPattern {case Success(true) => } } "return false if the value doesn't exist" in new DummyDAOComponentContext { - dao.exists("keyNotFound") should be(false) + dao.exists("keyNotFound") should matchPattern {case Success(false) => } } } @@ -72,7 +74,7 @@ class DaoComponentTest extends WordSpec with Matchers { "return false if the operation is not successful" in new DummyDAOComponentContext { dao.delete("keyNotFound") - dao.getAll().size should be(3) + dao.getAll().map(_.size) should matchPattern {case Success(3) => } } } @@ -86,7 +88,7 @@ class DaoComponentTest extends WordSpec with Matchers { "return false if the operation is not successful" in new DummyDAOComponentContext { dao.update("keyNotFound", DummyModel("newValue")) - dao.getAll().size should be(3) + dao.getAll().map(_.size) should matchPattern {case Success(3) => } } } @@ -104,7 +106,7 @@ class DaoComponentTest extends WordSpec with Matchers { "return false if the operation is not successful" in new DummyDAOComponentContext { dao.update("keyNotFound", DummyModel("newValue")) - dao.getAll().size should be(3) + dao.getAll().map(_.size) should matchPattern {case Success(3) => } } } diff --git a/src/test/scala/com/stratio/common/utils/components/repository/DummyRepositoryComponent.scala b/src/test/scala/com/stratio/common/utils/components/repository/DummyRepositoryComponent.scala index 49b356c..6b4225f 100644 --- a/src/test/scala/com/stratio/common/utils/components/repository/DummyRepositoryComponent.scala +++ b/src/test/scala/com/stratio/common/utils/components/repository/DummyRepositoryComponent.scala @@ -16,6 +16,7 @@ package com.stratio.common.utils.components.repository import scala.collection.mutable +import scala.util.{Failure, Success, Try} trait DummyRepositoryComponent extends RepositoryComponent[String, String] { @@ -32,55 +33,49 @@ trait DummyRepositoryComponent extends RepositoryComponent[String, String] { class DummyRepository() extends Repository { - def get(entity:String, id: String): Option[String] = - memoryMap.get(entity).flatMap(_.get(id)) + def get(entity: String, id: String): Try[Option[String]] = + Try(memoryMap.get(entity).flatMap(_.get(id))) - def getAll(entity:String): List[String] = - memoryMap.get(entity) match { - case Some(map: mutable.Map[String,String]) => { - map.values.toList.sortBy(x => x) - } - case _ => List.empty[String] - } + def getAll(entity: String): Try[Seq[String]] = + Try(memoryMap.get(entity).map(_.values.toList.sortBy(identity)).getOrElse(Seq.empty)) - def getNodes(entity:String): List[String] = - memoryMap.get(entity) match { - case Some(map: mutable.Map[String,String]) => { - map.keys.toList.sortBy(x => x) - } - case _ => List.empty[String] - } + def getNodes(entity: String): Try[Seq[String]] = + Try(memoryMap.get(entity).map(_.keys.toList.sortBy(identity)).getOrElse(Seq.empty)) - def count(entity: String): Long = - memoryMap.get(entity) match { - case Some(value) => value.size - case None => 0 - } + def count(entity: String): Try[Long] = + Try(memoryMap.get(entity).map(_.size).getOrElse(0).toLong) - def exists(entity:String, id: String): Boolean = - memoryMap.get(entity) match { - case Some(value) => value.get(id).isDefined - case None => false - } + def exists(entity: String, id: String): Try[Boolean] = + Try(memoryMap.exists { case (key, entityMap) => + key == entity && entityMap.keys.toList.contains(id) + }) - def create(entity:String, id: String, element: String): String = { - if (!exists(entity, id)) { - memoryMap.put(entity, mutable.Map(id -> element)) + def create(entity:String, id: String, element: String): Try[String] = { + exists(entity, id).foreach { + case false => memoryMap.put(entity, mutable.Map(id -> element)) + case true => () } - element + Success(element) } - override def upsert(entity: String, id: String, element: String): String = { + override def upsert(entity: String, id: String, element: String): Try[String] = { memoryMap.put(entity, mutable.Map(id -> element)) - element + Success(element) } - def update(entity:String, id: String, element: String): Unit = - if (exists(entity, id)) memoryMap.put(entity, mutable.Map(id -> element)) + def update(entity: String, id: String, element: String): Try[Unit] = + exists(entity, id).map { + case false => () + case true => memoryMap.put(entity, mutable.Map(id -> element)) + } - def delete(entity:String, id: String): Unit = - if (exists(entity, id)) memoryMap.get(entity).get.remove(id) + def delete(entity:String, id: String): Try[Unit] = { + exists(entity, id).map{ + case false => () + case true => memoryMap(entity).remove(id) + } + } - def deleteAll(entity:String): Unit = memoryMap.remove(entity) + def deleteAll(entity:String): Try[Unit] = Try(memoryMap.remove(entity)) } } diff --git a/src/test/scala/com/stratio/common/utils/components/repository/RepositoryComponentTest.scala b/src/test/scala/com/stratio/common/utils/components/repository/RepositoryComponentTest.scala index 2ec710b..245eba8 100644 --- a/src/test/scala/com/stratio/common/utils/components/repository/RepositoryComponentTest.scala +++ b/src/test/scala/com/stratio/common/utils/components/repository/RepositoryComponentTest.scala @@ -19,9 +19,11 @@ import org.junit.runner.RunWith import org.scalatest._ import org.scalatest.junit.JUnitRunner +import scala.util.Success + @RunWith(classOf[JUnitRunner]) class RepositoryComponentTest extends WordSpec - with Matchers { + with Matchers with Inside{ trait DummyRepositoryContext extends DummyRepositoryComponent @@ -33,98 +35,102 @@ class RepositoryComponentTest extends WordSpec "get an element" should { "return an option with the value if the key exists" in new DummyRepositoryContext { - repository.get(Entity, "key1") should be(Some("value1")) + repository.get(Entity, "key1") should be(Success(Some("value1"))) } "return None if the key doesn't exist" in new DummyRepositoryContext { - repository.get(Entity, keyNotFound) should be(None) + repository.get(Entity, keyNotFound) should be(Success(None)) } } "getAll elements" should { "return all elements if the operation is successful" in new DummyRepositoryContext { - repository.getAll(Entity) should be(List("value1", "value2", "value3")) + inside(repository.getAll(Entity)) { case Success(list) => + list should have length 3 + list should contain allOf ("value1", "value2", "value3") + } + } "return and empty list if the operation is not successful" in new DummyRepositoryContext { - repository.getAll(keyNotFound) should be(List.empty[String]) + repository.getAll(keyNotFound) should be(Success(List.empty[String])) } } "getNodes elements" should { "return all nodes if the operation is successful" in new DummyRepositoryContext { - repository.getNodes(Entity) should be(List("key1", "key2", "key3")) + repository.getNodes(Entity) should be(Success(List("key1", "key2", "key3"))) } "return and empty list if the operation is not successful" in new DummyRepositoryContext { - repository.getNodes(keyNotFound) should be(List.empty[String]) + repository.getNodes(keyNotFound) should be(Success(List.empty[String])) } } "check if a value exists" should { "return true if the value exists" in new DummyRepositoryContext { - repository.exists(Entity, "key1") should be(true) + repository.exists(Entity, "key1") should be (Success(true)) } "return false if the value doesn't exist" in new DummyRepositoryContext { - repository.exists(Entity, keyNotFound) should be(false) + repository.exists(Entity, keyNotFound) should be (Success(false)) } } "create a new value" should { "return true if the operation is successful" in new DummyRepositoryContext { - repository.get(Entity, keyNotFound) should be(None) - repository.create(Entity, keyNotFound, "newValue") should be("newValue") - repository.get(Entity, keyNotFound) should be(Some("newValue")) + repository.get(Entity, keyNotFound) should be(Success(None)) + repository.create(Entity, keyNotFound, "newValue") should be(Success("newValue")) + repository.get(Entity, keyNotFound) should be(Success(Some("newValue"))) } "return false if the operation is not successful" in new DummyRepositoryContext { - repository.create(Entity, "key1", "newValue") should be("newValue") - repository.count(Entity) should be(3) + repository.create(Entity, "key1", "newValue") should be(Success("newValue")) + repository.count(Entity) should be(Success(3)) } } "remove a value" should { "check that the element does not exist when it has been removed" in new DummyRepositoryContext { - repository.get(Entity, "key1") should be(Some("value1")) + repository.get(Entity, "key1") should be(Success(Some("value1"))) repository.delete(Entity, "key1") - repository.get(Entity, "key1") should be(None) + repository.get(Entity, "key1") should be(Success(None)) } "do anything when a not existing element is removed" in new DummyRepositoryContext { repository.delete(Entity, keyNotFound) - repository.count(Entity) should be(3) + repository.count(Entity) should be(Success(3)) } } "remove all values" should { "check that the element does not exist when it has been removed all" in new DummyRepositoryContext { - repository.get(Entity, "key1") should be(Some("value1")) + repository.get(Entity, "key1") should be(Success(Some("value1"))) repository.deleteAll(Entity) - repository.get(Entity, "key1") should be(None) + repository.get(Entity, "key1") should be(Success(None)) } "do anything when a not existing element is removed all" in new DummyRepositoryContext { repository.deleteAll(Entity) - repository.count(Entity) should be(0) + repository.count(Entity) should be(Success(0)) } } "update a value" should { "check that the element has been updated with the new value" in new DummyRepositoryContext { - repository.get(Entity, "key1") should be(Some("value1")) + repository.get(Entity, "key1") should be(Success(Some("value1"))) repository.update(Entity, "key1", "newValue") - repository.get(Entity, "key1") should be(Some("newValue")) + repository.get(Entity, "key1") should be(Success(Some("newValue"))) } "do anything when a not existing element is updated" in new DummyRepositoryContext { repository.update(Entity, keyNotFound, "newValue") - repository.count(Entity) should be(3) + repository.count(Entity) should be(Success(3)) } } } diff --git a/src/test/scala/com/stratio/common/utils/functional/TryUtilsTest.scala b/src/test/scala/com/stratio/common/utils/functional/TryUtilsTest.scala new file mode 100644 index 0000000..cebf03e --- /dev/null +++ b/src/test/scala/com/stratio/common/utils/functional/TryUtilsTest.scala @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 Stratio (http://stratio.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.stratio.common.utils.functional + +import org.scalatest.{FlatSpec, Inside, Matchers} + +import scala.util.{Failure, Success} + +class TryUtilsTest extends FlatSpec with Matchers with Inside{ + + val exception = new Exception("Error") + + behavior of "Try" + + it should "allow transforming a Seq[Try[A]] containing a Failure into a Failure" in { + + TryUtils.sequence(Seq(Success(1), Failure(exception))) shouldBe a[Failure[_]] + + } + + it should "allow transforming a Seq[Try[A]] without failures into a Success[Seq[A]]" in { + + inside(TryUtils.sequence(Seq(Success(1), Success(2)))) { + case Success(seq) => seq should contain theSameElementsInOrderAs Seq(1,2) + } + + } + +} \ No newline at end of file diff --git a/src/test/scala/com/stratio/common/utils/integration/ZookeeperTest.scala b/src/test/scala/com/stratio/common/utils/integration/ZookeeperTest.scala index 07e7561..38c5d1f 100644 --- a/src/test/scala/com/stratio/common/utils/integration/ZookeeperTest.scala +++ b/src/test/scala/com/stratio/common/utils/integration/ZookeeperTest.scala @@ -24,6 +24,8 @@ import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec} +import scala.util.{Failure, Success} + @RunWith(classOf[JUnitRunner]) class ZookeeperIntegrationTest extends WordSpec with Matchers @@ -55,32 +57,32 @@ class ZookeeperIntegrationTest extends WordSpec "save a dummy in ZK and get it" in new DummyDAOComponent { dao.create("test1", new Dummy("value")) - dao.get("test1") should be(Some(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")) - dao.get("test1") should be(Some(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")) - dao.get("test1") should be(Some(Dummy("newValue"))) + dao.get("test1") should be(Success(Some(Dummy("newValue")))) dao.upsert("test1", new Dummy("newValue2")) - dao.get("test1") should be(Some(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 { dao.delete("test1") - dao.exists("test1") should be(false) + dao.exists("test1") should be (Success(false)) } "save a dummy in ZK and delete all" in new DummyDAOComponent { dao.create("test1", new Dummy("value")) - dao.get("test1") should be(Some(Dummy("value"))) + dao.get("test1") should be(Success(Some(Dummy("value")))) dao.deleteAll - dao.exists("test1") should be(false) - dao.count() should be(0) + dao.exists("test1") should be (Success(false)) + dao.count() shouldBe a[Failure[_]] } } }