private void trashWikiAttachments(boolean restore) throws Exception { ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(TestPropsValues.getGroupId()); WikiNode wikiNode = WikiNodeLocalServiceUtil.addNode( TestPropsValues.getUserId(), ServiceTestUtil.randomString(), "", serviceContext); WikiPage wikiPage = WikiPageLocalServiceUtil.addPage( TestPropsValues.getUserId(), wikiNode.getNodeId(), ServiceTestUtil.randomString(), null, WikiPageConstants.NEW, true, serviceContext); String[] attachmentsFiles = wikiPage.getAttachmentsFiles(); int initialNotInTrashCount = attachmentsFiles.length; String[] deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); int initialTrashEntriesCount = deletedAttachmentsFiles.length; Class<?> clazz = getClass(); byte[] fileBytes = FileUtil.getBytes(clazz.getResourceAsStream("dependencies/OSX_Test.docx")); File file = null; if ((fileBytes != null) && (fileBytes.length > 0)) { file = FileUtil.createTempFile(fileBytes); } WikiPageLocalServiceUtil.addPageAttachment( TestPropsValues.getUserId(), wikiNode.getNodeId(), wikiPage.getTitle(), ServiceTestUtil.randomString() + ".txt", file); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); String fileName = attachmentsFiles[0]; WikiPageLocalServiceUtil.movePageAttachmentToTrash( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount + 1, deletedAttachmentsFiles.length); fileName = deletedAttachmentsFiles[0]; if (restore) { WikiPageLocalServiceUtil.movePageAttachmentFromTrash( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); } else { WikiPageLocalServiceUtil.deletePageAttachment( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); } }