diff --git a/pom.xml b/pom.xml
index 4ce6adb..6fc7c5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,6 +110,12 @@
2.0.0-M3
+
+ com.h2database
+ h2
+ test
+
+
diff --git a/src/main/java/com/lingxi/lingxi_java/common/BaseEntity.java b/src/main/java/com/lingxi/lingxi_java/common/BaseEntity.java
index 6dc9bbb..b8d2a4a 100644
--- a/src/main/java/com/lingxi/lingxi_java/common/BaseEntity.java
+++ b/src/main/java/com/lingxi/lingxi_java/common/BaseEntity.java
@@ -1,7 +1,8 @@
package com.lingxi.lingxi_java.common;
-import jakarta.persistence.*;
-import lombok.Data;
+import java.io.Serializable;
+import java.util.Date;
+
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
@@ -9,8 +10,12 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
-import java.io.Serializable;
-import java.util.Date;
+import jakarta.persistence.Column;
+import jakarta.persistence.EntityListeners;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.Id;
+import jakarta.persistence.MappedSuperclass;
+import lombok.Data;
@Data
@MappedSuperclass
diff --git a/src/test/java/com/lingxi/lingxi_java/auth/MyRepositoryTests.java b/src/test/java/com/lingxi/lingxi_java/auth/MyRepositoryTests.java
new file mode 100644
index 0000000..f08a200
--- /dev/null
+++ b/src/test/java/com/lingxi/lingxi_java/auth/MyRepositoryTests.java
@@ -0,0 +1,40 @@
+package com.lingxi.lingxi_java.auth;
+
+import java.util.Optional;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import com.lingxi.lingxi_java.auth.domain.User;
+import com.lingxi.lingxi_java.auth.domain.UserRepository;
+import com.lingxi.lingxi_java.utils.EncryptUtil;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SpringBootTest
+@ExtendWith(SpringExtension.class)
+class MyRepositoryTests {
+
+ @Autowired
+ private UserRepository repository;
+
+ @Test
+ void testExample() {
+ User user = new User();
+ String username = "holyliao";
+
+ user.setUsername(username);
+ user.setPassword(EncryptUtil.md5(username));
+ repository.save(user);
+ Optional target = this.repository.findOneByUsername(username);
+
+ assertTrue(target.isPresent());
+ assertEquals(target.get().getUsername(), username);
+ assertEquals(target.get().getPassword(), EncryptUtil.md5(username));
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/application-h2.yml b/src/test/resources/application-h2.yml
new file mode 100644
index 0000000..006d493
--- /dev/null
+++ b/src/test/resources/application-h2.yml
@@ -0,0 +1,28 @@
+spring:
+ datasource:
+ url: jdbc:h2:mem:lingxi;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=TRUE;MODE=MYSQL;;DB_CLOSE_ON_EXIT=FALSE
+ username: sa
+ password:
+ driverClassName: org.h2.Driver
+ jpa:
+ database-platform: org.hibernate.dialect.H2Dialect
+# hibernate:
+# ddl-auto: create
+ properties:
+ hibernate:
+ use_sql_comments: true
+ format_sql: true
+ auto_quote_keyword: true
+ generate-ddl: true
+ show-sql: true
+ defer-datasource-initialization: true
+ hibernate:
+ use-new-id-generator-mappings:
+ sql:
+ init:
+ mode: EMBEDDED
+ platform: h2
+ data-locations: classpath:data-h2.sql
+ config:
+ activate:
+ on-profile: h2
\ No newline at end of file
diff --git a/src/test/resources/application-mysql.yml b/src/test/resources/application-mysql.yml
new file mode 100644
index 0000000..53621f0
--- /dev/null
+++ b/src/test/resources/application-mysql.yml
@@ -0,0 +1,18 @@
+spring:
+ datasource:
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ username: root
+ password: 123456
+ url: jdbc:mysql://${MYSQL_HOST:localhost}:3306/lingxi
+ type: com.mysql.cj.jdbc.MysqlDataSource
+ jpa:
+ generate-ddl: true
+ show-sql: true
+ database-platform: org.hibernate.dialect.MySQL8Dialect
+ sql:
+ init:
+ platform: mysql
+ data-locations:
+ config:
+ activate:
+ on-profile: mysql
\ No newline at end of file
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index ccc78d0..499617b 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -5,18 +5,18 @@ logging:
type:
descriptor:
sql: trace
+
spring:
- datasource:
- driver-class-name: com.mysql.cj.jdbc.Driver
- username: root
- password: 123456
- url: jdbc:mysql://${MYSQL_HOST:localhost}:3306/lingxi
- jpa:
- generate-ddl: true
- show-sql: true
mvc:
pathmatch:
matching-strategy: ant_path_matcher
+ profiles:
+ active: h2
custom:
- jwt-secret: ${JWT_SECRET:lingxi_jwt}
\ No newline at end of file
+ jwt-secret: ${JWT_SECRET:lingxi_jwt}
+
+qiniu:
+ ak: ${QINIU_AK:lingxi}
+ sk: ${QINIU_SK:lingxi}
+ bucket: ${QINIU_SK:upload}
\ No newline at end of file
diff --git a/src/test/resources/data-h2.sql b/src/test/resources/data-h2.sql
new file mode 100644
index 0000000..3465628
--- /dev/null
+++ b/src/test/resources/data-h2.sql
@@ -0,0 +1,2 @@
+INSERT INTO "user" (id, created_at, created_by, updated_at, updated_by, avatar, nick_name, password, username)
+VALUES (10000, DEFAULT, DEFAULT, DEFAULT, DEFAULT, '/avatar.png', '灵希', '8b12aedc03901c59ba19a5a117e56936', 'lingxi');
\ No newline at end of file