@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (name == null) { return false; } try { UserManager.UserAttribute d = (UserManager.UserAttribute) obj; return name.equals(d.getName()); } catch (ClassCastException e) { return false; } } }
@Override public UserManager.UserAttribute answer(InvocationOnMock invocationOnMock) throws Throwable { final String _name = (String) invocationOnMock.getArguments()[0]; final Boolean _isMandatory = (Boolean) invocationOnMock.getArguments()[1]; final Boolean _isEditable = (Boolean) invocationOnMock.getArguments()[2]; final String _defaultValue = (String) invocationOnMock.getArguments()[3]; final UserManager.UserAttribute attribute = mock(UserManager.UserAttribute.class); when(attribute.getName()).thenReturn(_name); when(attribute.isMandatory()).thenReturn(_isMandatory); when(attribute.isEditable()).thenReturn(_isEditable); when(attribute.getDefaultValue()).thenReturn(_defaultValue); return attribute; } }).when(userSystemManager).createUserAttribute(anyString(),
@Test public void testOnAttributeCreated() { UserManager.UserAttribute attr2 = mock(UserManager.UserAttribute.class); when(attr2.getName()).thenReturn("attr2"); when(attr2.getDefaultValue()).thenReturn("v2"); when(attr2.isEditable()).thenReturn(true); when(attr2.isMandatory()).thenReturn(true); when(userSystemManager.getUserSupportedAttribute("attr2")).thenReturn(attr2); CreateUserAttributeEvent createUserAttributeEvent = mock(CreateUserAttributeEvent.class);
when(USER_ID.getName()).thenReturn(ATTRIBUTE_USER_ID); when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.getName()).thenReturn(ATTRIBUTE_USER_FIRST_NAME); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.getName()).thenReturn(ATTRIBUTE_USER_LAST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.getName()).thenReturn(ATTRIBUTE_USER_ENABLED); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.getName()).thenReturn(ATTRIBUTE_USER_EMAIL); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
when(USER_ID.getName()).thenReturn(ATTRIBUTE_USER_ID); when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.getName()).thenReturn(ATTRIBUTE_USER_FIRST_NAME); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.getName()).thenReturn(ATTRIBUTE_USER_LAST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.getName()).thenReturn(ATTRIBUTE_USER_ENABLED); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.getName()).thenReturn(ATTRIBUTE_USER_EMAIL); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
when(USER_ID.getName()).thenReturn(ATTRIBUTE_USER_ID); when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.getName()).thenReturn(ATTRIBUTE_USER_FIRST_NAME); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.getName()).thenReturn(ATTRIBUTE_USER_LAST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.getName()).thenReturn(ATTRIBUTE_USER_ENABLED); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.getName()).thenReturn(ATTRIBUTE_USER_EMAIL); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
@Test public void testGetValue() { UserManager.UserAttribute attribute1 = mock(UserManager.UserAttribute.class); when(attribute1.getName()).thenReturn("attr1"); when(attribute1.getDefaultValue()).thenReturn("v1"); when(attribute1.isEditable()).thenReturn(true); when(attribute1.isMandatory()).thenReturn(true); UserManager.UserAttribute attribute2 = mock(UserManager.UserAttribute.class); when(attribute2.getName()).thenReturn("attr2"); when(attribute2.getDefaultValue()).thenReturn("v2"); when(attribute2.isEditable()).thenReturn(true); when(attribute2.isMandatory()).thenReturn(true); Map<UserManager.UserAttribute, String> attrs = new HashMap<UserManager.UserAttribute, String>(1); attrs.put(attribute1, "value1"); attrs.put(attribute2, "value2"); presenter.attributes = attrs; Map<String, String> result = presenter.getValue(); assertNotNull(result); assertTrue(result.size() == 2); assertEquals("value1", result.get("attr1")); assertEquals("value2", result.get("attr2")); }
@Before public void setup() { when(newUserAttributeEditor.clear()).thenReturn(newUserAttributeEditor); when(userSystemManager.isUserCapabilityEnabled(any(Capability.class))).thenReturn(true); attribute = mock(UserManager.UserAttribute.class); when(attribute.getName()).thenReturn("attr1"); when(attribute.getDefaultValue()).thenReturn("v1"); when(attribute.isEditable()).thenReturn(true); when(attribute.isMandatory()).thenReturn(true); when(userSystemManager.getUserSupportedAttribute("attr1")).thenReturn(attribute); when(view.getColumnCount()).thenReturn(0); presenter = new UserAttributesEditor(userSystemManager, confirmBox, createUserAttributeEventEvent, updateUserAttributeEventEvent, deleteUserAttributeEventEvent, errorEvent, newUserAttributeEditor, view); }
protected void redraw() { userAttributesProvider.getList().clear(); buildViewColumns(); if (attributes != null) { for (final Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { final UserManager.UserAttribute attribute = entry.getKey(); final String value = entry.getValue(); final Map.Entry<String, String> attrEntry = createAttributeEntry(attribute.getName(), value); addAttributeEntry(attrEntry); } view.redraw(); } else { view.showEmpty(); } }
public User createNewUser(final String identifier) { User user = userSystemManager.createUser(identifier); final Collection<UserManager.UserAttribute> attrs = userSystemManager.getUserSupportedAttributes(); if (attrs != null) { for (UserManager.UserAttribute attribute : attrs) { final String name = attribute.getName(); final boolean isMandatory = attribute.isMandatory(); final boolean isEditable = attribute.isEditable(); if (isMandatory && isEditable && name != null) { final String defaultValue = attribute.getDefaultValue(); user.setProperty(name, defaultValue); } } } return user; }
public User createNewUser(final String identifier) { User user = userSystemManager.createUser(identifier); final Collection<UserManager.UserAttribute> attrs = userSystemManager.getUserSupportedAttributes(); if (attrs != null) { for (UserManager.UserAttribute attribute : attrs) { final String name = attribute.getName(); final boolean isMandatory = attribute.isMandatory(); final boolean isEditable = attribute.isEditable(); if (isMandatory && isEditable && name != null) { final String defaultValue = attribute.getDefaultValue(); user.setProperty(name, defaultValue); } } } return user; }
protected void redraw() { userAttributesProvider.getList().clear(); buildViewColumns(); if (attributes != null) { for (final Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { final UserManager.UserAttribute attribute = entry.getKey(); final String value = entry.getValue(); final Map.Entry<String, String> attrEntry = createAttributeEntry(attribute.getName(), value); addAttributeEntry(attrEntry); } view.redraw(); } else { view.showEmpty(); } }
private UserManager.UserAttribute getAttribute(final String name) { if (!isEmpty(name) && attributes != null && !attributes.isEmpty()) { for (final Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { final UserManager.UserAttribute attribute = entry.getKey(); if (name.equals(attribute.getName())) { return attribute; } } } return null; }
private UserManager.UserAttribute getAttribute(final String name) { if (!isEmpty(name) && attributes != null && !attributes.isEmpty()) { for (final Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { final UserManager.UserAttribute attribute = entry.getKey(); if (name.equals(attribute.getName())) { return attribute; } } } return null; }
@Override public Map<String, String> getValue() { final Map<String, String> result = new HashMap<String, String>(attributes.size()); for (Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { result.put(entry.getKey().getName(), entry.getValue()); } return result; }
public UserManager.UserAttribute getUserSupportedAttribute(final String attributeName) { if (attributeName != null && userManagerSettings != null && userManagerSettings.getSupportedAttributes() != null) { for (final UserManager.UserAttribute attribute : userManagerSettings.getSupportedAttributes()) { if (attributeName.equals(attribute.getName())) { return attribute; } } } return null; }
@Override public Map<String, String> getValue() { final Map<String, String> result = new HashMap<String, String>(attributes.size()); for (Map.Entry<UserManager.UserAttribute, String> entry : attributes.entrySet()) { result.put(entry.getKey().getName(), entry.getValue()); } return result; }
private UserManager.UserAttribute mockUserAttribute(String name, String defaultValue, boolean isMandatory, boolean isEditable) { UserManager.UserAttribute attr = mock(UserManager.UserAttribute.class); when(attr.getName()).thenReturn(name); when(attr.getDefaultValue()).thenReturn(defaultValue); when(attr.isMandatory()).thenReturn(isMandatory); when(attr.isEditable()).thenReturn(isEditable); return attr; } }
public UserManager.UserAttribute getUserSupportedAttribute(final String attributeName) { if (attributeName != null && userManagerSettings != null && userManagerSettings.getSupportedAttributes() != null) { for (final UserManager.UserAttribute attribute : userManagerSettings.getSupportedAttributes()) { if (attributeName.equals(attribute.getName())) { return attribute; } } } return null; }
private UserManager.UserAttribute mockUserAttribute(String name, String defaultValue, boolean isMandatory, boolean isEditable) { UserManager.UserAttribute attr = mock(UserManager.UserAttribute.class); when(attr.getName()).thenReturn(name); when(attr.getDefaultValue()).thenReturn(defaultValue); when(attr.isMandatory()).thenReturn(isMandatory); when(attr.isEditable()).thenReturn(isEditable); return attr; } }