Skip to content

Commit

Permalink
scalafmtAll despite no Scala
Browse files Browse the repository at this point in the history
  • Loading branch information
aednichols committed Aug 13, 2024
1 parent 61a691a commit 5e41b65
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object MethodConfigurationUtils {
case Success(None) =>
throw new RawlsExceptionWithErrorReport(
errorReport = ErrorReport(StatusCodes.NotFound,
s"Cannot get ${methodConfig.methodRepoMethod.methodUri} from method repo."
s"Cannot get ${methodConfig.methodRepoMethod.methodUri} from method repo."
)
)
case Success(Some(wdl)) =>
Expand All @@ -34,8 +34,8 @@ object MethodConfigurationUtils {
case Failure(throwable) =>
throw new RawlsExceptionWithErrorReport(
errorReport = ErrorReport(StatusCodes.BadGateway,
s"Unable to query the method repo.",
methodRepoDAO.toErrorReport(throwable)
s"Unable to query the method repo.",
methodRepoDAO.toErrorReport(throwable)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.OAuth2BearerToken
import com.typesafe.config.ConfigFactory
import org.broadinstitute.dsde.rawls.{RawlsException, RawlsExceptionWithErrorReport, TestExecutionContext, jobexec}
import org.broadinstitute.dsde.rawls.{jobexec, RawlsException, RawlsExceptionWithErrorReport, TestExecutionContext}
import org.broadinstitute.dsde.rawls.config.{MethodRepoConfig, WDLParserConfig}
import org.broadinstitute.dsde.rawls.dataaccess.{HttpMethodRepoDAO, MockCromwellSwaggerClient}
import org.broadinstitute.dsde.rawls.dataaccess.slick.TestDriverComponent
import org.broadinstitute.dsde.rawls.jobexec.MethodConfigResolver
import org.broadinstitute.dsde.rawls.jobexec.MethodConfigResolver.GatherInputsResult
import org.broadinstitute.dsde.rawls.jobexec.wdlparsing.CachingWDLParser
import org.broadinstitute.dsde.rawls.mock.RemoteServicesMockServer
import org.broadinstitute.dsde.rawls.model.{Agora, AgoraMethod, Dockstore, ErrorReport, ErrorReportSource, MethodConfiguration, RawlsRequestContext, RawlsUser, RawlsUserEmail, RawlsUserSubjectId, UserInfo}
import org.broadinstitute.dsde.rawls.model.{
Agora,
AgoraMethod,
Dockstore,
ErrorReport,
ErrorReportSource,
MethodConfiguration,
RawlsRequestContext,
RawlsUser,
RawlsUserEmail,
RawlsUserSubjectId,
UserInfo
}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatest.flatspec.AnyFlatSpec
Expand All @@ -30,34 +42,43 @@ class MethodConfigurationUtilsSpec extends AnyFlatSpec with Matchers with TestDr

val mockServer: RemoteServicesMockServer = RemoteServicesMockServer()
val methodRepoDAO: HttpMethodRepoDAO = mock[HttpMethodRepoDAO]
val ctx: RawlsRequestContext = RawlsRequestContext(UserInfo(testData.userProjectOwner.userEmail, OAuth2BearerToken("foo"), 0, testData.userProjectOwner.userSubjectId))
val ctx: RawlsRequestContext = RawlsRequestContext(
UserInfo(testData.userProjectOwner.userEmail, OAuth2BearerToken("foo"), 0, testData.userProjectOwner.userSubjectId)
)

val agoraMethodConf: MethodConfiguration = MethodConfiguration("dsde",
"no_input",
Some("Sample"),
None,
Map.empty,
Map.empty,
AgoraMethod("dsde", "no_input", 1))
"no_input",
Some("Sample"),
None,
Map.empty,
Map.empty,
AgoraMethod("dsde", "no_input", 1)
)

behavior of "MethodConfigurationUtils"

it should "return results when method when found" in {
when(methodRepoDAO.getMethod(any(), any())).thenReturn(Future.successful(Option(meth1WDL)))

val future = MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver)
val future =
MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver)
Await.ready(future, 30.seconds)
val Success(result) = future.value.get

// verify that it returns GatherInputsResult
result shouldBe a [GatherInputsResult]
result shouldBe a[GatherInputsResult]
result.missingInputs shouldBe Set("meth1.method1.i1")
}

it should "return 404 if method is not found" in {
when(methodRepoDAO.getMethod(any(), any())).thenReturn(Future.successful(None))

val exception = intercept[RawlsExceptionWithErrorReport](Await.result(MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver), 30.seconds))
val exception = intercept[RawlsExceptionWithErrorReport](
Await.result(
MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver),
30.seconds
)
)

// assert that if method is not found it returns 404
exception shouldBe a[RawlsExceptionWithErrorReport]
Expand All @@ -66,11 +87,17 @@ class MethodConfigurationUtilsSpec extends AnyFlatSpec with Matchers with TestDr
}

it should "return 502 when something unexpected happens" in {
when(methodRepoDAO.getMethod(any(), any())).thenReturn(Future.failed(new RawlsException("exception thrown for testing purposes")))
when(methodRepoDAO.getMethod(any(), any()))
.thenReturn(Future.failed(new RawlsException("exception thrown for testing purposes")))
when(methodRepoDAO.errorReportSource).thenReturn(ErrorReportSource("agora"))
when(methodRepoDAO.toErrorReport(any())).thenCallRealMethod()

val exception = intercept[RawlsExceptionWithErrorReport](Await.result(MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver), 30.seconds))
val exception = intercept[RawlsExceptionWithErrorReport](
Await.result(
MethodConfigurationUtils.gatherMethodConfigInputs(ctx, methodRepoDAO, agoraMethodConf, methodConfigResolver),
30.seconds
)
)

// assert that when Future fails, a 502 is returned with wrapped exception
exception shouldBe a[RawlsExceptionWithErrorReport]
Expand Down

0 comments on commit 5e41b65

Please sign in to comment.