@Test public void managerIterationWithNoResults() throws Exception { final User mockUser = mock(User.class); final UserManager mockManager1 = mock(UserManager.class, "ldap"); final UserManager mockManager2 = mock(UserManager.class, "wiki"); final Map<String, UserManager> managers = new LinkedHashMap<>(); managers.put("ldap", mockManager1); managers.put("wiki", mockManager2); when(this.cm.<UserManager>getInstanceMap(UserManager.class)).thenReturn(managers); when(this.cm.getInstance(UserManager.class, "wiki")).thenReturn(mockManager2); when(mockManager1.getUser(this.adminUsername)).thenReturn(null); when(mockManager2.getUser(this.adminUsername)).thenReturn(null); when(this.configuration.getProperty("users.defaultUserManager", "wiki")).thenReturn("wiki"); when(mockManager2.getUser(this.adminUsername, true)).thenReturn(mockUser); User u = this.userManager.getUser(this.adminUsername, true); Assert.assertSame(mockUser, u); }
@Override public User getUser(String identifier, boolean force) { if (StringUtils.isBlank(identifier)) { return new InvalidUser(null, this.serializer); } User result = null; try { Map<String, UserManager> managers = this.componentManager.getInstanceMap(UserManager.class); managers.remove("default"); for (UserManager manager : managers.values()) { result = manager.getUser(identifier); if (result != null) { return result; } } } catch (ComponentLookupException ex) { } if (force) { try { UserManager defaultManager = this.componentManager.getInstance(UserManager.class, this.configuration.getProperty("users.defaultUserManager", "wiki")); return defaultManager.getUser(identifier, true); } catch (ComponentLookupException ex) { } } return new InvalidUser(getDefaultReference(identifier), this.serializer); }
MetaUserManager extends AbstractUserManager { @Override public User getUser(String identifier, boolean force) { if (StringUtils.isBlank(identifier)) { return new InvalidUser(null, this.serializer); } User result = null; try { Map<String, UserManager> managers = this.componentManager.getInstanceMap(UserManager.class); managers.remove("default"); for (UserManager manager : managers.values()) { result = manager.getUser(identifier); if (result != null) { return result; } } } catch (ComponentLookupException ex) { } if (force) { try { UserManager defaultManager = this.componentManager.getInstance(UserManager.class, this.configuration.getProperty("users.defaultUserManager", "wiki")); return defaultManager.getUser(identifier, true); } catch (ComponentLookupException ex) { } } return new InvalidUser(getDefaultReference(identifier), this.serializer); } }
MetaUserManager extends AbstractUserManager { @Override public User getUser(String identifier, boolean force) { if (StringUtils.isBlank(identifier)) { return new InvalidUser(null, this.serializer); } User result = null; try { Map<String, UserManager> managers = this.componentManager.getInstanceMap(UserManager.class); managers.remove("default"); for (UserManager manager : managers.values()) { result = manager.getUser(identifier); if (result != null) { return result; } } } catch (ComponentLookupException ex) { } if (force) { try { UserManager defaultManager = this.componentManager.getInstance(UserManager.class, this.configuration.getProperty("users.defaultUserManager", "wiki")); return defaultManager.getUser(identifier, true); } catch (ComponentLookupException ex) { } } return new InvalidUser(getDefaultReference(identifier), this.serializer); }  }
MetaUserManager extends AbstractUserManager { @Override public User getUser(String identifier, boolean force) { if (StringUtils.isBlank(identifier)) { return new InvalidUser(null, this.serializer); } User result = null; try { Map<String, UserManager> managers = this.componentManager.getInstanceMap(UserManager.class); managers.remove("default"); for (UserManager manager : managers.values()) { result = manager.getUser(identifier); if (result != null) { return result; } } } catch (ComponentLookupException ex) { } if (force) { try { UserManager defaultManager = this.componentManager.getInstance(UserManager.class, this.configuration.getProperty("users.defaultUserManager", "wiki")); return defaultManager.getUser(identifier, true); } catch (ComponentLookupException ex) { } } return new InvalidUser(getDefaultReference(identifier), this.serializer); }  @Override User getUser(String identifier, boolean force); @Override User getCurrentUser(); }
MetaUserManager extends AbstractUserManager { @Override public User getUser(String identifier, boolean force) { if (StringUtils.isBlank(identifier)) { return new InvalidUser(null, this.serializer); } User result = null; try { Map<String, UserManager> managers = this.componentManager.getInstanceMap(UserManager.class); managers.remove("default"); for (UserManager manager : managers.values()) { result = manager.getUser(identifier); if (result != null) { return result; } } } catch (ComponentLookupException ex) { } if (force) { try { UserManager defaultManager = this.componentManager.getInstance(UserManager.class, this.configuration.getProperty("users.defaultUserManager", "wiki")); return defaultManager.getUser(identifier, true); } catch (ComponentLookupException ex) { } } return new InvalidUser(getDefaultReference(identifier), this.serializer); }  @Override User getUser(String identifier, boolean force); @Override User getCurrentUser();  }