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

63 lines
2.0 KiB

import db.model.TaskModel;
import db.model.bilibili.ScheduledTaskEntity;
import db.util.ExportUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
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.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 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;
//让测试运行于SpringMVC
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig
@ContextConfiguration(classes = {AppConfig.class, SpringConfig.class})
public class HibernateTest {
private Logger log=LogManager.getLogger();
@Autowired
private DataService dataService;
@Autowired
private BiliService biliService;
@Test
public void count() {
DataModelForm form=new DataModelForm();
form.setTypeIds(new ArrayList<Integer>(){{add(32);add(33);}});
long c=dataService.rowCount(form);
log.info(c);
}
@Test
public void exportSql() throws IOException {
ExportUtil sql=new ExportUtil(biliService.getHibernateTemplate(),"E:\\Projects\\JAVA\\WebCrawler\\init\\typeid");
sql.exportType();
}
@Test
public void get(){
TaskModel taskModel=new TaskModel();
taskModel.setId(3);
log.info(biliService.get(taskModel));
}
@Test
public void findAll(){
biliService.find(DetachedCriteria.forClass(ScheduledTaskEntity.class)).forEach(a->log.info(a));
}
}