2016-01-21 23 views
0

我正在與wcm.ioAemContext單元測試我的AEM類。如何從wmc.io檢索會話AemContext

有什麼辦法從它獲取JCR會話?或者可能是郵件列表,可能會產生答案?

我試圖

import io.wcm.testing.mock.aem.junit.AemContext; 
import javax.jcr.Session; 
// ... 

public class MyTest { 

    @Rule 
    public AemContext aemContext = new AemContext(); 

    @Test 
    public void selfTest() throws Exception { 
     // something like this is called inside the class I test. 
     // I need the Session to *not* be null. 
     Session session = aemContext.resourceResolver().adaptTo(Session.class); 

     assertNotNull("session is " + session, session); 
    } 

    // actual tests follow that do not work due to the problem above 
    // ... 
} 

回答

1

只要你沒有指定ResorceResolver類型,它使用DEFAULT_RESOURCERESOLVER_TYPE,這是ResourceResolverType.RESOURCERESOLVER_MOCK(請API),沒有底層JCR存儲庫。

請檢查可用的類型,然後選擇一個適合您的套件there。 在大多數情況下,您可以使用JCR_MOCK。請參閱文檔以獲取更多信息。