-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix logic in SamExceptionFactory to extract message
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/test/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamExceptionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.broadinstitute.dsde.workbench.leonardo.dao.sam | ||
|
||
import akka.http.scaladsl.model.StatusCodes | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.broadinstitute.dsde.workbench.client.sam.ApiException | ||
import org.broadinstitute.dsde.workbench.client.sam.model.ErrorReport | ||
import org.broadinstitute.dsde.workbench.leonardo.LeonardoTestSuite | ||
import org.broadinstitute.dsde.workbench.model.TraceId | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
class SamExceptionSpec extends AnyFlatSpec with LeonardoTestSuite { | ||
val objectMapper = new ObjectMapper | ||
|
||
"SamException" should "create from an ApiException" in { | ||
val cause = new RuntimeException("cause") | ||
val errorReport = new ErrorReport().statusCode(400).message("error report message") | ||
val apiException = new ApiException( | ||
"test message", | ||
cause, | ||
400, | ||
Map("responseHeader1" -> List("responseHeader1Value").asJava).asJava, | ||
objectMapper.writeValueAsString(errorReport) | ||
) | ||
val samException = SamException.create("messagePrefix", apiException, TraceId("traceId")) | ||
|
||
samException.message shouldBe "messagePrefix: test message" | ||
samException.statusCode shouldBe StatusCodes.BadRequest | ||
samException.cause shouldBe cause | ||
} | ||
|
||
it should "extract the message from the ErrorReport if the top-level message is blank" in { | ||
val cause = new RuntimeException("cause") | ||
val errorReport = new ErrorReport().statusCode(400).message("error report message") | ||
val apiException = new ApiException( | ||
"", | ||
cause, | ||
400, | ||
Map("responseHeader1" -> List("responseHeader1Value").asJava).asJava, | ||
objectMapper.writeValueAsString(errorReport) | ||
) | ||
val samException = SamException.create("messagePrefix", apiException, TraceId("traceId")) | ||
|
||
samException.message shouldBe "messagePrefix: error report message" | ||
samException.statusCode shouldBe StatusCodes.BadRequest | ||
samException.cause shouldBe cause | ||
} | ||
} |