jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Failing Integration Tests when tests have different configurations #10488

Closed JamesBarnes88 closed 5 years ago

JamesBarnes88 commented 5 years ago
Overview of the issue

Project created via the generator will not pass the integration tests if a single integration test has a different configuration. When the tests run, h2 in memory instance is ran for the datastore, and a testClient is created via "Jest" for elasticsearch. If a single IT(integration test) class has a different configuration for instance adding a custom UserDetailsService for the test, the tests will fail and it will not just fail for the test with the different configuration. (see Test Results below)

Stace Trace - Elasticsearch exception

```java java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:97) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.java:349) at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.java:349) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312) at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743) at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeTestInstancePostProcessors(ClassTestDescriptor.java:348) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:270) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:259) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$3(ClassTestDescriptor.java:263) at java.util.Optional.orElseGet(Optional.java:267) at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$4(ClassTestDescriptor.java:262) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:82) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:59) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$0(NodeTestTask.java:83) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:83) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:69) at java.util.ArrayList.forEach(ArrayList.java:1249) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74) at java.util.ArrayList.forEach(ArrayList.java:1249) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$4(NodeTestTask.java:112) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:98) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:74) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150) at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418) Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [com/bizequity/test/config/ElasticsearchConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namedbf83167-99d7-4640-bc9e-36c1191081dc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:119) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ... 55 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testClient' defined in class path resource [com/github/vanroy/springboot/autoconfigure/data/jest/ElasticsearchJestAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namedbf83167-99d7-4640-bc9e-36c1191081dc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ... 73 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.searchbox.client.JestClient]: Factory method 'testClient' threw exception; nested exception is java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namedbf83167-99d7-4640-bc9e-36c1191081dc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ... 87 common frames omitted Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[target/elasticsearch/data/internal-test-cluster-namedbf83167-99d7-4640-bc9e-36c1191081dc]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.elasticsearch.env.NodeEnvironment.(NodeEnvironment.java:247) at org.elasticsearch.node.Node.(Node.java:274) at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$InternalNode.(ElasticsearchJestAutoConfiguration.java:200) at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.createInternalNode(ElasticsearchJestAutoConfiguration.java:167) at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration.testClient(ElasticsearchJestAutoConfiguration.java:82) at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$345d578d.CGLIB$testClient$2() at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$345d578d$$FastClassBySpringCGLIB$$8bfa852c.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) at com.github.vanroy.springboot.autoconfigure.data.jest.ElasticsearchJestAutoConfiguration$$EnhancerBySpringCGLIB$$345d578d.testClient() 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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 88 common frames omitted ```

Test Results
[INFO] Running com.bizequity.test.web.rest.UserResourceIT
[ERROR] Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 0.24 s <<< FAILURE! - in com.bizequity.test.web.rest.UserResourceIT
[ERROR] createUserWithExistingEmail  Time elapsed: 0 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] createUserWithExistingLogin  Time elapsed: 0 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] getAllUsers  Time elapsed: 0 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] updateUser  Time elapsed: 0 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] getAllAuthorities  Time elapsed: 0.043 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] getUser  Time elapsed: 0.011 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] createUserWithExistingId  Time elapsed: 0.009 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] testUserDTOtoUser  Time elapsed: 0.016 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] testUserEquals  Time elapsed: 0.009 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] getNonExistingUser  Time elapsed: 0.008 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] testAuthorityEquals  Time elapsed: 0.014 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] updateUserExistingEmail  Time elapsed: 0.023 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] updateUserExistingLogin  Time elapsed: 0.011 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] createUser  Time elapsed: 0.009 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] updateUserLogin  Time elapsed: 0.009 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] deleteUser  Time elapsed: 0.03 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

[ERROR] testUserToUserDTO  Time elapsed: 0.02 s  <<< ERROR!
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.bizequity.test.web.rest.UserResourceIT.setup(UserResourceIT.java:108)

With that said, I think the internal instance of elasticsearch and h2 aren't playing well with multiple contexts being generated for the differences in configurations for the ITs. Noted by Spring: here

Spring’s test framework caches application contexts between tests. Therefore, as long as your tests share the same configuration (no matter how it is discovered), the potentially time-consuming process of loading the context happens only once.

I'm no spring expert, but I feel like the elasticsearch and h2 instances are still running in the other context. The new context is trying to make new instances generating this elasticsearch error and causing a bunch of other errors.

The point of this issue is to get some clarification on how to handle situations like this. Should our tests always refer to external instances of the datastore and elasticsearch instead of relying on these internal instances? (Especially when we have difference in the configuration for ITs) Also is there some issue with how I'm specifying the configuration or some other fundamental that I'm missing.

I think this also related to the generated Cucumber Test also not passing from a generated project as it throws essentially the same error. #10302 I would also assume Spring is making another context for the Cucumber test creating the same environment that causes this issue with the ITs.

Motivation for or Use Case

I was attempting to use a customUserDetailsService for a specific IT. However the test will run and pass if running the single test only. When running multiple/all the tests it fails.

Reproduce the error

To reproduce this:

In a brand new project with cucumber test disabled. I created a new IT and a configuration file to the classes list. @SpringBootTest(classes = {TestingApp.class, UserExtendedResourceIT.UserTestConfig.class})

That configuration can be blank if you just want to reproduce this.

    @TestConfiguration
    public static class UserTestConfig {

    }

For an actual use case I wanted to return specific users by creating a new UserDetailsService used by one of my tests and this was how I wired it up. (By adding it to the classes list)

Original Use Case Config

``` @TestConfiguration public static class SpringSecurityWebAuxTestConfig { @Bean @Primary public UserDetailsService userDetailsService() { User user = createUser("user@email.com", Collections.singleton(createAuthority(AuthoritiesConstants.USER))); User adminUser = createUser("admin@email.com", Collections.singleton(createAuthority(AuthoritiesConstants.ADMIN))); UserDetails userDetails = createUserDetails(user); UserDetails adminUserDetails = createUserDetails(adminUser); return new InMemoryUserDetailsManager(Arrays.asList( userDetails, adminUserDetails )); } private User createUser(String login, Set authorities) { User user = new User(); user.setEmail("email@email.com"); user.setLogin(login); user.setPassword("password"); user.setActivated(true); user.setFirstName("john"); user.setLastName("doe"); user.setAuthorities(authorities); return user; } private Authority createAuthority(String name ) { Authority authority = new Authority(); authority.setName(name); return authority; } private UserDetails createUserDetails(User user) { List grantedAuthorities = user.getAuthorities().stream() .map(authority -> new SimpleGrantedAuthority(authority.getName())) .collect(Collectors.toList()); return new org.springframework.security.core.userdetails.User(user.getLogin(), user.getPassword(), grantedAuthorities); } } ```

I then run ./mvnw clean verify

Related issues

10302

Suggest a Fix

So far my guess is to stay away from differing configurations and run the same configurations for all tests so multiple contexts are not generated.

JHipster Version(s)
testing@0.0.0 /Users/jbarnes/Programming/bizequity/jhipster-test
└── generator-jhipster@6.2.0
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.bizequity.test"
    },
    "jhipsterVersion": "6.2.0",
    "applicationType": "monolith",
    "baseName": "testing",
    "packageName": "com.bizequity.test",
    "packageFolder": "com/bizequity/test",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "hazelcast",
    "enableHibernateCache": true,
    "websocket": "spring-websocket",
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": "eureka",
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "",
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "testFrameworks": ["gatling", "cucumber", "protractor"],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": false,
    "blueprints": []
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

git version 2.16.0

node: v10.16.3

npm: 6.9.0

yeoman: 3.1.0

yarn: 1.10.1

Docker version 19.03.1, build 74b1e89

docker-compose version 1.24.1, build 4667896b

Browsers and Operating System

MacOS - 10.14.3

pascalgrimaud commented 5 years ago

I don't understand well.

vishal423 commented 5 years ago

To fix context issues, you should annotate your tests with @DirtiesContext.

I think JHipster doesn't support true integration tests. In one of my project, I create separate integration tests and use TestRestTemplate to call endpoints. To start/stop external service/database, I use docker maven plugin.

pascalgrimaud commented 5 years ago

It should be similar to what we did for our Kafka integration tests. See https://github.com/jhipster/generator-jhipster/blob/master/generators/server/templates/src/test/java/package/web/rest/KafkaResourceIT.java.ejs#L61

JamesBarnes88 commented 5 years ago

To answer @pascalgrimaud :

  1. So without modifying the application, there is an issue with the generated Cucumber test. It doesn't pass. It generates the same elasticsearch error as above. Disabling the cucumber test, the other originally generated tests will pass as expected.

  2. When I add a single integration test class and add a configuration class to this test, it fails the new test(created by me) and errors out on other tests (tests from the generated classes). As in the above Test Results section.

Today I added @DirtiesContext to a new (created by me) IT(integration test) and now the new test does not fail but the others still error out because of hazelcast. (Hazelcast is not Active) Note that this IT test does nothing. It prints hello world and the configuration does nothing as well (empty class). This was me attempting to reproduce the error in a simple way. I can also upload this test project to a repo if it makes it easier.

I feel as though adding such a simple test should just work and not break other tests. There is also the Cucumber test issue. So I do think this is a bug in how the tests are run with certain jhipster configurations made when the project was generated.

Side Note:

@vishal423 Thanks, I didn't know about @DirtiesContext before this. I did some reading and is it true that adding a single configuration class as in my case dirties the context?

Use this annotation if a test has modified the context — for example, by modifying the state of a singleton bean, modifying the state of an embedded database, etc. Subsequent tests that request the same context will be supplied a new context.

pascalgrimaud commented 5 years ago

Thanks for reporting this issue @JamesBarnes88

I understand your problem, but here, we only track issue with JHipster project without any modification. For cucumber and elasticsearch, there is already a ticket for that : https://github.com/jhipster/generator-jhipster/issues/10302

For this kind of problem, you should use DirtiesContext as suggested but it depends on other config you added in your class too. And for these questions, you should ask to StackOverFlow instead.

That's why I'm closing this