[
https://issues.apache.org/jira/browse/CAMEL-20838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17856705#comment-17856705
]
Marco Santarelli edited comment on CAMEL-20838 at 6/21/24 9:21 AM:
-------------------------------------------------------------------
>From the discussion on Zulip, I am getting the following error with
>4.7.0-SNAPSHOT
```
java.lang.NullPointerException: Cannot invoke
"org.apache.camel.test.junit5.CamelContextManager.setGlobalStore(org.junit.jupiter.api.extension.ExtensionContext$Store)"
because "this.contextManager" is null
at
org.apache.camel.test.junit5.CamelTestSupport.beforeAll(CamelTestSupport.java:148)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Suppressed: java.lang.NullPointerException: Cannot invoke
"org.apache.camel.test.junit5.CamelContextManager.stop()" because
"this.contextManager" is null
at
org.apache.camel.test.junit5.CamelTestSupport.afterAll(CamelTestSupport.java:153)
... 1 more
```
My test class just has the `@ExtendWith(CamelExtension.class)` annotation,
nothing else special about this test. It is not calling any deprecated API.
It seems to be caused by this line in beforeAll:
```
contextManager.setGlobalStore(globalStore);
```
it tries to access the contextManager, which in case there is no per-class
lifecycle, is only instantiated in the beforeEach, which runs always after the
beforeAll.
I believe in order to fix this, the following lines should be moved from
beforeEach to beforeAll:
```
if (contextManager == null) {
LOG.trace("Creating a transient context manager for {}",
context.getDisplayName());
contextManager =
contextManagerFactory.createContextManager(ContextManagerFactory.Type.BEFORE_EACH,
testConfigurationBuilder, camelContextConfiguration);
}
```
was (Author: santa.85):
>From the discussion on Zulip, I am getting the following error with
>4.7.0-SNAPSHOT
```
java.lang.NullPointerException: Cannot invoke
"org.apache.camel.test.junit5.CamelContextManager.setGlobalStore(org.junit.jupiter.api.extension.ExtensionContext$Store)"
because "this.contextManager" is null
at
org.apache.camel.test.junit5.CamelTestSupport.beforeAll(CamelTestSupport.java:148)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Suppressed: java.lang.NullPointerException: Cannot invoke
"org.apache.camel.test.junit5.CamelContextManager.stop()" because
"this.contextManager" is null
at
org.apache.camel.test.junit5.CamelTestSupport.afterAll(CamelTestSupport.java:153)
... 1 more
```
My test class just has the `@ExtendWith(CamelExtension.class)` annotation,
nothing else special about this test. It is not calling any deprecated API.
> camel-test: block usages of internal APIs.
> ------------------------------------------
>
> Key: CAMEL-20838
> URL: https://issues.apache.org/jira/browse/CAMEL-20838
> Project: Camel
> Issue Type: Task
> Components: camel-test
> Affects Versions: 4.7.0
> Reporter: Otavio Rodolfo Piske
> Assignee: Otavio Rodolfo Piske
> Priority: Major
> Fix For: 4.x
>
>
> Over the course of years, multiple additions and changes to the
> CamelTestSupport class have made it extremely fragile, tightly coupled and
> hard to maintain.
> Among the problems of this class:
> * Mixing up being responsibilities
> ** It is both a JUnit 5 extension and *also* a base test class
> *** Which leads to multiple ways to setup and tear down the test (either via
> extension methods or via setup/tearDown methods + the setup/tearDown from the
> tests itself)
> ** In addition to being also a JUnit 5 extension and a base test class ...
> it is ALSO a BreakPoint.
> ** And a utility class that provides helper methods (i.e.: providing utility
> methods for useful operations - send/receive requests)
> ** And also a test configuration class in itself (i.e.: allowing tests to
> configure themselves by overriding methods)
> * Over-complexity
> ** the code tries to handle different lifecycle supported by JUnit
> ** along with concurrency
> ** as well as setting up and managing the CamelContext
> * Mix up assertions with assumptions
> * Little control about the initialization order of the extension (itself ?)
> via JUnit's Order annotation
> * Three ways to manage JMX: useJMX, enableJMX, disableJMX.
>
> To make things even worse, the wide open interfaces provided by this [class
> have leaked to other
> projects|https://github.com/apache/camel-quarkus/blob/main/test-framework/junit5/src/main/java/org/apache/camel/quarkus/test/CamelQuarkusTestSupport.java]
> (such as Camel Quarkus).
>
> The work on this ticket is prevent tests from abusing internal APIs from
> CamelTestSupport and related classes. As of 4.7.0 they have been marked as
> deprecated, but need to wait until the next LTS release is out before we can
> finish this.
>
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)