0
votes

I have a Jhipster Generated with v3.4.0 (using Gradle).

I'm attempting to run and debug unit tests from STS.

From documentation:

Those tests can be run directly in your IDE, by right-clicking on each test class, or by running mvn clean test (or ./gradlew test if you run Gradle).

While the gradle task $.gradlew test executes as expected, when I attempt to "right click" and Run As Junit Test or Debug As Junit test - I get exceptions around the database:

Small part of stacktrace:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService web.myapp.core.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private web.myapp.core.repository.UserRepository web.myapp.core.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#1c752902' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1c752902': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.

My assumption is that the correct profile for the test-database is not initialized: src/test/resources/application.yml

Any advice on setting this profile in STS?

Update

I have updated with some screen-shops per the https://jhipster.github.io/configuring-ide-eclipse-gradle/:

  1. No Resource Filters Project Properties > Resource > Resource Filters (none were added by STS when I imported the project No Resource Filters Project Properties > Resource > Resource Filters (none were added by STS when I imported the project

  2. Checked to make sure the build/generated/source/apt/main is added to my Java Build Path settings under Project Properties > Java Build Path Checked to make sure the build/generated/source/apt/main is added to my Java Build Path settings under Project Properties > Java Build Path

1
Did you follow the Eclipse and Gradle setup guide ? Your issue is because the test resource folder is not correctly set up, which should have been the case normally.Julien Dubois
@JulienDubois I did follow it as closely as possible and installed the buildship plugin (though it was after I imported my project) I will uninstall the Gradle STS Plugin, and re-import with buildship installed.jordan.baucke
Hi @jordan.baucke, sorry for commenting in this old thread but, have you been able to find a solution to this issue? I'm having the same problem and I couldn't find any solution yet. Thanks!Lucas Colombo

1 Answers

1
votes

I had the same problem and this is how I got it working:
1. You need to initially run the test at least once as part of the gradle build task before you can then run it interactively with JUnit
2. JHipster generates the build.gradle file by default to only run tests that are named *UnitTest or *IntTest. If you have this default configuration, but have named your test differently, then step 1 above won't work because although the build may complete successfully it hasn't actually run your test and as a result it still can't be run in JUnit.
3. Follow the steps given in the screenshots that have been added above as an update to the original question.
Now trying running as JUnit Test.