-2

repository = JcrUtils.getRepository('http" + ":" + "/"+ "/" + "localhost" + ":"+ "4502" + "/crx/server");

session = repository.login( new SimpleCredentials("admin","admin".toCharArray()),"crx.default");

How to get dummy repository and session in junit test class.

i searched below url's

https://stackoverflow.com/questions/11550568/unit-testing-by-mocking-the-data-layer-or-using-embedded-database?noredirect=1&lq=1

  • 3
    Stop using a static method to get a repository. Use dependency injection. That's the whole point of Spring. – JB Nizet Aug 10 '17 at 17:57

1 Answers1

0

Use the Sling JCR Mocks API

Add the following Maven dependency

<dependency>
  <groupId>org.apache.sling</groupId>
  <artifactId>org.apache.sling.testing.jcr-mock</artifactId>
  <version>1.3.0</version>
  <scope>test</scope>
</dependency>

and use MockJcr to get session and repository:

@Test public void testJcrMocks() {
    // get session
    Session session = MockJcr.newSession();

    // get repository
    Repository repository = MockJcr.newRepository();
}
Yegor Kozlov
  • 106
  • 2