Skip to content

Instantly share code, notes, and snippets.

@agnaldo4j
Created November 6, 2012 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agnaldo4j/4027700 to your computer and use it in GitHub Desktop.
Save agnaldo4j/4027700 to your computer and use it in GitHub Desktop.
BDD, como ajuda para métrica de progresso
package persistence
import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
import models.nereida.{Restaurant, City, RestaurantSystem}
import persistence.commands.restaurant.{AddNewRestaurant, FindAllRestaurants, UpdateRestaurant, DeleteRestaurant, FindRestaurantById}
class PrevaylerRestaurantSpec extends Specification with PrevalentSystemWithCities {
"The Prevayler Restaurants" should {
deleteDatIfExists
prepareCities
"add new restaurant in system" ! prevalentSystemForTest().addNewRestaurant
"contains one restaurant in system" ! prevalentSystemForTest().containsOneRestaurantInSystem
"find existent restaurant by id" ! prevalentSystemForTest().findExistentRestaurantById()
"update name of existent restaurant in system" ! prevalentSystemForTest().updateNameOfRestaurantOnSystem
"update city of existent restaurant in system" ! prevalentSystemForTest().updateCityOfRestaurantOnSystem
"update name and city of existent restaurant in system" ! prevalentSystemForTest().updateNameAndCityOfRestaurantOnSystem
"delete existent restaurant in system" ! prevalentSystemForTest().deleteRestaurantOnSystem
}
case class prevalentSystemForTest() {
def addNewRestaurant() = {
val restaurant = (prevayler.executeTransaction(AddNewRestaurant.build("California", firstCity)))
restaurant must not be equalTo(null)
}
def containsOneRestaurantInSystem() = (prevayler.executeQuery(FindAllRestaurants())) must have size(1)
def findExistentRestaurantById() = {
val restaurant = (prevayler.executeQuery(FindRestaurantById(oldRestaurant.id)))
restaurant must not be equalTo(null)
}
def updateNameOfRestaurantOnSystem() = {
val parameters = ("Brasileirinho", null)
val restaurant = (prevayler.executeTransaction(UpdateRestaurant.build(oldRestaurant, parameters))).get
restaurant.name must be equalTo("Brasileirinho")
}
def updateCityOfRestaurantOnSystem() = {
val parameters = (null, secondCity)
val restaurant = (prevayler.executeTransaction(UpdateRestaurant.build(oldRestaurant, parameters))).get
restaurant.city must be equalTo(secondCity)
}
def updateNameAndCityOfRestaurantOnSystem() = {
val parameters = ("Verdinho", firstCity)
val restaurant = (prevayler.executeTransaction(UpdateRestaurant.build(oldRestaurant, parameters))).get
restaurant.city must be equalTo(firstCity)
restaurant.name must be equalTo("Verdinho")
}
def deleteRestaurantOnSystem() = {
prevayler.executeTransaction(DeleteRestaurant.build(oldRestaurant))
(prevayler.executeQuery(FindAllRestaurants())) must have size(0)
}
def oldRestaurant():Restaurant = prevayler.executeQuery(FindAllRestaurants()).head
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment