@Test public void binderAndSectionAndPageAccessRights() { Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-3"); Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-4"); Identity reviewer = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-5"); String title = "My published binder"; String summary = "My live"; Binder binder = portfolioService.createNewBinder(title, summary, null, owner); dbInstance.commit(); portfolioService.appendNewSection("Section", "Coached section", null, null, binder); dbInstance.commit(); List<Section> sections = portfolioService.getSections(binder); Section section = sections.get(0); portfolioService.appendNewPage(owner, "Reviewed page", "", null, null, section); portfolioService.addAccessRights(section, coach, PortfolioRoles.coach); dbInstance.commit(); List<Page> pages = portfolioService.getPages(section); Page page = pages.get(0); portfolioService.addAccessRights(page, reviewer, PortfolioRoles.reviewer); // load right List<AccessRights> rights = portfolioService.getAccessRights(binder); Assert.assertNotNull(rights); Assert.assertEquals(4, rights.size()); boolean foundOwner = false; boolean foundCoach = false; boolean foundReviewer = false; for (AccessRights right : rights) { if (PortfolioRoles.owner.equals(right.getRole()) && owner.equals(right.getIdentity())) { foundOwner = true; } else if (PortfolioRoles.coach.equals(right.getRole()) && coach.equals(right.getIdentity())) { foundCoach = true; } else if (PortfolioRoles.reviewer.equals(right.getRole()) && reviewer.equals(right.getIdentity())) { foundReviewer = true; } } Assert.assertTrue(foundOwner); Assert.assertTrue(foundCoach); Assert.assertTrue(foundReviewer); }
@Test public void binderAccessRights() { Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("port-u-2"); String title = "My private binder"; String summary = "My live"; Binder binder = portfolioService.createNewBinder(title, summary, null, owner); dbInstance.commitAndCloseSession(); // load right List<AccessRights> rights = portfolioService.getAccessRights(binder); Assert.assertNotNull(rights); Assert.assertEquals(1, rights.size()); AccessRights ownerRight = rights.get(0); Assert.assertEquals(binder.getKey(), ownerRight.getBinderKey()); Assert.assertEquals(owner, ownerRight.getIdentity()); Assert.assertEquals(PortfolioRoles.owner, ownerRight.getRole()); }