-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add query param on http RequestBuilder (#157)
- Loading branch information
1 parent
e914062
commit 6ece293
Showing
3 changed files
with
56 additions
and
0 deletions.
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
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
48 changes: 48 additions & 0 deletions
48
akka-javasdk/src/test/scala/akka/javasdk/impl/http/HttpClientImplSpec.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,48 @@ | ||
/* | ||
* Copyright (C) 2021-2024 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.javasdk.impl.http | ||
|
||
import akka.actor.typed.ActorSystem | ||
import akka.actor.typed.scaladsl.Behaviors | ||
import akka.http.javadsl.model.HttpHeader | ||
import akka.javasdk.http.RequestBuilder | ||
import akka.util.ByteString | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
class HttpClientImplSpec extends AnyWordSpec with Matchers { | ||
val system: ActorSystem[Nothing] = ActorSystem[Nothing](Behaviors.empty[Nothing], "httpClient") | ||
|
||
"RequestBuilderImpl" should { | ||
"add query parameter" in new HttpClientImplSuite { | ||
val builder: RequestBuilderImpl[ByteString] = get { builder => | ||
builder | ||
.addQueryParameter("key", "some value") | ||
.addQueryParameter("another", "name") | ||
} | ||
builder.request.getUri.toString shouldBe "http://test.com/test?key=some+value&another=name" | ||
} | ||
} | ||
|
||
} | ||
|
||
trait HttpClientImplSuite { | ||
implicit private val system: ActorSystem[Nothing] = | ||
ActorSystem[Nothing](Behaviors.empty[Nothing], "RequestBuilderImplSpec") | ||
|
||
val baseUrl = "http://test.com" | ||
val path = "/test" | ||
val headers: Seq[HttpHeader] = Seq.empty | ||
|
||
private def client = new HttpClientImpl(system, baseUrl, headers) | ||
|
||
private def get(url: String)( | ||
builder: RequestBuilder[ByteString] => RequestBuilder[ByteString]): RequestBuilderImpl[ByteString] = { | ||
builder(client.GET(url)) | ||
.asInstanceOf[RequestBuilderImpl[ByteString]] | ||
} | ||
def get(builder: RequestBuilder[ByteString] => RequestBuilder[ByteString]): RequestBuilderImpl[ByteString] = | ||
get(path)(builder) | ||
} |