Skip to content

Commit

Permalink
Merge pull request #13 from taco-official/KL-100/sql-초기실행-설정
Browse files Browse the repository at this point in the history
chore(Kl-100): set up sql initialization
  • Loading branch information
ohhamma authored Jul 22, 2024
2 parents 934d8b7 + f112700 commit dc166d6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import taco.klkl.domain.user.domain.User;
import taco.klkl.domain.user.service.UserService;

@Slf4j
@RestController
@RequestMapping("api/v1/users")
@Tag(name = "1. 유저", description = "유저 관련 API")
@RequestMapping("/v1/users")
public class UserController {
final UserService userService;

public UserController(UserService userService) {
this.userService = userService;
}

@Operation(summary = "내 정보 조회", description = "내 정보를 조회합니다. (테스트용)")
@GetMapping("/me")
public ResponseEntity<User> getMe() {
User user = userService.me();
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/application-h2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ spring:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create
defer-datasource-initialization: true
properties:
hibernate:
show-sql: true
format-sql: true
format-sql: true
sql:
init:
data-locations: classpath:database/data.sql # 더미데이터 파일 연결
mode: always
platform: h2
17 changes: 17 additions & 0 deletions src/main/resources/database/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* User */
INSERT INTO User(user_id, profile, name, gender, age, description, created_at)
VALUES (1, 'image/test.jpg', 'testUser', '', 20, '테스트입니다.', now());

/* Product */

/* Like */

/* Comment */

/* Region */

/* Category */

/* Filter */

/* Notification */
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import taco.klkl.domain.user.dao.UserRepository;
import taco.klkl.domain.user.domain.User;
import taco.klkl.domain.user.service.UserService;
import taco.klkl.global.common.enums.Gender;

@SpringBootTest
@AutoConfigureMockMvc
Expand All @@ -29,19 +28,13 @@ public class UserIntegrationTest {
@Autowired
UserRepository userRepository;

User user;

@Test
public void testUserMe() throws Exception {
// given
User user = new User(null, "testUser", Gender.MALE, 20, "테스트 유저입니다.");

// when
userRepository.save(user);
user = userService.me();
// given, when
User user = userService.me();

// then
mockMvc.perform(get("/api/v1/users/me"))
mockMvc.perform(get("/v1/users/me"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess", is(true)))
.andExpect(jsonPath("$.code", is("C000")))
Expand All @@ -50,7 +43,7 @@ public void testUserMe() throws Exception {
.andExpect(jsonPath("$.data.gender", is(user.getGender().toString())))
.andExpect(jsonPath("$.data.age", is(user.getAge())))
.andExpect(jsonPath("$.data.description", is(user.getDescription())))
.andExpect(jsonPath("$.data.profile", is("image/default.jpg")))
.andExpect(jsonPath("$.data.profile", is("image/test.jpg")))
.andExpect(jsonPath("$.data.createdAt", notNullValue()))
.andExpect(jsonPath("$.timestamp", notNullValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void getMe() throws Exception {
Mockito.when(userService.me()).thenReturn(user);

// when & then
mockMvc.perform(get("/api/v1/users/me")
mockMvc.perform(get("/v1/users/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess", is(true)))
Expand Down

0 comments on commit dc166d6

Please sign in to comment.