Search in sources :

Example 6 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserServiceTest method getCustomAttribute_existentAttribute_user.

@Test
private void getCustomAttribute_existentAttribute_user() {
    User user = spy(getBasicUser("123", "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);
    CustomObjectAttribute resultAttribute = userService.getCustomAttribute(user, "attribute1");
    assertNotNull(resultAttribute);
    assertEquals(resultAttribute.getName(), "attribute1");
    assertEquals(resultAttribute.getValue(), "value1");
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) Test(org.testng.annotations.Test)

Example 7 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserServiceTest method addUserAttributeByUserInum_existentAttributeNoValue_user.

@Test
private void addUserAttributeByUserInum_existentAttributeNoValue_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", "value3");
    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");
    assertTrue(resultUser.getCustomAttributes().get(1).getValues().size() == 2);
    assertEquals(resultUser.getCustomAttributes().get(1).getValues().get(0), "value2");
    assertEquals(resultUser.getCustomAttributes().get(1).getValues().get(1), "value3");
}
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 8 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserServiceTest method getCustomAttribute_noExistentAttribute_null.

@Test
private void getCustomAttribute_noExistentAttribute_null() {
    User user = spy(getBasicUser("123", "dn123"));
    user.setCustomAttributes(new ArrayList<>());
    CustomObjectAttribute resultAttribute = userService.getCustomAttribute(user, "attribute1");
    assertNull(resultAttribute);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) User(io.jans.as.common.model.common.User) Test(org.testng.annotations.Test)

Example 9 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute in project jans by JanssenProject.

the class UserServiceTest method removeUserAttribute_noExistentAttribute_null.

@Test
private void removeUserAttribute_noExistentAttribute_null() {
    String userId = "123";
    String baseDn = "dn123";
    User user = spy(getBasicUser("123", "dn123"));
    CustomObjectAttribute customAttribute1 = new CustomObjectAttribute("attribute1", "value1");
    user.setCustomAttributes(new ArrayList<>());
    user.getCustomAttributes().add(customAttribute1);
    when(dataSourceTypeService.isSpanner(anyString())).thenReturn(true);
    when(persistenceEntryManager.findEntries(anyString(), any(), any(), any())).thenReturn(getListBasicOneUser(userId, baseDn));
    User resultUser = userService.removeUserAttributeValue(userId, "attribute2", "value2");
    assertNull(resultUser);
}
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 10 with CustomObjectAttribute

use of io.jans.orm.model.base.CustomObjectAttribute 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)

Aggregations

CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)32 User (io.jans.as.common.model.common.User)12 Filter (io.jans.orm.search.filter.Filter)9 Test (org.testng.annotations.Test)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SimpleUser (io.jans.orm.cloud.spanner.model.SimpleUser)4 SimpleUser (io.jans.orm.sql.model.SimpleUser)4 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)3 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)3 CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)3 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)3 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)3 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)3 SimpleUser (io.jans.as.common.model.common.SimpleUser)1 GluuAttribute (io.jans.model.GluuAttribute)1 SimpleAttribute (io.jans.orm.cloud.spanner.model.SimpleAttribute)1 SimpleGrant (io.jans.orm.cloud.spanner.model.SimpleGrant)1 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)1