This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#11, DB 커넥션을 맺는 기능과 DB 에 엑세스 하기 위한 기능에 대한 책임 관계 분리
- Loading branch information
Showing
9 changed files
with
86 additions
and
26 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/flabedu/blackpostoffice/dao/ConnectionMaker.kt
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,9 @@ | ||
package com.flabedu.blackpostoffice.dao | ||
|
||
import java.sql.Connection | ||
import kotlin.jvm.Throws | ||
|
||
interface ConnectionMaker { | ||
@Throws | ||
fun makeConnection(): Connection | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/flabedu/blackpostoffice/dao/FConnectionMaker.kt
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,17 @@ | ||
package com.flabedu.blackpostoffice.dao | ||
|
||
import java.sql.Connection | ||
import java.sql.DriverManager | ||
import kotlin.jvm.Throws | ||
|
||
class FConnectionMaker: ConnectionMaker { | ||
|
||
@Throws | ||
override fun makeConnection(): Connection { | ||
Class.forName("org.h2.Driver") | ||
|
||
val c: Connection = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "") | ||
|
||
return c | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +0,0 @@ | ||
spring.datasource.url=jdbc:h2:mem:test | ||
spring.datasource.username=sa | ||
spring.datasource.password= | ||
spring.datasource.driver-class-name=org.h2.Driver | ||
|
||
spring.h2.console.enabled=true | ||
2 changes: 1 addition & 1 deletion
2
...lin/com/flabedu/blackpostoffice/H2Test.kt → .../flabedu/blackpostoffice/config/H2Test.kt
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
35 changes: 35 additions & 0 deletions
35
src/test/kotlin/com/flabedu/blackpostoffice/dao/UserDaoTest.kt
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,35 @@ | ||
package com.flabedu.blackpostoffice.dao | ||
|
||
import com.flabedu.blackpostoffice.domain.User | ||
import junit.framework.Assert.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.runner.RunWith | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner | ||
|
||
@RunWith(SpringJUnit4ClassRunner::class) | ||
@SpringBootTest(properties = ["classpath:application.properties"]) | ||
class UserDaoTest { | ||
|
||
@Test | ||
fun `유저 등록 테스드`() { | ||
val connectionMaker: ConnectionMaker = FConnectionMaker() | ||
|
||
val dao = UserDao(connectionMaker) | ||
|
||
val user = User() | ||
|
||
user.id = "dudrnxps" | ||
user.name = "박영환" | ||
user.password = "1234" | ||
|
||
dao.add(user) | ||
|
||
assertEquals(user.id, "dudrnxps") | ||
|
||
val user2: User = dao.get(user.id) | ||
|
||
assertEquals(user.id, user2.id) | ||
assertEquals(user.password, user2.password) | ||
} | ||
} |
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,6 @@ | ||
spring.datasource.url=jdbc:h2:mem:test;INIT=RUNSCRIPT FROM './src/main/resources/schema.sql' | ||
spring.datasource.driver-class-name=org.h2.Driver | ||
spring.datasource.username=sa | ||
spring.datasource.password= | ||
|
||
spring.h2.console.enabled=true |
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,7 @@ | ||
DROP TABLE IF EXISTS users; | ||
|
||
CREATE TABLE users ( | ||
id VARCHAR(10) PRIMARY KEY, | ||
name VARCHAR(20) NOT NULL, | ||
password VARCHAR(10) NOT NULL | ||
); |