java - An Error during unitTest Testing Spring mvc controller using mock -
it's first time using mockito test spring mvc controller .here error don't know why. project using spring3.2 , mybatis. controller code follow this:
@controller @requestmapping(value = "/person") public class mocktestcontroller { private appusermodel appusermodel; @autowired public mocktestcontroller(appusermodel appusermodel) { this.appusermodel = appusermodel; } @requestmapping(value = "/{id}", method = requestmethod.get) public string getperson(@pathvariable long id, model model) { model.addattribute("person", appusermodel.getmemberbyid(id)); return "test/person"; } }
and here unittest code:
@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath*:/spring.xml", "file:web/web-inf/spring/operator-servlet.xml" }) public class mockcontrollertest { @mock private appusermodel appusermodel; @injectmocks private mocktestcontroller mockcontroller; private mockmvc mockmvc; @before public void setup() { mockitoannotations.initmocks(this); mockmvc = mockmvcbuilders.standalonesetup(mockcontroller).build(); } @test public void testgetperson() throws exception { when(appusermodel.getmemberbyid(1108l)).thenreturn(new member()); mockmvc.perform(get("/person/{id}", 1108l)).andexpect(status().isok()) .andexpect(view().name("test/person")) .andexpect(model().attribute("person", new member())); } }
then junit show erro log:
caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.validation.beanvalidation.localvalidatorfactorybean#0': invocation of init method failed; nested exception javax.validation.validationexception: unable instantiate configuration. @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1486) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:524) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:461) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:607) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:106) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:57) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.delegateloading(abstractdelegatingsmartcontextloader.java:100) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.loadcontext(abstractdelegatingsmartcontextloader.java:248) @ org.springframework.test.context.testcontext.loadapplicationcontext(testcontext.java:124) @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:148) ... 24 more caused by: javax.validation.validationexception: unable instantiate configuration. @ javax.validation.validation$genericbootstrapimpl.configure(validation.java:272) @ org.springframework.validation.beanvalidation.localvalidatorfactorybean.afterpropertiesset(localvalidatorfactorybean.java:182) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1545) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1483) ... 39 more caused by: java.lang.nullpointerexception @ java.util.resourcebundle.getbundle(resourcebundle.java:960) @ org.hibernate.validator.engine.resourcebundlemessageinterpolator.loadbundle(resourcebundlemessageinterpolator.java:202) @ org.hibernate.validator.engine.resourcebundlemessageinterpolator.getfilebasedresourcebundle(resourcebundlemessageinterpolator.java:182) @ org.hibernate.validator.engine.resourcebundlemessageinterpolator.(resourcebundlemessageinterpolator.java:81) @ org.hibernate.validator.engine.resourcebundlemessageinterpolator.(resourcebundlemessageinterpolator.java:73) @ org.hibernate.validator.engine.configurationimpl.(configurationimpl.java:57) @ org.hibernate.validator.hibernatevalidator.creategenericconfiguration(hibernatevalidator.java:43) @ javax.validation.validation$genericbootstrapimpl.configure(validation.java:269) ... 42 more
this project didn't uesd hibernate .i need help
Comments
Post a Comment