Skip to content

Commit

Permalink
Merge pull request #28 from broadinstitute/fix_unit_tests
Browse files Browse the repository at this point in the history
Fix search and unit tests
  • Loading branch information
jacarey committed May 9, 2015
2 parents 0e0d6d9 + 8c14dfe commit 5de522f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ case class AgoraSearch(@(ApiModelProperty@field)(required = false, value = "The
name: Option[String] = None,
@(ApiModelProperty@field)(required = false, value = "The method id")
var id: Option[Int] = None,
@(ApiModelProperty@field)(required = false, value = "User who owns this method in the methods repo")
owner: Option[String] = None,
@(ApiModelProperty@field)(required = false, value = "A short description of the method")
synopsis: Option[String] = None,
@(ApiModelProperty@field)(required = false, value = "Method documentation")
documentation: Option[String] = None,
@(ApiModelProperty@field)(required = false, value = "User who owns this method in the methods repo")
owner: Option[String] = None,
@(ApiModelProperty@field)(required = false, value = "The method payload")
payload: Option[String] = None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ trait AgoraTestData {
val namespace2 = "hellbender"
val name1 = "testMethod1"
val name2 = "testMethod2"
val synopsis = "This is a test method"
val documentation = "This is the documentation"
val synopsis1 = "This is a test method"
val synopsis2 = "This is another test method"
val documentation1 = "This is the documentation"
val documentation2 = "This is documentation for another method"
// NB: save io by storing output.
val bigDocumentation: String = getBigDocumentation
val owner1 = "bob"
val owner2 = "dave"
val payload = """task wc {
val payload1 = """task wc {
| command {
| echo "${str}" | wc -c
| }
Expand All @@ -34,38 +36,77 @@ trait AgoraTestData {
| call wc{input: str=s}
| }
|}""".stripMargin
val payload2 = "task test {}"

val testEntity1 = AgoraEntity(namespace = Option(namespace1), name = Option(name1), owner = Option(owner1))
val testEntity2 = AgoraEntity(namespace = Option(namespace1), name = Option(name2), owner = Option(owner1))
val testEntity3 = AgoraEntity(namespace = Option(namespace2), name = Option(name1), owner = Option(owner1))
val testEntity4 = AgoraEntity(namespace = Option(namespace1), name = Option(name1), owner = Option(owner2))

val testEntity1 = AgoraEntity(namespace = Option(namespace1),
name = Option(name1),
synopsis = Option(synopsis1),
documentation = Option(documentation1),
owner = Option(owner1),
payload = Option(payload1))
val testEntity2 = AgoraEntity(namespace = Option(namespace2),
name = Option(name1),
synopsis = Option(synopsis1),
documentation = Option(documentation1),
owner = Option(owner1),
payload = Option(payload1))
val testEntity3 = AgoraEntity(namespace = Option(namespace1),
name = Option(name2),
synopsis = Option(synopsis1),
documentation = Option(documentation1),
owner = Option(owner1),
payload = Option(payload1))
val testEntity4 = AgoraEntity(namespace = Option(namespace1),
name = Option(name2),
synopsis = Option(synopsis2),
documentation = Option(documentation1),
owner = Option(owner1),
payload = Option(payload1))
val testEntity5 = AgoraEntity(namespace = Option(namespace1),
name = Option(name2),
synopsis = Option(synopsis1),
documentation = Option(documentation2),
owner = Option(owner1),
payload = Option(payload1))
val testEntity6 = AgoraEntity(namespace = Option(namespace1),
name = Option(name2),
synopsis = Option(synopsis1),
documentation = Option(documentation1),
owner = Option(owner2),
payload = Option(payload1))
val testEntity7 = AgoraEntity(namespace = Option(namespace1),
name = Option(name2),
synopsis = Option(synopsis1),
documentation = Option(documentation1),
owner = Option(owner1),
payload = Option(payload2))

val testAddRequest = new AgoraAddRequest(
namespace = namespace1,
name = name1,
synopsis = synopsis,
documentation = documentation,
synopsis = synopsis1,
documentation = documentation1,
owner = owner1,
payload = payload
payload = payload1
)

val badPayload = "task test {"

val testBadAddRequest = new AgoraAddRequest(
namespace = namespace1,
name = name1,
synopsis = synopsis,
documentation = documentation,
synopsis = synopsis1,
documentation = documentation1,
owner = owner1,
payload = badPayload
)

val testAddRequestBigDoc = new AgoraAddRequest(
namespace = namespace1,
name = name1,
synopsis = synopsis,
synopsis = synopsis1,
documentation = bigDocumentation,
owner = owner1,
payload = payload
payload = payload1
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,72 @@ class ApiServiceSpec extends FlatSpec with Matchers with Directives with Scalate
Get(ApiUtil.Methods.withLeadingSlash + "/" + namespace1 + "/" + name1 + "/"
+ insertedEntity.id.get) ~> methodsService.queryByNamespaceNameIdRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
response === insertedEntity
val response = grater[AgoraEntity].fromJSONArray(rawResponse).head
assert(response === insertedEntity)
}
}

"Agora" should "return methods matching the query" in {
"Agora" should "return methods matching query by namespace and name" in {
agoraDao.insert(testEntity2)
agoraDao.insert(testEntity3)
agoraDao.insert(testEntity4)
Get(ApiUtil.Methods.withLeadingSlash + "?namespace=" + namespace1 + "&owner=" + owner1) ~> methodsService.queryRoute ~> check {
agoraDao.insert(testEntity5)
agoraDao.insert(testEntity6)
agoraDao.insert(testEntity7)
Get(ApiUtil.Methods.withLeadingSlash + "?namespace=" + namespace1 + "&name=" + name2) ~> methodsService.queryRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
assert(response === Seq(testEntity3, testEntity4, testEntity5, testEntity6, testEntity7))
}
}

"Agora" should "return methods matching query by synopsis and documentation" in {
print(uriEncode(synopsis1))
Get(ApiUtil.Methods.withLeadingSlash + "?synopsis=" + uriEncode(synopsis1) + "&documentation=" + uriEncode(documentation1)) ~> methodsService.queryRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
assert(response === Seq(testEntity1, testEntity2, testEntity3, testEntity6, testEntity7))
}
}

"Agora" should "return methods matching query by owner and payload" in {
Get(ApiUtil.Methods.withLeadingSlash + "?owner=" + owner1 + "&payload=" + uriEncode(payload1)) ~> methodsService.queryRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSONArray(rawResponse)
response === Seq(testEntity1, testEntity2)
assert(response === Seq(testEntity1, testEntity2, testEntity3, testEntity4, testEntity5))
}
}

"Agora" should "create and return a method" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
val rawResponse = responseAs[String]
val response = grater[AgoraEntity].fromJSON(rawResponse)
response.namespace === namespace1
response.name === name1
response.synopsis === synopsis
response.documentation === documentation
response.owner === owner1
response.payload === payload
response.id === 1
response.createDate != null
assert(response.namespace.get === namespace1)
assert(response.name.get === name1)
assert(response.synopsis.get === synopsis1)
assert(response.documentation.get === documentation1)
assert(response.owner.get === owner1)
assert(response.payload.get === payload1)
assert(response.id.get !== None)
assert(response.createDate.get != 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
assert(status === BadRequest)
assert(responseAs[String] != null)
}
}

"Agora" should "store 10kb of github markdown as method documentation and return it without alteration" in {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequestBigDoc)) ~> methodsService.postRoute ~> check {
val rawResponse = responseAs[String]
grater[AgoraEntity].fromJSON(rawResponse).documentation === bigDocumentation
assert(grater[AgoraEntity].fromJSON(rawResponse).documentation.get === bigDocumentation)
}
}

def uriEncode(uri: String): String = {
java.net.URLEncoder.encode(uri, "UTF-8")
}
}

0 comments on commit 5de522f

Please sign in to comment.