JcrSessionFactory implements InitializingBean, DisposableBean, SessionFactory { protected Session addListeners(Session session) throws RepositoryException { if (eventListeners != null && eventListeners.length > 0) { Workspace ws = session.getWorkspace(); ObservationManager manager = ws.getObservationManager(); if (LOG.isDebugEnabled()) LOG.debug("adding listeners " + Arrays.asList(eventListeners).toString() + " for session " + session); for (int i = 0; i < eventListeners.length; i++) { manager.addEventListener(eventListeners[i].getListener(), eventListeners[i].getEventTypes(), eventListeners[i].getAbsPath(), eventListeners[i].isDeep(), eventListeners[i].getUuid(), eventListeners[i].getNodeTypeName(), eventListeners[i].isNoLocal()); } } return session; } JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials);  JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager);  JcrSessionFactory(); @Override void afterPropertiesSet(); @Override void destroy(); @Override Session getSession(); @Override SessionHolder getSessionHolder(Session session); Repository getRepository(); void setRepository(Repository repository); void setWorkspaceName(String workspaceName); void setCredentials(Credentials credentials); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); EventListenerDefinition[] getEventListeners(); void setEventListeners(EventListenerDefinition[] eventListenerDefinitions); Properties getNamespaces(); void setNamespaces(Properties namespaces); SessionHolderProviderManager getSessionHolderProviderManager(); void setSessionHolderProviderManager(SessionHolderProviderManager sessionHolderProviderManager); void setKeepNewNamespaces(boolean keepNamespaces); void setForceNamespacesRegistration(boolean forceNamespacesRegistration); void setSkipExistingNamespaces(boolean skipRegisteredNamespace); boolean isForceNamespacesRegistration(); boolean isKeepNewNamespaces(); boolean isSkipExistingNamespaces(); Credentials getCredentials(); String getWorkspaceName();  }
@Test public void testAddListeners() throws RepositoryException { EventListenerDefinition def1 = new EventListenerDefinition(); EventListenerDefinition def2 = new EventListenerDefinition(); EventListenerDefinition listeners[] = new EventListenerDefinition[] { def1, def2 }; factory.setEventListeners(listeners); Session session = createMock(Session.class); Workspace workspace = createMock(Workspace.class); ObservationManager observationManager = createMock(ObservationManager.class); expect(repository.login(null, null)).andReturn(session); expect(session.getWorkspace()).andReturn(workspace); expect(workspace.getObservationManager()).andReturn(observationManager); observationManager.addEventListener(def1.getListener(), def1.getEventTypes(), def1.getAbsPath(), def1.isDeep(), def1.getUuid(), def1.getNodeTypeName(), def1.isNoLocal()); observationManager.addEventListener(def2.getListener(), def2.getEventTypes(), def2.getAbsPath(), def2.isDeep(), def2.getUuid(), def2.getNodeTypeName(), def2.isNoLocal()); replay(repository, session, workspace, observationManager); assertSame(listeners, factory.getEventListeners()); Session sess = factory.getSession(); assertSame(session, sess); verify(repository, session, workspace, observationManager); }