-
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
4 changed files
with
70 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
src/main/java/com/likelionsch/simpleapiexample/item/ItemDto.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
53 changes: 53 additions & 0 deletions
53
src/test/java/com/likelionsch/simpleapiexample/item/ItemControllerTest.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,53 @@ | ||
package com.likelionsch.simpleapiexample.item; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
@SpringBootTest | ||
@ExtendWith(SpringExtension.class) | ||
@AutoConfigureMockMvc | ||
class ItemControllerTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
@Autowired | ||
ItemService itemService; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
ItemDto itemDto1 = ItemDto.builder() | ||
.name("item1") | ||
.price(3000) | ||
.build(); | ||
itemService.createItem(itemDto1); | ||
|
||
ItemDto itemDto2 = ItemDto.builder() | ||
.name("item2") | ||
.price(4000) | ||
.build(); | ||
itemService.createItem(itemDto2); | ||
} | ||
|
||
@Test | ||
public void getAllItems() throws Exception { | ||
|
||
mockMvc.perform(get("/api/item")) | ||
.andDo(print()); | ||
|
||
} | ||
|
||
} |
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,14 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:h2:tcp://localhost/~/simpleexample | ||
username: sa | ||
password: | ||
driver-class-name: org.h2.Driver | ||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
logging.level: | ||
org.hibernate.SQL: debug |