Compare commits
27 Commits
feature/ch
...
feature/cr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56e475c119 | ||
|
|
f7b6f019b9 | ||
|
|
e6e8139171 | ||
|
|
587b27ac35 | ||
|
|
4b07ac0ac6 | ||
|
|
032ec69e25 | ||
|
|
812a646e07 | ||
|
|
9d35115ed4 | ||
|
|
a1a4f39d19 | ||
|
|
6a3885a12e | ||
|
|
ca16370bfc | ||
|
|
0c8386f6f6 | ||
|
|
ccf2b95201 | ||
|
|
cd3e1bdea2 | ||
|
|
1f4b06b102 | ||
|
|
45b5bbb02a | ||
|
|
7ad71a0445 | ||
|
|
f6c80ce1cc | ||
|
|
08219996bf | ||
|
|
b60f641b1d | ||
|
|
12b86fab36 | ||
|
|
7cc661521f | ||
|
|
3c6fbbe304 | ||
|
|
64036fa8a6 | ||
|
|
7e22abb9dd | ||
|
|
1138860305 | ||
|
|
2870351d99 |
3
server/.gitignore
vendored
3
server/.gitignore
vendored
@@ -200,4 +200,7 @@ gradle-app.setting
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# log
|
||||
/logs
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,visualstudiocode
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
java
|
||||
id ("org.springframework.boot") version "2.6.7"
|
||||
id ("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||
id("org.springframework.boot") version "2.6.7"
|
||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||
}
|
||||
|
||||
group = "com.ticketing"
|
||||
@@ -26,14 +26,14 @@ repositories {
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
// implementation ("org.springframework.boot:spring-boot-starter-security")
|
||||
implementation ("org.springframework.boot:spring-boot-starter-validation")
|
||||
implementation ("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation ("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||
implementation ("org.springframework.boot:spring-boot-starter-log4j2")
|
||||
implementation ("com.lmax:disruptor:3.4.2")
|
||||
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
||||
implementation("com.lmax:disruptor:3.4.2")
|
||||
|
||||
modules {
|
||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
||||
@@ -41,12 +41,12 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
compileOnly ("org.projectlombok:lombok")
|
||||
runtimeOnly ("mysql:mysql-connector-java")
|
||||
annotationProcessor ("org.projectlombok:lombok")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
runtimeOnly("mysql:mysql-connector-java")
|
||||
annotationProcessor("org.projectlombok:lombok")
|
||||
|
||||
testImplementation ("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation ("org.springframework.security:spring-security-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation("org.springframework.security:spring-security-test")
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ticketing.server.global.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
@Configuration
|
||||
public class MessagesConfig {
|
||||
|
||||
@Bean
|
||||
public ResourceBundleMessageSource messageSource() {
|
||||
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||
messageSource.setBasename("i18n/messages");
|
||||
messageSource.setDefaultEncoding("UTF-8");
|
||||
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LocalValidatorFactoryBean getValidator() {
|
||||
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
||||
factoryBean.setValidationMessageSource(messageSource());
|
||||
|
||||
return factoryBean;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.ticketing.server.global.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.cors().disable()
|
||||
.csrf().disable()
|
||||
.formLogin().disable()
|
||||
.headers().frameOptions().disable();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ticketing.server.global.validator.constraints;
|
||||
|
||||
import com.ticketing.server.global.validator.constraintvalidators.PhoneValidator;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = {PhoneValidator.class})
|
||||
@Documented
|
||||
public @interface Phone {
|
||||
|
||||
String message() default "{validation.phone}";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ticketing.server.global.validator.constraintvalidators;
|
||||
|
||||
import com.ticketing.server.global.validator.constraints.Phone;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
public class PhoneValidator implements ConstraintValidator<Phone, String> {
|
||||
|
||||
private static final String PATTERN = "\\d{3}-\\d{4}-\\d{4}";
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Pattern.matches(PATTERN, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,36 @@
|
||||
package com.ticketing.server.user.application;
|
||||
|
||||
import com.ticketing.server.user.application.request.SignUpRequest;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.service.UserServiceImpl;
|
||||
import java.util.Optional;
|
||||
import javax.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
private final UserServiceImpl userService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Object> register(@RequestBody @Valid SignUpRequest signUpRequest) {
|
||||
Optional<User> user = userService.register(signUpRequest.toSignUp(passwordEncoder));
|
||||
|
||||
if (user.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ticketing.server.user.application.request;
|
||||
|
||||
import com.ticketing.server.global.validator.constraints.Phone;
|
||||
import com.ticketing.server.user.service.dto.SignUp;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Getter
|
||||
public class SignUpRequest {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.name}")
|
||||
private String name;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String password;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||
@Phone
|
||||
private String phone;
|
||||
|
||||
public SignUp toSignUp(PasswordEncoder passwordEncoder) {
|
||||
return new SignUp(name, email, getEncodePassword(passwordEncoder), phone);
|
||||
}
|
||||
|
||||
private String getEncodePassword(PasswordEncoder passwordEncoder) {
|
||||
return passwordEncoder.encode(password);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
||||
import com.ticketing.server.global.validator.constraints.Phone;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -15,28 +18,34 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class User extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@Column(name = "name")
|
||||
@NotEmpty(message = "{validation.not.empty.name}")
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "email")
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "password")
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String password;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "grade")
|
||||
@NotNull(message = "{validation.not.empty.grade}")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private UserGrade grade;
|
||||
private UserGrade grade = UserGrade.GUEST;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "phone")
|
||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||
@Phone
|
||||
private String phone;
|
||||
|
||||
private boolean isDeleted = false;
|
||||
|
||||
private LocalDateTime deletedAt;
|
||||
|
||||
@Builder
|
||||
protected User(String name, String email, String password, UserGrade grade, String phone) {
|
||||
public User(String name, String email, String password, UserGrade grade, String phone) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.ticketing.server.user.domain.repository;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
Optional<User> findByEmail(String email);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,37 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
||||
import com.ticketing.server.user.service.dto.SignUp;
|
||||
import com.ticketing.server.user.service.interfaces.UserService;
|
||||
import java.util.Optional;
|
||||
import javax.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Optional<User> register(@Valid SignUp signUpDto) {
|
||||
Optional<User> user = userRepository.findByEmail(signUpDto.getEmail());
|
||||
if (user.isPresent()) {
|
||||
log.error("이미 존재하는 이메일이기 때문에 신규 회원가입을 진행할 수 없습니다. :: {}", signUpDto);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
User newUser = userRepository.save(signUpDto.toUser());
|
||||
return Optional.of(newUser);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import com.ticketing.server.global.validator.constraints.Phone;
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class SignUp {
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.name}")
|
||||
private String name;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.email}")
|
||||
@Email(message = "{validation.email}")
|
||||
private String email;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.password}")
|
||||
private String password;
|
||||
|
||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||
@Phone
|
||||
private String phone;
|
||||
|
||||
public SignUp(String name, String email, String password, String phone) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public User toUser() {
|
||||
return new User(this.name, this.email, password, UserGrade.GUEST, this.phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SignUp{" +
|
||||
"name='" + name + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", phone='" + phone + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package com.ticketing.server.user.service.interfaces;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.service.dto.SignUp;
|
||||
import java.util.Optional;
|
||||
import javax.validation.Valid;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
Optional<User> register(@Valid SignUp signUpDto);
|
||||
|
||||
}
|
||||
|
||||
7
server/src/main/resources/i18n/messages.properties
Normal file
7
server/src/main/resources/i18n/messages.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||
7
server/src/main/resources/i18n/messages_en.properties
Normal file
7
server/src/main/resources/i18n/messages_en.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
validation.not.empty.name="name is required."
|
||||
validation.not.empty.email="email is required."
|
||||
validation.not.empty.password="password is required."
|
||||
validation.not.empty.grade="user grade is required."
|
||||
validation.not.empty.phone="phone is required."
|
||||
validation.email="email is not valid."
|
||||
validation.phone="phone is not valid."
|
||||
7
server/src/main/resources/i18n/messages_ko.properties
Normal file
7
server/src/main/resources/i18n/messages_ko.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||
@@ -2,10 +2,8 @@ package com.ticketing.server;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
|
||||
@SpringBootTest
|
||||
@EnableJpaAuditing
|
||||
class ServerApplicationTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.ticketing.server.user.domain;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class UserTest {
|
||||
|
||||
private static Validator validator;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
||||
validator = factory.getValidator();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("유저 검증 성공")
|
||||
void validateSuccess() {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).isEmpty();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@DisplayName("name null 혹은 빈값 검증")
|
||||
void nameNullOrEmpty(String name) {
|
||||
// given
|
||||
User user = new User(name, "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@DisplayName("email null or empty 검증")
|
||||
void emailNullOrEmpty(String email) {
|
||||
// given
|
||||
User user = new User("유저1", email, "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"email", "@hello.com", "12Bye#domain.com"})
|
||||
@DisplayName("email 실패 검증")
|
||||
void emailValid(String email) {
|
||||
// given
|
||||
User user = new User("유저1", email, "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@DisplayName("password null 혹은 빈값 검증")
|
||||
void passwordNullOrEmpty(String password) {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", password, UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("grade null 검증")
|
||||
void gradeNull() {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", null, "010-1234-5678");
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("phone null or empty 검증")
|
||||
@NullAndEmptySource
|
||||
void phoneNullOrEmpty(String phone) {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, phone);
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("phone 실패 검증")
|
||||
@ValueSource(strings = {"010-123-1234", "02-0444-4044", "033-7953", "033-0455-504"})
|
||||
void phoneValid(String phone) {
|
||||
// given
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, phone);
|
||||
|
||||
// when
|
||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||
|
||||
// then
|
||||
assertThat(constraintViolations).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,13 +19,7 @@ class UserRepositoryTest {
|
||||
@Test
|
||||
void 유저레포지토리테스트() {
|
||||
// given
|
||||
User user = User.builder()
|
||||
.name("동효")
|
||||
.password("test")
|
||||
.email("test@test.com")
|
||||
.grade(UserGrade.GUEST)
|
||||
.phone("010-1234-5678")
|
||||
.build();
|
||||
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
|
||||
|
||||
// when
|
||||
userRepository.save(user);
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.ticketing.server.user.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import com.ticketing.server.user.domain.UserGrade;
|
||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
||||
import com.ticketing.server.user.service.dto.SignUp;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UserServiceImplTest {
|
||||
|
||||
User user;
|
||||
SignUp signUp;
|
||||
|
||||
@Mock
|
||||
UserRepository userRepository;
|
||||
|
||||
@InjectMocks
|
||||
UserServiceImpl userService;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
|
||||
signUp = new SignUp("유저", "ticketing@gmail.com", "123456", "010-1234-5678");
|
||||
user = new User("유저", "ticketing@gmail.com", "123456", UserGrade.GUEST, "010-1234-5678");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("이미 동일한 이메일이 있을 경우")
|
||||
void duplicateEmailException() {
|
||||
// given
|
||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.of(user));
|
||||
|
||||
// when
|
||||
Optional<User> user = userService.register(signUp);
|
||||
|
||||
// then
|
||||
assertThat(user).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("회원가입 성공했을 경우")
|
||||
void UserServiceImplTest() {
|
||||
// given
|
||||
when(userRepository.findByEmail("ticketing@gmail.com")).thenReturn(Optional.empty());
|
||||
when(userRepository.save(any())).thenReturn(user);
|
||||
|
||||
// when
|
||||
Optional<User> user = userService.register(signUp);
|
||||
|
||||
// then
|
||||
assertThat(user).isPresent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ticketing.server.user.service.dto;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.ticketing.server.user.domain.User;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SignUpTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("toUser 메소드로 User 객체 생성")
|
||||
void toUser() {
|
||||
// given
|
||||
SignUp signUp = new SignUp("유저1", "ticketing@gmail.com", "123456", "010-1234-5678");
|
||||
|
||||
// when
|
||||
User user = signUp.toUser();
|
||||
|
||||
// then
|
||||
assertThat(user).isInstanceOf(User.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user