Skip to content

Commit

Permalink
서블릿 학습 테스트 코드 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hyungu committed Sep 11, 2023
1 parent 52ee778 commit e7c21ab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ Temporary Items

tomcat.*
tomcat.*/**

**/WEB-INF/classes/**
1 change: 1 addition & 0 deletions study/src/main/java/servlet/com/example/TomcatStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void await() {
public void stop() {
try {
tomcat.stop();
tomcat.destroy();
} catch (LifecycleException e) {
throw new RuntimeException(e);
}
Expand Down
7 changes: 4 additions & 3 deletions study/src/test/java/servlet/com/example/FilterTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package servlet.com.example;

import org.junit.jupiter.api.Test;
import support.HttpUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static servlet.com.example.KoreanServlet.인코딩;

class FilterTest {

@Test
void testFilter() throws Exception {
void testFilter() {
// 톰캣 서버 시작
final var tomcatStarter = TestHttpUtils.createTomcatStarter();
final var tomcatStarter = new TomcatStarter("src/main/webapp/");
tomcatStarter.start();

final var response = TestHttpUtils.send("/korean");
final var response = HttpUtils.send("/korean");

// 톰캣 서버 종료
tomcatStarter.stop();
Expand Down
23 changes: 13 additions & 10 deletions study/src/test/java/servlet/com/example/ServletTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package servlet.com.example;

import org.junit.jupiter.api.Test;
import support.HttpUtils;

import static org.assertj.core.api.Assertions.assertThat;

class ServletTest {

private final String WEBAPP_DIR_LOCATION = "src/main/webapp/";

@Test
void testSharedCounter() throws Exception {
void testSharedCounter() {
// 톰캣 서버 시작
final var tomcatStarter = TestHttpUtils.createTomcatStarter();
final var tomcatStarter = new TomcatStarter(WEBAPP_DIR_LOCATION);
tomcatStarter.start();

// shared-counter 페이지를 3번 호출한다.
final var PATH = "/shared-counter";
TestHttpUtils.send(PATH);
TestHttpUtils.send(PATH);
final var response = TestHttpUtils.send(PATH);
HttpUtils.send(PATH);
HttpUtils.send(PATH);
final var response = HttpUtils.send(PATH);

// 톰캣 서버 종료
tomcatStarter.stop();
Expand All @@ -29,16 +32,16 @@ void testSharedCounter() throws Exception {
}

@Test
void testLocalCounter() throws Exception {
void testLocalCounter() {
// 톰캣 서버 시작
final var tomcatStarter = TestHttpUtils.createTomcatStarter();
final var tomcatStarter = new TomcatStarter(WEBAPP_DIR_LOCATION);
tomcatStarter.start();

// local-counter 페이지를 3번 호출한다.
final var PATH = "/local-counter";
TestHttpUtils.send(PATH);
TestHttpUtils.send(PATH);
final var response = TestHttpUtils.send(PATH);
HttpUtils.send(PATH);
HttpUtils.send(PATH);
final var response = HttpUtils.send(PATH);

// 톰캣 서버 종료
tomcatStarter.stop();
Expand Down
28 changes: 0 additions & 28 deletions study/src/test/java/servlet/com/example/TestHttpUtils.java

This file was deleted.

0 comments on commit e7c21ab

Please sign in to comment.