admin: admin 관련 리팩토링
This commit is contained in:
parent
44daa3058b
commit
11b12faed7
|
|
@ -2,12 +2,14 @@ package com.bpgroup.poc.admin.domain.base.admin.entity;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.base.BaseEntity;
|
import com.bpgroup.poc.admin.domain.base.BaseEntity;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Builder;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "admin")
|
@Table(name = "admin")
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
public class Admin extends BaseEntity {
|
public class Admin extends BaseEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
@ -29,15 +31,27 @@ public class Admin extends BaseEntity {
|
||||||
@Embedded
|
@Embedded
|
||||||
private AdminRole adminRole;
|
private AdminRole adminRole;
|
||||||
|
|
||||||
@Builder
|
private Admin(String loginId, String password, String email, String name, AdminRole adminRole) {
|
||||||
public static Admin of(String loginId, String password, String email, String name, AdminRole adminRole) {
|
this.loginId = loginId;
|
||||||
Admin admin = new Admin();
|
this.password = password;
|
||||||
admin.loginId = loginId;
|
this.email = email;
|
||||||
admin.password = password;
|
this.name = name;
|
||||||
admin.email = email;
|
this.adminRole = adminRole;
|
||||||
admin.name = name;
|
}
|
||||||
admin.adminRole = adminRole;
|
|
||||||
return admin;
|
private Admin(String password, String email, String name, AdminRole adminRole) {
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
this.name = name;
|
||||||
|
this.adminRole = adminRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Admin createOf(String loginId, String password, String email, String name, AdminRole adminRole) {
|
||||||
|
return new Admin(loginId, password, email, name, adminRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Admin updateOf(String password, String email, String name, AdminRole adminRole) {
|
||||||
|
return new Admin(password, email, name, adminRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(Admin admin) {
|
public void update(Admin admin) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.bpgroup.poc.admin.domain.base.admin.entity.Admin;
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
|
@ -22,25 +21,20 @@ public class AdminCreateCommand {
|
||||||
@NotNull
|
@NotNull
|
||||||
private AdminRole adminRole;
|
private AdminRole adminRole;
|
||||||
|
|
||||||
@Builder
|
private AdminCreateCommand(String loginId, String password, String email, String name, AdminRole adminRole) {
|
||||||
|
this.loginId = loginId;
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
this.name = name;
|
||||||
|
this.adminRole = adminRole;
|
||||||
|
}
|
||||||
|
|
||||||
public static AdminCreateCommand of(String loginId, String password, String email, String name, AdminRole adminRole) {
|
public static AdminCreateCommand of(String loginId, String password, String email, String name, AdminRole adminRole) {
|
||||||
AdminCreateCommand command = new AdminCreateCommand();
|
return new AdminCreateCommand(loginId, password, email, name, adminRole);
|
||||||
command.loginId = loginId;
|
|
||||||
command.password = password;
|
|
||||||
command.email = email;
|
|
||||||
command.name = name;
|
|
||||||
command.adminRole = adminRole;
|
|
||||||
return command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Admin toEntity() {
|
public Admin toEntity() {
|
||||||
return Admin.builder()
|
return Admin.createOf(loginId, password, email, name, adminRole);
|
||||||
.loginId(loginId)
|
|
||||||
.password(password)
|
|
||||||
.email(email)
|
|
||||||
.name(name)
|
|
||||||
.adminRole(adminRole)
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Validated
|
@Validated
|
||||||
|
|
@ -28,21 +26,11 @@ public class AdminService {
|
||||||
public void update(
|
public void update(
|
||||||
@NotNull @Valid AdminUpdateCommand command
|
@NotNull @Valid AdminUpdateCommand command
|
||||||
) {
|
) {
|
||||||
Optional<Admin> findAdmin = adminRepository.findById(command.getId());
|
Admin findAdmin = adminRepository.findById(command.getId()).orElseThrow(() -> new IllegalArgumentException("Not found admin"));
|
||||||
if (findAdmin.isEmpty()) {
|
findAdmin.update(command.toEntity());
|
||||||
throw new IllegalArgumentException("Not found admin");
|
|
||||||
}
|
|
||||||
|
|
||||||
Admin admin = findAdmin.get();
|
|
||||||
admin.update(command.toEntity());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(@NotNull Long id) {
|
public void delete(@NotNull Long id) {
|
||||||
Optional<Admin> findAdmin = adminRepository.findById(id);
|
|
||||||
if (findAdmin.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Not found admin");
|
|
||||||
}
|
|
||||||
|
|
||||||
adminRepository.deleteById(id);
|
adminRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.bpgroup.poc.admin.domain.base.admin.entity.Admin;
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
|
@ -22,24 +21,20 @@ public class AdminUpdateCommand {
|
||||||
@NotNull
|
@NotNull
|
||||||
private AdminRole adminRole;
|
private AdminRole adminRole;
|
||||||
|
|
||||||
@Builder
|
private AdminUpdateCommand(Long id, String password, String email, String name, AdminRole adminRole) {
|
||||||
|
this.id = id;
|
||||||
|
this.password = password;
|
||||||
|
this.email = email;
|
||||||
|
this.name = name;
|
||||||
|
this.adminRole = adminRole;
|
||||||
|
}
|
||||||
|
|
||||||
public static AdminUpdateCommand of(Long id, String password, String email, String name, AdminRole adminRole) {
|
public static AdminUpdateCommand of(Long id, String password, String email, String name, AdminRole adminRole) {
|
||||||
AdminUpdateCommand command = new AdminUpdateCommand();
|
return new AdminUpdateCommand(id, password, email, name, adminRole);
|
||||||
command.id = id;
|
|
||||||
command.password = password;
|
|
||||||
command.email = email;
|
|
||||||
command.name = name;
|
|
||||||
command.adminRole = adminRole;
|
|
||||||
return command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Admin toEntity() {
|
public Admin toEntity() {
|
||||||
return Admin.builder()
|
return Admin.updateOf(password, email, name, adminRole);
|
||||||
.password(password)
|
|
||||||
.email(email)
|
|
||||||
.name(name)
|
|
||||||
.adminRole(adminRole)
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.bpgroup.poc.admin.web.main.admin.management;
|
||||||
|
|
||||||
|
import com.bpgroup.poc.admin.domain.base.admin.entity.Admin;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.admin.service.AdminCreateCommand;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.admin.service.AdminService;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.admin.service.AdminUpdateCommand;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.role.entity.Role;
|
||||||
|
import com.bpgroup.poc.admin.domain.base.role.service.RoleService;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminCreate;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminDelete;
|
||||||
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminUpdate;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Transactional
|
||||||
|
public class AdminManagementAppService {
|
||||||
|
|
||||||
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
private final AdminService adminService;
|
||||||
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
public AdminCreate.Response create(AdminCreate.Request request) {
|
||||||
|
Role findRole = roleService.find(request.getRoleId()).orElseThrow(() -> new IllegalArgumentException("Role Not Found"));
|
||||||
|
|
||||||
|
Admin savedAdmin = adminService.create(
|
||||||
|
AdminCreateCommand.of(
|
||||||
|
request.getLoginId(),
|
||||||
|
passwordEncoder.encode(request.getPassword()),
|
||||||
|
request.getEmail(),
|
||||||
|
request.getName(),
|
||||||
|
AdminRole.of(findRole)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return AdminCreate.Response.success(savedAdmin.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminUpdate.Response update(AdminUpdate.Request request) {
|
||||||
|
Role findRole = roleService.find(request.getRoleId()).orElseThrow(() -> new IllegalArgumentException("Role Not Found"));
|
||||||
|
|
||||||
|
adminService.update(
|
||||||
|
AdminUpdateCommand.of(
|
||||||
|
request.getId(),
|
||||||
|
passwordEncoder.encode(request.getPassword()),
|
||||||
|
request.getEmail(),
|
||||||
|
request.getName(),
|
||||||
|
AdminRole.of(findRole)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return AdminUpdate.Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminDelete.Response delete(AdminDelete.Request request) {
|
||||||
|
adminService.delete(request.getId());
|
||||||
|
return AdminDelete.Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
public class AdminManagementRestController {
|
public class AdminManagementRestController {
|
||||||
|
|
||||||
private final AdminManagementWebService adminManagementWebService;
|
private final AdminManagementWebService adminManagementWebService;
|
||||||
|
private final AdminManagementAppService adminManagementAppService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 전체 조회
|
* 전체 조회
|
||||||
|
|
@ -26,7 +27,7 @@ public class AdminManagementRestController {
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public ResponseEntity<?> getAdmins() {
|
public ResponseEntity<?> find() {
|
||||||
List<AdminFind.Response> response = adminManagementWebService.findAll();
|
List<AdminFind.Response> response = adminManagementWebService.findAll();
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +39,7 @@ public class AdminManagementRestController {
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{loginId}")
|
@GetMapping("/{loginId}")
|
||||||
public ResponseEntity<?> getAdmin(@PathVariable @NotBlank String loginId) {
|
public ResponseEntity<?> findAll(@PathVariable @NotBlank String loginId) {
|
||||||
AdminFind.Response response = adminManagementWebService.find(loginId);
|
AdminFind.Response response = adminManagementWebService.find(loginId);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
@ -51,20 +52,20 @@ public class AdminManagementRestController {
|
||||||
* @return 응답
|
* @return 응답
|
||||||
*/
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<?> createAdmin(
|
public ResponseEntity<?> create(
|
||||||
@RequestBody @Validated AdminCreate.Request request,
|
@RequestBody @Validated AdminCreate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
AdminCreate.Response response = adminManagementWebService.create(request);
|
AdminCreate.Response response = adminManagementAppService.create(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public ResponseEntity<?> updateAdmin(
|
public ResponseEntity<?> update(
|
||||||
@RequestBody @Validated AdminUpdate.Request request,
|
@RequestBody @Validated AdminUpdate.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
AdminUpdate.Response response = adminManagementWebService.update(request);
|
AdminUpdate.Response response = adminManagementAppService.update(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,11 +73,11 @@ public class AdminManagementRestController {
|
||||||
* 관리자 삭제
|
* 관리자 삭제
|
||||||
*/
|
*/
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ResponseEntity<?> deleteAdmin(
|
public ResponseEntity<?> delete(
|
||||||
@RequestBody @Validated AdminDelete.Request request,
|
@RequestBody @Validated AdminDelete.Request request,
|
||||||
BindingResult bindingResult
|
BindingResult bindingResult
|
||||||
) {
|
) {
|
||||||
AdminDelete.Response response = adminManagementWebService.delete(request);
|
AdminDelete.Response response = adminManagementAppService.delete(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,86 +1,22 @@
|
||||||
package com.bpgroup.poc.admin.web.main.admin.management;
|
package com.bpgroup.poc.admin.web.main.admin.management;
|
||||||
|
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.entity.Admin;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.service.AdminCreateCommand;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.service.AdminService;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.admin.service.AdminUpdateCommand;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.role.entity.Role;
|
|
||||||
import com.bpgroup.poc.admin.domain.base.role.service.RoleService;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminCreate;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminDelete;
|
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminFind;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminFind;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminUpdate;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Transactional
|
|
||||||
public class AdminManagementWebService {
|
public class AdminManagementWebService {
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
private final AdminService adminService;
|
|
||||||
private final RoleService roleService;
|
|
||||||
|
|
||||||
private final AdminManagementQueryRepository queryRepository;
|
private final AdminManagementQueryRepository queryRepository;
|
||||||
|
|
||||||
public List<AdminFind.Response> findAll() {
|
public List<AdminFind.Response> findAll() {
|
||||||
return queryRepository.findAll();
|
return queryRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminFind.Response find(String loginId) {
|
public AdminFind.Response find(String loginId) {
|
||||||
return queryRepository.findByLoginId(loginId);
|
return queryRepository.findByLoginId(loginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminCreate.Response create(AdminCreate.Request request) {
|
|
||||||
Optional<Role> findRole = roleService.find(request.getRoleId());
|
|
||||||
if (findRole.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Role Not Found");
|
|
||||||
}
|
|
||||||
Role role = findRole.get();
|
|
||||||
|
|
||||||
Admin savedAdmin = adminService.create(
|
|
||||||
AdminCreateCommand.builder()
|
|
||||||
.loginId(request.getLoginId())
|
|
||||||
.password(passwordEncoder.encode(request.getPassword()))
|
|
||||||
.email(request.getEmail())
|
|
||||||
.name(request.getName())
|
|
||||||
.adminRole(AdminRole.of(role))
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
return AdminCreate.Response.success(savedAdmin.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdminUpdate.Response update(AdminUpdate.Request request) {
|
|
||||||
Optional<Role> findRole = roleService.find(request.getRoleId());
|
|
||||||
if (findRole.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("Role Not Found");
|
|
||||||
}
|
|
||||||
Role role = findRole.get();
|
|
||||||
|
|
||||||
adminService.update(
|
|
||||||
AdminUpdateCommand.builder()
|
|
||||||
.id(request.getId())
|
|
||||||
.password(passwordEncoder.encode(request.getPassword()))
|
|
||||||
.email(request.getEmail())
|
|
||||||
.name(request.getName())
|
|
||||||
.adminRole(AdminRole.of(role))
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
return AdminUpdate.Response.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdminDelete.Response delete(AdminDelete.Request request) {
|
|
||||||
adminService.delete(request.getId());
|
|
||||||
return AdminDelete.Response.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@DisplayName("AdminService 테스트")
|
@DisplayName("AdminService 테스트")
|
||||||
class AdminServiceTest extends MariaDBTestEnv {
|
class AdminServiceTest extends MariaDBTestEnv {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdminService service;
|
private AdminService service;
|
||||||
|
|
@ -38,19 +38,19 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createAdminTest() {
|
void createAdminTest() {
|
||||||
Role role = getSaveRole();
|
Role role = getSaveRole();
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Admin savedAdmin = service.create(
|
Admin savedAdmin = service.create(
|
||||||
AdminCreateCommand.builder()
|
AdminCreateCommand.of(
|
||||||
.loginId("test")
|
"test",
|
||||||
.password("test")
|
"test",
|
||||||
.email("test")
|
"test",
|
||||||
.name("test")
|
"test",
|
||||||
.adminRole(AdminRole.of(role))
|
AdminRole.of(role)
|
||||||
.build()
|
)
|
||||||
);
|
);
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@DisplayName("Admin 수정 테스트")
|
@DisplayName("Admin 수정 테스트")
|
||||||
@Test
|
@Test
|
||||||
void updateAdminTest() {
|
void updateAdminTest() {
|
||||||
// given
|
// given
|
||||||
Role saveRole = getSaveRole();
|
Role saveRole = getSaveRole();
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
@ -81,13 +81,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
// when
|
// when
|
||||||
service.update(
|
service.update(
|
||||||
AdminUpdateCommand.builder()
|
AdminUpdateCommand.of(
|
||||||
.id(saveAdmin.getId())
|
saveAdmin.getId(),
|
||||||
.password("test2")
|
"test2",
|
||||||
.email("test2")
|
"test2",
|
||||||
.name("test2")
|
"test2",
|
||||||
.adminRole(AdminRole.of(updateRole))
|
AdminRole.of(updateRole)
|
||||||
.build()
|
)
|
||||||
);
|
);
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
@DisplayName("Admin 삭제 테스트")
|
@DisplayName("Admin 삭제 테스트")
|
||||||
@Test
|
@Test
|
||||||
void deleteAdminTest() {
|
void deleteAdminTest() {
|
||||||
// given
|
// given
|
||||||
Role saveRole = getSaveRole();
|
Role saveRole = getSaveRole();
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
@ -117,10 +117,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
// then
|
// then
|
||||||
assertThat(adminRepository.findById(saveAdmin.getId())).isEmpty();
|
assertThat(adminRepository.findById(saveAdmin.getId())).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Admin 삭제 시 Admin 동시 삭제 테스트")
|
@DisplayName("Admin 삭제 시 Admin 동시 삭제 테스트")
|
||||||
@Test
|
@Test
|
||||||
void deleteAdminAndAdminRoleTest() {
|
void deleteAdminAndAdminRoleTest() {
|
||||||
// given
|
// given
|
||||||
Role saveRole = getSaveRole();
|
Role saveRole = getSaveRole();
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
@ -149,13 +149,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
@NotNull
|
@NotNull
|
||||||
private Admin createAdmin(Role role) {
|
private Admin createAdmin(Role role) {
|
||||||
return adminRepository.save(
|
return adminRepository.save(
|
||||||
Admin.builder()
|
Admin.createOf(
|
||||||
.loginId("test")
|
"test",
|
||||||
.password("test")
|
"test",
|
||||||
.email("test")
|
"test",
|
||||||
.name("test")
|
"test",
|
||||||
.adminRole(AdminRole.of(role))
|
AdminRole.of(role)
|
||||||
.build()
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,25 +163,24 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
@DisplayName("AdminService method 호출 유효성 검사 테스트")
|
@DisplayName("AdminService method 호출 유효성 검사 테스트")
|
||||||
void validationTest() {
|
void validationTest() {
|
||||||
// create
|
// create
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId(null).password("password").email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of(null, "password", "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("").password("password").email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("", "password", "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password(null).email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", null, "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("").email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "", "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("password").email(null).name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "password", null, "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("password").email("").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "password", "", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("password").email("email").name(null).adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "password", "email", null, AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("password").email("email").name("").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "password", "email", "", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.create(AdminCreateCommand.builder().loginId("loginId").password("password").email("email").name("name").adminRole(null).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.create(AdminCreateCommand.of("loginId", "password", "email", "name", null))).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
||||||
// update
|
// update
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(null).password("password").email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(null, "password", "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password(null).email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "", "email", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("").email("email").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "password", null, "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("password").email(null).name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "password", "", "name", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("password").email("").name("name").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "password", "email", null, AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("password").email("email").name(null).adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "password", "email", "", AdminRole.of(new Role())))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("password").email("email").name("").adminRole(AdminRole.of(new Role())).build())).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.update(AdminUpdateCommand.of(1L, "password", "email", "name", null))).isInstanceOf(ConstraintViolationException.class);
|
||||||
assertThatThrownBy(() -> service.update(AdminUpdateCommand.builder().id(1L).password("password").email("email").name("name").adminRole(null).build())).isInstanceOf(ConstraintViolationException.class);
|
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
assertThatThrownBy(() -> service.delete(null)).isInstanceOf(ConstraintViolationException.class);
|
assertThatThrownBy(() -> service.delete(null)).isInstanceOf(ConstraintViolationException.class);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import com.bpgroup.poc.admin.domain.base.admin.entity.AdminRole;
|
||||||
import com.bpgroup.poc.admin.domain.base.role.entity.Role;
|
import com.bpgroup.poc.admin.domain.base.role.entity.Role;
|
||||||
import com.bpgroup.poc.admin.domain.base.role.entity.RoleRepository;
|
import com.bpgroup.poc.admin.domain.base.role.entity.RoleRepository;
|
||||||
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
import com.bpgroup.poc.admin.env.MariaDBTestEnv;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.AdminManagementWebService;
|
import com.bpgroup.poc.admin.web.main.admin.management.AdminManagementAppService;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminCreate;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminCreate;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminDelete;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminDelete;
|
||||||
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminUpdate;
|
import com.bpgroup.poc.admin.web.main.admin.management.reqres.AdminUpdate;
|
||||||
|
|
@ -19,10 +19,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@DisplayName("Admin Web Service 테스트")
|
@DisplayName("Admin Web Service 테스트")
|
||||||
@Transactional
|
@Transactional
|
||||||
class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
class AdminManagementAppServiceTest extends MariaDBTestEnv {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdminManagementWebService adminWebService;
|
private AdminManagementAppService adminAppService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdminRepository adminRepository;
|
private AdminRepository adminRepository;
|
||||||
|
|
@ -45,7 +45,7 @@ class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
||||||
request.setRoleId(savedRole.getId());
|
request.setRoleId(savedRole.getId());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdminCreate.Response response = adminWebService.create(request);
|
AdminCreate.Response response = adminAppService.create(request);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
assertThat(response.getResultCode()).isEqualTo("0000");
|
||||||
|
|
@ -57,13 +57,13 @@ class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
||||||
// given
|
// given
|
||||||
Role savedRole = getSavedRole();
|
Role savedRole = getSavedRole();
|
||||||
Admin savedAdmin = adminRepository.save(
|
Admin savedAdmin = adminRepository.save(
|
||||||
Admin.builder()
|
Admin.createOf(
|
||||||
.loginId("test")
|
"test",
|
||||||
.password("test")
|
"test",
|
||||||
.name("test")
|
"test",
|
||||||
.email("test")
|
"test",
|
||||||
.adminRole(AdminRole.of(savedRole))
|
AdminRole.of(savedRole)
|
||||||
.build()
|
)
|
||||||
);
|
);
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
||||||
request.setRoleId(savedRole.getId());
|
request.setRoleId(savedRole.getId());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdminUpdate.Response updateResponse = adminWebService.update(request);
|
AdminUpdate.Response updateResponse = adminAppService.update(request);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(updateResponse.getResultCode()).isEqualTo("0000");
|
assertThat(updateResponse.getResultCode()).isEqualTo("0000");
|
||||||
|
|
@ -87,13 +87,14 @@ class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
||||||
// given
|
// given
|
||||||
Role savedRole = getSavedRole();
|
Role savedRole = getSavedRole();
|
||||||
Admin savedAdmin = adminRepository.save(
|
Admin savedAdmin = adminRepository.save(
|
||||||
Admin.builder()
|
Admin.createOf(
|
||||||
.loginId("test")
|
"test",
|
||||||
.password("test")
|
"test",
|
||||||
.name("test")
|
"test",
|
||||||
.email("test")
|
"test",
|
||||||
.adminRole(AdminRole.of(savedRole))
|
AdminRole.of(savedRole)
|
||||||
.build()
|
)
|
||||||
|
|
||||||
);
|
);
|
||||||
flushAndClear();
|
flushAndClear();
|
||||||
|
|
||||||
|
|
@ -101,7 +102,7 @@ class AdminManagementWebServiceTest extends MariaDBTestEnv {
|
||||||
request.setId(savedAdmin.getId());
|
request.setId(savedAdmin.getId());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
AdminDelete.Response response = adminWebService.delete(request);
|
AdminDelete.Response response = adminAppService.delete(request);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(response.getResultCode()).isEqualTo("0000");
|
assertThat(response.getResultCode()).isEqualTo("0000");
|
||||||
Loading…
Reference in New Issue