Skip to content

Commit

Permalink
테스트 범위와 종류 finish - #88
Browse files Browse the repository at this point in the history
  • Loading branch information
rladuswl committed Feb 22, 2023
1 parent e5eed76 commit 87802a3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package study.tdd.chap09;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CardNumberValidatorTest {
/*
private WireMockServer wireMockServer;
@BeforeEach
void setUp() {
wireMockServer = new WireMockServer(options().port(8089));
wireMockServer.start();
}
@AfterEach
void tearDown() {
wireMockServer.stop();
}
@Test
void valid() {
wireMockServer.stubFor(post(urlEqualTo("/card"))
.withRequestBody(equalTo("1234567890"))
.willReturn(aResponse()
.withHeader("Content-Type", "text/plain")
.withBody("ok")));
CardNumberValidator validator = new CardNumberValidator("http://localhost:8089");
CardValidity validity = validator.validate("1234567890");
assertEquals(CardValidity.VALID, validity);
}
@Test
void timeout() {
wireMockServer.stubFor(post(urlEqualTo("/card"))
.willReturn(aResponse()
.withFixedDelay(5000)));
CardNumberValidator validator = new CardNumberValidator("http://localhost:8089");
CardValidity validity = validator.validate("1234567890");
assertEquals(CardValidity.TIMEOUT, validity);
}
*/
}
34 changes: 34 additions & 0 deletions 김연지/src/test/java/study/tdd/chap09/UserApiE2ETest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package study.tdd.chap09;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;

import java.net.URI;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class UserApiE2ETest {
/*
@Autowired
private TestRestTemplate restTemplate;
@Test
void weakPwResponse() {
String reqBody =
"{\"id\":\"id\", \"pw\":\"123\", \"email\":\"[email protected]\"}";
RequestEntity<String> request = RequestEntity.post(URI.create("/users"))
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(reqBody);
ResponseEntity<String> response = restTemplate.exchange(
request,
String.class);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
assertTrue(response.getBody().contains("WeakPasswordException"));
}
*/
}
48 changes: 48 additions & 0 deletions 김연지/src/test/java/study/tdd/chap09/UserRegisterIntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package study.tdd.chap09;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import study.tdd.chap07.join.DupIdException;
import study.tdd.chap07.join.UserRegister;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@SpringBootTest
public class UserRegisterIntTest {
/*
@Autowired
private UserRegister register;
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
void 동일ID가_이미_존재하면_익셉션() {
// 상황 : INSERT 쿼리 실행
jdbcTemplate.update(
"insert into user values (?,?,?) " +
"on duplicate key update password = ?, email = ?",
"cbk", "pw", "[email protected]", "pw", "[email protected]");
)
// 실행, 결과 확인
assertThrows(DupIdException.class, () -> register.register("cbk", "strongpw", "[email protected]")
);
}
@Test
void 존재하지_않으면_저장함() {
// 상황 : DELETE 쿼리 실행
jdbcTemplate.update("delete from user where id = ?", "cbk");
// 실행
register.register("cbk", "strongpw", "[email protected]");
// 결과 확인 : SELECT 쿼리 실행
SqlRowSet rs = jdbcTemplate.queryForRowSet(
"select * from user where id = ?", "cbk");
rs.next();
assertEquals("[email protected]", rs.getString("email"));
)
}
*/
}

0 comments on commit 87802a3

Please sign in to comment.