@Test
  public void testGetJournalXSD() throws Exception {
    String expectedXSD = read("test-journal-structure-all-fields.xml");

    Map<String, Map<String, String>> expectedMap = JournalTestUtil.getXsdMap(expectedXSD);

    String actualXSD =
        JournalConverterUtil.getJournalXSD(read("test-ddm-structure-all-fields.xml"));

    Map<String, Map<String, String>> actualMap = JournalTestUtil.getXsdMap(actualXSD);

    Assert.assertEquals(expectedMap, actualMap);
  }
  @Override
  protected BaseModel<?> getParentBaseModel(
      BaseModel<?> parentBaseModel, ServiceContext serviceContext) throws Exception {

    return JournalTestUtil.addFolder(
        (Long) parentBaseModel.getPrimaryKeyObj(), RandomTestUtil.randomString(), serviceContext);
  }
  @Test
  public void testTypeArticle() throws Exception {
    initExport();

    Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>();

    JournalArticle journalArticle =
        JournalTestUtil.addArticle(
            stagingGroup.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(),
            RandomTestUtil.randomString());

    addDependentStagedModel(dependentStagedModelsMap, JournalArticle.class, journalArticle);

    Layout layout =
        LayoutTestUtil.addTypeArticleLayout(
            stagingGroup.getGroupId(), journalArticle.getArticleId());

    addDependentLayoutFriendlyURLs(dependentStagedModelsMap, layout);

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

    validateExport(portletDataContext, layout, dependentStagedModelsMap);

    initImport();

    Layout exportedLayout = (Layout) readExportedStagedModel(layout);

    StagedModelDataHandlerUtil.importStagedModel(portletDataContext, exportedLayout);
  }
  @Test
  public void testJournalFolderTreePathWithJournalFolderInTrash() throws Exception {

    JournalFolder parentFolder =
        JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    JournalFolder folder =
        JournalTestUtil.addFolder(
            _group.getGroupId(), parentFolder.getFolderId(), RandomTestUtil.randomString());

    JournalFolderLocalServiceUtil.moveFolderToTrash(
        TestPropsValues.getUserId(), folder.getFolderId());

    JournalFolderLocalServiceUtil.deleteFolder(parentFolder.getFolderId(), false);

    doVerify();
  }
  @Test
  public void testJournalArticleTreePathWithJournalArticleInTrash() throws Exception {

    JournalFolder parentFolder =
        JournalTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString());

    JournalArticle article =
        JournalTestUtil.addArticle(
            _group.getGroupId(), parentFolder.getFolderId(), "title", "content");

    JournalArticleLocalServiceUtil.moveArticleToTrash(
        TestPropsValues.getUserId(), _group.getGroupId(), article.getArticleId());

    JournalFolderLocalServiceUtil.deleteFolder(parentFolder.getFolderId(), false);

    doVerify();
  }
  @Override
  protected BaseModel<?> getParentBaseModel(Group group, ServiceContext serviceContext)
      throws Exception {

    return JournalTestUtil.addFolder(
        JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
        RandomTestUtil.randomString(),
        serviceContext);
  }
  protected void testScheduleArticle(boolean approved, int when) throws Exception {

    int initialSearchArticlesCount =
        JournalTestUtil.getSearchArticlesCount(_group.getCompanyId(), _group.getGroupId());

    Date now = new Date();

    JournalArticle article = addArticle(_group.getGroupId(), now, when, approved);

    JournalArticleLocalServiceUtil.checkArticles();

    article = JournalArticleLocalServiceUtil.getArticle(article.getId());

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(
            JournalArticle.class.getName(), article.getResourcePrimKey());

    if (when == _WHEN_FUTURE) {
      Assert.assertFalse(article.isApproved());
      Assert.assertFalse(assetEntry.isVisible());

      if (approved) {
        Assert.assertTrue(article.isScheduled());
      } else {
        Assert.assertTrue(article.isDraft());
      }
    } else {
      Assert.assertFalse(article.isScheduled());
      Assert.assertEquals(approved, article.isApproved());
      Assert.assertEquals(approved, assetEntry.isVisible());

      if (approved) {
        Assert.assertEquals(
            initialSearchArticlesCount + 1,
            JournalTestUtil.getSearchArticlesCount(_group.getCompanyId(), _group.getGroupId()));
      } else {
        Assert.assertEquals(
            initialSearchArticlesCount,
            JournalTestUtil.getSearchArticlesCount(_group.getCompanyId(), _group.getGroupId()));
      }
    }
  }
  @Override
  protected StagedModel addStagedModel(
      Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception {

    List<StagedModel> dependentStagedModels =
        dependentStagedModelsMap.get(JournalFolder.class.getSimpleName());

    JournalFolder folder = (JournalFolder) dependentStagedModels.get(0);

    return JournalTestUtil.addFolder(
        group.getGroupId(), folder.getFolderId(), RandomTestUtil.randomString());
  }
  @Override
  protected Map<String, List<StagedModel>> addDependentStagedModelsMap(Group group)
      throws Exception {

    Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>();

    JournalFolder folder =
        JournalTestUtil.addFolder(group.getGroupId(), RandomTestUtil.randomString());

    addDependentStagedModel(dependentStagedModelsMap, JournalFolder.class, folder);

    return dependentStagedModelsMap;
  }
  @Override
  protected BaseModel<?> addBaseModelWithWorkflow(
      BaseModel<?> parentBaseModel,
      boolean approved,
      String keywords,
      ServiceContext serviceContext)
      throws Exception {

    JournalFolder parentFolder = (JournalFolder) parentBaseModel;

    long folderId = JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    if (parentFolder != null) {
      folderId = parentFolder.getFolderId();
    }

    return JournalTestUtil.addFolder(folderId, keywords, serviceContext);
  }
  @Override
  protected StagedModel addStagedModel(long groupId, Date createdDate) throws Exception {

    String title = RandomTestUtil.randomString();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId);

    serviceContext.setCommand(Constants.ADD);
    serviceContext.setCreateDate(createdDate);
    serviceContext.setLayoutFullURL("http://localhost");
    serviceContext.setModifiedDate(createdDate);

    return JournalTestUtil.addArticle(
        groupId,
        JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
        JournalArticleConstants.CLASSNAME_ID_DEFAULT,
        title,
        title,
        RandomTestUtil.randomString(),
        LocaleUtil.getSiteDefault(),
        false,
        false,
        serviceContext);
  }
 @Override
 protected StagedModel addStagedModel(long groupId) throws Exception {
   return JournalTestUtil.addArticle(
       groupId, RandomTestUtil.randomString(), RandomTestUtil.randomString());
 }
  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());
  }