1+ /*
2+ * Copyright (C) 2023 Edgar Asatryan
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io.github.nstdio.http.ext
18+
19+ import io.kotest.matchers.optional.shouldBeEmpty
20+ import io.kotest.matchers.optional.shouldBePresent
21+ import io.kotest.matchers.should
22+ import io.kotest.matchers.shouldBe
23+ import org.junit.jupiter.api.Test
24+ import org.mockito.Mockito
25+ import java.net.http.HttpClient
26+ import java.net.http.HttpRequest
27+ import javax.net.ssl.SSLSession
28+
29+ class StaticHttpResponseTest {
30+ @Test
31+ fun `Should create proper response` () {
32+ // given
33+ val body = " abc"
34+ val uri = " https://example.com" .toUri()
35+ val request = HttpRequest .newBuilder(uri).build()
36+ val statusCode = 200
37+ val headers = HttpHeadersBuilder ().add(" A" , " 1" ).build()
38+ val sslSession = Mockito .mock(SSLSession ::class .java)
39+ val version = HttpClient .Version .HTTP_2
40+
41+ // when
42+ val response = StaticHttpResponse .builder<String >()
43+ .body(body)
44+ .request(request)
45+ .uri(uri)
46+ .statusCode(statusCode)
47+ .headers(headers)
48+ .sslSession(sslSession)
49+ .version(version)
50+ .build()
51+
52+ // then
53+ response.should {
54+ it.body() shouldBe body
55+ it.uri() shouldBe uri
56+ it.request() shouldBe request
57+ it.statusCode() shouldBe statusCode
58+ it.headers() shouldBe headers
59+ it.sslSession().shouldBePresent { shouldBe(sslSession) }
60+ it.version() shouldBe version
61+ it.previousResponse().shouldBeEmpty()
62+ }
63+ }
64+ }
0 commit comments