Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-9754

Sling Testing Mocks: Emit classpath file name in case of exception in ModelAdapterFactoryUtil.addModelsForManifestEntries()

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: Testing Sling Mock 2.6.2
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      None

      Description

      If you see an exception like

      [ERROR] myPackage.MyTest.testMethod  Time elapsed: 0.052 s  <<< ERROR!
      java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class com.adobe.granite.haf.annotations.ApiModel.modelLookup()
              at java.lang.reflect.Method.getDefaultValue(Method.java:612)
              at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:132)
              at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85)
              at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:266)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
              at java.lang.Class.createAnnotationData(Class.java:3521)
              at java.lang.Class.annotationData(Class.java:3510)
              at java.lang.Class.getAnnotation(Class.java:3415)
              at org.apache.sling.models.impl.ModelPackageBundleListener.analyzeClass(ModelPackageBundleListener.java:145)
              at org.apache.sling.models.impl.ModelPackageBundleListener.addingBundle(ModelPackageBundleListener.java:125)
              at org.apache.sling.models.impl.ModelPackageBundleListener.addingBundle(ModelPackageBundleListener.java:52)
              at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:475)
              at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:420)
              at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
              at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
              at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450)
              at org.apache.sling.testing.mock.osgi.MockBundleContext.sendBundleEvent(MockBundleContext.java:383)
              at org.apache.sling.testing.mock.osgi.MockOsgi.sendBundleEvent(MockOsgi.java:62)
              at org.apache.sling.testing.mock.sling.context.ModelAdapterFactoryUtil.addModelsForPackages(ModelAdapterFactoryUtil.java:95)
              at org.apache.sling.testing.mock.sling.context.ModelAdapterFactoryUtil.addModelsForManifestEntries(ModelAdapterFactoryUtil.java:128)
              at org.apache.sling.testing.mock.sling.context.SlingContextImpl.registerDefaultServices(SlingContextImpl.java:187)
              at io.wcm.testing.mock.aem.context.AemContextImpl.registerDefaultServices(AemContextImpl.java:67)
              at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:131)
              at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:94)
              at io.wcm.testing.mock.aem.junit.AemContext.access$100(AemContext.java:49)
              at io.wcm.testing.mock.aem.junit.AemContext$1.before(AemContext.java:183)
              at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:298)
              at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
              at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:218)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:160)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:134)
              at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
              at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
              at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:136)
              at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
              at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
              at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
              at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
              at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
              at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
              at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
              at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:377)
              at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:138)
              at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:465)
              at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:451)
      

      It is not obvious which class path entry is the culprit. Extended logging in org.apache.sling.testing.mock.sling.context.ModelAdapterFactoryUtil#addModelsForManifestEntries(BundleContext) would be helpful here.

      Also the annotation parser (ModelPackageBundleListener.analyzeClass) should probably be more lenient. This error is caused by the fact that the Sling Model at com.adobe.cq.screens.impl.aemio.ScreensApplicationsFolderModel references the annotation ApiModel which itself references a default class which is not available in the classpath:

      
      public @interface ApiModel {
      ....
      Class<? extends ModelLookup> modelLookup() default NullModelLookup.class; // NullModelLookup.class is not on the classpath
      ...
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                kwin Konrad Windszus
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: