Skip to content

Commit

Permalink
Merge branch 'feature/login2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
choisungwook committed Oct 8, 2021
2 parents 4064b0c + af4d496 commit d6d3cf0
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
log.debug("로그인 성공");
// todo - jwt토큰 발급
super.successfulAuthentication(request, response, chain, authResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.infp.ciat.config.security;

import lombok.NoArgsConstructor;

/***
* 로그인 요청 dto
*/
@NoArgsConstructor
public class RequestLoginDTO {
private String email;
private String password;
Expand All @@ -22,4 +25,9 @@ public void setEmail(String email) {
public void setPassword(String password) {
this.password = password;
}

public RequestLoginDTO(String email, String password) {
this.email = email;
this.password = password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class AccountController {
private final AccountService accountService;

@PostMapping("/users")
@PostMapping("/signup")
public ResponseEntity<SignUpResponse> SignUp(@Valid @RequestBody SignupRequestDTO requestDTO) {
log.info("------------------- 회원가입 요청 -----------------------");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.infp.ciat.config.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
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.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.jupiter.api.Assertions.*;
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.status;

@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
class LoginfilterTest {
@Autowired
private MockMvc mockMvc;

@Test
@DisplayName("회원가입 후 로그인")
public void SignUp() throws Exception {
SignupRequestDTO signup_requestdto1 = create_signup_requestdto("[email protected]", "test1", "password");

mockMvc.perform(
post("/signup")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(signup_requestdto1))
)
.andExpect(status().isCreated())
.andDo(print());

RequestLoginDTO requestLoginDTO1 = new RequestLoginDTO(signup_requestdto1.getEmail(), signup_requestdto1.getPassword());

mockMvc.perform(
post("/signin")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(requestLoginDTO1))
)
.andExpect(status().isOk())
.andDo(print());
}

/***
* 회원가입 요청 DTO 생성
* @param email
* @param nickname
* @param password
* @return
*/
private SignupRequestDTO create_signup_requestdto(String email, String nickname, String password) {
SignupRequestDTO signupRequestDTO = new SignupRequestDTO();
signupRequestDTO.setEmail(email);
signupRequestDTO.setNickname(nickname);
signupRequestDTO.setPassword(password);

return signupRequestDTO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.infp.ciat.user.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
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.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;

import static org.junit.jupiter.api.Assertions.*;
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.status;

@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
class AccountControllerTest {
@Autowired
private MockMvc mockMvc;

@Test
@DisplayName("회원가입")
public void SignUp() throws Exception {
SignupRequestDTO signup_requestdto1 = create_signup_requestdto("[email protected]", "test1", "password");

mockMvc.perform(
post("/signup")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(signup_requestdto1))
)
.andExpect(status().isCreated())
.andDo(print());
}

/***
* 회원가입 요청 DTO 생성
* @param email
* @param nickname
* @param password
* @return
*/
private SignupRequestDTO create_signup_requestdto(String email, String nickname, String password) {
SignupRequestDTO signupRequestDTO = new SignupRequestDTO();
signupRequestDTO.setEmail(email);
signupRequestDTO.setNickname(nickname);
signupRequestDTO.setPassword(password);

return signupRequestDTO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import static org.junit.jupiter.api.Assertions.*;

import com.infp.ciat.user.entity.Account;
import com.infp.ciat.user.repository.AccountRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;


//@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = "spring.config.location=classpath:application-test.yml")
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Transactional
class AccountServiceTest {

Expand Down

0 comments on commit d6d3cf0

Please sign in to comment.