This repository has been archived by the owner on Aug 13, 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.
- Account create에 대한 Test code 작성 - Account create에 대한 Service, controller 비즈니스 로직 완성
- Loading branch information
Showing
8 changed files
with
174 additions
and
12 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
20 changes: 20 additions & 0 deletions
20
src/main/java/me/jjeda/mall/accounts/Service/AccountService.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,20 @@ | ||
package me.jjeda.mall.accounts.Service; | ||
|
||
import lombok.AllArgsConstructor; | ||
import me.jjeda.mall.accounts.domain.Account; | ||
import me.jjeda.mall.accounts.dto.AccountDto; | ||
import me.jjeda.mall.accounts.repository.AccountRepository; | ||
import org.springframework.hateoas.mvc.ControllerLinkBuilder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class AccountService { | ||
|
||
AccountRepository accountRepository; | ||
|
||
public Account saveAccount(AccountDto dto) { | ||
//TODO : passwordEncoder로 비밀번호 hashing처리 | ||
return accountRepository.save(dto.toEntity()); | ||
} | ||
} |
28 changes: 26 additions & 2 deletions
28
src/main/java/me/jjeda/mall/accounts/controller/AccountController.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 |
---|---|---|
@@ -1,7 +1,31 @@ | ||
package me.jjeda.mall.accounts.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import lombok.AllArgsConstructor; | ||
import me.jjeda.mall.accounts.Service.AccountService; | ||
import me.jjeda.mall.accounts.domain.Account; | ||
import me.jjeda.mall.accounts.dto.AccountDto; | ||
import org.springframework.hateoas.MediaTypes; | ||
import org.springframework.hateoas.mvc.ControllerLinkBuilder; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Controller | ||
import java.net.URI; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping(value = "/api/accounts", produces = MediaTypes.HAL_JSON_UTF8_VALUE) | ||
public class AccountController { | ||
|
||
AccountService accountService; | ||
|
||
@PostMapping | ||
public ResponseEntity createAccount(@RequestBody AccountDto requestAccount) { | ||
Account account = accountService.saveAccount(requestAccount); | ||
URI uri = ControllerLinkBuilder.linkTo(AccountController.class).slash(account.getId()).toUri(); | ||
|
||
return ResponseEntity.created(uri).body(account); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package me.jjeda.mall.common; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.SOURCE) | ||
public @interface TestDescription { String value();} |
93 changes: 92 additions & 1 deletion
93
src/test/java/me/jjeda/mall/accounts/controller/AccountControllerTest.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 |
---|---|---|
@@ -1,7 +1,98 @@ | ||
package me.jjeda.mall.accounts.controller; | ||
|
||
import static org.junit.Assert.*; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import me.jjeda.mall.accounts.domain.AccountRole; | ||
import me.jjeda.mall.accounts.domain.Address; | ||
import me.jjeda.mall.accounts.dto.AccountDto; | ||
import me.jjeda.mall.accounts.repository.AccountRepository; | ||
import me.jjeda.mall.common.TestDescription; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
public class AccountControllerTest { | ||
|
||
@Autowired | ||
AccountRepository accountRepository; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
@TestDescription("정상적으로 계정을 생성하는 테스트") | ||
public void createAccount() throws Exception { | ||
//given | ||
AccountDto dto = AccountDto.builder() | ||
.email("jjeda@naver.com") | ||
.password("pass") | ||
.userName("jjeda") | ||
.phone("010-1234-1234") | ||
.accountRole(AccountRole.USER) | ||
.address(new Address("seoul", "anju", "1234")) | ||
.build(); | ||
accountRepository.save(dto.toEntity()); | ||
|
||
// when & then | ||
mockMvc.perform(post("/api/accounts") | ||
.contentType(MediaType.APPLICATION_JSON_UTF8) | ||
.content(objectMapper.writeValueAsString(dto))) | ||
.andDo(print()) | ||
.andExpect(status().isCreated()) | ||
.andExpect(jsonPath("id").exists()) | ||
.andExpect(jsonPath("userName").value("jjeda")); | ||
// .andExpect(jsonPath("password").doesNotExist()); | ||
} | ||
|
||
@Test | ||
@TestDescription("입력 값이 유효하지 않는 경우 에러가 발생하는 테스트") | ||
public void createAccount_Bad_Request_Wrong_Input() { | ||
|
||
} | ||
|
||
@Test | ||
@TestDescription("30명의 유저에서 10명씩 2번째 페이지 조회하기") | ||
public void queryAccount() { | ||
|
||
} | ||
|
||
@Test | ||
@TestDescription("정상적으로 유저 한명을 조회하는 테스트") | ||
public void getAccount() { | ||
|
||
} | ||
|
||
@Test | ||
@TestDescription("정상적으로 비밀번호를 변경하는 테스트") | ||
public void modifyPassword() { | ||
|
||
} | ||
|
||
@Test | ||
@TestDescription("정상적으로 개인정보를 변경하는 테스트") | ||
public void modifyAccount() { | ||
|
||
} | ||
|
||
@Test | ||
@TestDescription("정상적으로 계정정보를 삭제하는 테스트") | ||
public void deleteAccount() { | ||
|
||
} | ||
|
||
} |