testing - Spring Data Neo4j 4.0.0.M1 Test Configuration -
i new spring data , trying configure spring data neo4j 4.0.0.m1 test. has taken me 2 days without result , can't seem find example on sdn4 this.
here simple test class :
@runwith(springjunit4classrunner.class) @contextconfiguration(classes = myconfigurationtest.class) @dirtiescontext public class projectrepositorytests { @autowired platformtransactionmanager transactionmanager; @autowired projectrepository projectrepository; @transactional @test public void testaddproject() { project project = new project(); project.setname("projecta"); project.setcreationdate(new date()); project.setdescription("description"); projectrepository.save(project); project addedproject = projectrepository.findprojectbyname("projecta"); assert.assertnotnull("should have found something", addedproject); projectrepository.delete(addedproject); } }
here configuration class :
@configuration @enableneo4jrepositories(basepackages = "project.repository") @enabletransactionmanagement public class myconfigurationtest extends neo4jconfiguration { @bean public neo4jserver neo4jserver() { return new inprocessserver(); } @bean @scope(value = "session", proxymode = scopedproxymode.target_class) public session getsession() throws exception { return super.getsession(); } @bean public sessionfactory getsessionfactory() { // domain entity base package(s) return new sessionfactory("project.domain"); } }
and here dependencies :
dependencies { compile "org.springframework.data:spring-data-neo4j:${sdnversion}" compile "com.rabbitmq:amqp-client:${rmqversion}" compile "com.google.code.gson:gson:${gsonversion}" compile "org.neo4j:neo4j:${neo4jversion}" compile "com.graphaware.neo4j:timetree:${neo4jtimetreeversion}" testcompile group: 'org.neo4j', name: 'neo4j-ogm-test', version: '1.0.0.build-snapshot', classifier: 'tests' testcompile group: 'org.springframework.data', name: 'spring-data-neo4j', version: sdnversion, classifier: 'tests' testcompile group: 'org.springframework', name: 'spring-test', version: springtestversion testcompile group: 'junit', name: 'junit', version: '4.11' }
the problem is, got error :
java.lang.illegalstateexception: failed load applicationcontext @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontext(defaultcacheawarecontextloaderdelegate.java:94) @ org.springframework.test.context.defaulttestcontext.getapplicationcontext(defaulttestcontext.java:72) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.injectdependencies(dependencyinjectiontestexecutionlistener.java:117) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.preparetestinstance(dependencyinjectiontestexecutionlistener.java:83) @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:212) @ org.springframework.test.context.junit4.springjunit4classrunner.createtest(springjunit4classrunner.java:200) @ org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall(springjunit4classrunner.java:259) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.springframework.test.context.junit4.springjunit4classrunner.methodblock(springjunit4classrunner.java:261) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:219) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:83) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:68) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:163) @ org.junit.runner.junitcore.run(junitcore.java:137) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:78) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:212) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:68) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'neo4jserver' defined in class myconfigurationtest: instantiation of bean failed; nested exception org.springframework.beans.factory.beandefinitionstoreexception: factory method [public org.springframework.data.neo4j.server.neo4jserver myconfigurationtest.neo4jserver()] threw exception; nested exception java.lang.noclassdeffounderror: org/neo4j/server/helpers/communityserverbuilder @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:597) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1095) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:990) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:504) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:475) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:229) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:298) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:706) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:762) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:482) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:125) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:60) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.delegateloading(abstractdelegatingsmartcontextloader.java:109) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.loadcontext(abstractdelegatingsmartcontextloader.java:261) @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontextinternal(defaultcacheawarecontextloaderdelegate.java:68) @ org.springframework.test.context.defaultcacheawarecontextloaderdelegate.loadcontext(defaultcacheawarecontextloaderdelegate.java:86) ... 28 more caused by: org.springframework.beans.factory.beandefinitionstoreexception: factory method [public org.springframework.data.neo4j.server.neo4jserver myconfigurationtest.neo4jserver()] threw exception; nested exception java.lang.noclassdeffounderror: org/neo4j/server/helpers/communityserverbuilder @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:188) @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:586) ... 45 more caused by: java.lang.noclassdeffounderror: org/neo4j/server/helpers/communityserverbuilder @ org.springframework.data.neo4j.server.inprocessserver.<init>(inprocessserver.java:31) @ myconfigurationtest.neo4jserver(myconfigurationtest.java:23) @ myconfigurationtest$$enhancerbyspringcglib$$44afa770.cglib$neo4jserver$0(<generated>) @ myconfigurationtest$$enhancerbyspringcglib$$44afa770$$fastclassbyspringcglib$$d8d802f1.invoke(<generated>) @ org.springframework.cglib.proxy.methodproxy.invokesuper(methodproxy.java:228) @ org.springframework.context.annotation.configurationclassenhancer$beanmethodinterceptor.intercept(configurationclassenhancer.java:311) @ myconfigurationtest$$enhancerbyspringcglib$$44afa770.neo4jserver(<generated>) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ org.springframework.beans.factory.support.simpleinstantiationstrategy.instantiate(simpleinstantiationstrategy.java:166) ... 46 more caused by: java.lang.classnotfoundexception: org.neo4j.server.helpers.communityserverbuilder @ java.net.urlclassloader$1.run(urlclassloader.java:366) @ java.net.urlclassloader$1.run(urlclassloader.java:355) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:354) @ java.lang.classloader.loadclass(classloader.java:425) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:308) @ java.lang.classloader.loadclass(classloader.java:358) ... 58 more
thank in advance , appreciated!
for maven, please include following dependency:
<dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-neo4j</artifactid> <version>4.0.0.m1</version> <type>test-jar</type> </dependency>
for gradle should work:
dependencies { compile(group: 'org.springframework.data', name: 'spring-data-neo4j', version: '4.0.0.m1', classifier: 'tests') }
if want latest green build version, available '4.0.0-build-snapshot'. version has number of bug fixes , additional features since m1.
to use build-snapshot release you'll need add repository:
maven:
<repository> <id>spring-libs-snapshot</id> <url>http://repo.spring.io/libs-snapshot</url> </repository>
gradle:
repositories { spring-libs-snapshot { url 'http://repo.spring.io/libs-snapshot' } }
Comments
Post a Comment