From 2310173b84c8f1dd4a3c8ea100bb653174845f03 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 2 May 2025 22:58:38 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E9=87=8D=E6=9E=84=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/jdbc/test/AccountPO.java | 137 ++++++++++++++++++ .../jdbc/test/SimpleJdbcTemplateTests.java | 126 +--------------- 2 files changed, 144 insertions(+), 119 deletions(-) create mode 100644 src/test/java/xyz/zhouxy/jdbc/test/AccountPO.java diff --git a/src/test/java/xyz/zhouxy/jdbc/test/AccountPO.java b/src/test/java/xyz/zhouxy/jdbc/test/AccountPO.java new file mode 100644 index 0000000..de7608d --- /dev/null +++ b/src/test/java/xyz/zhouxy/jdbc/test/AccountPO.java @@ -0,0 +1,137 @@ +/* + * Copyright 2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package xyz.zhouxy.jdbc.test; + +import java.time.LocalDateTime; +import java.util.Objects; + +public class AccountPO { + Long id; + String username; + String accountStatus; + LocalDateTime createTime; + Long createdBy; + LocalDateTime updateTime; + Long updatedBy; + Long version; + + public AccountPO() { + } + + public AccountPO(Long id, String username, String accountStatus, LocalDateTime createTime, Long createdBy, + LocalDateTime updateTime, Long updatedBy, Long version) { + this.id = id; + this.username = username; + this.accountStatus = accountStatus; + this.createTime = createTime; + this.createdBy = createdBy; + this.updateTime = updateTime; + this.updatedBy = updatedBy; + this.version = version; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + + public Long getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(Long createdBy) { + this.createdBy = createdBy; + } + + public LocalDateTime getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(LocalDateTime updateTime) { + this.updateTime = updateTime; + } + + public Long getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(Long updatedBy) { + this.updatedBy = updatedBy; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + @Override + public int hashCode() { + return Objects.hash(id, username, accountStatus, createTime, createdBy, updateTime, updatedBy, version); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccountPO other = (AccountPO) obj; + return Objects.equals(id, other.id) && Objects.equals(username, other.username) + && Objects.equals(accountStatus, other.accountStatus) && Objects.equals(createTime, other.createTime) + && Objects.equals(createdBy, other.createdBy) && Objects.equals(updateTime, other.updateTime) + && Objects.equals(updatedBy, other.updatedBy) && Objects.equals(version, other.version); + } + + @Override + public String toString() { + return "AccountPO [id=" + id + ", username=" + username + ", accountStatus=" + accountStatus + ", createTime=" + + createTime + ", createdBy=" + createdBy + ", updateTime=" + updateTime + ", updatedBy=" + updatedBy + + ", version=" + version + "]"; + } +} diff --git a/src/test/java/xyz/zhouxy/jdbc/test/SimpleJdbcTemplateTests.java b/src/test/java/xyz/zhouxy/jdbc/test/SimpleJdbcTemplateTests.java index 93a2644..f318d49 100644 --- a/src/test/java/xyz/zhouxy/jdbc/test/SimpleJdbcTemplateTests.java +++ b/src/test/java/xyz/zhouxy/jdbc/test/SimpleJdbcTemplateTests.java @@ -9,11 +9,11 @@ import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import org.h2.jdbcx.JdbcDataSource; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +42,7 @@ class SimpleJdbcTemplateTests { } @BeforeAll - static void setUp() throws SQLException { + static void createTable() throws SQLException { jdbcTemplate.update("CREATE TABLE sys_account (" + "\n" + " id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY" + "\n" + " ,username VARCHAR(255) NOT NULL" @@ -53,6 +53,11 @@ class SimpleJdbcTemplateTests { + "\n" + " ,updated_by BIGINT DEFAULT NULL" + "\n" + " ,version BIGINT NOT NULL DEFAULT 0" + "\n" + ")"); + } + + @BeforeEach + void initData() throws SQLException { + jdbcTemplate.update("truncate table sys_account"); jdbcTemplate.batchUpdate("INSERT INTO sys_account(id, username, account_status, created_by) VALUES (?, ?, ?, ?)", Lists.newArrayList( buildParams(2L, "zhouxy2", "0", 108L), buildParams(3L, "zhouxy3", "0", 108L), @@ -251,120 +256,3 @@ class SimpleJdbcTemplateTests { log.info("{}", t); } } - -class AccountPO { - Long id; - String username; - String accountStatus; - LocalDateTime createTime; - Long createdBy; - LocalDateTime updateTime; - Long updatedBy; - Long version; - - public AccountPO() { - } - - public AccountPO(Long id, String username, String accountStatus, LocalDateTime createTime, Long createdBy, - LocalDateTime updateTime, Long updatedBy, Long version) { - this.id = id; - this.username = username; - this.accountStatus = accountStatus; - this.createTime = createTime; - this.createdBy = createdBy; - this.updateTime = updateTime; - this.updatedBy = updatedBy; - this.version = version; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getAccountStatus() { - return accountStatus; - } - - public void setAccountStatus(String accountStatus) { - this.accountStatus = accountStatus; - } - - public LocalDateTime getCreateTime() { - return createTime; - } - - public void setCreateTime(LocalDateTime createTime) { - this.createTime = createTime; - } - - public Long getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(Long createdBy) { - this.createdBy = createdBy; - } - - public LocalDateTime getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(LocalDateTime updateTime) { - this.updateTime = updateTime; - } - - public Long getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(Long updatedBy) { - this.updatedBy = updatedBy; - } - - public Long getVersion() { - return version; - } - - public void setVersion(Long version) { - this.version = version; - } - - @Override - public int hashCode() { - return Objects.hash(id, username, accountStatus, createTime, createdBy, updateTime, updatedBy, version); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AccountPO other = (AccountPO) obj; - return Objects.equals(id, other.id) && Objects.equals(username, other.username) - && Objects.equals(accountStatus, other.accountStatus) && Objects.equals(createTime, other.createTime) - && Objects.equals(createdBy, other.createdBy) && Objects.equals(updateTime, other.updateTime) - && Objects.equals(updatedBy, other.updatedBy) && Objects.equals(version, other.version); - } - - @Override - public String toString() { - return "AccountPO [id=" + id + ", username=" + username + ", accountStatus=" + accountStatus + ", createTime=" - + createTime + ", createdBy=" + createdBy + ", updateTime=" + updateTime + ", updatedBy=" + updatedBy - + ", version=" + version + "]"; - } -}