유저 DB 저장 테스트

롬복 생성자 어노테이션 추가
This commit is contained in:
geek 2019-07-20 23:47:19 +09:00
parent 4bf0676b2d
commit 73b5ba7545
4 changed files with 160 additions and 29 deletions

View File

@ -3,23 +3,23 @@ package com.totopia.server.user.model;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
@Entity
@Table(name = "USER")
@Table(name = "TBL_USER")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
private static final long serialVersionUID = 2783105197387637187L;
@ -58,10 +58,14 @@ public class User implements Serializable {
private Boolean sendEmail;
@Basic
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "register_date", nullable = false)
private Date registerDate;
@Basic
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "lastvisit_date", nullable = false)
private Date lastvisitDate;
@ -70,6 +74,8 @@ public class User implements Serializable {
private String activation;
@Basic
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_reset_time", nullable = false)
private Date lastResetTime;

View File

@ -0,0 +1,44 @@
package com.totopia.server.user.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "TBL_USER_GROUP")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserGroup implements Serializable {
@Id
@GeneratedValue(generator = "user_group_generator")
@SequenceGenerator(name = "user_group_generator", sequenceName = "user_group_sequence", initialValue = 1, allocationSize = 1)
private Long id;
@Basic
@Column(name = "title", nullable = false, length = 100)
@JsonIgnore
private String title;
@Basic
@Column(columnDefinition = "text", name = "description", nullable = true)
private String description;
@Basic
@Column(name = "is_default", nullable = false, columnDefinition = "bool default false")
private Boolean isDefault;
@Basic
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "register_date", nullable = false)
private Date registerDate;
}

View File

@ -11,13 +11,20 @@ spring:
url: jdbc:postgresql://localhost:15432/postgres
data-username: postgres
password: qwer5795
username: postgres
# JPA properties
jpa:
hibernate:
ddl-auto: update
ddl-auto: create-drop
database: postgresql
show-sql: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
# Logger configuration
logging:
@ -33,22 +40,3 @@ server:
servlet:
context-path: /api
# spring.datasource.url=jdbc:postgresql://localhost:54320/postgres
# spring.datasource.username=postgres
# spring.datasource.password=root
# spring.jpa.show-sql=true
#
# ## Hibernate Properties
# # The SQL dialect makes Hibernate generate better SQL for the chosen database
# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
# spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
#
# # Hibernate ddl auto (create, create-drop, validate, update)
# spring.jpa.hibernate.ddl-auto=update
# spring.jpa.database=postgresql
#
# logging.level.root=info
# logging.pattern.console=%d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger.%M - %msg%n
#
# server.port=8282

View File

@ -0,0 +1,93 @@
package com.totopia.server.user.repository;
import com.totopia.server.user.model.User;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserRepositoryTest {
@Autowired
private UserRepository userRepository;
private User.UserBuilder user;
@Before
public void setUp() throws Exception {
user = User.builder()
.activation("Y")
.block(false)
.email("geekdev@naver.com")
.isAdmin(true)
.nickname("admin")
.otep("")
.otpKey("")
.password("qwer5795")
.username("admin")
.requireReset(false)
.resetCount(Long.valueOf(0));
}
@Test
public void findByUsername() throws Exception {
User tempUser = user.build();
this.userRepository.save(tempUser);
User user1 = this.userRepository.findByUsername(tempUser.getUsername());
assertEquals("Equlas", user.build().getUsername(), user1.getUsername());
}
@Test
public void findByEmail() {
}
@Test
public void findAllByNickname() {
}
@Test
public void findAllByBlockTrue() {
}
@Test
public void findAllByBlockFalse() {
}
@Test
public void findAllByIsAdminTrue() {
}
@Test
public void findAllByRequireResetTrue() {
}
@Test
public void findAllByIsAdminFalseAndActivationEquals() {
}
@Test
public void findAllByRegisterDateBetween() {
}
@Test
public void findAllByLastvisitDateBetween() {
}
@Test
public void findAllByLastResetTimeBetween() {
}
@Test
public void countByRegisterDateGreaterThanEqual() {
}
}