Search in sources :

Example 26 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class UserServiceTest method getUsersByAttribute_multiValuedTrue_null.

@Test
private void getUsersByAttribute_multiValuedTrue_null() {
    String userId = "123";
    String baseDn = "baseDn";
    String attributeName = "attribute1";
    String attributeValue = "value1";
    List<String> lisAttributes = new ArrayList<>();
    lisAttributes.add(attributeName);
    when(persistenceEntryManager.findEntries(anyString(), any(), any(), anyInt())).thenReturn(getListBasicOneUser(userId, baseDn));
    List<User> resultListUser = userService.getUsersByAttribute(attributeName, attributeValue, true, 1);
    assertNotNull(resultListUser);
    assertTrue(resultListUser.size() == 1);
}
Also used : User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 27 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class UserServiceTest method getUserByAttributes_attributeNamesEmpty_null.

@Test
private void getUserByAttributes_attributeNamesEmpty_null() {
    String[] attributeNames = {};
    User resultUser = userService.getUserByAttributes(null, attributeNames, null);
    assertNull(resultUser);
}
Also used : User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 28 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class UserServiceTest method updateUser_validUser_user.

@Test
private void updateUser_validUser_user() {
    User user = getBasicUser("123", "dn123");
    doNothing().when(persistenceEntryManager).merge(user);
    when(persistenceEntryManager.find(anyString(), any(), any())).thenReturn(user);
    User resultUser = userService.updateUser(user);
    assertNotNull(user);
    assertNotNull(user.getUserId());
    assertTrue(resultUser.getUserId().equals(user.getUserId()));
}
Also used : User(io.jans.as.common.model.common.User) Test(org.testng.annotations.Test)

Example 29 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class UserServiceTest method addUserAttributeByUserInum_existentAttributeExistentValue_user.

@Test
private void addUserAttributeByUserInum_existentAttributeExistentValue_user() {
    String inumUser = "inumUser";
    User user = spy(getBasicUser("123", "dn123"));
    user.setDn("dn123");
    CustomObjectAttribute customAttribute1 = new CustomObjectAttribute("attribute1", "value1");
    CustomObjectAttribute customAttribute2 = new CustomObjectAttribute("attribute2", "value2");
    user.setCustomAttributes(new ArrayList<>());
    user.getCustomAttributes().add(customAttribute1);
    user.getCustomAttributes().add(customAttribute2);
    when(persistenceEntryManager.find(any(), any(), any())).thenReturn(user);
    doNothing().when(persistenceEntryManager).merge(user);
    User resultUser = userService.addUserAttributeByUserInum(inumUser, "attribute2", "value2");
    assertNotNull(resultUser);
    assertTrue(resultUser.getCustomAttributes().size() == 2);
    assertEquals(resultUser.getCustomAttributes().get(0).getName(), "attribute1");
    assertEquals(resultUser.getCustomAttributes().get(0).getValue(), "value1");
    assertEquals(resultUser.getCustomAttributes().get(1).getName(), "attribute2");
    assertEquals(resultUser.getCustomAttributes().get(1).getValue(), "value2");
    assertTrue(resultUser.getCustomAttributes().get(1).getValues().size() == 1);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 30 with User

use of io.jans.as.common.model.common.User in project jans by JanssenProject.

the class UserServiceTest method replaceUserAttribute_existentAttribute_user.

@Test
private void replaceUserAttribute_existentAttribute_user() {
    String userId = "123";
    String baseDn = "dn123";
    User user = spy(getBasicUser("123", "dn123"));
    user.setDn(baseDn);
    CustomObjectAttribute customAttribute1 = new CustomObjectAttribute("attribute1", "value1");
    CustomObjectAttribute customAttribute2 = new CustomObjectAttribute("attribute2", "value2");
    user.setCustomAttributes(new ArrayList<>());
    user.getCustomAttributes().add(customAttribute1);
    user.getCustomAttributes().add(customAttribute2);
    when(dataSourceTypeService.isSpanner(anyString())).thenReturn(true);
    when(persistenceEntryManager.findEntries(anyString(), any(), any(), any())).thenReturn(getListBasicOneUser(user));
    when(persistenceEntryManager.find(anyString(), any(), any())).thenReturn(user);
    doNothing().when(persistenceEntryManager).merge(any());
    User resultUser = userService.replaceUserAttribute(userId, "attribute1", "value1", "newValue1");
    assertNotNull(resultUser);
    assertEquals(resultUser.getCustomAttributes().get(0).getValue(), "newValue1");
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

User (io.jans.as.common.model.common.User)95 Test (org.testng.annotations.Test)54 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)12 Client (io.jans.as.common.model.registration.Client)11 Date (java.util.Date)11 SessionId (io.jans.as.server.model.common.SessionId)9 Scope (io.jans.as.persistence.model.Scope)8 ArrayList (java.util.ArrayList)8 SimpleUser (io.jans.as.common.model.common.SimpleUser)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)5 Response (javax.ws.rs.core.Response)5 JsonWebResponse (io.jans.as.model.token.JsonWebResponse)4 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)4 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)3 CibaRequestCacheControl (io.jans.as.server.model.common.CibaRequestCacheControl)3 CustomAttribute (io.jans.orm.model.base.CustomAttribute)3