Coverage Report - pt.digitalis.dif.utils.identity.tests.AbstractIdentityManagerImplTest
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractIdentityManagerImplTest
0%
0/623
0%
0/106
3,348
AbstractIdentityManagerImplTest$1
0%
0/6
N/A
3,348
 
 1  0
 /**
 2  
  * 2007, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
 3  
  * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
 4  
  */
 5  
 
 6  
 package pt.digitalis.dif.utils.identity.tests;
 7  
 
 8  
 import java.util.ArrayList;
 9  
 import java.util.HashMap;
 10  
 import java.util.List;
 11  
 import java.util.Map;
 12  
 import java.util.Set;
 13  
 
 14  
 import junit.framework.TestCase;
 15  
 import pt.digitalis.dif.controller.security.managers.IIdentityManager;
 16  
 import pt.digitalis.dif.controller.security.managers.impl.IdentityManagerStaticImpl;
 17  
 import pt.digitalis.dif.controller.security.objects.DIFGroupImpl;
 18  
 import pt.digitalis.dif.controller.security.objects.DIFUserImpl;
 19  
 import pt.digitalis.dif.controller.security.objects.IDIFGroup;
 20  
 import pt.digitalis.dif.controller.security.objects.IDIFUser;
 21  
 import pt.digitalis.dif.exception.InternalFrameworkException;
 22  
 import pt.digitalis.dif.exception.security.IdentityManagerException;
 23  
 import pt.digitalis.dif.ioc.DIFIoCRegistry;
 24  
 import pt.digitalis.dif.utils.Pagination;
 25  
 
 26  
 /**
 27  
  * Defines unit tests for the identity manager implementation.
 28  
  * 
 29  
  * @author Luis Pinto <a href="mailto:lpinto@digitalis.pt">lpinto@digitalis.pt</a><br/>
 30  
  * @created 2012/10/30
 31  
  */
 32  0
 public abstract class AbstractIdentityManagerImplTest extends TestCase {
 33  
 
 34  
     /** A bulk parameter name. */
 35  
     final static protected String A_BULK_ATTRIBUTE_NAME = "aBulkAttributeName";
 36  
 
 37  
     /** A bulk parameter value. */
 38  
     final static protected String A_BULK_ATTRIBUTE_VALUE = "aBulkAttributeValue";
 39  
 
 40  
     /** A changed attribute value. */
 41  
     final static protected String A_CHANGED_ATTRIBUTE_VALUE = "aChangedAttributeValue";
 42  
 
 43  
     /** A changed bulk parameter value. */
 44  
     final static protected String A_CHANGED_BULK_ATTRIBUTE_VALUE = "aChangedBulkAttributeValue";
 45  
 
 46  
     /** An attribute name. */
 47  
     final static protected String AN_ATTRIBUTE_NAME = "anAttributeName";
 48  
 
 49  
     /** An attribute value. */
 50  
     final static protected String AN_ATTRIBUTE_VALUE = "anAttributeValue";
 51  
 
 52  
     /** Another attribute name. */
 53  
     final static protected String ANOTHER_ATTRIBUTE_NAME = "anotherAttributeName";
 54  
 
 55  
     /** Another parameter value. */
 56  
     final static protected String ANOTHER_ATTRIBUTE_VALUE = "anotherAttributeValue";
 57  
 
 58  
     /** Another bulk parameter name. */
 59  
     final static protected String ANOTHER_BULK_ATTRIBUTE_NAME = "anotherBulkAttributeName";
 60  
 
 61  
     /** Another bulk parameter value. */
 62  
     final static protected String ANOTHER_BULK_ATTRIBUTE_VALUE = "anotherBulkAttributeValue";
 63  
 
 64  
     /** Another changed parameter value. */
 65  
     final static protected String ANOTHER_CHANGED_ATTRIBUTE_VALUE = "anotherChangedAttributeValue";
 66  
 
 67  
     /** Another changed bulk parameter value. */
 68  
     final static protected String ANOTHER_CHANGED_BULK_PARAMETER_VALUE = "anotherChangedBulkAttributeValue";
 69  
 
 70  
     /** The new user ID. */
 71  
     final static private String ATTRIBUTE_KEY = "key";
 72  
 
 73  
     /**  */
 74  
     final static private String ATTRIBUTE_VALUE = "some attribute value";
 75  
 
 76  
     /** A bad group ID. */
 77  
     final static private String BAD_GROUP = "badGroup";
 78  
 
 79  
     /** A bad password. */
 80  
     final static private String BAD_PASS = "badPass";
 81  
 
 82  
     /** A bad username. */
 83  
     final static private String BAD_USER = "badUser";
 84  
 
 85  
     /** Changed group description. */
 86  
     final static private String CHANGED_DESC = "changedGroupDesc";
 87  
 
 88  
     /** Changed group name. */
 89  
     final static private String CHANGED_GROUP_NAME = "newGroup";
 90  
 
 91  
     /** The changed mail. */
 92  
     final static private String CHANGED_MAIL = "changed@mail.pt";
 93  
 
 94  
     /** Changed group name. */
 95  
     final static private String CHANGED_PARENT_GROUP_NAME = "childGroup";
 96  
 
 97  
     /** A changed password. */
 98  
     final static private String CHANGED_PASS = "changedPass";
 99  
 
 100  
     /** Changed attributes value. */
 101  
     final static private String CHANGED_USER = "changedUser";
 102  
 
 103  
     /** A child group ID. */
 104  
     final static private String CHILD_GROUP_1_ID = "childGroup1ID";
 105  
 
 106  
     /** Another child group ID. */
 107  
     final static private String CHILD_GROUP_2_ID = "childGroup2ID";
 108  
 
 109  
     /** Group description. */
 110  
     final static private String DESC = "aGroupDesc";
 111  
 
 112  
     /** A parent group ID. */
 113  
     final static private String GRAND_PARENT_GROUP_ID = "grandParentGroupID";
 114  
 
 115  
     /** The 'N/A' String literal. */
 116  
     final static public String N_A = "N/A";
 117  
 
 118  
     /** New group name. */
 119  
     final static private String NEW_GROUP_NAME = "newGroup";
 120  
 
 121  
     /** The new user ID. */
 122  
     final static private String NEW_USER = "newUser";
 123  
 
 124  
     /** A parent group ID. */
 125  
     final static private String PARENT_GROUP_ID = "parentGroupID";
 126  
 
 127  
     /** The user mail. */
 128  
     final static private String USER_MAIL = "user@mail.pt";
 129  
 
 130  
     /** The user password. */
 131  
     final static private String USER_PASS = "passwd";
 132  
 
 133  
     /** The test object. */
 134  0
     protected IIdentityManager identityManagerImpl = null;
 135  
 
 136  
     /** Main group name. */
 137  0
     protected String MAIN_GROUP_NAME = "mainGroup";
 138  
 
 139  
     /** Test group 1. */
 140  0
     private String TEST_GRP_1_ID = "testGroup1";
 141  
 
 142  
     /** Test group 2. */
 143  0
     private String TEST_GRP_2_ID = "testGroup2";
 144  
 
 145  
     /** Test group 3. */
 146  0
     private String TEST_GRP_3_ID = "testGroup3";
 147  
 
 148  
     /** Test user 1. */
 149  0
     private String TEST_USER_1_ID = "testUser1";
 150  
 
 151  
     /** Test user 2. */
 152  0
     private String TEST_USER_2_ID = "testUser2";
 153  
 
 154  
     /** Test user 3. */
 155  0
     private String TEST_USER_3_ID = "testUser3";
 156  
 
 157  
     /**
 158  
      * Creates a group and adds it to the identity manager.
 159  
      * 
 160  
      * @throws IdentityManagerException
 161  
      *             if the user can't be created
 162  
      */
 163  
     protected void createGroup() throws IdentityManagerException
 164  
     {
 165  0
         createGroup(null);
 166  0
     }
 167  
 
 168  
     /**
 169  
      * Creates a group and adds it to the identity manager.
 170  
      * 
 171  
      * @param groupName
 172  
      * @throws IdentityManagerException
 173  
      *             if the user can't be created
 174  
      */
 175  
     protected void createGroup(String groupName) throws IdentityManagerException
 176  
     {
 177  0
         createGroup(groupName, MAIN_GROUP_NAME);
 178  0
     }
 179  
 
 180  
     /**
 181  
      * Creates a group and adds it to the identity manager.
 182  
      * 
 183  
      * @param groupName
 184  
      *            the group name
 185  
      * @param parentGroup
 186  
      *            the group parent group
 187  
      * @throws IdentityManagerException
 188  
      *             if the user can't be created
 189  
      */
 190  
     protected void createGroup(String groupName, String parentGroup) throws IdentityManagerException
 191  
     {
 192  0
         String finalGroupName = groupName;
 193  0
         if (finalGroupName == null || "".equals(finalGroupName))
 194  
         {
 195  0
             finalGroupName = NEW_GROUP_NAME;
 196  
         }
 197  
 
 198  
         // Create group for addition
 199  0
         IDIFGroup transferGroup = new DIFGroupImpl();
 200  0
         transferGroup.setID(finalGroupName);
 201  0
         transferGroup.setName(finalGroupName);
 202  0
         transferGroup.setDescription(DESC);
 203  0
         if (!finalGroupName.equals(parentGroup))
 204  
         {
 205  0
             transferGroup.setParentGroupID(parentGroup);
 206  
 
 207  0
             if (!identityManagerImpl.groupExists(parentGroup))
 208  
             {
 209  0
                 createGroup(parentGroup);
 210  
             }
 211  
         }
 212  
 
 213  
         // Add group if it doesn't exist and verify it's existence
 214  0
         if (identityManagerImpl.groupExists(finalGroupName))
 215  
         {
 216  0
             removeGroup(finalGroupName);
 217  0
             assertFalse(identityManagerImpl.groupExists(finalGroupName));
 218  
         }
 219  0
         identityManagerImpl.addGroup(transferGroup);
 220  0
         assertTrue(identityManagerImpl.groupExists(finalGroupName));
 221  0
     }
 222  
 
 223  
     /**
 224  
      * Creates a user and adds it to the identity manager.
 225  
      * 
 226  
      * @throws IdentityManagerException
 227  
      *             if the user can't be created
 228  
      * @throws InternalFrameworkException
 229  
      */
 230  
     protected void createUser() throws IdentityManagerException, InternalFrameworkException
 231  
     {
 232  0
         this.createUser(NEW_USER);
 233  0
     }
 234  
 
 235  
     /**
 236  
      * Creates a user and adds it to the identity manager.
 237  
      * 
 238  
      * @param userID
 239  
      *            the user ID
 240  
      * @throws IdentityManagerException
 241  
      *             if the user can't be created
 242  
      * @throws InternalFrameworkException
 243  
      */
 244  
     protected void createUser(String userID) throws IdentityManagerException, InternalFrameworkException
 245  
     {
 246  
         // Create user for addition
 247  0
         IDIFUser newUser = new DIFUserImpl();
 248  0
         newUser.setID(userID);
 249  0
         newUser.setName(userID);
 250  0
         newUser.setNick(userID);
 251  0
         newUser.setEmail(USER_MAIL);
 252  0
         newUser.setPassword(USER_PASS);
 253  0
         newUser.setProfileID(MAIN_GROUP_NAME);
 254  
 
 255  0
         if (!identityManagerImpl.groupExists(MAIN_GROUP_NAME))
 256  
         {
 257  0
             createGroup(MAIN_GROUP_NAME);
 258  
         }
 259  
 
 260  
         // Add user if it doesn't exist and verify it's existence
 261  0
         if (identityManagerImpl.userExists(userID))
 262  
         {
 263  0
             identityManagerImpl.removeUser(userID);
 264  
         }
 265  
 
 266  0
         assertFalse(identityManagerImpl.userExists(userID));
 267  
 
 268  0
         identityManagerImpl.addUser(newUser);
 269  0
         newUser.setAttribute(ATTRIBUTE_KEY, ATTRIBUTE_VALUE);
 270  
 
 271  0
         assertTrue(identityManagerImpl.userExists(userID));
 272  0
     }
 273  
 
 274  
     /**
 275  
      * Removes the group NEW_GROUP_NAME from the identity manager.
 276  
      * 
 277  
      * @throws IdentityManagerException
 278  
      *             if the user can't be created
 279  
      */
 280  
     protected void removeGroup() throws IdentityManagerException
 281  
     {
 282  
 
 283  0
         removeGroup(NEW_GROUP_NAME);
 284  0
     }
 285  
 
 286  
     /**
 287  
      * Removes a group from the identity manager.
 288  
      * 
 289  
      * @param groupId
 290  
      *            the group ID to remove
 291  
      * @throws IdentityManagerException
 292  
      */
 293  
     protected void removeGroup(String groupId) throws IdentityManagerException
 294  
     {
 295  0
         for (String groupID: identityManagerImpl.getGroupGroups(groupId).keySet())
 296  
         {
 297  0
             removeGroup(groupID);
 298  
         }
 299  
 
 300  
         // Remove group and assure it's been removed
 301  0
         if (identityManagerImpl.groupExists(groupId))
 302  
         {
 303  
             // First remove any pending test users
 304  0
             for (String userID: identityManagerImpl.getGroup(groupId).getUserIDs())
 305  0
                 identityManagerImpl.removeUser(userID);
 306  
 
 307  0
             identityManagerImpl.removeGroup(groupId);
 308  
         }
 309  0
         assertFalse(identityManagerImpl.groupExists(groupId));
 310  0
     }
 311  
 
 312  
     /**
 313  
      * Removes a user from the identity manager.
 314  
      * 
 315  
      * @param userId
 316  
      *            the id of the user to remove
 317  
      * @throws IdentityManagerException
 318  
      *             if the user can't be created
 319  
      */
 320  
     protected void removeUser(String userId) throws IdentityManagerException
 321  
     {
 322  
         // Remove user and assure it's been removed
 323  0
         identityManagerImpl.removeUser(userId);
 324  0
         assertFalse(identityManagerImpl.userExists(userId));
 325  0
     }
 326  
 
 327  
     /**
 328  
      * @see junit.framework.TestCase#setUp()
 329  
      */
 330  
     @Override
 331  
     protected void setUp() throws Exception
 332  
     {
 333  0
         System.out.print(".");
 334  0
         super.setUp();
 335  0
     }
 336  
 
 337  
     /**
 338  
      * @see junit.framework.TestCase#tearDown()
 339  
      */
 340  
     @Override
 341  
     public void tearDown()
 342  
     {
 343  0
         System.out.println(".");
 344  
         try
 345  
         {
 346  0
             if (identityManagerImpl.userExists(NEW_USER))
 347  0
                 removeUser(NEW_USER);
 348  0
             if (identityManagerImpl.userExists(CHANGED_USER))
 349  0
                 removeUser(CHANGED_USER);
 350  0
             if (identityManagerImpl.userExists(TEST_USER_1_ID))
 351  0
                 removeUser(TEST_USER_1_ID);
 352  0
             if (identityManagerImpl.userExists(TEST_USER_2_ID))
 353  0
                 removeUser(TEST_USER_2_ID);
 354  0
             if (identityManagerImpl.userExists(TEST_USER_3_ID))
 355  0
                 removeUser(TEST_USER_3_ID);
 356  
             /*
 357  
              * if (identityManagerImpl.groupExists(NEW_GROUP_NAME)) identityManagerImpl.removeGroup(NEW_GROUP_NAME); if
 358  
              * (identityManagerImpl.groupExists(TEST_GRP_1_ID)) identityManagerImpl.removeGroup(TEST_GRP_1_ID); if
 359  
              * (identityManagerImpl.groupExists(TEST_GRP_2_ID)) identityManagerImpl.removeGroup(TEST_GRP_2_ID); if
 360  
              * (identityManagerImpl.groupExists(TEST_GRP_3_ID)) identityManagerImpl.removeGroup(TEST_GRP_3_ID); if
 361  
              * (identityManagerImpl.groupExists(PARENT_GROUP_ID)) identityManagerImpl.removeGroup(PARENT_GROUP_ID); if
 362  
              * (identityManagerImpl.groupExists(CHILD_GROUP_1_ID)) identityManagerImpl.removeGroup(CHILD_GROUP_1_ID); if
 363  
              * (identityManagerImpl.groupExists(CHILD_GROUP_2_ID)) identityManagerImpl.removeGroup(CHILD_GROUP_2_ID); if
 364  
              * (identityManagerImpl.groupExists(CHANGED_PARENT_GROUP_NAME))
 365  
              * identityManagerImpl.removeGroup(CHANGED_PARENT_GROUP_NAME);
 366  
              */
 367  
 
 368  0
             if (identityManagerImpl.groupExists(MAIN_GROUP_NAME))
 369  0
                 removeGroup(MAIN_GROUP_NAME);
 370  
 
 371  
         }
 372  0
         catch (IdentityManagerException identityManagerException)
 373  
         {
 374  0
             identityManagerException.printStackTrace();
 375  
         }
 376  
 
 377  0
         identityManagerImpl.resetIdentityManager();
 378  0
         identityManagerImpl = null;
 379  0
     }
 380  
 
 381  
     /**
 382  
      * Tests if the obtainance of all groups in the system work correctly
 383  
      * 
 384  
      * @throws IdentityManagerException
 385  
      */
 386  
     public void testFindAllGroups() throws IdentityManagerException
 387  
     {
 388  0
         IDIFGroup group1 = DIFIoCRegistry.getRegistry().getImplementation(IDIFGroup.class);
 389  0
         IDIFGroup group2 = DIFIoCRegistry.getRegistry().getImplementation(IDIFGroup.class);
 390  0
         IDIFGroup group3 = DIFIoCRegistry.getRegistry().getImplementation(IDIFGroup.class);
 391  
 
 392  0
         int numElements = identityManagerImpl.getAllGroups().size();
 393  
 
 394  0
         assertEquals(numElements, identityManagerImpl.countAllGroups());
 395  
 
 396  0
         group1.setID(TEST_GRP_1_ID);
 397  0
         if (identityManagerImpl.getGroup(TEST_GRP_1_ID) == null)
 398  
         {
 399  0
             identityManagerImpl.addGroup(group1);
 400  0
             numElements++;
 401  
         }
 402  
 
 403  0
         group2.setID(TEST_GRP_2_ID);
 404  0
         if (identityManagerImpl.getGroup(TEST_GRP_2_ID) == null)
 405  
         {
 406  0
             identityManagerImpl.addGroup(group2);
 407  0
             numElements++;
 408  
         }
 409  
 
 410  0
         group3.setID(TEST_GRP_3_ID);
 411  0
         if (identityManagerImpl.getGroup(TEST_GRP_3_ID) == null)
 412  
         {
 413  0
             identityManagerImpl.addGroup(group3);
 414  0
             numElements++;
 415  
         }
 416  
 
 417  0
         Set<IDIFGroup> allGroups = identityManagerImpl.getAllGroups();
 418  
 
 419  0
         assertTrue(allGroups.contains(group1));
 420  0
         assertTrue(allGroups.contains(group2));
 421  0
         assertTrue(allGroups.contains(group3));
 422  0
         assertEquals(allGroups.size(), numElements);
 423  
 
 424  
         // TODO: Waiting for Pagination bug resolution
 425  
         // Pagination pagination = new Pagination(1, numElements);
 426  
         // assertEquals(identityManagerImpl.getGroups(pagination).size(), numElements);
 427  
 
 428  
         // TODO: Waiting for Pagination bug resolution
 429  
         // pagination = new Pagination(1, 2);
 430  
         // assertEquals(identityManagerImpl.getGroups(pagination).size(), 2);
 431  
 
 432  
         // TODO: Waiting for Pagination bug resolution
 433  
         // for (int i = 1; i <= numElements; i++)
 434  
         // {
 435  
         // pagination = new Pagination(i, 1);
 436  
         // assertEquals(identityManagerImpl.getGroups(pagination).size(), 1);
 437  
         // }
 438  
 
 439  0
         identityManagerImpl.removeGroup(TEST_GRP_1_ID);
 440  0
         numElements--;
 441  0
         identityManagerImpl.removeGroup(TEST_GRP_2_ID);
 442  0
         numElements--;
 443  0
         identityManagerImpl.removeGroup(TEST_GRP_3_ID);
 444  0
         numElements--;
 445  
 
 446  0
         assertFalse(identityManagerImpl.getAllGroups().contains(group1));
 447  0
         assertFalse(identityManagerImpl.getAllGroups().contains(group2));
 448  0
         assertFalse(identityManagerImpl.getAllGroups().contains(group3));
 449  0
         assertEquals(identityManagerImpl.getAllGroups().size(), numElements);
 450  0
     }
 451  
 
 452  
     /**
 453  
      * Tests if the obtainance of all users in the system work correctly
 454  
      * 
 455  
      * @throws IdentityManagerException
 456  
      */
 457  
     public void testFindllUsers() throws IdentityManagerException
 458  
     {
 459  0
         createGroup(MAIN_GROUP_NAME);
 460  
 
 461  0
         IDIFUser testUser1 = new DIFUserImpl();
 462  0
         testUser1.setID(TEST_USER_1_ID);
 463  0
         testUser1.setName(TEST_USER_1_ID);
 464  0
         testUser1.setNick(TEST_USER_1_ID);
 465  0
         testUser1.setEmail(USER_MAIL);
 466  0
         testUser1.setPassword(USER_PASS);
 467  0
         testUser1.setProfileID(MAIN_GROUP_NAME);
 468  
 
 469  0
         IDIFUser testUser2 = new DIFUserImpl();
 470  0
         testUser2.setID(TEST_USER_2_ID);
 471  0
         testUser2.setName(TEST_USER_2_ID);
 472  0
         testUser2.setNick(TEST_USER_2_ID);
 473  0
         testUser2.setEmail(USER_MAIL);
 474  0
         testUser2.setPassword(USER_PASS);
 475  0
         testUser2.setProfileID(MAIN_GROUP_NAME);
 476  
 
 477  0
         IDIFUser testUser3 = new DIFUserImpl();
 478  0
         testUser3.setID(TEST_USER_3_ID);
 479  0
         testUser3.setName(TEST_USER_3_ID);
 480  0
         testUser3.setNick(TEST_USER_3_ID);
 481  0
         testUser3.setEmail(USER_MAIL);
 482  0
         testUser3.setPassword(USER_PASS);
 483  0
         testUser3.setProfileID(MAIN_GROUP_NAME);
 484  
 
 485  0
         int numElements = identityManagerImpl.getAllUsers().size();
 486  
 
 487  0
         assertEquals(numElements, identityManagerImpl.countAllUsers());
 488  
 
 489  0
         identityManagerImpl.addUser(testUser1);
 490  0
         identityManagerImpl.addUser(testUser2);
 491  0
         identityManagerImpl.addUser(testUser3);
 492  
 
 493  0
         numElements += 3;
 494  
 
 495  0
         assertTrue(identityManagerImpl.getAllUsers().contains(testUser1));
 496  0
         assertTrue(identityManagerImpl.getAllUsers().contains(testUser2));
 497  0
         assertTrue(identityManagerImpl.getAllUsers().contains(testUser3));
 498  0
         assertEquals(identityManagerImpl.getAllUsers().size(), numElements);
 499  
 
 500  
         // TODO: Waiting for Pagination bug resolution
 501  
         // Pagination pagination = new Pagination(1, numElements);
 502  
         // assertEquals(identityManagerImpl.getUsers(pagination).size(), numElements);
 503  
 
 504  
         // TODO: Waiting for Pagination bug resolution
 505  
         // for (int i = 1; i <= numElements; i++)
 506  
         // {
 507  
         // pagination = new Pagination(i, 1);
 508  
         // assertEquals(identityManagerImpl.getUsers(pagination).size(), 1);
 509  
         // }
 510  
 
 511  0
         identityManagerImpl.removeUser(TEST_USER_1_ID);
 512  0
         identityManagerImpl.removeUser(TEST_USER_2_ID);
 513  0
         identityManagerImpl.removeUser(TEST_USER_3_ID);
 514  
 
 515  0
         numElements -= 3;
 516  
 
 517  0
         assertFalse(identityManagerImpl.getAllUsers().contains(testUser1));
 518  0
         assertFalse(identityManagerImpl.getAllUsers().contains(testUser2));
 519  0
         assertFalse(identityManagerImpl.getAllUsers().contains(testUser3));
 520  0
         assertEquals(identityManagerImpl.getAllUsers().size(), numElements);
 521  
 
 522  0
     }
 523  
 
 524  
     /**
 525  
      * Test the find user groups methods
 526  
      */
 527  
     public void testFindUserGroups()
 528  
     {
 529  0
         final String GROUP1 = "testFindUserGroupsGroup1";
 530  0
         final String GROUP2 = "testFindUserGroupsGroup2";
 531  0
         final String GROUP3 = "testFindUserGroupsGroup3";
 532  
         try
 533  
         {
 534  0
             createUser();
 535  
 
 536  0
             createGroup(GRAND_PARENT_GROUP_ID);
 537  0
             createGroup(PARENT_GROUP_ID, GRAND_PARENT_GROUP_ID);
 538  
 
 539  0
             createGroup(GROUP1);
 540  0
             createGroup(GROUP2);
 541  0
             createGroup(GROUP3, PARENT_GROUP_ID);
 542  
 
 543  0
             identityManagerImpl.addUserToGroup(NEW_USER, GROUP1);
 544  0
             identityManagerImpl.addUserToGroup(NEW_USER, GROUP2);
 545  0
             identityManagerImpl.addUserToGroup(NEW_USER, GROUP3);
 546  
 
 547  0
             int totalGroups = identityManagerImpl.countAllGroupsOfUser(NEW_USER);
 548  0
             assertEquals(totalGroups, 4);
 549  
 
 550  0
             totalGroups = identityManagerImpl.countAllGroupsOfUser(NEW_USER, true);
 551  0
             assertEquals(totalGroups, 6);
 552  
 
 553  0
             totalGroups = identityManagerImpl.countAllGroupsOfUser(NEW_USER, false);
 554  0
             assertEquals(totalGroups, 4);
 555  
 
 556  0
             Set<String> groupIDs = identityManagerImpl.getUserGroupsIDs(NEW_USER);
 557  0
             assertEquals(groupIDs.size(), 4);
 558  0
             assertTrue(groupIDs.contains(GROUP1));
 559  0
             assertTrue(groupIDs.contains(GROUP2));
 560  0
             assertTrue(groupIDs.contains(GROUP3));
 561  0
             assertFalse(groupIDs.contains(PARENT_GROUP_ID));
 562  0
             assertFalse(groupIDs.contains(GRAND_PARENT_GROUP_ID));
 563  0
             assertTrue(groupIDs.contains(MAIN_GROUP_NAME));
 564  
 
 565  0
             groupIDs = identityManagerImpl.getUserGroupsIDs(NEW_USER, true);
 566  0
             assertEquals(groupIDs.size(), 6);
 567  0
             assertTrue(groupIDs.contains(GROUP1));
 568  0
             assertTrue(groupIDs.contains(GROUP2));
 569  0
             assertTrue(groupIDs.contains(GROUP3));
 570  0
             assertTrue(groupIDs.contains(PARENT_GROUP_ID));
 571  0
             assertTrue(groupIDs.contains(GRAND_PARENT_GROUP_ID));
 572  0
             assertTrue(groupIDs.contains(MAIN_GROUP_NAME));
 573  
 
 574  0
             groupIDs = identityManagerImpl.getUserGroupsIDs(NEW_USER, false);
 575  0
             assertEquals(groupIDs.size(), 4);
 576  0
             assertTrue(groupIDs.contains(GROUP1));
 577  0
             assertTrue(groupIDs.contains(GROUP2));
 578  0
             assertTrue(groupIDs.contains(GROUP3));
 579  0
             assertFalse(groupIDs.contains(PARENT_GROUP_ID));
 580  0
             assertFalse(groupIDs.contains(GRAND_PARENT_GROUP_ID));
 581  0
             assertTrue(groupIDs.contains(MAIN_GROUP_NAME));
 582  
 
 583  0
             Map<String, IDIFGroup> groups = identityManagerImpl.getUserGroups(NEW_USER);
 584  0
             assertEquals(groups.size(), 4);
 585  0
             assertTrue(groups.containsKey(GROUP1));
 586  0
             assertTrue(groups.containsKey(GROUP2));
 587  0
             assertTrue(groups.containsKey(GROUP3));
 588  0
             assertFalse(groups.containsKey(PARENT_GROUP_ID));
 589  0
             assertFalse(groups.containsKey(GRAND_PARENT_GROUP_ID));
 590  0
             assertTrue(groups.containsKey(MAIN_GROUP_NAME));
 591  
 
 592  0
             groups = identityManagerImpl.getUserGroups(NEW_USER, true);
 593  0
             assertEquals(groups.size(), 6);
 594  0
             assertTrue(groups.containsKey(GROUP1));
 595  0
             assertTrue(groups.containsKey(GROUP2));
 596  0
             assertTrue(groups.containsKey(GROUP3));
 597  0
             assertTrue(groups.containsKey(PARENT_GROUP_ID));
 598  0
             assertTrue(groups.containsKey(GRAND_PARENT_GROUP_ID));
 599  0
             assertTrue(groups.containsKey(MAIN_GROUP_NAME));
 600  
 
 601  0
             groups = identityManagerImpl.getUserGroups(NEW_USER, false);
 602  0
             assertEquals(groups.size(), 4);
 603  0
             assertTrue(groups.containsKey(GROUP1));
 604  0
             assertTrue(groups.containsKey(GROUP2));
 605  0
             assertTrue(groups.containsKey(GROUP3));
 606  0
             assertFalse(groups.containsKey(PARENT_GROUP_ID));
 607  0
             assertFalse(groups.containsKey(GRAND_PARENT_GROUP_ID));
 608  0
             assertTrue(groups.containsKey(MAIN_GROUP_NAME));
 609  
 
 610  0
             List<String> groupList = new ArrayList<String>();
 611  
 
 612  0
             Pagination page = new Pagination(1, 2);
 613  0
             groups = identityManagerImpl.getUserGroupsPagination(NEW_USER, page);
 614  0
             assertEquals(groups.size(), 2);
 615  0
             groupList.addAll(groups.keySet());
 616  
 
 617  0
             page = new Pagination(2, 2);
 618  0
             assertEquals(page.getEndRow(), 4);
 619  0
             assertEquals(page.getPage(), 2);
 620  
 
 621  0
             groups = identityManagerImpl.getUserGroupsPagination(NEW_USER, page);
 622  
 
 623  
             // Only one group exists because the getUserGroupsPagination doesn't consider the profile as a group
 624  0
             assertEquals(groups.size(), 1);
 625  0
             groupList.addAll(groups.keySet());
 626  
 
 627  0
             assertEquals(groupList.size(), 3);
 628  0
             assertTrue(groupList.contains(GROUP1));
 629  0
             assertTrue(groupList.contains(GROUP2));
 630  0
             assertTrue(groupList.contains(GROUP3));
 631  0
             assertFalse(groupList.contains(MAIN_GROUP_NAME));
 632  0
             assertFalse(groupList.contains(PARENT_GROUP_ID));
 633  
 
 634  0
             assertEquals(identityManagerImpl.countAllUsers(GROUP1), 1);
 635  0
             assertEquals(identityManagerImpl.countAllUsers(GROUP2), 1);
 636  0
             assertEquals(identityManagerImpl.countAllUsers(GROUP3), 1);
 637  0
             assertEquals(identityManagerImpl.countAllUsers(MAIN_GROUP_NAME), 0);
 638  0
             assertEquals(identityManagerImpl.countAllUsers(PARENT_GROUP_ID), 0);
 639  
         }
 640  0
         catch (IdentityManagerException e)
 641  
         {
 642  0
             e.printStackTrace();
 643  0
             assertFalse(true);
 644  
         }
 645  0
         catch (InternalFrameworkException e)
 646  
         {
 647  0
             e.printStackTrace();
 648  0
             assertFalse(true);
 649  
         }
 650  0
     }
 651  
 
 652  
     /**
 653  
      * Tests searching for groups with a given parent.
 654  
      * 
 655  
      * @throws IdentityManagerException
 656  
      *             if the identity manager can't be accessed
 657  
      */
 658  
     public void testGroupGroups() throws IdentityManagerException
 659  
     {
 660  0
         createGroup(GRAND_PARENT_GROUP_ID);
 661  0
         createGroup(PARENT_GROUP_ID, GRAND_PARENT_GROUP_ID);
 662  0
         createGroup(CHILD_GROUP_1_ID, PARENT_GROUP_ID);
 663  0
         createGroup(CHILD_GROUP_2_ID, PARENT_GROUP_ID);
 664  
 
 665  0
         assertTrue(identityManagerImpl.groupExists(PARENT_GROUP_ID));
 666  0
         assertTrue(identityManagerImpl.groupExists(CHILD_GROUP_1_ID));
 667  0
         assertTrue(identityManagerImpl.groupExists(CHILD_GROUP_2_ID));
 668  
 
 669  0
         Map<String, IDIFGroup> groupGroups = identityManagerImpl.getGroupGroups(GRAND_PARENT_GROUP_ID);
 670  0
         assertNotNull(groupGroups);
 671  0
         assertEquals(groupGroups.size(), 3);
 672  0
         assertFalse(groupGroups.containsKey(GRAND_PARENT_GROUP_ID));
 673  0
         assertTrue(groupGroups.containsKey(PARENT_GROUP_ID));
 674  0
         assertTrue(groupGroups.containsKey(CHILD_GROUP_1_ID));
 675  0
         assertTrue(groupGroups.containsKey(CHILD_GROUP_2_ID));
 676  0
         assertEquals(groupGroups.get(CHILD_GROUP_1_ID).getParentGroupID(), PARENT_GROUP_ID);
 677  0
         assertEquals(groupGroups.get(CHILD_GROUP_2_ID).getParentGroupID(), PARENT_GROUP_ID);
 678  
 
 679  0
         identityManagerImpl.removeGroup(CHILD_GROUP_1_ID);
 680  0
         identityManagerImpl.removeGroup(CHILD_GROUP_2_ID);
 681  0
         identityManagerImpl.removeGroup(PARENT_GROUP_ID);
 682  0
         identityManagerImpl.removeGroup(GRAND_PARENT_GROUP_ID);
 683  
 
 684  0
         assertFalse(identityManagerImpl.groupExists(CHILD_GROUP_1_ID));
 685  0
         assertFalse(identityManagerImpl.groupExists(CHILD_GROUP_2_ID));
 686  0
         assertFalse(identityManagerImpl.groupExists(PARENT_GROUP_ID));
 687  0
         assertFalse(identityManagerImpl.groupExists(GRAND_PARENT_GROUP_ID));
 688  0
     }
 689  
 
 690  
     /**
 691  
      * Tests the group operations.
 692  
      */
 693  
     public void testGroupOperations()
 694  
     {
 695  
         try
 696  
         {
 697  0
             createGroup();
 698  
 
 699  
             // Test group integrity
 700  0
             IDIFGroup retrievedGroup = identityManagerImpl.getGroup(NEW_GROUP_NAME);
 701  0
             assertEquals(retrievedGroup.getID(), NEW_GROUP_NAME);
 702  0
             assertEquals(retrievedGroup.getName(), NEW_GROUP_NAME);
 703  0
             assertEquals(retrievedGroup.getDescription(), DESC);
 704  0
             assertTrue(retrievedGroup.getParentGroupID().contains(MAIN_GROUP_NAME));
 705  
 
 706  0
             createGroup(CHANGED_PARENT_GROUP_NAME);
 707  
 
 708  
             // Set group data for modification
 709  0
             IDIFGroup group = new DIFGroupImpl();
 710  0
             group.setID(CHANGED_GROUP_NAME);
 711  0
             group.setName(CHANGED_GROUP_NAME);
 712  0
             group.setDescription(CHANGED_DESC);
 713  0
             group.setParentGroupID(CHANGED_PARENT_GROUP_NAME);
 714  
 
 715  
             // Modify group data
 716  0
             identityManagerImpl.updateGroup(group);
 717  0
             assertTrue(identityManagerImpl.groupExists(NEW_GROUP_NAME));
 718  
 
 719  
             // Test group integrity
 720  0
             retrievedGroup = identityManagerImpl.getGroup(CHANGED_GROUP_NAME);
 721  0
             assertEquals(retrievedGroup.getID(), CHANGED_GROUP_NAME);
 722  0
             assertEquals(retrievedGroup.getName(), CHANGED_GROUP_NAME);
 723  0
             assertEquals(retrievedGroup.getDescription(), CHANGED_DESC);
 724  0
             assertTrue(retrievedGroup.getParentGroupID().contains(CHANGED_PARENT_GROUP_NAME));
 725  
 
 726  0
             removeGroup();
 727  
 
 728  
         }
 729  0
         catch (IdentityManagerException e)
 730  
         {
 731  0
             e.printStackTrace();
 732  
         }
 733  0
     }
 734  
 
 735  
     /**
 736  
      * Tests the group operations forcing failure behavior.
 737  
      * 
 738  
      * @throws IdentityManagerException
 739  
      *             if the identity manager can't be accessed
 740  
      */
 741  
     @SuppressWarnings("unused")
 742  
     public void testGroupOperationsInFailureBehaviour() throws IdentityManagerException
 743  
     {
 744  
         // Create group for addition
 745  0
         IDIFGroup transferGroup = new DIFGroupImpl();
 746  
 
 747  
         // Tries to group an user without id...must fail!!
 748  
         try
 749  
         {
 750  0
             identityManagerImpl.addGroup(transferGroup);
 751  
         }
 752  0
         catch (IdentityManagerException e)
 753  
         {
 754  
             // User must not have been added...
 755  0
             assertFalse(identityManagerImpl.groupExists(""));
 756  
         }
 757  
 
 758  
         // Try to fetch data for an inexistent group
 759  
         try
 760  
         {
 761  0
             IDIFGroup retrievedGroup = identityManagerImpl.getGroup(BAD_GROUP);
 762  
         }
 763  0
         catch (IdentityManagerException identityManagerException)
 764  
         {
 765  
         }
 766  
 
 767  
         // Tries to modify a bad group...must fail!!
 768  
         try
 769  
         {
 770  0
             identityManagerImpl.updateGroup(transferGroup);
 771  
         }
 772  0
         catch (IdentityManagerException e)
 773  
         {
 774  
             // User must not have been added...
 775  0
             assertFalse(identityManagerImpl.groupExists(BAD_GROUP));
 776  
         }
 777  
 
 778  
         // Tries to remove a bad user...must fail!!
 779  
         try
 780  
         {
 781  0
             identityManagerImpl.removeGroup(BAD_GROUP);
 782  
         }
 783  0
         catch (IdentityManagerException e)
 784  
         {
 785  
             // User must not exist
 786  0
             assertFalse(identityManagerImpl.groupExists(BAD_GROUP));
 787  
         }
 788  0
     }
 789  
 
 790  
     /**
 791  
      * Tests the illegal operations.
 792  
      * 
 793  
      * @throws InternalFrameworkException
 794  
      */
 795  
     public void testIllegalOperations() throws InternalFrameworkException
 796  
     {
 797  
 
 798  0
         IDIFGroup badGroup = null;
 799  0
         IDIFUser badUser = null;
 800  
 
 801  
         // Force exception throwing on addGroup
 802  
         try
 803  
         {
 804  0
             createGroup();
 805  0
             badGroup = new DIFGroupImpl();
 806  0
             badGroup.setID(NEW_GROUP_NAME);
 807  0
             identityManagerImpl.addGroup(badGroup);
 808  
         }
 809  0
         catch (IdentityManagerException e)
 810  
         {
 811  
         }
 812  
         finally
 813  0
         {
 814  
             try
 815  
             {
 816  0
                 removeGroup();
 817  
             }
 818  0
             catch (IdentityManagerException e1)
 819  
             {
 820  0
                 e1.printStackTrace();
 821  
             }
 822  0
         }
 823  
 
 824  
         // Force exception throwing on addUser
 825  
         try
 826  
         {
 827  0
             createUser();
 828  0
             badUser = new DIFUserImpl();
 829  0
             badUser.setID(NEW_USER);
 830  0
             identityManagerImpl.addUser(badUser);
 831  
         }
 832  0
         catch (IdentityManagerException e)
 833  
         {
 834  
         }
 835  
         finally
 836  0
         {
 837  
             try
 838  
             {
 839  0
                 removeUser(NEW_USER);
 840  
             }
 841  0
             catch (IdentityManagerException e1)
 842  
             {
 843  0
                 e1.printStackTrace();
 844  
             }
 845  0
         }
 846  
 
 847  
         // Receive null group
 848  
         try
 849  
         {
 850  0
             identityManagerImpl.getGroup(null);
 851  
         }
 852  0
         catch (IdentityManagerException e)
 853  
         {
 854  
         }
 855  
 
 856  
         // Force exception throwing on convertFromXXXUserToDIFUser
 857  
         try
 858  
         {
 859  0
             final String BAD_USER_ID = "BAD_USER";
 860  0
             identityManagerImpl.updateUserAttribute(BAD_USER_ID, AN_ATTRIBUTE_NAME, new Object());
 861  0
             assertTrue(false);
 862  
         }
 863  0
         catch (IdentityManagerException e)
 864  
         {
 865  0
             assertTrue(true);
 866  
         }
 867  
 
 868  0
     }
 869  
 
 870  
     /**
 871  
      * Tests the static Identity Manager Initialization
 872  
      */
 873  
     public void testInitialization()
 874  
     {
 875  
         // executions for increasing code coverage purpose
 876  0
         identityManagerImpl.getExclusionCharaters();
 877  0
         identityManagerImpl.getGroupAttributeName();
 878  0
         identityManagerImpl.gatherManagedAttributes();
 879  0
         assertFalse(identityManagerImpl.isReadOnly());
 880  
 
 881  0
         int managedAttributes = identityManagerImpl.getManagedAttributes().size();
 882  0
         identityManagerImpl.addManagedAttributes("dummy1,dummy2");
 883  0
         identityManagerImpl.addManagedAttribute("dummy3");
 884  0
         assertEquals(identityManagerImpl.getManagedAttributes().size(), managedAttributes + 3);
 885  
 
 886  
         // Only the static implementation have a initialization
 887  0
         if (identityManagerImpl instanceof IdentityManagerStaticImpl)
 888  
         {
 889  0
             ((IdentityManagerStaticImpl) identityManagerImpl).initializeStaticCustomUsers();
 890  
 
 891  
             try
 892  
             {
 893  0
                 IDIFUser user = identityManagerImpl.getUser("pedro");
 894  0
                 Map<String, IDIFGroup> groups = user.getGroups();
 895  0
                 assertTrue(groups.containsKey("alunos"));
 896  0
                 assertTrue(groups.containsKey("docentes"));
 897  0
                 assertEquals(user.getAttribute("cd_aluno"), "1");
 898  0
                 assertEquals(user.getAttribute("cd_curso"), "2");
 899  0
                 assertEquals(user.getAttribute("cd_docente"), "3");
 900  
 
 901  0
                 user = identityManagerImpl.getUser("viegas");
 902  0
                 groups = user.getGroups();
 903  0
                 assertTrue(groups.containsKey("alunos"));
 904  0
                 assertTrue(groups.containsKey("docentes"));
 905  0
                 assertEquals(user.getAttribute("cd_aluno"), "11");
 906  0
                 assertEquals(user.getAttribute("cd_curso"), "12");
 907  0
                 assertEquals(user.getAttribute("cd_docente"), "13");
 908  
 
 909  0
                 assertNotNull(identityManagerImpl.getGroup("alunos"));
 910  0
                 assertNotNull(identityManagerImpl.getGroup("candidatos"));
 911  
             }
 912  0
             catch (IdentityManagerException e)
 913  
             {
 914  0
                 e.printStackTrace();
 915  0
                 assertFalse(true);
 916  
             }
 917  
         }
 918  
 
 919  0
     }
 920  
 
 921  
     /**
 922  
      * Not available test condition
 923  
      * 
 924  
      * @throws IdentityManagerException
 925  
      */
 926  
     public void testNotAvailable() throws IdentityManagerException
 927  
     {
 928  0
         assertNull(identityManagerImpl.getGroup(N_A));
 929  0
     }
 930  
 
 931  
     /**
 932  
      * Tests the identity manager's relation operations.
 933  
      * 
 934  
      * @throws IdentityManagerException
 935  
      *             if the operation can't be executed
 936  
      * @throws InternalFrameworkException
 937  
      */
 938  
     public void testRelationOperations() throws IdentityManagerException, InternalFrameworkException
 939  
     {
 940  
 
 941  
         // Test settings
 942  0
         createUser();
 943  0
         createGroup(PARENT_GROUP_ID, GRAND_PARENT_GROUP_ID);
 944  0
         createGroup(NEW_GROUP_NAME, PARENT_GROUP_ID);
 945  
 
 946  
         // Add user to group
 947  0
         identityManagerImpl.addUserToGroup(NEW_USER, NEW_GROUP_NAME);
 948  0
         assertTrue(identityManagerImpl.isUserInGroup(NEW_USER, NEW_GROUP_NAME));
 949  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, PARENT_GROUP_ID));
 950  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, GRAND_PARENT_GROUP_ID));
 951  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, "InexistentGroupMustReturnFalse"));
 952  
 
 953  0
         assertTrue(identityManagerImpl.isUserInGroup(NEW_USER, NEW_GROUP_NAME, true));
 954  0
         assertTrue(identityManagerImpl.isUserInGroup(NEW_USER, PARENT_GROUP_ID, true));
 955  0
         assertTrue(identityManagerImpl.isUserInGroup(NEW_USER, GRAND_PARENT_GROUP_ID, true));
 956  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, "InexistentGroupMustReturnFalse", true));
 957  
 
 958  0
         assertTrue(identityManagerImpl.isUserInGroup(NEW_USER, NEW_GROUP_NAME, false));
 959  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, PARENT_GROUP_ID, false));
 960  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, GRAND_PARENT_GROUP_ID, false));
 961  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, "InexistentGroupMustReturnFalse", false));
 962  
 
 963  
         // Verify user is in group and group contains user
 964  0
         assertTrue(identityManagerImpl.getGroupUsers(NEW_GROUP_NAME).keySet().contains(NEW_USER));
 965  0
         assertTrue(identityManagerImpl.getUserIDsInGroup(NEW_GROUP_NAME).contains(NEW_USER));
 966  0
         assertTrue(identityManagerImpl.getUserGroups(NEW_USER).keySet().contains(NEW_GROUP_NAME));
 967  0
         assertTrue(identityManagerImpl.getUserGroupsIDs(NEW_USER).contains(NEW_GROUP_NAME));
 968  0
         assertFalse(identityManagerImpl.getUserGroups(NEW_USER).keySet().contains(PARENT_GROUP_ID));
 969  0
         assertFalse(identityManagerImpl.getUserGroupsIDs(NEW_USER).contains(PARENT_GROUP_ID));
 970  0
         assertFalse(identityManagerImpl.getUserGroups(NEW_USER).keySet().contains(GRAND_PARENT_GROUP_ID));
 971  0
         assertFalse(identityManagerImpl.getUserGroupsIDs(NEW_USER).contains(GRAND_PARENT_GROUP_ID));
 972  
 
 973  0
         assertTrue(identityManagerImpl.getUserGroups(NEW_USER, true).keySet().contains(PARENT_GROUP_ID));
 974  0
         assertTrue(identityManagerImpl.getUserGroupsIDs(NEW_USER, true).contains(PARENT_GROUP_ID));
 975  0
         assertTrue(identityManagerImpl.getUserGroups(NEW_USER, true).keySet().contains(GRAND_PARENT_GROUP_ID));
 976  0
         assertTrue(identityManagerImpl.getUserGroupsIDs(NEW_USER, true).contains(GRAND_PARENT_GROUP_ID));
 977  
 
 978  
         // Remove user from group
 979  0
         identityManagerImpl.removeUserFromGroup(NEW_USER, NEW_GROUP_NAME);
 980  0
         assertFalse(identityManagerImpl.isUserInGroup(NEW_USER, NEW_GROUP_NAME));
 981  
 
 982  
         // Clean test settings
 983  0
         removeUser(NEW_USER);
 984  0
         removeGroup();
 985  0
     }
 986  
 
 987  
     /**
 988  
      * Tests the finders by attributes
 989  
      * 
 990  
      * @throws InternalFrameworkException
 991  
      * @throws IdentityManagerException
 992  
      */
 993  
     public void testUserAttributes() throws IdentityManagerException, InternalFrameworkException
 994  
     {
 995  0
         Map<String, String> attribToSearch = new HashMap<String, String>();
 996  
 
 997  0
         createUser();
 998  
 
 999  0
         attribToSearch.put(identityManagerImpl.getMailAttributeName(), USER_MAIL);
 1000  0
         attribToSearch.put(identityManagerImpl.getUserLoginAttributeName(), NEW_USER);
 1001  0
         attribToSearch.put(identityManagerImpl.getNameAttributeName(), NEW_USER);
 1002  0
         attribToSearch.put(identityManagerImpl.getUserParentGroupAttributeName(), MAIN_GROUP_NAME);
 1003  0
         attribToSearch.put(ATTRIBUTE_KEY, ATTRIBUTE_VALUE);
 1004  0
         assertEquals(identityManagerImpl.getUsersByAttributes(attribToSearch).size(), 1);
 1005  0
         attribToSearch.clear();
 1006  
 
 1007  0
         attribToSearch.put(ATTRIBUTE_KEY, ATTRIBUTE_VALUE);
 1008  0
         int usersWithAttrib = identityManagerImpl.countUsers(attribToSearch);
 1009  
 
 1010  0
         createUser(TEST_USER_1_ID);
 1011  0
         createUser(TEST_USER_2_ID);
 1012  0
         createUser(TEST_USER_3_ID);
 1013  
 
 1014  0
         usersWithAttrib += 3;
 1015  
 
 1016  0
         assertEquals(identityManagerImpl.countUsers(attribToSearch), usersWithAttrib);
 1017  0
         assertEquals(identityManagerImpl.getUsersByAttribute(ATTRIBUTE_KEY, ATTRIBUTE_VALUE).size(), usersWithAttrib);
 1018  0
         assertEquals(identityManagerImpl.getUsersByAttributes(attribToSearch).size(), usersWithAttrib);
 1019  
 
 1020  0
         Pagination page = new Pagination(1, 4);
 1021  
         // TODO: Waiting for Pagination bug resolution
 1022  
         // assertEquals(identityManagerImpl.getUsersByAttributes(attribToSearch, page).size(), 4);
 1023  
 
 1024  0
         page = new Pagination(1, 2);
 1025  0
         assertEquals(identityManagerImpl.getUsersByAttributes(attribToSearch, page).size(), 2);
 1026  
 
 1027  0
         page = new Pagination(2, 2);
 1028  
         // TODO: Waiting for Pagination bug resolution
 1029  
         // assertEquals(identityManagerImpl.getUsersByAttributes(attribToSearch, page).size(), 2);
 1030  
 
 1031  
         // Test find user by email
 1032  0
         boolean userFound = false;
 1033  
 
 1034  0
         for (IDIFUser difUser: identityManagerImpl.getUsersByEmail(USER_MAIL))
 1035  0
             if (difUser.getID().equals(NEW_USER) && difUser.getEmail().equals(USER_MAIL))
 1036  
             {
 1037  0
                 userFound = true;
 1038  0
                 break;
 1039  
             }
 1040  
 
 1041  0
         assertTrue(userFound);
 1042  
 
 1043  
         // Test find user by attribute (key)
 1044  0
         userFound = false;
 1045  
 
 1046  0
         for (IDIFUser difUser: identityManagerImpl.getUsersByAttribute(ATTRIBUTE_KEY, ATTRIBUTE_VALUE))
 1047  0
             if (difUser.getID().equals(NEW_USER) && difUser.getAttribute(ATTRIBUTE_KEY).equals(ATTRIBUTE_VALUE))
 1048  
             {
 1049  0
                 userFound = true;
 1050  0
                 break;
 1051  
             }
 1052  0
         assertTrue(userFound);
 1053  
 
 1054  
         // Test find user by several attributes
 1055  
 
 1056  0
         removeUser(NEW_USER);
 1057  0
     }
 1058  
 
 1059  
     /**
 1060  
      * Tests the user operations.
 1061  
      * 
 1062  
      * @throws IdentityManagerException
 1063  
      *             if the attribute values can't be changed
 1064  
      * @throws InternalFrameworkException
 1065  
      */
 1066  
     @SuppressWarnings("serial")
 1067  
     public void testUserOperations() throws IdentityManagerException, InternalFrameworkException
 1068  
     {
 1069  0
         String USER_DEFAULT_PASSWORD = "userDefaultPassword";
 1070  
 
 1071  0
         createUser(USER_DEFAULT_PASSWORD);
 1072  0
         assertFalse(identityManagerImpl.isIdentityValid(USER_DEFAULT_PASSWORD, "password"));
 1073  0
         removeUser(USER_DEFAULT_PASSWORD);
 1074  
 
 1075  0
         createUser();
 1076  
 
 1077  
         // User identity MUST be valid! (This is the correct way to validate the password).
 1078  0
         assertTrue(identityManagerImpl.isIdentityValid(NEW_USER, USER_PASS));
 1079  
         // Test user integrity
 1080  0
         IDIFUser retrievedUser = identityManagerImpl.getUser(NEW_USER);
 1081  
 
 1082  
         /* Test user data integrity */
 1083  0
         assertEquals(retrievedUser.getID(), NEW_USER);
 1084  0
         assertEquals(retrievedUser.getName(), NEW_USER);
 1085  0
         assertEquals(retrievedUser.getNick(), NEW_USER);
 1086  0
         assertEquals(retrievedUser.getEmail(), USER_MAIL);
 1087  0
         assertEquals(retrievedUser.getProfileID(), MAIN_GROUP_NAME);
 1088  
 
 1089  
         try
 1090  
         {
 1091  0
             retrievedUser.setAttribute(AN_ATTRIBUTE_NAME, AN_ATTRIBUTE_VALUE);
 1092  
         }
 1093  0
         catch (InternalFrameworkException internalFrameworkException)
 1094  
         {
 1095  0
             internalFrameworkException.printStackTrace();
 1096  
         }
 1097  
 
 1098  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1099  0
         assertEquals(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME), AN_ATTRIBUTE_VALUE);
 1100  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME), AN_ATTRIBUTE_VALUE);
 1101  0
         assertEquals(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME.toUpperCase()), AN_ATTRIBUTE_VALUE);
 1102  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME.toUpperCase()), AN_ATTRIBUTE_VALUE);
 1103  0
         assertEquals(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME.toLowerCase()), AN_ATTRIBUTE_VALUE);
 1104  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME.toLowerCase()), AN_ATTRIBUTE_VALUE);
 1105  
 
 1106  
         try
 1107  
         {
 1108  0
             retrievedUser.setAttribute(ANOTHER_ATTRIBUTE_NAME, ANOTHER_ATTRIBUTE_VALUE);
 1109  
         }
 1110  0
         catch (InternalFrameworkException internalFrameworkException)
 1111  
         {
 1112  0
             internalFrameworkException.printStackTrace();
 1113  
         }
 1114  
 
 1115  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1116  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME), ANOTHER_ATTRIBUTE_VALUE);
 1117  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME), ANOTHER_ATTRIBUTE_VALUE);
 1118  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME.toUpperCase()), ANOTHER_ATTRIBUTE_VALUE);
 1119  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME.toUpperCase()), ANOTHER_ATTRIBUTE_VALUE);
 1120  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME.toLowerCase()), ANOTHER_ATTRIBUTE_VALUE);
 1121  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME.toLowerCase()), ANOTHER_ATTRIBUTE_VALUE);
 1122  
 
 1123  
         try
 1124  
         {
 1125  0
             retrievedUser.setAttribute(A_BULK_ATTRIBUTE_NAME, A_BULK_ATTRIBUTE_VALUE);
 1126  
         }
 1127  0
         catch (InternalFrameworkException internalFrameworkException)
 1128  
         {
 1129  0
             internalFrameworkException.printStackTrace();
 1130  
         }
 1131  
 
 1132  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1133  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1134  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1135  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME.toUpperCase()), A_BULK_ATTRIBUTE_VALUE);
 1136  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME.toUpperCase()), A_BULK_ATTRIBUTE_VALUE);
 1137  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME.toLowerCase()), A_BULK_ATTRIBUTE_VALUE);
 1138  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME.toLowerCase()), A_BULK_ATTRIBUTE_VALUE);
 1139  
 
 1140  
         try
 1141  
         {
 1142  0
             retrievedUser.setAttribute(ANOTHER_BULK_ATTRIBUTE_NAME, ANOTHER_BULK_ATTRIBUTE_VALUE);
 1143  
         }
 1144  0
         catch (InternalFrameworkException internalFrameworkException)
 1145  
         {
 1146  0
             internalFrameworkException.printStackTrace();
 1147  
         }
 1148  
 
 1149  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1150  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1151  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1152  
 
 1153  
         /* Removes the attributes one by one */
 1154  0
         retrievedUser.removeAttribute(AN_ATTRIBUTE_NAME);
 1155  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1156  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1157  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1158  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME), ANOTHER_ATTRIBUTE_VALUE);
 1159  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1160  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1161  
 
 1162  0
         retrievedUser.removeAttribute(ANOTHER_ATTRIBUTE_NAME);
 1163  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1164  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1165  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1166  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1167  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1168  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1169  
 
 1170  0
         retrievedUser.removeAttribute(A_BULK_ATTRIBUTE_NAME);
 1171  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1172  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1173  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1174  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1175  0
         assertNull(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME));
 1176  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1177  
 
 1178  0
         retrievedUser.removeAttribute(ANOTHER_BULK_ATTRIBUTE_NAME);
 1179  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1180  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1181  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1182  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1183  0
         assertNull(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME));
 1184  0
         assertNull(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME));
 1185  
 
 1186  
         /*
 1187  
          * Method 'getPassword()' is undefined for type IDIFUser. Commented for reference.
 1188  
          * assertEquals(user.getPassword(),"passwd");
 1189  
          */
 1190  
 
 1191  0
         if (identityManagerImpl.userExists(CHANGED_USER))
 1192  
         {
 1193  0
             identityManagerImpl.removeUser(CHANGED_USER);
 1194  
         }
 1195  0
         assertFalse(identityManagerImpl.userExists(CHANGED_USER));
 1196  
 
 1197  0
         createGroup(CHANGED_PARENT_GROUP_NAME);
 1198  
 
 1199  
         // Set user data for modification- change the user id
 1200  0
         IDIFUser user = new DIFUserImpl();
 1201  0
         user.setID(CHANGED_USER);
 1202  0
         user.setName(CHANGED_USER);
 1203  0
         user.setNick(CHANGED_USER);
 1204  0
         user.setEmail(CHANGED_MAIL);
 1205  0
         user.setPassword(CHANGED_PASS);
 1206  0
         user.setProfileID(CHANGED_PARENT_GROUP_NAME);
 1207  
 
 1208  
         // Modify user data
 1209  0
         identityManagerImpl.updateUser(user, NEW_USER);
 1210  0
         assertTrue(identityManagerImpl.userExists(CHANGED_USER));
 1211  
 
 1212  
         // Update attributes AFTER changing user data (setting attributes requires that the user exists on the
 1213  
         // server).
 1214  
         try
 1215  
         {
 1216  0
             user.setAttribute(ATTRIBUTE_KEY, ATTRIBUTE_VALUE);
 1217  0
             user.setAttribute(A_BULK_ATTRIBUTE_NAME, A_CHANGED_BULK_ATTRIBUTE_VALUE);
 1218  0
             user.setAttribute(ANOTHER_BULK_ATTRIBUTE_NAME, ANOTHER_CHANGED_BULK_PARAMETER_VALUE);
 1219  0
             user.setAttribute(AN_ATTRIBUTE_NAME, A_CHANGED_ATTRIBUTE_VALUE);
 1220  0
             user.setAttribute(ANOTHER_ATTRIBUTE_NAME, ANOTHER_CHANGED_ATTRIBUTE_VALUE);
 1221  
         }
 1222  0
         catch (InternalFrameworkException internalFrameworkException)
 1223  
         {
 1224  0
             throw new IdentityManagerException("Could not set attribute!!", internalFrameworkException);
 1225  
         }
 1226  
 
 1227  
         // Force attribute if branch on convertFromDIFUserToXUser
 1228  0
         identityManagerImpl.updateUser(user, CHANGED_USER);
 1229  
         // Test user integrity
 1230  0
         assertTrue(identityManagerImpl.isIdentityValid(CHANGED_USER, CHANGED_PASS));
 1231  
 
 1232  0
         retrievedUser = identityManagerImpl.getUser(CHANGED_USER);
 1233  0
         assertEquals(retrievedUser.getID(), CHANGED_USER);
 1234  0
         assertEquals(retrievedUser.getName(), CHANGED_USER);
 1235  0
         assertEquals(retrievedUser.getNick(), CHANGED_USER);
 1236  0
         assertEquals(retrievedUser.getEmail(), CHANGED_MAIL);
 1237  0
         assertEquals(retrievedUser.getProfile().getID(), CHANGED_PARENT_GROUP_NAME);
 1238  
 
 1239  
         /* Attributes */
 1240  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME), A_CHANGED_BULK_ATTRIBUTE_VALUE);
 1241  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_BULK_ATTRIBUTE_NAME),
 1242  0
                 ANOTHER_CHANGED_BULK_PARAMETER_VALUE);
 1243  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME), A_CHANGED_ATTRIBUTE_VALUE);
 1244  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME), ANOTHER_CHANGED_ATTRIBUTE_VALUE);
 1245  
 
 1246  
         // Change attributes (restore old values)
 1247  0
         identityManagerImpl.updateUserAttribute(CHANGED_USER, AN_ATTRIBUTE_NAME, AN_ATTRIBUTE_VALUE);
 1248  0
         identityManagerImpl.updateUserAttribute(CHANGED_USER, ANOTHER_ATTRIBUTE_NAME, ANOTHER_ATTRIBUTE_VALUE);
 1249  0
         identityManagerImpl.updateUserAttribute(CHANGED_USER, A_BULK_ATTRIBUTE_NAME, A_BULK_ATTRIBUTE_VALUE);
 1250  0
         identityManagerImpl
 1251  0
                 .updateUserAttribute(CHANGED_USER, ANOTHER_BULK_ATTRIBUTE_NAME, ANOTHER_BULK_ATTRIBUTE_VALUE);
 1252  
 
 1253  0
         retrievedUser = identityManagerImpl.getUser(CHANGED_USER);
 1254  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1255  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1256  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME), AN_ATTRIBUTE_VALUE);
 1257  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME), ANOTHER_ATTRIBUTE_VALUE);
 1258  
 
 1259  
         /* Removes the attributes one by one */
 1260  0
         retrievedUser.removeAttribute(AN_ATTRIBUTE_NAME);
 1261  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1262  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1263  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1264  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME), ANOTHER_ATTRIBUTE_VALUE);
 1265  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1266  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1267  
 
 1268  0
         retrievedUser.removeAttribute(ANOTHER_ATTRIBUTE_NAME);
 1269  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1270  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1271  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1272  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1273  0
         assertEquals(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME), A_BULK_ATTRIBUTE_VALUE);
 1274  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1275  
 
 1276  0
         retrievedUser.removeAttribute(A_BULK_ATTRIBUTE_NAME);
 1277  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1278  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1279  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1280  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1281  0
         assertNull(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME));
 1282  0
         assertEquals(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME), ANOTHER_BULK_ATTRIBUTE_VALUE);
 1283  
 
 1284  0
         retrievedUser.removeAttribute(ANOTHER_BULK_ATTRIBUTE_NAME);
 1285  0
         identityManagerImpl.updateUser(retrievedUser, retrievedUser.getID());
 1286  0
         retrievedUser = identityManagerImpl.getUser(retrievedUser.getID());
 1287  0
         assertNull(retrievedUser.getAttribute(AN_ATTRIBUTE_NAME));
 1288  0
         assertNull(retrievedUser.getAttribute(ANOTHER_ATTRIBUTE_NAME));
 1289  0
         assertNull(retrievedUser.getAttribute(A_BULK_ATTRIBUTE_NAME));
 1290  0
         assertNull(retrievedUser.getAttribute(ANOTHER_BULK_ATTRIBUTE_NAME));
 1291  
 
 1292  
         // Mass attribute change
 1293  0
         Map<String, Object> massAttributes = new HashMap<String, Object>() {
 1294  
 
 1295  
             {
 1296  0
                 put(A_BULK_ATTRIBUTE_NAME, A_CHANGED_BULK_ATTRIBUTE_VALUE);
 1297  0
                 put(ANOTHER_BULK_ATTRIBUTE_NAME, ANOTHER_CHANGED_BULK_PARAMETER_VALUE);
 1298  0
                 put(AN_ATTRIBUTE_NAME, A_CHANGED_ATTRIBUTE_VALUE);
 1299  0
                 put(ANOTHER_ATTRIBUTE_NAME, ANOTHER_CHANGED_ATTRIBUTE_VALUE);
 1300  
             }
 1301  
         };
 1302  
 
 1303  
         try
 1304  
         {
 1305  0
             identityManagerImpl.updateUserAttributes("InexistentUserMustReturnExpcetion", massAttributes);
 1306  0
             assertFalse(true);
 1307  
         }
 1308  0
         catch (IdentityManagerException e)
 1309  
         {
 1310  0
             assertTrue(true);
 1311  
         }
 1312  0
         identityManagerImpl.updateUserAttributes(CHANGED_USER, massAttributes);
 1313  
 
 1314  0
         retrievedUser = identityManagerImpl.getUser(CHANGED_USER);
 1315  0
         assertEquals(retrievedUser.getAttributes().get(A_BULK_ATTRIBUTE_NAME), A_CHANGED_BULK_ATTRIBUTE_VALUE);
 1316  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_BULK_ATTRIBUTE_NAME),
 1317  0
                 ANOTHER_CHANGED_BULK_PARAMETER_VALUE);
 1318  0
         assertEquals(retrievedUser.getAttributes().get(AN_ATTRIBUTE_NAME), A_CHANGED_ATTRIBUTE_VALUE);
 1319  0
         assertEquals(retrievedUser.getAttributes().get(ANOTHER_ATTRIBUTE_NAME), ANOTHER_CHANGED_ATTRIBUTE_VALUE);
 1320  
 
 1321  
         // Test password changing
 1322  0
         assertFalse(identityManagerImpl.isIdentityValid(CHANGED_USER, "WrongPassword"));
 1323  0
         identityManagerImpl.changePassword(CHANGED_USER, USER_PASS);
 1324  0
         assertTrue(identityManagerImpl.isIdentityValid(CHANGED_USER, USER_PASS));
 1325  
 
 1326  0
         removeUser(CHANGED_USER);
 1327  0
     }
 1328  
 
 1329  
     /**
 1330  
      * Tests the user operations forcing failure behavior.
 1331  
      * 
 1332  
      * @throws IdentityManagerException
 1333  
      *             if the identity manager can't be accessed
 1334  
      */
 1335  
     @SuppressWarnings("unused")
 1336  
     public void testUserOperationsInFailureBehaviour() throws IdentityManagerException
 1337  
     {
 1338  
         // Create user for addition
 1339  0
         IDIFUser transferUser = new DIFUserImpl();
 1340  
 
 1341  
         // Tries to add an user without id...must fail!!
 1342  
         try
 1343  
         {
 1344  0
             identityManagerImpl.addUser(transferUser);
 1345  
         }
 1346  0
         catch (IdentityManagerException e)
 1347  
         {
 1348  
             // User must not have been added...
 1349  0
             assertFalse(identityManagerImpl.userExists(""));
 1350  
         }
 1351  
 
 1352  
         try
 1353  
         {
 1354  0
             assertFalse(identityManagerImpl.isIdentityValid(BAD_USER, BAD_PASS));
 1355  
         }
 1356  0
         catch (IdentityManagerException e)
 1357  
         {
 1358  
 
 1359  
         }
 1360  
 
 1361  
         // Try to fetch data for an inexistent user
 1362  
         try
 1363  
         {
 1364  0
             IDIFUser retrievedUser = identityManagerImpl.getUser(BAD_USER);
 1365  
         }
 1366  0
         catch (IdentityManagerException identityManagerException)
 1367  
         {
 1368  
         }
 1369  
 
 1370  
         // Tries to modify a bad user...must fail!!
 1371  
         try
 1372  
         {
 1373  0
             identityManagerImpl.updateUser(transferUser, BAD_USER);
 1374  
         }
 1375  0
         catch (IdentityManagerException e)
 1376  
         {
 1377  
             // User must not have been added...
 1378  0
             assertFalse(identityManagerImpl.userExists(BAD_USER));
 1379  
         }
 1380  
 
 1381  
         // Tries to remove a bad user...must fail!!
 1382  
         try
 1383  
         {
 1384  0
             identityManagerImpl.removeUser(CHANGED_USER);
 1385  
         }
 1386  0
         catch (IdentityManagerException e)
 1387  
         {
 1388  
             // User must not exist
 1389  0
             assertFalse(identityManagerImpl.userExists(NEW_USER));
 1390  
         }
 1391  0
     }
 1392  
 }