dao层修改 单元测试
This commit is contained in:
@@ -17,11 +17,12 @@ public class WebUpdate {
|
|||||||
|
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
|
private boolean delete;
|
||||||
|
|
||||||
public WebUpdate() {
|
public WebUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebUpdate(String updateInfo, Date updateTime) {
|
public WebUpdate(String updateInfo) {
|
||||||
this.updateInfo = updateInfo;
|
this.updateInfo = updateInfo;
|
||||||
this.updateTime = updateTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,7 @@ public interface WebUpdateInfoMapper {
|
|||||||
|
|
||||||
List<WebUpdate> findAll();
|
List<WebUpdate> findAll();
|
||||||
|
|
||||||
|
List<WebUpdate> findAllNotDeleted();
|
||||||
|
|
||||||
WebUpdate getLastestOne();
|
WebUpdate getLastestOne();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,47 +2,53 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.celess.blog.mapper.WebUpdateInfoMapper">
|
<mapper namespace="cn.celess.blog.mapper.WebUpdateInfoMapper">
|
||||||
<resultMap id="webUpdateResultMap" type="cn.celess.blog.entity.WebUpdate">
|
<resultMap id="webUpdateResultMap" type="cn.celess.blog.entity.WebUpdate">
|
||||||
<id column="update_id" property="id"/>
|
<id column="wu_id" property="id"/>
|
||||||
<result column="update_info" property="updateInfo"/>
|
<result column="wu_info" property="updateInfo"/>
|
||||||
<result column="update_time" property="updateTime"/>
|
<result column="wu_time" property="updateTime"/>
|
||||||
|
<result column="is_delete" property="delete"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<insert id="insert" parameterType="cn.celess.blog.entity.WebUpdate">
|
|
||||||
insert into web_update(update_info, update_time)
|
<insert id="insert" parameterType="cn.celess.blog.entity.WebUpdate" useGeneratedKeys="true" keyProperty="id">
|
||||||
values (#{updateInfo}, #{updateTime})
|
insert into web_update(wu_info, wu_time, is_delete)
|
||||||
<selectKey resultType="java.lang.Long" keyProperty="id">
|
values (#{updateInfo}, now(), false)
|
||||||
SELECT LAST_INSERT_ID() AS id
|
|
||||||
</selectKey>
|
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="update">
|
<update id="update">
|
||||||
update web_update
|
update web_update
|
||||||
set update_info=#{info}
|
set wu_info=#{info}
|
||||||
where update_id = #{id};
|
where wu_id = #{id};
|
||||||
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="delete">
|
<update id="delete">
|
||||||
delete
|
update web_update
|
||||||
from web_update
|
set is_delete = true
|
||||||
where update_id = #{id}
|
where wu_id = #{id}
|
||||||
</delete>
|
</update>
|
||||||
<select id="existsById" resultType="java.lang.Boolean">
|
<select id="existsById" resultType="java.lang.Boolean">
|
||||||
select EXISTS(select * from web_update where update_id = #{id})
|
select EXISTS(select * from web_update where wu_id = #{id})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findById" resultMap="webUpdateResultMap">
|
<select id="findById" resultMap="webUpdateResultMap">
|
||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
where update_id = #{id}
|
where wu_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAll" resultMap="webUpdateResultMap">
|
<select id="findAll" resultMap="webUpdateResultMap">
|
||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="findAllNotDeleted" resultMap="webUpdateResultMap">
|
||||||
|
select *
|
||||||
|
from web_update
|
||||||
|
where is_delete = false
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
order by update_id desc
|
order by wu_id desc
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package cn.celess.blog.mapper;
|
||||||
|
|
||||||
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class WebUpdateInfoMapperTest extends BaseTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
WebUpdateInfoMapper webUpdateInfoMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insert() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
assertNotNull(webUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void delete() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
assertEquals(1, webUpdateInfoMapper.delete(webUpdate.getId()));
|
||||||
|
assertTrue(webUpdateInfoMapper.findById(webUpdate.getId()).isDelete());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void update() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
assertEquals(1, webUpdateInfoMapper.update(webUpdate.getId(), randomStr(6)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void existsById() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
assertTrue(webUpdateInfoMapper.existsById(webUpdate.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findById() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
WebUpdate byId = webUpdateInfoMapper.findById(webUpdate.getId());
|
||||||
|
assertEquals(webUpdate.getUpdateInfo(), byId.getUpdateInfo());
|
||||||
|
assertEquals(webUpdate.getId(), byId.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAll() {
|
||||||
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
|
assertNotEquals(0, all.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllNotDeleted() {
|
||||||
|
this.delete();
|
||||||
|
List<WebUpdate> allNotDeleted = webUpdateInfoMapper.findAllNotDeleted();
|
||||||
|
allNotDeleted.forEach(webUpdate -> assertFalse(webUpdate.isDelete()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLastestOne() {
|
||||||
|
WebUpdate webUpdate = generateUpdateInfo();
|
||||||
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
|
List<WebUpdate> allNotDeleted = webUpdateInfoMapper.findAllNotDeleted();
|
||||||
|
all.sort(((o1, o2) -> (int) (o2.getId() - o1.getId())));
|
||||||
|
allNotDeleted.sort(((o1, o2) -> (int) (o2.getId() - o1.getId())));
|
||||||
|
assertEquals(webUpdate.getId(), all.get(0).getId());
|
||||||
|
assertEquals(webUpdate.getId(), allNotDeleted.get(0).getId());
|
||||||
|
assertEquals(webUpdate.getId(), webUpdateInfoMapper.getLastestOne().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebUpdate generateUpdateInfo() {
|
||||||
|
WebUpdate webUpdate = new WebUpdate(randomStr(8));
|
||||||
|
webUpdateInfoMapper.insert(webUpdate);
|
||||||
|
return webUpdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user