icfnext / prosper

A Spock-based integration testing library for prosperous AEM development.
Other
28 stars 19 forks source link

pageDecorator.getAbsoluteParent() throwing null pointer #23

Closed ehtulhaq closed 4 years ago

ehtulhaq commented 4 years ago

When i'm trying to test a method that uses pageDecorator.getAbsoluteParent(), the test fails throwing a null pointer exception. When i checked the AEM library code's test classes for page decorator, they've used page.getAbsoluteParent() which works perfectly fine. (Not sure how the tests were passed)

Here is the content:-

def setupSpec() {
        pageBuilder.content {
            xyz{blueprint{en{abc{}}}}}}

Error_-

page.getAbsoluteParent(2) != null
|    |
|    java.lang.NullPointerException: Cannot invoke method getPage() on null object
DefaultPageDecorator{path=/content/xyz/blueprint/en/abc, title=}

    at com.company.aem.utils.UtiliySpec.check page decorator(UtiliySpec.groovy:189)
Caused by: java.lang.NullPointerException: Cannot invoke method getPage() on null object
    at com.icfolson.aem.library.core.page.impl.DefaultPageDecorator.getAbsoluteParent(DefaultPageDecorator.groovy:487)
    ... 1 more
markdaugherty commented 4 years ago

Add this line to your setupSpec method:

slingContext.registerAdapterFactory(new AemLibraryAdapterFactory())

ehtulhaq commented 4 years ago

Thanks! that worked