@Test
  public void testAddAndFindGroupByName() throws Exception {
    final Group createdGroup = groupDao.add(TestData.Group.getTestData());

    TestData.Group.assertEqualsTestGroup(createdGroup);

    final Group retrievedGroup = groupDao.findByName(TestData.DIRECTORY_ID, TestData.Group.NAME);

    TestData.Group.assertEqualsTestGroup(retrievedGroup);
  }
  @Test
  public void testAddAndStoreAttributesAndFindGroupWithAttributesByName() throws Exception {
    final Group createdGroup = groupDao.add(TestData.Group.getTestData());
    TestData.Group.assertEqualsTestGroup(createdGroup);

    groupDao.storeAttributes(createdGroup, TestData.Attributes.getTestData());

    final GroupWithAttributes retrievedGroup =
        groupDao.findByNameWithAttributes(TestData.DIRECTORY_ID, TestData.Group.NAME);
    TestData.Group.assertEqualsTestGroup(retrievedGroup);
    TestData.Attributes.assertEqualsTestData(retrievedGroup);
  }
  @Test
  public void testRemoveGroup() throws Exception {
    groupDao.add(TestData.Group.getTestData());
    assertNotNull(groupDao.findByName(TestData.DIRECTORY_ID, TestData.Group.NAME));

    groupDao.remove(TestData.Group.getTestData());
    try {
      groupDao.findByName(TestData.DIRECTORY_ID, TestData.Group.NAME);
      fail("Should have thrown a user not found exception");
    } catch (GroupNotFoundException e) {
      assertEquals(TestData.Group.NAME, e.getGroupName());
    }
  }
  @Test
  public void testSearchAllGroupNames() {
    final String groupName2 = "group2";
    groupDao.add(TestData.Group.getTestData());
    groupDao.add(TestData.Group.getGroup(groupName2, DIRECTORY_ID, true, "d", GroupType.GROUP));

    @SuppressWarnings("unchecked")
    final GroupQuery<String> query = mock(GroupQuery.class);
    when(query.getReturnType()).thenReturn(String.class);

    final List<String> groupNames = groupDao.search(DIRECTORY_ID, query);

    assertEquals(2, groupNames.size());
    assertTrue(groupNames.contains(TestData.Group.NAME));
    assertTrue(groupNames.contains(groupName2));
  }
  @Test
  public void testRemoveAttribute() throws Exception {
    final Group createdGroup = groupDao.add(TestData.Group.getTestData());
    groupDao.storeAttributes(createdGroup, TestData.Attributes.getTestData());

    TestData.Attributes.assertEqualsTestData(
        groupDao.findByNameWithAttributes(TestData.DIRECTORY_ID, TestData.Group.NAME));

    groupDao.removeAttribute(createdGroup, TestData.Attributes.ATTRIBUTE1);
    final GroupWithAttributes groupWithLessAttributes =
        groupDao.findByNameWithAttributes(TestData.DIRECTORY_ID, TestData.Group.NAME);

    assertNull(groupWithLessAttributes.getValue(TestData.Attributes.ATTRIBUTE1));
  }
  @Test
  public void testUpdateGroup() throws Exception {
    final Group createdGroup = groupDao.add(TestData.Group.getTestData());
    TestData.Group.assertEqualsTestGroup(createdGroup);

    final boolean updatedIsActive = false;
    final String updatedDescription = "updated Description";

    groupDao.update(
        TestData.Group.getGroup(
            createdGroup.getName(),
            createdGroup.getDirectoryId(),
            updatedIsActive,
            updatedDescription,
            createdGroup.getType()));

    final Group updatedGroup = groupDao.findByName(TestData.DIRECTORY_ID, TestData.Group.NAME);

    assertEquals(TestData.Group.NAME, updatedGroup.getName());
    assertEquals(TestData.DIRECTORY_ID, updatedGroup.getDirectoryId());
    assertEquals(TestData.Group.TYPE, updatedGroup.getType());
    assertEquals(updatedIsActive, updatedGroup.isActive());
    assertEquals(updatedDescription, updatedGroup.getDescription());
  }