Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69f3053

Browse files
author
kimyonghwa
committed
Modified the unit test
1 parent 189e741 commit 69f3053

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

‎src/main/java/com/rest/api/controller/v1/UserController.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public SingleResult<User> findUser() {
5151
@ApiOperation(value = "회원 수정", notes = "회원정보를 수정한다")
5252
@PutMapping(value = "/user")
5353
public SingleResult<User> modify(
54-
@ApiParam(value = "회원번호", required = true) @RequestParam long msrl,
5554
@ApiParam(value = "회원이름", required = true) @RequestParam String name) {
56-
User user = User.builder()
57-
.msrl(msrl)
58-
.name(name)
59-
.build();
55+
56+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
57+
String id = authentication.getName();
58+
User user = userJpaRepo.findByUid(id).orElseThrow(CUserNotFoundException::new);
59+
user.setName(name);
6060
return responseService.getSingleResult(userJpaRepo.save(user));
6161
}
6262

‎src/main/java/com/rest/api/entity/User.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.rest.api.entity.common.CommonDateEntity;
6-
import lombok.AllArgsConstructor;
7-
import lombok.Builder;
8-
import lombok.Getter;
9-
import lombok.NoArgsConstructor;
6+
import lombok.*;
107
import org.springframework.security.core.GrantedAuthority;
118
import org.springframework.security.core.authority.SimpleGrantedAuthority;
129
import org.springframework.security.core.userdetails.UserDetails;
@@ -20,6 +17,7 @@
2017
@Builder // builder를 사용할수 있게 합니다.
2118
@Entity // jpa entity임을 알립니다.
2219
@Getter // user 필드값의 getter를 자동으로 생성합니다.
20+
@Setter
2321
@NoArgsConstructor // 인자없는 생성자를 자동으로 생성합니다.
2422
@AllArgsConstructor // 인자를 모두 갖춘 생성자를 자동으로 생성합니다.
2523
@Table(name = "user") // 'user' 테이블과 매핑됨을 명시

‎src/test/java/com/rest/api/controller/v1/UserControllerTest.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class UserControllerTest {
4747

4848
@Before
4949
public void setUp() throws Exception {
50-
userJpaRepo.save(User.builder().uid("happydaddy@naver.com").name("happydaddy").password(passwordEncoder.encode("1234")).roles(Collections.singletonList("ROLE_USER")).build());
50+
//userJpaRepo.save(User.builder().uid("happydaddy@naver.com").name("happydaddy").password(passwordEncoder.encode("1234")).roles(Collections.singletonList("ROLE_USER")).build());
5151
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
5252
params.add("id", "happydaddy@naver.com");
5353
params.add("password", "1234");
@@ -75,8 +75,8 @@ public void invalidToken() throws Exception {
7575
.get("/v1/users")
7676
.header("X-AUTH-TOKEN", "XXXXXXXXXX"))
7777
.andDo(print())
78-
.andExpect(status().isOk())
79-
.andExpect(forwardedUrl("/exception/entrypoint"));
78+
.andExpect(status().is3xxRedirection())
79+
.andExpect(redirectedUrl("/exception/entrypoint"));
8080
}
8181

8282
@Test
@@ -86,8 +86,8 @@ public void accessdenied() throws Exception {
8686
.get("/v1/users"))
8787
//.header("X-AUTH-TOKEN", token))
8888
.andDo(print())
89-
.andExpect(status().isOk())
90-
.andExpect(forwardedUrl("/exception/accessdenied"));
89+
.andExpect(status().is3xxRedirection())
90+
.andExpect(redirectedUrl("/exception/accessdenied"));
9191
}
9292

9393
@Test
@@ -115,15 +115,16 @@ public void findUser() throws Exception {
115115
@Test
116116
public void modify() throws Exception {
117117
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
118-
params.add("msrl", "1");
118+
params.add("uid", "happydaddy@naver.com");
119119
params.add("name", "행복전도사");
120120
mockMvc.perform(MockMvcRequestBuilders
121121
.put("/v1/user")
122122
.header("X-AUTH-TOKEN", token)
123123
.params(params))
124124
.andDo(print())
125125
.andExpect(status().isOk())
126-
.andExpect(jsonPath("$.success").value(true));
126+
.andExpect(jsonPath("$.success").value(true))
127+
.andExpect(jsonPath("$.data.name").value("행복전도사"));
127128
}
128129

129130
@Test

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /