执行test报错org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec,日志如下:
[WARN ] 2017-04-05 14:40:18,718 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:200) - clear cache fail: [cms_news]
java.lang.NullPointerException
at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.getCache(EhcacheDaoCacheProvider.java:44)
at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.clear(EhcacheDaoCacheProvider.java:34)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:195)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithTransaction(NutDaoRunner.java:104)
at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:88)
at org.nutz.dao.impl.sql.run.NutDaoRunner$1.run(NutDaoRunner.java:74)
at org.nutz.trans.Trans.exec(Trans.java:174)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:72)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:245)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:257)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.insert(NutDao.java:145)
at cn.wizzer.SimpleTest.test_user_service_create_user(SimpleTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:33)
at org.nutz.mock.NutTestRunner.runChild(NutTestRunner.java:14)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
测试类如下
package cn.wizzer;
import cn.wizzer.app.cms.modules.models.Cms_news;
import cn.wizzer.app.cms.modules.services.CmsNewsService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.nutz.dao.Dao;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.random.R;
import org.nutz.log.Log;
import org.nutz.log.Logs;
@RunWith(MyNutTestRunner.class)
@IocBean // 必须有
public class SimpleTest extends Assert {
Log log = Logs.get();
//private static final Log log = Logs.get();
// 跟通常的@Inject完全一样.
@Inject("refer:$ioc")
protected Ioc ioc;
@Inject
protected Dao dao;
@Inject
protected CmsNewsService cmsNewsService;
@Test
public void test_user_service_create_user() {
dao.create(Cms_news.class, false);
Cms_news news = new Cms_news();
news.setTitle("我们都很好");
String id = R.UU16();
news.setId(id);
cmsNewsService.insert(news);
news = dao.fetch(Cms_news.class, id);
log.info("newsString:"+news.toString());
}
}
Runner类如下
package cn.wizzer;
import cn.wizzer.app.web.commons.core.Module;
import org.junit.runners.model.InitializationError;
import org.nutz.mock.NutTestRunner;
/**
* Created by Wayne on 2017/4/5.
*/
public class MyNutTestRunner extends NutTestRunner {
public MyNutTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
public Class<?> getMainModule() {
return Module.class;
}
/**
* 可覆盖createIoc,实现参数覆盖, bean替换,等定制.
*//*
protected Ioc createIoc() {
Ioc ioc = super.createIoc();
PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");
conf.put("db.url", "jdbc:h2:~/test");
return ioc;
}*/
}
dao.js配置如下: