コード例 #1
0
  @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 initActionableDynamicQuery(ActionableDynamicQuery actionableDynamicQuery) {
    actionableDynamicQuery.setBaseLocalService(
        com.liferay.journal.service.JournalArticleImageLocalServiceUtil.getService());
    actionableDynamicQuery.setClassLoader(getClassLoader());
    actionableDynamicQuery.setModelClass(JournalArticleImage.class);

    actionableDynamicQuery.setPrimaryKeyPropertyName("articleImageId");
  }
  @Override
  public ActionableDynamicQuery getActionableDynamicQuery() {
    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();

    actionableDynamicQuery.setBaseLocalService(
        com.liferay.journal.service.JournalArticleImageLocalServiceUtil.getService());
    actionableDynamicQuery.setClassLoader(getClassLoader());
    actionableDynamicQuery.setModelClass(JournalArticleImage.class);

    actionableDynamicQuery.setPrimaryKeyPropertyName("articleImageId");

    return actionableDynamicQuery;
  }