Skip to content

Commit

Permalink
feat: 운영체제 파일 시스템 차이로 인한 테스트 실패 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonJeWoong committed Sep 4, 2023
1 parent f03a1a7 commit 6a30330
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nextstep.org.apache.coyote.http11;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -9,8 +10,6 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -95,7 +94,8 @@ public void process(final Socket connection) {
if (Objects.nonNull(handler) && httpMethod.equals("POST")
&& requestedUrl.equals("/login")) {
LoginController loginController = (LoginController) handler;
LoginResponseDto loginDto = loginController.login(httpCookie, parsedBody.get("account"),
LoginResponseDto loginDto = loginController.login(httpCookie,
parsedBody.get("account"),
parsedBody.get("password"));

response = String.join("\r\n",
Expand Down Expand Up @@ -194,10 +194,9 @@ private String createResponseBody(String requestURL) {
resourceName += ".html";
}
URL resource = getClass().getClassLoader().getResource(resourceName);
Path path = Paths.get(resource.getPath().substring(1));

try {
return Files.readString(path);
return new String(Files.readAllBytes(new File(resource.getFile()).toPath()));
} catch (IOException | NullPointerException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void index() throws IOException {

// then
final URL resource = getClass().getClassLoader().getResource("static/index.html");
File file = new File(resource.getPath());
File file = new File(resource.getFile());
var expected = "HTTP/1.1 200 OK \r\n" +
"Content-Type: text/html;charset=utf-8 \r\n" +
// "Content-Length: 5564 \r\n" +
Expand Down Expand Up @@ -84,7 +84,7 @@ void css() throws IOException {

// then
final URL resource = getClass().getClassLoader().getResource("static/css/styles.css");
File file = new File(resource.getPath());
File file = new File(resource.getFile());
var expected = "HTTP/1.1 200 OK \r\n" +
"Content-Type: text/css;charset=utf-8 \r\n" +
String.format("Content-Length: %d \r\n", file.length()) +
Expand Down Expand Up @@ -112,7 +112,7 @@ void login() throws IOException {

// then
final URL resource = getClass().getClassLoader().getResource("static/login.html");
File file = new File(resource.getPath());
File file = new File(resource.getFile());
var expected = "HTTP/1.1 200 OK \r\n" +
"Content-Type: text/html;charset=utf-8 \r\n" +
String.format("Content-Length: %d \r\n", file.length()) +
Expand Down Expand Up @@ -140,7 +140,7 @@ void register() throws IOException {

// then
final URL resource = getClass().getClassLoader().getResource("static/register.html");
File file = new File(resource.getPath());
File file = new File(resource.getFile());
var expected = "HTTP/1.1 200 OK \r\n" +
"Content-Type: text/html;charset=utf-8 \r\n" +
String.format("Content-Length: %d \r\n", file.length()) +
Expand Down Expand Up @@ -257,7 +257,6 @@ void sessionTest() {
List<String> splited = Arrays.asList(output.split("\r\n"));
List<String> headers = splited.subList(1, splited.size());
for (String line : headers) {
System.out.println("line: " + line);
String[] splitedLine = line.split(": ");
requestHeaders.put(splitedLine[0], splitedLine[1].strip());
}
Expand Down Expand Up @@ -318,7 +317,6 @@ private String loginAndGetSessionId() {
List<String> splited = Arrays.asList(preOutput.split("\r\n"));
List<String> headers = splited.subList(1, splited.size());
for (String line : headers) {
System.out.println("line: " + line);
String[] splitedLine = line.split(": ");
requestHeaders.put(splitedLine[0], splitedLine[1].strip());
}
Expand Down

0 comments on commit 6a30330

Please sign in to comment.