import com.mapper.SqlMapper;
import com.mapper.UserMapper;
import com.pojo.entity.UserEntity;
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.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestSqlMapper {
    SqlMapper sqlMapper;
    @Before
    public void before() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = build.openSession(true);
        sqlMapper = sqlSession.getMapper(SqlMapper.class);
    }

    /**
     * 模糊查询
     */
    @Test
    public void testLike() {
        List<UserEntity> na = sqlMapper.getUserByLike("na");
    }
    @Test
    public void testList() {
        List<Integer> integers = Arrays.asList(1, 2);
        List<UserEntity> na = sqlMapper.getUserByList(integers);
    }
    @Test
    public void testTableName() {
        List<UserEntity> na = sqlMapper.getUserByTableName("user");
    }

    /**
     * 插入获取自增主键
     */
    @Test
    public void addUserGeneratedKey() {
        UserEntity userEntity = new UserEntity();
        userEntity.setName("张贤胜");
        userEntity.setAge(27);
        userEntity.setAddress("地址");
        int i = sqlMapper.insertGeneratedKey(userEntity);

    }
}
