Skip to content

Commit

Permalink
Added test suite for bringing up agora and embedded mongo before all …
Browse files Browse the repository at this point in the history
…tests and tearing it down after all tests.

Removing mongodb service from travis yaml.
  • Loading branch information
jacarey committed May 6, 2015
1 parent 782e96b commit a8e226f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 193 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: scala
scala:
- 2.11.6
services:
- mongodb
jdk:
- oraclejdk8
script: sbt clean coverage test
Expand Down
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ libraryDependencies ++= Seq(
"cglib" % "cglib-nodep" % "2.2",
"io.spray" %% "spray-can" % sprayV,
"io.spray" %% "spray-routing" % sprayV,
"io.spray" %% "spray-json" % "1.3.1", // NB: Not at sprayV. 1.3.2 does not exist.
"io.spray" %% "spray-json" % "1.3.1", // NB: Not at sprayV. 1.3.2 does not exist.
"io.spray" %% "spray-client" % sprayV,
"com.typesafe.akka" %% "akka-actor" % "2.3.4",
"ch.qos.logback" % "logback-classic" % "1.1.2",
Expand All @@ -26,12 +26,13 @@ libraryDependencies ++= Seq(
"com.novus" %% "salat" % "1.9.9",
//---------- Test libraries -------------------//
"io.spray" %% "spray-testkit" % sprayV % Test,
"org.scalatest" %% "scalatest" % "2.2.4" % Test
"org.scalatest" %% "scalatest" % "2.2.4" % Test,
"com.github.simplyscala" %% "scalatest-embedmongo" % "0.2.2" % Test
)

releaseSettings

shellPrompt := { state => "%s| %s> ".format(GitCommand.prompt.apply(state), version.value)}
shellPrompt := { state => "%s| %s> ".format(GitCommand.prompt.apply(state), version.value) }

jarName in assembly := "agora-" + version.value + ".jar"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.broadinstitute.dsde.agora.server

import org.broadinstitute.dsde.agora.server.model.{AgoraAddRequest, AgoraEntity}

trait AgoraTestData {
val namespace = "broad"

val name = "testMethod"

val synopsis = "This is a test method"

val documentation = "This is the documentation"

val owner = "bob the builder"

val payload = """task wc {
| command {
| echo "${str}" | wc -c
| }
| output {
| int count = read_int("stdout") - 1
| }
|}
|
|workflow wf {
| array[string] str_array
| scatter(s in str_array) {
| call wc{input: str=s}
| }
|}""".stripMargin

val testEntity = AgoraEntity(namespace = Option(namespace), name = Option(name))

val testAddRequest = new AgoraAddRequest(
namespace = namespace,
name = name,
synopsis = synopsis,
documentation = documentation,
owner = owner,
payload = payload
)

val badPayload = "task test {"

val testBadAddRequest = new AgoraAddRequest(
namespace = namespace,
name = name,
synopsis = synopsis,
documentation = documentation,
owner = owner,
payload = badPayload
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.broadinstitute.dsde.agora.server

import com.github.simplyscala.{MongoEmbedDatabase, MongodProps}
import org.broadinstitute.dsde.agora.server.dataaccess.AgoraDao
import org.broadinstitute.dsde.agora.server.dataaccess.mongo.MethodsDbTest
import org.broadinstitute.dsde.agora.server.webservice.ApiServiceSpec
import org.scalatest.{BeforeAndAfterAll, Suites}

trait AgoraDbTest {
val agoraDao = AgoraDao.createAgoraDao
}

class AgoraTestSuite extends Suites(new ApiServiceSpec, new MethodsDbTest) with BeforeAndAfterAll with MongoEmbedDatabase {
var mongoProps: MongodProps = null

override def beforeAll() {
println("Starting embedded mongo db instance.")
mongoProps = mongoStart(port = Agora.server.mongoDbPort)
println("Starting Agora web services.")
Agora.start()
}

override def afterAll() {
println("Stopping embedded mongo db instance.")
mongoStop(mongoProps)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,59 +1,37 @@
package org.broadinstitute.dsde.agora.server.dataaccess.mongo

import java.util.Date

import org.broadinstitute.dsde.agora.server.dataaccess.AgoraDao
import org.broadinstitute.dsde.agora.server.model.AgoraEntity
import org.scalatest.{BeforeAndAfterAll, FlatSpec}

class MethodsDbTest extends FlatSpec with BeforeAndAfterAll {

val agoraTestMethod: AgoraEntity = new AgoraEntity(
namespace = Option("broadinstitute"),
name = Option("echo"),
synopsis = Option("The is a method that echoes a string to standard out"),
documentation = Option("This string a quite a bit longer than the synopsis as it should contain the documentation for the method (perhaps using mark(up/down) language"),
owner = Option("jcarey"),
createDate = Option(new Date()),
payload = Option("{\"executable\":\"echo\"}")
)

def fixture =
new {
val agoraDao = AgoraDao.createAgoraDao
}

import org.broadinstitute.dsde.agora.server.{AgoraDbTest, AgoraTestData}
import org.scalatest.{DoNotDiscover, FlatSpec}

@DoNotDiscover
class MethodsDbTest extends FlatSpec with AgoraDbTest with AgoraTestData {

"Agora" should "be able to store a method" in {
val testFixture = fixture
agoraDao.insert(testEntity)

testFixture.agoraDao.insert(agoraTestMethod)

val entity = testFixture.agoraDao.findSingle(agoraTestMethod).get
val entity = agoraDao.findSingle(testEntity).get

assert(entity == agoraTestMethod)
assert(entity == testEntity)
}

"Agora" should "be able to query by namespace, name and version and get back a single entity" in {
val testFixture = fixture

//NB: agoraTestMethod has already been stored.
val queryEntity = new AgoraEntity(namespace = Option("broadinstitute"), name = Option("echo"), id = agoraTestMethod.id)
val queryEntity = new AgoraEntity(namespace = Option(namespace), name = Option(name), id = testEntity.id)

val entity = testFixture.agoraDao.findSingle(queryEntity).get
val entity = agoraDao.findSingle(queryEntity).get

assert(entity == agoraTestMethod)
assert(entity == testEntity)
}

"Agora" should "increment the id number if we insert the same namespace/name entity" in {
val testFixture = fixture

testFixture.agoraDao.insert(agoraTestMethod)
agoraDao.insert(testEntity)

val previousVersionEntity = agoraTestMethod.copy()
previousVersionEntity.id = Option(agoraTestMethod.id.get - 1)
val previousVersionEntity = testEntity.copy()
previousVersionEntity.id = Option(testEntity.id.get - 1)

val entity1 = testFixture.agoraDao.findSingle(previousVersionEntity).get
val entity2 = testFixture.agoraDao.findSingle(agoraTestMethod).get
val entity1 = agoraDao.findSingle(previousVersionEntity).get
val entity2 = agoraDao.findSingle(testEntity).get

assert(entity1.id.get == entity2.id.get - 1)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.broadinstitute.dsde.agora.server.webservice

import org.broadinstitute.dsde.agora.server.model.AgoraEntity
import org.broadinstitute.dsde.agora.server.model.AgoraEntity._
import org.broadinstitute.dsde.agora.server.webservice.methods.MethodsService
import org.broadinstitute.dsde.agora.server.webservice.util.{ApiUtil, ServiceHandlerProps}
import org.broadinstitute.dsde.agora.server.{AgoraDbTest, AgoraTestData}
import org.scalatest.{DoNotDiscover, FlatSpec, Matchers}
import spray.http.StatusCodes._
import spray.httpx.marshalling._
import spray.routing.Directives
import spray.testkit.ScalatestRouteTest

@DoNotDiscover
class ApiServiceSpec extends FlatSpec with Matchers with Directives with ScalatestRouteTest with AgoraTestData with AgoraDbTest {

trait ActorRefFactoryContext {
def actorRefFactory = system
}

val methodsService = new MethodsService with ActorRefFactoryContext with ServiceHandlerProps

"Agora" should "return information about a method, including metadata " in {
val insertedEntity = agoraDao.insert(testEntity)

Get(ApiUtil.Methods.withLeadingSlash + "/" + namespace + "/" + name + "/"
+ insertedEntity.id.get) ~> methodsService.queryRoute ~> check {
responseAs[AgoraEntity] === insertedEntity
}
}

"Agora" should "create and return a method" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
val response = responseAs[AgoraEntity]
response.namespace === namespace
response.name === name
response.synopsis === synopsis
response.documentation === documentation
response.owner === owner
response.payload === payload
response.id === 1
response.createDate != null
}
}

"Agora" should "return a 400 bad request when posting a malformed payload" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testBadAddRequest)) ~> methodsService.postRoute ~> check {
status === BadRequest
responseAs[String] != null
}
}

}

0 comments on commit a8e226f

Please sign in to comment.