コード例 #1
0
 @Test
 public void getPrimaryGroupUserIDsWhenNoMembersReturnsEmptyList()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   when(sql.sqlQuery(anyString())).thenReturn(result);
   when(result.next()).thenReturn(false);
   assertEquals(0, webGroupDao.getUserIDsFromPrimaryGroup(group1).size());
 }
コード例 #2
0
 @Test
 public void getPrimaryGroupKeylessWithUnknownIDReturnsBlank()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   configuration.webappPrimaryGroupUsesKey = false;
   when(sql.sqlQuery(anyString())).thenReturn(result);
   assertEquals("", webGroupDao.getPrimaryGroupID(user_id1));
 }
コード例 #3
0
 @Test
 public void convertDelimitedStringWithTwoItemsReturnsTwoItems() {
   List<String> idList = webGroupDao.convertDelimitedIDString(group1 + "," + group2);
   assertEquals(2, idList.size());
   assertTrue(idList.contains(group1));
   assertTrue(idList.contains(group2));
 }
コード例 #4
0
  @Test
  public void addCleanIDDoesNotAddEmptyString() {
    List<String> list = new ArrayList<String>();

    webGroupDao.addCleanID("", list);
    assertEquals(0, list.size());
  }
コード例 #5
0
 @Test
 public void getPrimaryGroupKeyedWithValidIDReturnsGroup()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   when(sql.sqlQuery(anyString())).thenReturn(result);
   when(result.next()).thenReturn(Boolean.TRUE);
   when(result.getString(configuration.webappPrimaryGroupGroupIDColumn)).thenReturn(group1);
   assertEquals(group1, webGroupDao.getPrimaryGroupID(user_id1));
 }
コード例 #6
0
  @Test
  public void addCleanIDDoesCleansWhitespace() {
    List<String> list = new ArrayList<String>();

    webGroupDao.addCleanID(" 1  ", list);
    assertEquals(1, list.size());
    assertTrue(list.contains("1"));
  }
コード例 #7
0
 @Test
 public void getSecondaryGroupsWithNullReturnsEmptyList()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   groups = "          ";
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(null);
   List<String> secondaryGroups = webGroupDao.getSecondaryGroupIDs(USER_ID);
   assertEquals(0, secondaryGroups.size());
 }
コード例 #8
0
 @Test
 public void getSecondaryGroupUserIDsWhenWhitespaceResultsReturnsEmptyList()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   groups = "              ";
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(groups);
   List<String> secondaryGroups = webGroupDao.getSecondaryGroupUserIDs(GROUP_ID);
   assertEquals(0, secondaryGroups.size());
 }
コード例 #9
0
 @Test
 public void addGroupWithTwoCountUsesCorrectQuery()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   String query = getAddGroupUpdateQuery(",");
   doNothing().when(sql).updateQuery(query);
   webGroupDao.addUserToGroup(USER_ID, GROUP_ID, 2);
   verify(sql).updateQuery(query);
 }
コード例 #10
0
  @Test
  public void addCleanIDAddsID() {
    List<String> list = new ArrayList<String>();

    webGroupDao.addCleanID(group1, list);
    assertEquals(1, list.size());
    assertTrue(list.contains(group1));
  }
コード例 #11
0
 @Test
 public void getSecondaryGroupsReturnsOneGroupID()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   groups = RandomStringUtils.randomNumeric(2);
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(groups);
   List<String> secondaryGroups = webGroupDao.getSecondaryGroupIDs(USER_ID);
   assertEquals(1, secondaryGroups.size());
   assertEquals(groups, secondaryGroups.get(0));
 }
コード例 #12
0
 @Test
 public void getSecondaryGroupsReturnsOnlyGroupIDs()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   groups = " , " + group2;
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(groups);
   List<String> secondaryGroups = webGroupDao.getSecondaryGroupIDs(USER_ID);
   assertEquals(1, secondaryGroups.size());
   assertTrue(secondaryGroups.contains(group2));
 }
コード例 #13
0
 @Test
 public void removeGroupUsesCorrectReadQuery()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   String query = getRemoveGroupReadQuery();
   when(sql.sqlQuery(query)).thenReturn(result);
   when(result.next()).thenReturn(false);
   webGroupDao.removeUserFromGroup(USER_ID, GROUP_ID);
   verify(sql).sqlQuery(query);
 }
コード例 #14
0
 @Test
 public void getPrimaryGroupUserIDsReturnsUserID()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   when(sql.sqlQuery(anyString())).thenReturn(result);
   when(result.next()).thenReturn(true, false);
   when(result.getString(configuration.webappPrimaryGroupUserIDColumn)).thenReturn(user_id1);
   List<String> groupMembers = webGroupDao.getUserIDsFromPrimaryGroup(group1);
   assertEquals(1, groupMembers.size());
   assertEquals(user_id1, groupMembers.get(0));
 }
コード例 #15
0
 private void testRemoveGroupUpdateQuery(String before, String after)
     throws SQLException, IllegalAccessException, MalformedURLException, InstantiationException {
   when(sql.sqlQuery(getRemoveGroupReadQuery())).thenReturn(result);
   when(result.next()).thenReturn(true);
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(before);
   String query = getRemoveGroupUpdateQuery(after);
   doNothing().when(sql).updateQuery(query);
   webGroupDao.removeUserFromGroup(USER_ID, group1);
   verify(sql).updateQuery(query);
 }
コード例 #16
0
  @Test
  public void getPrimaryGroupUserIDsWithMultipleUserIDsReturnUserIDs()
      throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
    String userID2 = RandomStringUtils.randomNumeric(2);
    when(sql.sqlQuery(anyString())).thenReturn(result);
    when(result.next()).thenReturn(true, true, false);
    when(result.getString(configuration.webappPrimaryGroupUserIDColumn))
        .thenReturn(user_id1, userID2);

    List<String> groupMembers = webGroupDao.getUserIDsFromPrimaryGroup(group1);
    assertEquals(2, groupMembers.size());
    assertEquals(user_id1, groupMembers.get(0));
    assertEquals(userID2, groupMembers.get(1));
  }
コード例 #17
0
 @Test
 public void getSecondaryGroupsReturnsTwoUserIDs()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   String userID2 = RandomStringUtils.randomNumeric(2);
   groups = group1 + "," + group2;
   when(result.next()).thenReturn(true, true, false);
   when(result.getString(configuration.webappSecondaryGroupGroupIDColumn)).thenReturn(groups);
   when(result.getString(configuration.webappSecondaryGroupUserIDColumn))
       .thenReturn(USER_ID, userID2);
   List<String> secondaryGroups = webGroupDao.getSecondaryGroupUserIDs(group1);
   assertEquals(2, secondaryGroups.size());
   assertTrue(secondaryGroups.contains(USER_ID));
   assertTrue(secondaryGroups.contains(userID2));
 }
コード例 #18
0
  @Test
  public void getGroupUserIDs()
      throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
    String primaryID1 = RandomStringUtils.randomNumeric(2);
    String primaryID2 = RandomStringUtils.randomNumeric(2);
    when(sql.sqlQuery(anyString())).thenReturn(result);
    when(result.next()).thenReturn(true, true, false);
    when(result.getString(configuration.webappPrimaryGroupUserIDColumn))
        .thenReturn(primaryID1, primaryID2);

    List<String> groups = webGroupDao.getGroupUserIDs(group1);
    assertEquals(4, groups.size());
    assertTrue(groups.contains(primaryID1));
    assertTrue(groups.contains(primaryID2));
    assertTrue(groups.contains(user_id1));
    assertTrue(groups.contains(user_id2));
  }
コード例 #19
0
 @Test
 public void getPrimaryGroupUserIDsWhenPrimaryDisabledReturnsEmptyList()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   configuration.webappPrimaryGroupEnabled = false;
   assertEquals(0, webGroupDao.getUserIDsFromPrimaryGroup(group1).size());
 }
コード例 #20
0
 private void testGroupUserIDsGroupsException(Exception exception)
     throws SQLException, InstantiationException, IllegalAccessException, MalformedURLException {
   when(sql.sqlQuery(anyString())).thenThrow(exception);
   assertEquals(0, webGroupDao.getGroupUserIDs(group1).size());
   verify(log).severe(SingleWebGroupDao.EXCEPTION_MESSAGE_GET_USERIDS + exception.getMessage());
 }
コード例 #21
0
 @Test
 public void getSecondaryGroupUserIDsWhenNoQueryResultsReturnsEmptyList()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   when(result.next()).thenReturn(false);
   assertEquals(0, webGroupDao.getSecondaryGroupUserIDs(GROUP_ID).size());
 }
コード例 #22
0
 @Test
 public void getSecondaryGroupUserIDsWhenSecondaryDisabledReturnsEmptyList()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   configuration.webappSecondaryGroupEnabled = false;
   assertEquals(0, webGroupDao.getSecondaryGroupUserIDs(GROUP_ID).size());
 }
コード例 #23
0
 @Test
 public void getSecondaryGroupUserIDsNeverReturnNull()
     throws MalformedURLException, InstantiationException, IllegalAccessException, SQLException {
   assertNotNull(webGroupDao.getSecondaryGroupUserIDs(GROUP_ID));
 }
コード例 #24
0
 @Test
 public void getPrimaryGroupWithPrimaryDisabledReturnsBlank()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   configuration.webappPrimaryGroupEnabled = false;
   assertEquals("", webGroupDao.getPrimaryGroupID(user_id1));
 }
コード例 #25
0
 @Test
 public void getPrimaryGroupNeverReturnsNull()
     throws IllegalAccessException, SQLException, MalformedURLException, InstantiationException {
   configuration.webappPrimaryGroupEnabled = false;
   assertNotNull(webGroupDao.getPrimaryGroupID(""));
 }
コード例 #26
0
 @Test
 public void getSecondaryGroupsShouldHandleNoResult()
     throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException {
   when(result.next()).thenReturn(false);
   assertNotNull(webGroupDao.getSecondaryGroupIDs(USER_ID));
 }
コード例 #27
0
 @Test
 public void convertDelimitedStringWithOneItemReturnsOneItem() {
   List<String> idList = webGroupDao.convertDelimitedIDString(group1);
   assertEquals(1, idList.size());
   assertTrue(idList.contains(group1));
 }
コード例 #28
0
 @Test
 public void convertDelimitedStringWithWhitespaceStringReturnsEmpty() {
   assertEquals(0, webGroupDao.convertDelimitedIDString("  ").size());
 }
コード例 #29
0
 @Test
 public void convertDelimitedStringWithNullReturnsEmpty() {
   assertEquals(0, webGroupDao.convertDelimitedIDString(null).size());
 }
コード例 #30
0
 @Test
 public void convertDelimitedStringNeverReturnsNull() {
   assertNotNull(webGroupDao.convertDelimitedIDString(""));
 }