List of usage examples for com.liferay.portal.kernel.portletfilerepository PortletFileRepositoryUtil getPortletFileEntriesCount
public static int getPortletFileEntriesCount(long groupId, long folderId) throws PortalException
From source file:com.liferay.journal.trash.test.JournalArticleTrashHandlerTest.java
License:Open Source License
@Test public void testArticleImages() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); Class<?> clazz = getClass(); ClassLoader classLoader = clazz.getClassLoader(); String definition = StringUtil.read(classLoader, "com/liferay/journal/dependencies" + "/test-ddm-structure-image-field.xml"); DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(serviceContext.getScopeGroupId(), JournalArticle.class.getName(), ddmForm); DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(serviceContext.getScopeGroupId(), ddmStructure.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class)); InputStream inputStream = classLoader.getResourceAsStream("/com/liferay/journal/dependencies/liferay.png"); FileEntry tempFileEntry = TempFileEntryUtil.addTempFileEntry(group.getGroupId(), TestPropsValues.getUserId(), JournalArticle.class.getName(), "liferay.png", inputStream, ContentTypes.IMAGE_PNG);/* www . j ava 2s . co m*/ String content = StringUtil.read(classLoader, "com/liferay/journal/dependencies/test-journal-content-image-" + "field.xml"); Document document = SAXReaderUtil.read(content); Element dynamicContent = (Element) document.selectSingleNode("//dynamic-content"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("groupId", group.getGroupId()); jsonObject.put("name", "liferay.png"); jsonObject.put("tempFile", Boolean.TRUE.toString()); jsonObject.put("title", "liferay.png"); jsonObject.put("type", "journal"); jsonObject.put("uuid", tempFileEntry.getUuid()); dynamicContent.setText(jsonObject.toString()); baseModel = JournalTestUtil.addArticleWithXMLContent(JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, document.asXML(), ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext); JournalArticle article = (JournalArticle) baseModel; long folderId = article.getImagesFolderId(); Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId)); moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj()); Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId, WorkflowConstants.STATUS_APPROVED)); Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId, WorkflowConstants.STATUS_IN_TRASH)); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(getBaseModelClassName()); trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel)); Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId)); }
From source file:com.liferay.message.boards.service.test.MBMessageLocalServiceTest.java
License:Open Source License
@Test public void testDeleteAttachmentsWhenUpdatingMessageAndTrashDisabled() throws Exception { TrashUtil.disableTrash(_group);// ww w .j a v a2 s . c o m MBMessage message = addMessage(null, true); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), TestPropsValues.getUserId()); MBMessageLocalServiceUtil.updateMessage(TestPropsValues.getUserId(), message.getMessageId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), Collections.<ObjectValuePair<String, InputStream>>emptyList(), Collections.<String>emptyList(), 0, false, serviceContext); Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(message.getGroupId(), message.getAttachmentsFolderId())); }