Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
<version>2.0.0-M3</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/lingxi/lingxi_java/common/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
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;
import org.springframework.data.annotation.LastModifiedBy;
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
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/lingxi/lingxi_java/auth/MyRepositoryTests.java
Original file line number Diff line number Diff line change
@@ -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<User> target = this.repository.findOneByUsername(username);

assertTrue(target.isPresent());
assertEquals(target.get().getUsername(), username);
assertEquals(target.get().getPassword(), EncryptUtil.md5(username));
}

}
28 changes: 28 additions & 0 deletions src/test/resources/application-h2.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions src/test/resources/application-mysql.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
jwt-secret: ${JWT_SECRET:lingxi_jwt}

qiniu:
ak: ${QINIU_AK:lingxi}
sk: ${QINIU_SK:lingxi}
bucket: ${QINIU_SK:upload}
2 changes: 2 additions & 0 deletions src/test/resources/data-h2.sql
Original file line number Diff line number Diff line change
@@ -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');