@Test public void cloud928() { final NodeRef node = testNodes.createNodeWithTextContent( userHome, "CLOUD-928 Test Node", ContentModel.TYPE_CONTENT, user1.getUsername(), "Quick Share Test Node Content"); QuickShareDTO dto = share(node, user1.getUsername()); attributeService.removeAttribute(QuickShareServiceImpl.ATTR_KEY_SHAREDIDS_ROOT, dto.getId()); AuthenticationUtil.runAs( new RunAsWork<Object>() { @Override public Object doWork() throws Exception { nodeService.deleteNode(node); return null; } }, user1.getUsername()); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); Assert.assertFalse(nodeService.exists(node)); }
@Before public void createTestData() { userHome = repository.getUserHome(user1.getPersonNode()); testNode = testNodes.createNodeWithTextContent( userHome, "Quick Share Test Node", ContentModel.TYPE_CONTENT, user1.getUsername(), "Quick Share Test Node Content"); }
@Test public void unshare() { final QuickShareDTO dto = share(testNode, user1.getUsername()); unshare(dto.getId(), user1.getUsername()); AuthenticationUtil.runAsSystem( new RunAsWork<Void>() { @Override public Void doWork() throws Exception { assertFalse(nodeService.getAspects(testNode).contains(QuickShareModel.ASPECT_QSHARE)); assertNull(nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID)); assertNull(nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDBY)); return null; } }); }
@Test public void copyNode() { share(testNode, user1.getUsername()); AuthenticationUtil.runAs( new RunAsWork<Object>() { @Override public Object doWork() throws Exception { Assert.assertTrue(nodeService.hasAspect(testNode, QuickShareModel.ASPECT_QSHARE)); Assert.assertNotNull( nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDBY)); Assert.assertNotNull( nodeService.getProperty(testNode, QuickShareModel.PROP_QSHARE_SHAREDID)); Map<QName, Serializable> originalProps = nodeService.getProperties(testNode); NodeRef copyNodeRef = copyService.copyAndRename( testNode, userHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "copy"), true); Map<QName, Serializable> copyProps = nodeService.getProperties(copyNodeRef); Assert.assertFalse(nodeService.hasAspect(copyNodeRef, QuickShareModel.ASPECT_QSHARE)); Assert.assertNull( nodeService.getProperty(copyNodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY)); Assert.assertNull( nodeService.getProperty(copyNodeRef, QuickShareModel.PROP_QSHARE_SHAREDID)); for (QName property : originalProps.keySet()) { if (property.equals(QuickShareModel.PROP_QSHARE_SHAREDBY) || property.equals(QuickShareModel.PROP_QSHARE_SHAREDID)) { continue; } Assert.assertTrue("Mising property " + property, copyProps.containsKey(property)); } return null; } }, user1.getUsername()); }
/** * Content types that extend cm:content should be shareable. * * <p>See https://issues.alfresco.com/jira/browse/ALF-16274. */ @Test public void testWithCustomContentType() { ByteArrayInputStream modelStream = new ByteArrayInputStream(MODEL.getBytes()); temporaryModels.loadModel(modelStream); QName sharableType = QName.createQName("{http://bugtestmodel}doc"); QName unsharableType = QName.createQName("{http://bugtestmodel}doc2"); final NodeRef sharableNode = testNodes.createNodeWithTextContent( userHome, "Quick Share Custom Type Sharable Test Node", sharableType, user1.getUsername(), "Quick Share Test Node Content"); Map<String, Object> metadata = getMetadata(sharableNode, user1); assertTrue((Boolean) metadata.get("sharable")); QuickShareDTO dto = share(sharableNode, user1.getUsername()); unshare(dto.getId(), user1.getUsername()); final NodeRef unsharableNode = testNodes.createNodeWithTextContent( userHome, "Quick Share Custom Type Unsharable Test Node", unsharableType, user1.getUsername(), "Quick Share Test Node Content"); metadata = getMetadata(unsharableNode, user1); assertFalse((Boolean) metadata.get("sharable")); boolean exceptionThrown = false; try { // Prior to fixing ALF-16274, this would throw an InvalidNodeRefException. share(unsharableNode, user1.getUsername()); } catch (InvalidNodeRefException ex) { exceptionThrown = true; } assertTrue( "InvalidNodeRefException not thrown on trying to share an unsharable content type", exceptionThrown); }
@Test public void getMetadataFromShareId() { QuickShareDTO dto = share(testNode, user1.getUsername()); Map<String, Object> metadata = quickShareService.getMetaData(dto.getId()); assertNotNull(metadata); assertTrue(metadata.size() > 0); }
/** * Test for MNT-11960 * * <p>The node is created by user1 and shared by user2. * * <p>The modifier should not change to user2 after sharing. */ @Test public void testModifierAfterSharing() { AuthenticationUtil.runAs( new RunAsWork<Void>() { @Override public Void doWork() throws Exception { permissionService.setPermission( testNode, user2.getUsername(), PermissionService.CONSUMER, true); return null; } }, user1.getUsername()); final Serializable modifiedDate = AuthenticationUtil.runAsSystem( new RunAsWork<Serializable>() { @Override public Serializable doWork() throws Exception { return nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED); } }); share(testNode, user2.getUsername()); AuthenticationUtil.runAsSystem( new RunAsWork<Void>() { @Override public Void doWork() throws Exception { assertTrue(nodeService.getAspects(testNode).contains(ContentModel.ASPECT_AUDITABLE)); assertNotNull(nodeService.getProperty(testNode, ContentModel.PROP_MODIFIER)); assertEquals( "The modifier has changed after sharing.", user1.getUsername(), nodeService.getProperty(testNode, ContentModel.PROP_MODIFIER)); assertNotNull(nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED)); assertEquals( "The modified date has changed after sharing.", modifiedDate, nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED)); return null; } }); }
@SuppressWarnings("unchecked") private Map<String, Object> getMetadata(final NodeRef nodeRef, AlfrescoPerson user) { Map<String, Object> container = AuthenticationUtil.runAs( new RunAsWork<Map<String, Object>>() { @Override public Map<String, Object> doWork() throws Exception { return quickShareService.getMetaData(nodeRef); } }, user.getUsername()); return (Map<String, Object>) container.get("item"); }
@Test(expected = AccessDeniedException.class) public void getMetaDataFromNodeRefByNonOwner() { Map<String, Object> metadata = AuthenticationUtil.runAs( new RunAsWork<Map<String, Object>>() { @Override public Map<String, Object> doWork() throws Exception { return quickShareService.getMetaData(testNode); } }, user2.getUsername()); }
@Test public void getMetaDataFromNodeRefByOwner() { Map<String, Object> metadata = AuthenticationUtil.runAs( new RunAsWork<Map<String, Object>>() { @Override public Map<String, Object> doWork() throws Exception { return quickShareService.getMetaData(testNode); } }, user1.getUsername()); assertNotNull(metadata); assertTrue(metadata.size() > 0); }