@Test(expected = IllegalArgumentException.class) public void testInvalidArgument() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); callback.getGroupsForUser(null, null, null); fail("Should fail as it does not have valid configuration"); }
@Test public void testGroupNotExists() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); boolean exists = callback.existsGroup("HR"); assertFalse(exists); }
@Test public void testUserNotExists() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); boolean exists = callback.existsUser("mike"); assertFalse(exists); }
@Test public void testGroupExists() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); boolean exists = callback.existsGroup("PM"); assertTrue(exists); }
@Test public void testUserExists() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); boolean exists = callback.existsUser("john"); assertTrue(exists); }
@Test(expected = IllegalArgumentException.class) public void testInvalidConfiguration() { Properties invalidProps = new Properties(); DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(invalidProps); callback.getGroupsForUser("mike", null, null); fail("Should fail as it does not have valid configuration"); }
@Test public void testNoUserGroups() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); List<String> groups = callback.getGroupsForUser("mike", null, null); assertNotNull(groups); assertEquals(0, groups.size()); }
@Test public void testUserGroups() { DBUserGroupCallbackImpl callback = new DBUserGroupCallbackImpl(props); List<String> groups = callback.getGroupsForUser("john", null, null); assertNotNull(groups); assertEquals(1, groups.size()); assertEquals("PM", groups.get(0)); }