Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-16256

Allow testing runtime overrides when using RuntimeFeature

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 6.0
    • Fix Version/s: Postponed
    • Component/s: Runtime, Tests

      Description

      The RuntimeFeature annotation does not currently allow to stop and start the runtime on each method (like the CoreFeature Granularity.Method setting).

      This makes it difficult to test runtime components overrides in tests (also because deployment API is not good for it).

      Current workaround implies doing something like:

      @RunWith(FeaturesRunner.class)
      @Features({ TransactionalFeature.class, RuntimeFeature.class })
      @Deploy({ "xxx" })
      @LocalDeploy({ "xxx"})
      public class MyTest {
      
          @Inject
          protected RuntimeHarness harness;
      
          @Test
          public void testOverride() throws Exception {
              assertEquals(...);
              String contrib = "OSGI-INF/my-test-override-contrib.xml";
              URL url = getClass().getClassLoader().getResource(contrib);
              RuntimeContext ctx = null;
              try {
                  ctx = harness.deployTestContrib("my.current.bundle", url);
                  assertEquals(...);
              } finally {
                  if (ctx != null) {
                      // make sure initial state is restored for other tests in same class
                      ctx.destroy();
                  }
              }
          }
      
      }
      

      Example: https://github.com/nuxeo/nuxeo-target-platforms/blob/master/nuxeo-target-platforms-core/src/test/java/org/nuxeo/targetplatforms/core/service/test/TestTargetPlatformComponent.java

      A better implementation (that would also not produce strange behaviour when the undeploy feature is buggy on tested component) would be:

      @RunWith(FeaturesRunner.class)
      @Features({ TransactionalFeature.class, RuntimeFeature.class })
      @Deploy({ "xxx" })
      @LocalDeploy({ "xxx"})
      @SomeAnnotationPickedUpByRuntimeFeature(cleanup = Granularity.METHOD)
      public class MyTest {
      
          @Inject
          protected RuntimeHarness harness;
      
          @Test
          public void testOverride() throws Exception {
              assertEquals(...);
              String contrib = "OSGI-INF/my-test-override-contrib.xml";
              URL url = getClass().getClassLoader().getResource(contrib);
              harness.deployTestContrib("my.current.bundle", url);
              assertEquals(...);
          }
      
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: