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/SpringMVCTest.java

111 lines
3.7 KiB

6 years ago
import core.thrift.MyAsyncMethodCallback;
import core.thrift.ThriftClientPool;
6 years ago
import db.model.bilibili.ScheduledTaskEntity;
6 years ago
import db.util.ExportUtil;
6 years ago
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
6 years ago
import org.hibernate.criterion.DetachedCriteria;
6 years ago
import org.junit.Before;
import org.junit.Test;
6 years ago
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;
6 years ago
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
6 years ago
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
6 years ago
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
6 years ago
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
6 years ago
import web.config.AppConfig;
6 years ago
import web.config.SpringConfig;
6 years ago
import web.model.DataModelForm;
import web.service.BiliService;
import web.service.DataService;
6 years ago
import java.io.IOException;
6 years ago
import java.util.ArrayList;
6 years ago
//让测试运行于Spring环境
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig
6 years ago
@ContextConfiguration(classes = {AppConfig.class, SpringConfig.class})
6 years ago
public class SpringMVCTest {
6 years ago
private static Logger log = LogManager.getLogger();
6 years ago
private MockMvc mockMvc;
@Autowired
WebApplicationContext wac;
6 years ago
@Autowired
private DataService dataService;
6 years ago
6 years ago
@Autowired
private BiliService biliService;
@Autowired
6 years ago
@Qualifier("Hweb.service.BiliService")
private HibernateTemplate template2;
6 years ago
@Before
6 years ago
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
6 years ago
}
6 years ago
@Test
public void test() throws Exception {
6 years ago
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/table").param("currentPage", "0").param("pageSize", "10").param("typeIds","33"));
6 years ago
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
public void test2() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/R").param("cid","9987062"));
6 years ago
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
6 years ago
}
6 years ago
@Test
6 years ago
public void test3() {
// 查询总条数
6 years ago
// 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);
6 years ago
}
6 years ago
@Test
public void test4() throws IOException {
ExportUtil sql=new ExportUtil(template2,"E:\\Projects\\JAVA\\WebCrawler\\init\\typeid");
sql.exportType();
}
6 years ago
6 years ago
@Test
public void test5(){
dataService.getHibernateTemplate();
biliService.getHibernateTemplate();
}
6 years ago
6 years ago
@Test
public void test6() throws Exception {
ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/data/count").param("cids","49052"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
6 years ago
6 years ago
@Test
public void test7(){
biliService.find(DetachedCriteria.forClass(ScheduledTaskEntity.class)).forEach(a->log.info(a));
}
6 years ago
6 years ago
}