package com.prolog.cs.base.gsp;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.prolog.cs.base.gsp.dao.GspUnqualifiedLossMapper;
import com.prolog.cs.base.gsp.dao.GspUpkeepCheckMapper;
import com.prolog.cs.base.gsp.resource.ItemClient;
import com.prolog.cs.base.gsp.resource.PrestoClient;
import com.prolog.cs.base.gsp.service.GspUnqualifiedLossService;
import com.prolog.cs.base.gsp.service.GspUpkeepCheckService;
import com.prolog.cs.base.gsp.service.impl.AutoUpKeepTask;
import com.prolog.cs.base.gsp.service.impl.GspUnqualifiedLossServiceImpl;
import com.prolog.framework.bz.common.search.SearchApi;
import com.prolog.framework.bz.common.search.TestModel;
import com.prolog.framework.utils.MapUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.util.List;


/**
 * 基础测试类
 *
 * @author stylefeng
 * @Date 2017/5/21 16:10
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
//@Transactional //打开的话测试之后数据可自动回滚
public class BaseJunit {

    @Autowired
    WebApplicationContext webApplicationContext;

    protected MockMvc mockMvc;

    @Autowired
    private SearchApi searchApi;

    @Autowired
    private GspUnqualifiedLossService gspUnqualifiedLossService;

    @Autowired
    private GspUnqualifiedLossMapper GspUnqualifiedLossMapper;

    @Autowired
    private ItemClient itemClient;
    
    @Autowired
    private GspUpkeepCheckMapper GspUpkeepCheckMapper;

    @Autowired
    private GspUnqualifiedLossServiceImpl GspUnqualifiedLossServiceImpl;
    
    @Autowired
    private PrestoClient prestoClient;

    @Autowired
    private GspUpkeepCheckService gspUpkeepCheckService;
    
    @Autowired
    private AutoUpKeepTask autoUpKeepTask;
    
    @Before
    public void setupMockMvc(){
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Before
    public void initDatabase(){
    }
    
    

    @Test
    public void search(){
        try {
//            List<Map> models = searchApi.search(
//                    "578687106776436736",
//                    MapUtils.put("参数","参数值").getMap(),
//                    Map.class
//            );
//            new RestTemplate();
//            SearchApi api = new SearchApi();

            searchApi.setUrl("http://192.168.40.143:8810/search");
            List<TestModel> models = searchApi.search("564170480207138817", MapUtils.put("username", "kzy-admin").getMap(), TestModel.class);
            System.out.println(((TestModel)models.get(0)).getP_email_addr());
            System.out.println(JSON.toJSONString(models));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void autoUpKeepTask() throws Exception {
        //autoUpKeepTask.autoUpKeepTask("599581702716788736");
        //autoUpKeepTask.autoUpKeepTask("726788113300975616");
    }
}
