-
Notifications
You must be signed in to change notification settings - Fork 0
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
130 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
김연지/src/test/java/study/tdd/chap09/CardNumberValidatorTest.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,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); | ||
} | ||
*/ | ||
} |
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,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
48
김연지/src/test/java/study/tdd/chap09/UserRegisterIntTest.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,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")); | ||
) | ||
} | ||
*/ | ||
} |