I am quite confused on how to write a integration test for a Akka Http end point. In Java its as easy as use Dropwizard rule to launch the API locally and just carry out get or post for the local end point. The test has the env var needed. I am looking for the same in AKKA HTTP
I would like to bring up the application locally and follow the structure as mentioned in this post. Akka Net Integration Test
Are there any good examples of this
This is what i have in the controller.
@GET
@Path("/jobs")
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
@Operation(
summary = "See Status of All Workflow Jobs",
description = "See Status of All Workflow Jobs.",
method = "GET",
security = Array(new SecurityRequirement(name = "bearerAuth")))
def getJobs: Route = jobs
I wrote the following test. Just like junit has before how do i launch application locally
"The service" should {
"return jobs response" in {
val headers =
RawHeader("Authorization", "Bearer token")
val httpRequest =
HttpRequest(
HttpMethods.GET,
"http://localhost:8080/jobs?ids=20388241",
scala.collection.immutable.Seq(headers))
def sendRequest(): Future[String] = {
val responseFuture: Future[HttpResponse] = Http().singleRequest(httpRequest)
Await.result(responseFuture, 5.seconds)
val entityFuture: Future[HttpEntity.Strict] =
responseFuture.flatMap(response => response.entity.toStrict(10.seconds))
entityFuture.map(entity => entity.data.utf8String)
}
val mapper = new ObjectMapper
mapper.registerModule(DefaultScalaModule)
sendRequest().map(response =>
assert(
mapper.readValue(response, classOf[WorkflowsResponse]).workflows.get(0).workflowId > 0))
}
}
Response String is a json String of type Workflow Response. How do i fix the above test to launch application and run the test