-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 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
32 changes: 32 additions & 0 deletions
32
tomcat/src/test/java/org/apache/coyote/http11/request/Http11RequestHeaderParserTest.java
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,32 @@ | ||
package org.apache.coyote.http11.request; | ||
|
||
import static org.assertj.core.api.SoftAssertions.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
class Http11RequestHeaderParserTest { | ||
|
||
@Test | ||
void RequestHeader_파싱() { | ||
final var requestHeaders = List.of( | ||
"Host: localhost:8080", | ||
"Connection: keep-alive", | ||
"Cookie: yummy_cookie=choco; tasty_cookie=strawberry; JSESSIONID=656cef62-e3c4-40bc-a8df-94732920ed46" | ||
); | ||
|
||
final var parsed = Http11RequestHeaderParser.parse(requestHeaders); | ||
|
||
assertSoftly(softly -> { | ||
softly.assertThat(parsed.find("Host")).isEqualTo("localhost:8080"); | ||
softly.assertThat(parsed.find("Connection")).isEqualTo("keep-alive"); | ||
softly.assertThat(parsed.findCookie("yummy_cookie").get()).isEqualTo("choco"); | ||
softly.assertThat(parsed.findSessionId().get()).isEqualTo("656cef62-e3c4-40bc-a8df-94732920ed46"); | ||
}); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tomcat/src/test/java/org/apache/coyote/http11/request/Http11RequestLineParserTest.java
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,28 @@ | ||
package org.apache.coyote.http11.request; | ||
|
||
import static org.apache.coyote.HttpMethod.*; | ||
import static org.assertj.core.api.SoftAssertions.*; | ||
|
||
import org.apache.coyote.HttpProtocolVersion; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
class Http11RequestLineParserTest { | ||
|
||
@Test | ||
void RequestLine을_올바르게_파싱한다() { | ||
final var requestLine = "GET /login?account=gugu&password=pw HTTP/1.1"; | ||
|
||
final var parsed = Http11RequestLineParser.parse(requestLine); | ||
|
||
assertSoftly(softly -> { | ||
softly.assertThat(parsed.hasMethod(GET)).isTrue(); | ||
softly.assertThat(parsed.findQueryParam("account")).isEqualTo("gugu"); | ||
softly.assertThat(parsed.findQueryParam("password")).isEqualTo("pw"); | ||
softly.assertThat(parsed.getVersion()).isEqualTo(HttpProtocolVersion.HTTP11); | ||
}); | ||
} | ||
} |