You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
webcrawler/web/src/test/java/SpringTest.java

110 lines
3.6 KiB

import core.thrift.MyAsyncMethodCallback;
import core.thrift.ThriftClientPool;
import db.util.ExportUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import web.config.AppConfig;
import web.config.SpringConfig;
import web.model.DataModelForm;
import web.service.BiliService;
import web.service.DataService;
import java.io.IOException;
import java.util.ArrayList;
//让测试运行于Spring环境
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig
@ContextConfiguration(classes = {AppConfig.class, SpringConfig.class})
public class SpringTest {
private static Logger log = LogManager.getLogger();
private MockMvc mockMvc;
@Autowired
WebApplicationContext wac;
@Autowired
private DefaultListableBeanFactory beanFactory;
@Autowired
private DataService dataService;
@Autowired
private BiliService biliService;
@Autowired
@Qualifier("Hweb.service.DataService")
private HibernateTemplate template1;
@Autowired
@Qualifier("Hweb.service.BiliService")
private HibernateTemplate template2;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void test() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/table").param("currentPage", "0").param("pageSize", "10").param("typeIds","33"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
public void test2() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/R").param("cid","9987062"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
public void test3() {
// 查询总条数
// log.info("记录数:"+dataService.rowCount(DetachedCriteria.forClass(DataModel.class)));
// log.info(dataService.rowCount(null));
DataModelForm form=new DataModelForm();
form.setTypeIds(new ArrayList<Integer>(){{add(32);add(33);}});
long c=dataService.rowCount(form);
log.info(c);
}
@Test
public void test4() throws IOException {
ExportUtil sql=new ExportUtil(template2,"E:\\Projects\\JAVA\\WebCrawler\\init\\typeid");
sql.exportType();
}
@Test
public void test5(){
dataService.getHibernateTemplate();
biliService.getHibernateTemplate();
}
@Test
public void test6() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/count").param("cids","49052"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
}