Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8475

CamelSpringDelegatingTestContextLoader and TestNG

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 2.14.1
    • Fix Version/s: None
    • Labels:
      None

      Description

      I'm trying to use CamelSpringDelegatingTestContextLoader with TestNG. Here's my test class:

      MyTest.java
      @ContextConfiguration(classes = SpringTestConfiguration.class, loader = CamelSpringDelegatingTestContextLoader.class)
      public class MyTest extends AbstractCamelTestNGSpringContextTests {
          @Autowired
          private CamelContext camelContext;
      
          @Test
          public void test() {
              Assert.notNull(camelContext);
          }
      }
      

      Configuration class:

      SpringTestConfiguration.java
      @Configuration
      @ComponentScan(basePackageClasses = {SpringTestRoot.class})
      public class SpringTestConfiguration extends CamelConfiguration {
      }
      

      Here's the exception I'm getting:

      org.testng.TestNGException: 
      Cannot instantiate class com.mycompany.demo.MyTest
      	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:38)
      	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:380)
      	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:293)
      	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:115)
      	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:200)
      	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
      	at org.testng.TestRunner.initMethods(TestRunner.java:409)
      	at org.testng.TestRunner.init(TestRunner.java:235)
      	at org.testng.TestRunner.init(TestRunner.java:205)
      	at org.testng.TestRunner.<init>(TestRunner.java:160)
      	at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:141)
      	at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:271)
      	at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:575)
      	at org.testng.SuiteRunner.init(SuiteRunner.java:159)
      	at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)
      	at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
      	at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
      	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
      	at org.testng.TestNG.run(TestNG.java:1057)
      	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
      	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
      	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
      	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:483)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      Caused by: java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
      	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
      	... 27 more
      Caused by: java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults, and no ApplicationContextInitializers were declared for context configuration [ContextConfigurationAttributes@327b636c declaringClass = 'org.apache.camel.testng.AbstractCamelTestNGSpringContextTests', classes = '{}', locations = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.apache.camel.testng.AbstractCamelTestNGSpringContextTests$TestNGCamelSpringTestContextLoader']
      	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.processContextConfiguration(AbstractDelegatingSmartContextLoader.java:201)
      	at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:607)
      	at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:560)
      	at org.springframework.test.context.TestContext.<init>(TestContext.java:99)
      	at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:121)
      	at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:107)
      	at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.<init>(AbstractTestNGSpringContextTests.java:108)
      	at org.apache.camel.testng.AbstractCamelTestNGSpringContextTests.<init>(AbstractCamelTestNGSpringContextTests.java:49)
      	at com.mycompany.demo.MyTest.<init>(MyTest.java:12)
      	... 32 more
      

      If I drop AbstractCamelTestNGSpringContextTests and use AbstractTestNGSpringContextTests and copy the listeners I'm able to execute the test.

      Will there be TestNG support for CamelSpringDelegatingTestContextLoader?

        Attachments

          Activity

            People

            • Assignee:
              njiang Willem Jiang
              Reporter:
              janil Jani
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: