Commit 8939e0fc01921314a092539fe19d600095bc454e
1 parent
80bab78a
feat(usr): LoginReq + LoginVo + UserInfoVo REQ-USR-001
Showing
4 changed files
with
117 additions
and
0 deletions
backend/src/main/java/com/xly/erp/module/usr/dto/LoginReq.java
0 → 100644
| 1 | +package com.xly.erp.module.usr.dto; | ||
| 2 | + | ||
| 3 | +import jakarta.validation.constraints.NotBlank; | ||
| 4 | +import jakarta.validation.constraints.Size; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Data | ||
| 8 | +public class LoginReq { | ||
| 9 | + | ||
| 10 | + @NotBlank | ||
| 11 | + @Size(max = 50) | ||
| 12 | + private String username; | ||
| 13 | + | ||
| 14 | + @NotBlank | ||
| 15 | + @Size(max = 128) | ||
| 16 | + private String password; | ||
| 17 | + | ||
| 18 | + @NotBlank | ||
| 19 | + @Size(max = 50) | ||
| 20 | + private String companyCode; | ||
| 21 | +} |
backend/src/main/java/com/xly/erp/module/usr/vo/LoginVo.java
0 → 100644
backend/src/main/java/com/xly/erp/module/usr/vo/UserInfoVo.java
0 → 100644
| 1 | +package com.xly.erp.module.usr.vo; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 4 | +import lombok.Builder; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Data | ||
| 8 | +@Builder | ||
| 9 | +@JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 10 | +public class UserInfoVo { | ||
| 11 | + private Integer userId; | ||
| 12 | + private String username; | ||
| 13 | + private String userType; | ||
| 14 | + private String language; | ||
| 15 | + private String employeeName; | ||
| 16 | + private String companyCode; | ||
| 17 | +} |
backend/src/test/java/com/xly/erp/module/usr/dto/LoginReqValidationTest.java
0 → 100644
| 1 | +package com.xly.erp.module.usr.dto; | ||
| 2 | + | ||
| 3 | +import jakarta.validation.ConstraintViolation; | ||
| 4 | +import jakarta.validation.Validation; | ||
| 5 | +import jakarta.validation.Validator; | ||
| 6 | +import jakarta.validation.ValidatorFactory; | ||
| 7 | +import org.junit.jupiter.api.Test; | ||
| 8 | + | ||
| 9 | +import java.util.Set; | ||
| 10 | + | ||
| 11 | +import static org.junit.jupiter.api.Assertions.*; | ||
| 12 | + | ||
| 13 | +class LoginReqValidationTest { | ||
| 14 | + | ||
| 15 | + private static final Validator VALIDATOR = | ||
| 16 | + Validation.buildDefaultValidatorFactory().getValidator(); | ||
| 17 | + | ||
| 18 | + private LoginReq build(String u, String p, String c) { | ||
| 19 | + LoginReq r = new LoginReq(); | ||
| 20 | + r.setUsername(u); | ||
| 21 | + r.setPassword(p); | ||
| 22 | + r.setCompanyCode(c); | ||
| 23 | + return r; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Test | ||
| 27 | + void blankUsername_fails() { | ||
| 28 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build("", "Password1!", "HQ")); | ||
| 29 | + assertFalse(v.isEmpty()); | ||
| 30 | + assertTrue(v.stream().anyMatch(c -> c.getPropertyPath().toString().equals("username"))); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Test | ||
| 34 | + void blankPassword_fails() { | ||
| 35 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build("alice", "", "HQ")); | ||
| 36 | + assertFalse(v.isEmpty()); | ||
| 37 | + assertTrue(v.stream().anyMatch(c -> c.getPropertyPath().toString().equals("password"))); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Test | ||
| 41 | + void blankCompanyCode_fails() { | ||
| 42 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build("alice", "Password1!", "")); | ||
| 43 | + assertFalse(v.isEmpty()); | ||
| 44 | + assertTrue(v.stream().anyMatch(c -> c.getPropertyPath().toString().equals("companyCode"))); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Test | ||
| 48 | + void tooLongUsername_fails() { | ||
| 49 | + String tooLong = "a".repeat(51); | ||
| 50 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build(tooLong, "Password1!", "HQ")); | ||
| 51 | + assertFalse(v.isEmpty()); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Test | ||
| 55 | + void tooLongPassword_fails() { | ||
| 56 | + String tooLong = "a".repeat(129); | ||
| 57 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build("alice", tooLong, "HQ")); | ||
| 58 | + assertFalse(v.isEmpty()); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Test | ||
| 62 | + void allFieldsPresent_passes() { | ||
| 63 | + Set<ConstraintViolation<LoginReq>> v = VALIDATOR.validate(build("alice", "Password1!", "HQ")); | ||
| 64 | + assertTrue(v.isEmpty()); | ||
| 65 | + } | ||
| 66 | +} |