Skip to content
Snippets Groups Projects
Commit 9483d60d authored by Jie's avatar Jie Committed by Wei
Browse files

attribute entity Test and fix

parent 7619b9c7
No related branches found
No related tags found
No related merge requests found
......@@ -28,27 +28,26 @@
select
id,name,view_id,is_delete,gmt_create,gmt_modified
from entity
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
and id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="viewId != null">
view_id = #{viewId,jdbcType=BIGINT},
and view_id = #{viewId,jdbcType=BIGINT}
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<insert id="insert" parameterType="com.ic.er.bean.entity.EntityDO">
......@@ -60,7 +59,7 @@
<if test="name != null">
name,
</if>
<if test="view_id != null">
<if test="viewId != null">
view_id,
</if>
</trim>
......
package com.ic.er;
import com.ic.er.bean.entity.AttributeDO;
import com.ic.er.bean.entity.EntityDO;
import com.ic.er.dao.AttributeMapper;
import com.ic.er.dao.EntityMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Date;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
/**
*
* @author jie
* @data 18/10/2022
*
*
*/
public class attributeMapperTest {
public static SqlSession sqlSession;
public static Connection connection;
public static AttributeMapper attributeMapper;
@Before
public void init() throws IOException {
InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is);
sqlSession = sqlSessionFactory.openSession(true);
connection = sqlSession.getConnection();
System.out.println(connection);
}
@Test
public void insertAttribute() {
Long id = Long.valueOf(123);
Long entityId = Long.valueOf(456);
Long viewId = Long.valueOf(789);
String name = "a";
String dataType = "int";
int isPrimary = 0;
int isForeign = 1;
int isDelete = 0;
Date gmtCreate = new Date();
Date gmtModified = new Date();
AttributeDO attributeDO = new AttributeDO(id, entityId, viewId,
name, dataType, isPrimary, isForeign, isDelete, gmtCreate, gmtModified);
Assert.assertNotNull(sqlSession);
AttributeMapper attributeMapper = sqlSession.getMapper(AttributeMapper.class);
attributeMapper.insert(attributeDO);
}
@Test
public void selectByAttributeTest() {
Long id = Long.valueOf(123);
Long entityId = Long.valueOf(456);
Long viewId = Long.valueOf(789);
String name = "a";
String dataType = "int";
int isPrimary = 0;
int isForeign = 1;
int isDelete = 0;
Date gmtCreate = null;
Date gmtModified = null;
AttributeDO attributeDO = new AttributeDO(id, entityId, viewId,
name, dataType, isPrimary, isForeign, isDelete, gmtCreate, gmtModified);
Assert.assertNotNull(sqlSession);
AttributeMapper attributeMapper = sqlSession.getMapper(AttributeMapper.class);
attributeMapper.selectByAttribute(attributeDO);
}
@Test
public void selectByIdTest(){
Long id = Long.valueOf(123);
Assert.assertNotNull(sqlSession);
AttributeMapper attributeMapper = sqlSession.getMapper(AttributeMapper.class);
attributeMapper.selectById(id);
}
@Test
public void updateByIdTest(){
Long id = Long.valueOf(123);
Long entityId = Long.valueOf(456);
Long viewId = Long.valueOf(789);
String name = "b";
String dataType = "varchar";
int isPrimary = 0;
int isForeign = 1;
int isDelete = 0;
Date gmtCreate = null;
Date gmtModified = null;
AttributeDO attributeDO = new AttributeDO(id, entityId, viewId,
name, dataType, isPrimary, isForeign, isDelete, gmtCreate, gmtModified);
Assert.assertNotNull(sqlSession);
AttributeMapper attributeMapper = sqlSession.getMapper(AttributeMapper.class);
attributeMapper.updateById(attributeDO);
}
@Test
public void deleteByIdTest(){
Long id = Long.valueOf(123);
Assert.assertNotNull(sqlSession);
AttributeMapper attributeMapper = sqlSession.getMapper(AttributeMapper.class);
attributeMapper.deleteById(id);
}
}
......@@ -2,7 +2,6 @@ package com.ic.er;
import com.ic.er.bean.entity.EntityDO;
import com.ic.er.dao.EntityMapper;
import com.ic.er.dao.ViewMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
......@@ -11,12 +10,10 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Date;
import java.time.LocalDateTime;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Date;
/**
*
......@@ -42,6 +39,22 @@ public class entityMapperTest {
@Test
public void insertEntity() {
long id = Long.valueOf(456);
String name = "b";
long viewId = Long.valueOf(2234);
Date create = new Date();
Date modify = new Date();
int isDelete = 0;
EntityDO entity = new EntityDO(id,name,viewId,isDelete,create,modify);
Assert.assertNotNull(sqlSession);
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.insert(entity);
}
@Test
public void insertEntityTest() {
long id = 12334;
String name = "b";
long viewId = 789;
......@@ -50,12 +63,69 @@ public class entityMapperTest {
int isDelete = 0;
EntityDO entity = new EntityDO(id,name,viewId,isDelete,create,modify);
Assert.assertNotNull(sqlSession);
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.insert(entity);
}
@Test
public void selectByEntityTest() {
long id = Long.valueOf(12334);
String name = null;
long viewId = Long.valueOf(789);
Date create = null;
Date modify = null;
int isDelete = 0;
EntityDO entity = new EntityDO(id,name,viewId,isDelete,create,modify);
Assert.assertNotNull(sqlSession);
entityMapper.insert(entity);
sqlSession.close();
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.selectByEntity(entity);
}
@Test
public void selectByIdTest() {
Long id = Long.valueOf(123);
Assert.assertNotNull(sqlSession);
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.selectById(id);
}
@Test
public void updateByIdTest() {
long id = Long.valueOf(123);
String name = "b";
long viewId = Long.valueOf(456);
Date create = new Date();
Date modify = new Date();
int isDelete = 0;
EntityDO entityDo = new EntityDO(id,name,viewId,isDelete,create,modify);
Assert.assertNotNull(sqlSession);
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.updateById(entityDo);
}
@Test
public void deleteByIdTest() {
long id = Long.valueOf(123);
Assert.assertNotNull(sqlSession);
EntityMapper entityMapper = sqlSession.getMapper(EntityMapper.class);
entityMapper.deleteById(id);
}
}
......@@ -28,27 +28,26 @@
select
id,name,view_id,is_delete,gmt_create,gmt_modified
from entity
where
<trim suffixOverrides=",">
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
and id = #{id,jdbcType=BIGINT}
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="viewId != null">
view_id = #{viewId,jdbcType=BIGINT},
and view_id = #{viewId,jdbcType=BIGINT}
</if>
<if test="isDelete != null">
is_delete = #{isDelete,jdbcType=TINYINT},
and is_delete = #{isDelete,jdbcType=TINYINT}
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=DATETIME},
and gmt_create = #{gmtCreate,jdbcType=DATETIME}
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=DATETIME},
and gmt_modified = #{gmtModified,jdbcType=DATETIME}
</if>
</trim>
</where>
</select>
<insert id="insert" parameterType="com.ic.er.bean.entity.EntityDO">
......@@ -60,7 +59,7 @@
<if test="name != null">
name,
</if>
<if test="view_id != null">
<if test="viewId != null">
view_id,
</if>
</trim>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment