Skip to content

Commit

Permalink
Merge pull request #18 from broadinstitute/bt_fix_add_model
Browse files Browse the repository at this point in the history
Add Request elements should not be optional.
  • Loading branch information
David Shiga committed May 4, 2015
2 parents 2141680 + 38c87b3 commit b5dd11c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ object AgoraEntity {
}

def fromAgoraAddRequest(agoraAddRequest: AgoraAddRequest, createDate: Option[Date]) = {
new AgoraEntity(namespace = agoraAddRequest.namespace,
name = agoraAddRequest.name,
synopsis = agoraAddRequest.synopsis,
documentation = agoraAddRequest.documentation,
owner = agoraAddRequest.owner,
createDate = createDate,
payload = agoraAddRequest.payload)
new AgoraEntity(namespace = Option(agoraAddRequest.namespace),
name = Option(agoraAddRequest.name),
synopsis = Option(agoraAddRequest.synopsis),
documentation = Option(agoraAddRequest.documentation),
owner = Option(agoraAddRequest.owner),
createDate = createDate,
payload = Option(agoraAddRequest.payload)
)
}

}
Expand All @@ -41,7 +42,6 @@ object AgoraAddRequest {
implicit val AgoraAddRequestUnmarshaller =
Unmarshaller[AgoraAddRequest](`application/json`) {
case HttpEntity.NonEmpty(contentType, data) grater[AgoraAddRequest].fromJSON(data.asString)
case HttpEntity.Empty new AgoraAddRequest()
}

implicit val AgoraAddRequestMarshaller =
Expand Down Expand Up @@ -71,15 +71,15 @@ case class AgoraEntity(@(ApiModelProperty@field)(required = true, value = "The n

@ApiModel(value = "Request to add method")
case class AgoraAddRequest(@(ApiModelProperty@field)(required = true, value = "The namespace to which the method belongs")
namespace: Option[String] = None,
@(ApiModelProperty@field)(required = true, value = "The method name ")
name: Option[String] = None,
@(ApiModelProperty@field)(required = true, value = "A short description of the method")
synopsis: Option[String] = None,
@(ApiModelProperty@field)(required = true, value = "Method documentation")
documentation: Option[String] = None,
@(ApiModelProperty@field)(required = true, value = "User who owns this method in the methods repo")
owner: Option[String] = None, // TODO: remove (use authenticated user)
@(ApiModelProperty@field)(required = true, value = "The method payload")
payload: Option[String] = None
)
namespace: String,
@(ApiModelProperty@field)(required = true, value = "The method name ")
name: String,
@(ApiModelProperty@field)(required = true, value = "A short description of the method")
synopsis: String,
@(ApiModelProperty@field)(required = true, value = "Method documentation")
documentation: String,
@(ApiModelProperty@field)(required = true, value = "User who owns this method in the methods repo")
owner: String, // TODO: remove (use authenticated user)
@(ApiModelProperty@field)(required = true, value = "The method payload")
payload: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ class ApiServiceSpec extends FlatSpec with Matchers with Directives with Scalate
val documentation = "This is the documentation"
val owner = "bob the builder"
val payload = "echo 'hello world'"
val testMethod = AgoraEntity(namespace = Option(namespace), name = Option(name))
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
)

"Agora" should "return information about a method, including metadata " in {
val testFixture = fixture

val insertedEntity = testFixture.agoraDao.insert(testMethod)
val insertedEntity = testFixture.agoraDao.insert(testEntity)

Get(ApiUtil.Methods.withLeadingSlash + "/" + namespace + "/" + name + "/" + insertedEntity.id.get) ~> methodsService.queryRoute ~> check {
responseAs[AgoraEntity] === insertedEntity
Expand All @@ -46,9 +54,7 @@ class ApiServiceSpec extends FlatSpec with Matchers with Directives with Scalate
"Agora" should "create and return a method" in {
val testFixture = fixture

val agoraAddRequest = new AgoraAddRequest()

Post(ApiUtil.Methods.withLeadingSlash, marshal(testMethod)) ~> methodsService.postRoute ~> check {
Post(ApiUtil.Methods.withLeadingSlash, marshal(testAddRequest)) ~> methodsService.postRoute ~> check {
val response = responseAs[AgoraEntity]
response.namespace === namespace
response.name === name
Expand Down

0 comments on commit b5dd11c

Please sign in to comment.