2016-01-21 57 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。请参阅文档以获取更多信息。