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

Camel main TestSupport class is incompatible with the CDI specification

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.12.5, 2.14.2
    • Fix Version/s: 2.14.3, 2.15.1, 2.16.0
    • Component/s: camel-test
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      JUnit4 test support class (org.apache.camel.test.junit4.TestSupport) contains the following declaration:

          // CHECKSTYLE:OFF
          @Rule
          public TestName testName = new TestName();
          // CHECKSTYLE:ON
      

      In addition to being a terrible idea overall, this public field also breaks CDI integration, as any tests attempted to be bootstrapped in CDI will throw the following error (WELD trace is shown for an example):

      org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field:  [EnhancedAnnotatedFieldImpl] @Rule public com.netotc.ha.route.TestCDI.testName
      	at org.jboss.weld.bean.ManagedBean.checkBeanImplementation(ManagedBean.java:227)
      	at org.jboss.weld.bean.AbstractClassBean.internalInitialize(AbstractClassBean.java:74)
      	at org.jboss.weld.bean.ManagedBean.internalInitialize(ManagedBean.java:105)
      	at org.jboss.weld.bean.RIBean.initialize(RIBean.java:66)
      	at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:121)
      	at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:118)
      	at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
      	at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:745)
      
      

      Suggesting to create a getter for this field, making the field private, and moving the @Rule annotation to the getter.

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              alex_savitsky Alex Savitsky
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: