Skip to content

Commit

Permalink
test: RequestParser 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
xxeol2 committed Sep 11, 2023
1 parent de1a2b6 commit df09781
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public String findQueryParam(final String key) {
public String getPath() {
return uri.getPath();
}

public HttpProtocolVersion getVersion() {
return version;
}
}
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");
});
}
}
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);
});
}
}

0 comments on commit df09781

Please sign in to comment.