Search in sources :

Example 1 with DefaultLoginsHealthCheck

use of org.apache.sling.hc.support.impl.DefaultLoginsHealthCheck in project sling by apache.

the class DefaultLoginsHealthCheckTest method getTestResult.

private Result getTestResult(String login) throws Exception {
    final DefaultLoginsHealthCheck c = new DefaultLoginsHealthCheck();
    SetField.set(c, "logins", Arrays.asList(new String[] { login }));
    final SlingRepository repo = Mockito.mock(SlingRepository.class);
    SetField.set(c, "repository", repo);
    final Session s = Mockito.mock(Session.class);
    Mockito.when(repo.login(Matchers.any(Credentials.class))).thenAnswer(new Answer<Session>() {

        @Override
        public Session answer(InvocationOnMock invocation) {
            final SimpleCredentials c = (SimpleCredentials) invocation.getArguments()[0];
            if ("admin".equals(c.getUserID())) {
                return s;
            }
            return null;
        }
    });
    return c.execute();
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SimpleCredentials(javax.jcr.SimpleCredentials) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultLoginsHealthCheck(org.apache.sling.hc.support.impl.DefaultLoginsHealthCheck) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Aggregations

Credentials (javax.jcr.Credentials)1 Session (javax.jcr.Session)1 SimpleCredentials (javax.jcr.SimpleCredentials)1 DefaultLoginsHealthCheck (org.apache.sling.hc.support.impl.DefaultLoginsHealthCheck)1 SlingRepository (org.apache.sling.jcr.api.SlingRepository)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1