getting IllegalStateException when I run my integrationTest.
below is my test class:
@ActiveProfiles("local")
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = [DemoApplication])
class ApplicationIT extends Specification {
@Autowired
ApplicationContext applicationContext
def "check applicationContext"() {
expect:
applicationContext
}
}
this class running fine.
when I extend this in other class and trying to make service calls. then it's failing.
class TrainServiceTest extends ApplicationIT {
@Autowired
TrainService trainService
@Autowired
TrainClient trainClient
def "verify trainClient"() {
given:
def paymentDetail = createPaymentDetail()
when:
def sessionId = trainClient.getTrainTranscation(paymentDetail)
def result = trainService.getTranscationDetails(sessionId)
then:
result.firstName == 'test'
result.lastName == 'lname'
result.city == 'city'
}
}
when I run this in debug mode, all the assertions happening in then block.
finally, call happened to class org.spockframework.spring.SpringInterceptor and method is public void interceptCleanupSpecMethod(IMethodInvocation invocation) throws Throwable and in this method failing statement is manager.afterTestClass();
getting below error:
java.lang.IllegalStateException: The ApplicationContext loaded for [[WebMergedContextConfiguration@51c80219 testClass = TrainServiceTest, locations = '{}', classes = '{class com.test.DemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{local}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = set[org.spockframework.spring.mock.SpockContextCustomizer@0, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@22c86919, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@21ec5d87, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@363f6148, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@138fe6ec, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@2e5c7f0b, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@57c758ac], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. This may be due to one of the following reasons: 1) the context was closed programmatically by user code; 2) the context was closed during parallel test execution either according to @DirtiesContext semantics or due to automatic eviction from the ContextCache due to a maximum cache size policy.