@Test public void mergeTwoUserPolicies() { // create a map final PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap( ident1, "Remove policies", "Description"); final PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description"); assertNotNull(page1); dbInstance.commitAndCloseSession(); // save a list of policies final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>(); // first user policy final EPMapPolicy userPolicy1 = new EPMapPolicy(); userPolicy1.setType(Type.user); userPolicy1.getIdentities().add(ident2); userPolicy1.getIdentities().add(ident3); policies.add(userPolicy1); // second user policy final EPMapPolicy userPolicy2 = new EPMapPolicy(); userPolicy2.setType(Type.user); userPolicy2.getIdentities().add(ident1); policies.add(userPolicy2); epFrontendManager.updateMapPolicies(map, policies); dbInstance.commitAndCloseSession(); // check if the policies are correctly merged final List<EPMapPolicy> mergedPolicies = epFrontendManager.getMapPolicies(map); assertNotNull(mergedPolicies); assertEquals(1, mergedPolicies.size()); final EPMapPolicy mergedPolicy = mergedPolicies.get(0); final List<Identity> identities = mergedPolicy.getIdentities(); assertEquals(3, identities.size()); int count1, count2, count3; count1 = count2 = count3 = 0; for (final Identity identity : identities) { if (identity.equalsByPersistableKey(ident1)) { count1++; } else if (identity.equalsByPersistableKey(ident2)) { count2++; } else if (identity.equalsByPersistableKey(ident3)) { count3++; } } assertEquals(1, count1); assertEquals(1, count2); assertEquals(1, count3); }
@Test public void saveMapPolicy() { // create a map final PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description"); final PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description"); assertNotNull(page1); dbInstance.commitAndCloseSession(); // policies are empty final List<EPMapPolicy> policies = epFrontendManager.getMapPolicies(map); assertEquals(0, policies.size()); // owner policy // save a user policy final EPMapPolicy userPolicy = new EPMapPolicy(); userPolicy.setType(Type.user); userPolicy.getIdentities().add(ident2); epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy)); dbInstance.commitAndCloseSession(); // one policy final List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map); assertEquals(1, policies1.size()); // check visiblity (is owner) assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource())); // check visibility (is in policy) assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource())); // check not visible (not in policy) assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource())); }
@Test public void allMapPolicies() { // create a map final PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description"); final PortfolioStructure page1 = epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description"); assertNotNull(page1); dbInstance.commitAndCloseSession(); // save a list of policies final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>(); // user policy final EPMapPolicy userPolicy = new EPMapPolicy(); userPolicy.setType(Type.user); userPolicy.getIdentities().add(ident2); userPolicy.getIdentities().add(ident3); policies.add(userPolicy); // invitation final Invitation invitation = securityManager.createAndPersistInvitation(); invitation.setFirstName("John"); invitation.setLastName("Doe"); invitation.setMail("*****@*****.**"); final EPMapPolicy invitationPolicy = new EPMapPolicy(); invitationPolicy.setType(Type.invitation); invitationPolicy.setInvitation(invitation); policies.add(invitationPolicy); epFrontendManager.updateMapPolicies(map, policies); dbInstance.commitAndCloseSession(); // check visiblity (is owner) assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource())); // check visibility (is in policy) assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource())); // check visible (is in policy) assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource())); // retrieved policies final List<EPMapPolicy> savedPolicies = epFrontendManager.getMapPolicies(map); assertTrue(!savedPolicies.isEmpty()); }