package com.brctl.test;

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 org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;


/**
 * 单元测试类
 * Created by duanxiaoxing on 16/11/27.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-config.xml", "classpath:spring-mvc-config.xml"})
public class ArticleTester {

    private SqlSessionFactory sqlSessionFactory;
    private final static Logger logger = LoggerFactory.getLogger(ArticleTester.class);

    @Before
    public void preHandler() throws FileNotFoundException {
        logger.info("========== Pre Handler Starts... ==========");
        InputStream is = new FileInputStream(new File("src/main/resources/mybatis-config.xml"));
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        sqlSessionFactory = builder.build(is);
    }


    @Test
    public void test() {
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //sqlSession.select("select * from ");
    }
}

@@ -18,16 +18,91 @@
 .test;%0A%0A
+import com.brctl.domain.Article;%0Aimport com.brctl.service.IArticleService;%0A
 import o
@@ -134,24 +134,24 @@
 SqlSession;%0A
-
 import org.a
@@ -379,32 +379,95 @@
 .LoggerFactory;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import org.sprin
@@ -585,16 +585,50 @@
 unner;%0A%0A
+import javax.annotation.Resource;%0A
 import j
@@ -738,16 +738,39 @@
 Stream;%0A
+import java.util.List;%0A
 %0A%0A/**%0A *
@@ -860,16 +860,48 @@
 .class)%0A
+// %E6%AD%A4%E7%A7%8D%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E6%96%B9%E5%BC%8F%E6%97%A0%E6%B3%95%E5%AE%8C%E6%88%90%E6%B3%A8%E5%85%A5  TODO  WHY%0A// 
 @Context
@@ -993,16 +993,82 @@
 g.xml%22%7D)
+%0A%0A@ContextConfiguration(locations = %22classpath:spring-config.xml%22)
 %0Apublic 
@@ -1090,16 +1090,23 @@
 ster %7B%0A%0A
+    /*%0A
     priv
@@ -1749,16 +1749,531 @@
 rom %22);%0A
-
     %7D%0A
+    */%0A%0A    @Autowired%0A    private IArticleService articleService;%0A%0A    public void setArticleService(IArticleService articleService) %7B%0A        this.articleService = articleService;%0A    %7D%0A    public IArticleService getArticleService() %7B%0A        return this.articleService;%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A        List%3CArticle%3E articles = articleService.findAll();%0A        System.out.println();%0A        for(Article article: articles) %7B%0A            System.out.println(article.getAuthor());%0A        %7D%0A    %7D%0A%0A
 %7D%0A

use junit to query data from the mysql db