java.lang.IllegalStateException: Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details.

Spring JIRA | Benoit AVERTY | 8 months ago
  1. 0

    When using the {{@Rule}} and {{@ClassRule}} classes SpringTestRule and SpringMethodRule in conjunction with a custom Runner that allows to use nested classes to create hierarchical tests, the tests in subclasses fail with a {{IllegalStateException}}. Example of a hierarchical runner : - https://github.com/bechte/junit-hierarchicalcontextrunner/wiki - https://github.com/NitorCreations/CoreComponents/tree/master/junit-runners The second one doesn't have the same error but i'm guessing the problem is similar. StackTrace : {noformat} java.lang.IllegalStateException: Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details. at org.springframework.test.context.junit4.rules.SpringMethodRule.validateSpringClassRuleConfiguration(SpringMethodRule.java:233) at org.springframework.test.context.junit4.rules.SpringMethodRule.apply(SpringMethodRule.java:143) at de.bechte.junit.runners.context.statements.builder.HierarchicalRunRulesStatementBuilder.createStatement(HierarchicalRunRulesStatementBuilder.java:42) at de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:80) at de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:57) at de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38) at de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27) at de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28) at de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134) at de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:26) at de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:15) at de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38) at de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103) at org.springframework.test.context.junit4.rules.SpringClassRule$TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:248) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28) at de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {noformat} The exception makes sense because the nested class indeed doesn't have the static SpringClassRule. But it can't have it because the nested class isn't static. Moreover, I'm not sure it would need it because the rule would be evaluated twice. Is it possible to correct this behavior or find a workaround ?

    Spring JIRA | 8 months ago | Benoit AVERTY
    java.lang.IllegalStateException: Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details.
  2. 0

    h4. Status Quo The _Spring TestContext Framework_ has traditionally supported only top-level or static nested test classes. With support for {{@Nested}} test classes in JUnit 5 and custom runners in JUnit 4, however, there is increased need to support nested non-static test classes (i.e., _inner_ classes). h4. Deliverables # (/) Introduce support for loading a test {{ApplicationContext}} via {{@ContextConfiguration}} and related annotations for a _nested_ test class. #- This already works without modifications to the existing code base: a _nested_ (i.e., non-static _inner_) test class is still a {{Class}}, so the TestContext framework doesn't need to do anything special here. # (/) Ensure that JUnit Jupiter based {{@Nested}} test classes work with the TestContext framework. #- This already works for the same reasons mentioned for deliverable #1. # (/) Ensure that {{SpringClassRule}} and {{SpringMethodRule}} work in conjunction with JUnit 4 based runners that support _nested_ test classes. #- Introduced a workaround which is documented in this issue's comments section. h4. JUnit 4 Hierarchical Runners When using the {{@Rule}} and {{@ClassRule}} classes {{SpringMethodRule}} and {{SpringClassRule}} in conjunction with a custom JUnit 4 {{Runner}} that allows one to use nested classes to create hierarchical tests, the tests in subclasses fail with an {{IllegalStateException}}. Examples of hierarchical runners: - https://github.com/bechte/junit-hierarchicalcontextrunner/wiki - https://github.com/NitorCreations/CoreComponents/tree/master/junit-runners The second one doesn't have the same error, but I'm guessing the problem is similar. {noformat:title=Stack Trace} java.lang.IllegalStateException: Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details. at org.springframework.test.context.junit4.rules.SpringMethodRule.validateSpringClassRuleConfiguration(SpringMethodRule.java:233) at org.springframework.test.context.junit4.rules.SpringMethodRule.apply(SpringMethodRule.java:143) at de.bechte.junit.runners.context.statements.builder.HierarchicalRunRulesStatementBuilder.createStatement(HierarchicalRunRulesStatementBuilder.java:42) at de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:80) at de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:57) at de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38) at de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27) at de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28) at de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134) at de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:26) at de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:15) at de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38) at de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103) at org.springframework.test.context.junit4.rules.SpringClassRule$TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:248) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28) at de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {noformat} The exception makes sense because the nested class indeed doesn't have the static {{SpringClassRule}}. But it can't have it because the nested class isn't static. Moreover, I'm not sure it would need it because the rule would be evaluated twice.

    Spring JIRA | 8 months ago | Benoit AVERTY
    java.lang.IllegalStateException: Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details.
  3. 0

    [mongo-jackson-mapper] play-mongojack testing leads to Exception: "this Mongo has been closed" - Grokbase

    grokbase.com | 1 year ago
    java.lang.IllegalStateException: this Mongo has been closed" * in the second test. Here is basically what I have (I removed the asserts here because the error persists even without them): // Data reference for the test private String userEmail = " "; private String userName = "Test User"; private String userPassword = "secret"; @Test public void createUser() { running(fakeApplication(), new Runnable() { public void run() { // Create new user with reference information User user = new User(); user.email = userEmail; user.name = userName; user.password = userPassword; // Add user to database User.create(user); } }); } @Test public void deleteUser() { running(fakeApplication(), new Runnable() { public void run() { // Delete user from database User.delete(userEmail); } }); } ...the stack trace... Test models.UserTest.deleteUser failed: java.lang.IllegalStateException:   this Mongo has been closed at com.mongodb.DBTCPConnector._checkClosed(DBTCPConnector.java:135)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    View topic - Startup exception • Broadleaf Commerce Discussion Forums

    broadleafcommerce.org | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in resource loaded from byte array: Cannot resolve reference to bean 'blPersistenceUnitManager' while setting bean property 'persistenceUnitManager'; nested e$ [org.broadleafcommerce.common.currency.domain.BroadleafCurrencyImpl, org.broadleafcommerce.common.locale.domain.LocaleImpl, org.broadleafcommerce.common.currency.domain.BroadleafCurrencyImpl] are managed classes within the MergePersistenceUnitManager but were not detected as being transformed by the EntityMarkerClassTransformer. These classes are likely loaded earlier in the application startup lifecyle by the servlet container. Verify that an empty <absolute-ordering /> element is contained in your web.xml to disable scanning for ServletContainerInitializer classes by your servlet container which can trigger early class loading. If the problem persists, ensure that there are no bean references to your entity class anywhere else in your Spring applicationContext and consult the documentation for your servlet container to determine if classes are loaded prior to the Spring context initialization.
  6. 0

    Eclipse Community Forums: Remote Application Platform (RAP) » Problem with RWTLifeCycle / disposed context and Jaas Example implemetation

    eclipse.org | 1 year ago
    java.lang.IllegalStateException: The context has been disposed. but only if i try to refresh a browser window after more than 30sekonds (session timeout?) i think its a wrong approach in my app but i do not know where. thanks for any suggestions phil Philipp Mohrenweiser schrieb: > Ok a little bit reading and i got it myself. i was using a singleton i > implemented myself... so it did not create another one but used the > same.. using SessionSingletonBase solved the problem. > > > public class MySingleton extends SessionSingletonBase { > public static MySingleton getInstance() { > return (MySingleton)getInstance(MySingleton.class); > } > // all the other stuff comes here > } > > I found it in the book Eclipse Rich Ajax Platform but nowhere in the > web, could someone tell me where to find such things ? i would also like > to collect and publish them in some wiki, the rap wiki seems to be a > good idea? > > thanks phil > > > > Philipp Mohrenweiser schrieb: Hello, I tried to implement a simple JAAS Callback Handler from the JAAS Tutorial with RAP. I got many things working. But i have a stange behavior if i try to open a second browser window (another session): The first time i request the URI i yust get a blank workbench, the second time the server goes into a exception loop (see end of post) I am not sure what i did wrong i think it is no bug in rwt i think its the way i am working with it. as far as i understand i should try to make sure aother session gets created for the other browser window. i thought its done but if i change the asyncexec call into an synced exec call i got other exceptions. Can you tell me where the new session is created, so i could try to do this explicitly and the display i use to show my jaashandlerdialog would perhabs use the right one. And is there any further documentation where i could find such topics? sincerely philipp a. mohrenweiser. async run: Authentication failed: org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadTerm inatedError at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.sleep(RWTLif eCycle.java:303)

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Failed to find 'public static final SpringClassRule' field in test class [com.example.unit.testing.application.PlacingOrderTest$WithExistingCustomer]. Consult the javadoc for SpringClassRule for details.

      at org.springframework.test.context.junit4.rules.SpringMethodRule.validateSpringClassRuleConfiguration()
    2. org.springframework.test
      SpringMethodRule.apply
      1. org.springframework.test.context.junit4.rules.SpringMethodRule.validateSpringClassRuleConfiguration(SpringMethodRule.java:233)
      2. org.springframework.test.context.junit4.rules.SpringMethodRule.apply(SpringMethodRule.java:143)
      2 frames
    3. de.bechte.junit
      RunAll.evaluate
      1. de.bechte.junit.runners.context.statements.builder.HierarchicalRunRulesStatementBuilder.createStatement(HierarchicalRunRulesStatementBuilder.java:42)
      2. de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:80)
      3. de.bechte.junit.runners.context.processing.MethodExecutor.run(MethodExecutor.java:57)
      4. de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38)
      5. de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27)
      6. de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28)
      7. de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134)
      8. de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:26)
      9. de.bechte.junit.runners.context.processing.ContextExecutor.run(ContextExecutor.java:15)
      10. de.bechte.junit.runners.context.statements.RunChildren.evaluate(RunChildren.java:38)
      11. de.bechte.junit.runners.context.statements.RunAll.evaluate(RunAll.java:27)
      11 frames
    4. Spring TestContext
      ProfileValueChecker.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      3. org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103)
      3 frames
    5. org.springframework.test
      SpringClassRule$TestContextManagerCacheEvictor.evaluate
      1. org.springframework.test.context.junit4.rules.SpringClassRule$TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:248)
      1 frame
    6. JUnit
      RunRules.evaluate
      1. org.junit.rules.RunRules.evaluate(RunRules.java:20)
      1 frame
    7. de.bechte.junit
      HierarchicalContextRunner.run
      1. de.bechte.junit.runners.context.statements.StatementExecutor.execute(StatementExecutor.java:28)
      2. de.bechte.junit.runners.context.HierarchicalContextRunner.run(HierarchicalContextRunner.java:134)
      2 frames
    8. JUnit4 Runner
      JUnit4TestReference.run
      1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      1 frame
    9. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
      5 frames