/** Tests the "hasAccess(User)" method returns false when the User is not logged in. */ @Test public void testHasAccessAnonymousUser() { survey.setPublic(true); Assert.assertFalse(survey.hasAccess(null)); }
/** * Tests the "hasAccess(User)" method returns true when the User is logged in and the Survey is * public. (open to all Users). */ @Test public void testHasAccessPublicSurvey() { User user = createUser("user", false); survey.setPublic(true); Assert.assertTrue(survey.hasAccess(user)); }
/** Tests that a user has access to a survey when that user is in the surveys "users" Set. */ @Test public void testHasAccessInUsers() { User user = createUser("user", false); survey.setPublic(false); survey.getUsers().add(user); Assert.assertTrue(survey.hasAccess(user)); }
/** * Tests that a user has access to a survey when that user is member of a Group configured on the * Survey. */ @Test public void testHasAccessInGroup() { User user = createUser("user", false); Group group = createGroup("group"); group.getUsers().add(user); survey.setPublic(false); survey.getGroups().add(group); Assert.assertTrue(survey.hasAccess(user)); }
/** Tests the "hasAccess(User)" method returns true when the User is an administrator. */ @Test public void testHasAccessAdmin() { User admin = createUser("admin", true); // Note that the admin has not been configured as a user of this survey. User owner = createUser("owner", false); survey.setPublic(false); survey.getUsers().add(owner); Assert.assertTrue(survey.hasAccess(admin)); }
@Test public void testHasAccessNotInGroup() { User user = createUser("user", false); Group group = createGroup("group"); Group nestedGroup = createGroup("nestedGroup"); nestedGroup.getAdmins().add(user); group.getGroups().add(nestedGroup); survey.setPublic(false); survey.getGroups().add(group); User otherUser = createUser("other", false); Assert.assertFalse(survey.hasAccess(otherUser)); }