java - Testing playframework 2.4 with spring-data injection out of Eclipse Scala IDE -


i want learn , try set project using

  • play framework 2.4
  • java
  • spring data
  • eclipse ide

i took 'my inspiration' from

  1. play-scala-spring-data-jpa showing how load spring data via guice.
  2. multiproject showing sub-project configuration (as use @ least 2 applications have common code base, should packaged separately, able deployed different machines)

i managed activator run first sub-project, java-port of play-scala-spring-data-jpa. injection magic spring data works provided example (models.personrepository) should.

now i'm stuck when comes testing. can't manage set test class , inject models.personrepository, when want load , test controller class (e.g. functional test of controllers.application), but when running test(s) of sub-project core out of eclipse ide (core eclipse project created executing activator eclipse). doing activator test works , test shown below runs successfully.

public class applicationtest extends withapplication {      @inject private personrepository repo;      @inject application application;      @before     public void setup() {         // here supposes happen more make personrepository injection work when running junit tests out of eclipse ide         guiceapplicationbuilder builder = new guiceapplicationloader()             .builder(new context(environment.simple()));         guice.createinjector(builder.applicationmodule()).injectmembers(this);     }      @after     public void teardown() {       helpers.stop(application);     }      @test     public void testinjection() {         assertnotnull(repo);     } 

although working through testing-related pages of playframework manual (starting here), couldn't find helpful.

as receive error when testing out of eclipse ide,

com.google.inject.configurationexception: guice configuration errors:  1) no implementation models.personrepository bound.   while locating models.personrepository     field @ core.applicationtest.repo(applicationtest.java:32)   while locating core.applicationtest 

so think problem is, have refer sub-project's application config (core/conf/core-application.conf) enables guice spring module sub-project. secondly, have make sure, configs.appconfig loaded appropriately, class manages spring data configuration.

as absolutely new this, maybe 1 me out, showing

  1. what do, make tests work when running out of eclipse ide (scala ide plugin)
  2. how force provided test class use dedicated in-memory test database (necessarily not using 1 defined sub-project core/conf/meta-inf/persistence.xml).

full source code here

edit i've found out, classpath differs when using junit test eclipse ide instead of activator test, assume reason why injection not work.

# classpath output sorted before $ diff activatorcp eclipsecp 0a1 >  88,89d88 < /h/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.6.jar < /h/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.6.jar 130,136c129,131 < /h/.sbt/boot/scala-2.10.5/org.scala-sbt/sbt/0.13.9/test-agent-0.13.9.jar < /h/.sbt/boot/scala-2.10.5/org.scala-sbt/sbt/0.13.9/test-interface-1.0.jar < /h/workspace/springtest/core/target/scala-2.11/classes/ < /h/workspace/springtest/core/target/scala-2.11/test-classes/ < /h/workspace/springtest/core/target/web/classes/main/ < /h/workspace/springtest/core/target/web/classes/test < /h/workspace/springtest/core/target/web/public/test/ --- > /h/workspace/springtest/core/bin/ > /opt/eclipse-mars/configuration/org.eclipse.osgi/213/0/.cp/ > /opt/eclipse-mars/configuration/org.eclipse.osgi/214/0/.cp/ 

as i've created eclipse's project using activator compile eclipse, wonder else have do, matching classpaths

the difference in behavior came customizing java options in project's build.sbt allowing activator test run correctly. these customization have manually carried on eclipse project's run configuration. after that, tests out of eclipse ide run, successfully.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -