2017-12-06 4 views
0

spring-cloud-taskベースのアプリケーションでjunitテストを実行する際に奇妙なエラーが発生しましたが、原因を見つけることができませんでした。spring-cloud-taskアノテーションを使用してjunitテストを実行中にエラーが発生しました

これは私のテストクラスの断片で、エラースタックトレースが続きます。 @EnableTaskアノテーションを削除しても、テストの実行に問題はありません。

誰にも提案はありますか?

ありがとうここ

package eu.wheesbee.cloud.stream.app.discoverit.fundedproject.task.config; 

import javax.annotation.PostConstruct; 
import javax.sql.DataSource; 

import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.test.context.SpringBootTest; 
import org.springframework.cloud.task.configuration.EnableTask; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.core.io.Resource; 
import org.springframework.core.io.ResourceLoader; 
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; 
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; 
import org.springframework.test.annotation.DirtiesContext; 
import org.springframework.test.context.junit4.SpringRunner; 


@DirtiesContext 
@RunWith(SpringRunner.class) 
@SpringBootTest(classes = FundedProjectImporterBatchTest.FundedProjectImporterTestConfiguration.class, 
         webEnvironment = SpringBootTest.WebEnvironment.NONE) 
public abstract class FundedProjectImporterBatchTest { 

    @Autowired 
    protected ResourceLoader resourceLoader; 

    public static class TestBatchConfigurationSuccess extends FundedProjectImporterBatchTest { 

    @Test 
    public void testBatchConfigurationSuccess() throws Exception { 
     System.out.println("----------------------------------------- Ciao!!!!!!!!"); 
    } 
    } 


    @EnableTask 
    @SpringBootApplication 
    public static class FundedProjectImporterTestConfiguration { 

    @Autowired 
    private ResourceLoader resourceLoader; 

    @Autowired 
    private DataSource dataSource; 

    @PostConstruct 
    protected void initialize() { 
     ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); 
     populator.addScript(resourceLoader.getResource("classpath:db/schema-all.sql")); 
     populator.addScript(resourceLoader.getResource("classpath:db/data.sql")); 
     populator.setContinueOnError(false); 

     DatabasePopulatorUtils.execute(populator, dataSource); 
    } 
    } 

} 

スタックトレース:

java.lang.IllegalStateException: The ApplicationContext loaded for [[[email protected] testClass = FundedProjectImporterBatchTest.TestBatchConfigurationSuccess, locations = '{}', classes = '{class eu.wheesbee.cloud.stream.app.discoverit.fundedproject.task.config.FundedProjectImporterBatchTest$FundedProjectImporterTestConfiguration, class eu.wheesbee.cloud.stream.app.discoverit.fundedproject.task.config.FundedProjectImporterBatchTest$FundedProjectImporterTestConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.sp[email protected]23faf8f2, org.springfr[email protected]64729b1e, org.springframework.boot.test.json.DuplicateJsonObje[email protected]6895a785, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]ea1a8d5], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]] is not active. Ensure that the context has not been closed programmatically. 
    at org.springframework.util.Assert.state(Assert.java:70) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:87) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44) ~[spring-boot-test-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12] 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12] 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12] 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12] 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12] 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12] 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE] 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na] 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na] 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539) [.cp/:na] 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761) [.cp/:na] 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461) [.cp/:na] 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207) [.cp/:na] 

答えて

関連する問題