@Test public void testArticleImages() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); int initialArticleImagesCount = JournalArticleImageLocalServiceUtil.getArticleImagesCount(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 = DDMFormXSDDeserializerUtil.deserialize(definition); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure( serviceContext.getScopeGroupId(), JournalArticle.class.getName(), ddmForm); DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate( serviceContext.getScopeGroupId(), ddmStructure.getStructureId()); String content = StringUtil.read( classLoader, "com/liferay/journal/dependencies" + "/test-journal-content-image-field.xml"); Map<String, byte[]> images = new HashMap<>(); images.put( "_image_1_0_en_US", FileUtil.getBytes(clazz, "/com/liferay/journal/dependencies/liferay.png")); baseModel = JournalTestUtil.addArticleWithXMLContent( JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), images, serviceContext); Assert.assertEquals( initialArticleImagesCount + 1, JournalArticleImageLocalServiceUtil.getArticleImagesCount(group.getGroupId())); moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj()); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(getBaseModelClassName()); trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel)); Assert.assertEquals( initialArticleImagesCount, JournalArticleImageLocalServiceUtil.getArticleImagesCount(group.getGroupId())); }
protected void exportImportJournalArticle(boolean companyScopeDependencies) throws Exception { JournalArticle article = null; DDMStructure ddmStructure = null; DDMTemplate ddmTemplate = null; long groupId = group.getGroupId(); Company company = CompanyLocalServiceUtil.fetchCompany(group.getCompanyId()); Group companyGroup = company.getGroup(); if (companyScopeDependencies) { groupId = companyGroup.getGroupId(); } ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName()); ddmTemplate = DDMTemplateTestUtil.addTemplate(groupId, ddmStructure.getStructureId()); String content = DDMStructureTestUtil.getSampleStructuredContent(); article = JournalTestUtil.addArticleWithXMLContent( group.getGroupId(), content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey()); exportImportPortlet(PortletKeys.JOURNAL); int articlesCount = JournalArticleLocalServiceUtil.getArticlesCount(importedGroup.getGroupId()); Assert.assertEquals(1, articlesCount); JournalArticle groupArticle = JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId( article.getUuid(), importedGroup.getGroupId()); Assert.assertNotNull(groupArticle); groupId = importedGroup.getGroupId(); if (companyScopeDependencies) { DDMStructure importedDDMStructure = DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId( ddmStructure.getUuid(), groupId); Assert.assertNull(importedDDMStructure); DDMTemplate importedDDMTemplate = DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId( ddmTemplate.getUuid(), groupId); Assert.assertNull(importedDDMTemplate); groupId = companyGroup.getGroupId(); } DDMStructure dependentDDMStructure = DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId( ddmStructure.getUuid(), groupId); Assert.assertNotNull(dependentDDMStructure); DDMTemplate dependentDDMTemplate = DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId( ddmTemplate.getUuid(), groupId); Assert.assertNotNull(dependentDDMTemplate); Assert.assertEquals(article.getDDMStructureKey(), dependentDDMStructure.getStructureKey()); Assert.assertEquals(article.getDDMTemplateKey(), dependentDDMTemplate.getTemplateKey()); Assert.assertEquals(dependentDDMTemplate.getClassPK(), dependentDDMStructure.getStructureId()); }
protected JournalArticle addArticle(long groupId, Date displayDate, int when, boolean approved) throws Exception { Map<Locale, String> titleMap = new HashMap<Locale, String>(); titleMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString()); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); descriptionMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString()); String content = DDMStructureTestUtil.getSampleStructuredContent(); String definition = DDMStructureTestUtil.getSampleStructureDefinition(); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName(), definition); DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(groupId, ddmStructure.getStructureId()); Calendar displayDateCalendar = getCalendar(displayDate, when); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId); if (approved) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); } else { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } return JournalArticleLocalServiceUtil.addArticle( TestPropsValues.getUserId(), groupId, JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0, StringPool.BLANK, true, JournalArticleConstants.VERSION_DEFAULT, titleMap, descriptionMap, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), null, displayDateCalendar.get(Calendar.MONTH), displayDateCalendar.get(Calendar.DAY_OF_MONTH), displayDateCalendar.get(Calendar.YEAR), displayDateCalendar.get(Calendar.HOUR_OF_DAY), displayDateCalendar.get(Calendar.MINUTE), 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, null, null, null, null, serviceContext); }