@Before
  public void setUp() throws Exception {
    FinderCacheUtil.clearCache();

    ServiceContextThreadLocal.pushServiceContext(ServiceTestUtil.getServiceContext());

    // Group

    group = GroupTestUtil.addGroup();

    // Global scope article

    Company company = CompanyUtil.fetchByPrimaryKey(group.getCompanyId());

    globalGroupId = company.getGroupId();

    globalJournalArticle =
        JournalTestUtil.addArticle(globalGroupId, "Global Article", "Global Content");

    // Layout prototype

    layoutPrototype = LayoutTestUtil.addLayoutPrototype(ServiceTestUtil.randomString());

    layoutPrototypeLayout = layoutPrototype.getLayout();

    LayoutTestUtil.updateLayoutTemplateId(layoutPrototypeLayout, initialLayoutTemplateId);

    doSetUp();
  }
  @Test
  public void testExportImportPortletPreferences() throws Exception {

    // Check preferences after site creation

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            _group.getGroupId(), _layoutSetPrototypeJournalArticle.getUrlTitle());

    Layout layout =
        LayoutLocalServiceUtil.getFriendlyURLLayout(
            _group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL());

    javax.portlet.PortletPreferences jxPreferences =
        getPortletPreferences(
            layout.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));

    Assert.assertEquals(
        String.valueOf(true), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));

    // Update site template preferences

    javax.portlet.PortletPreferences layoutSetprototypeJxPreferences =
        getPortletPreferences(
            _layoutSetPrototypeLayout.getCompanyId(),
            _layoutSetPrototypeLayout.getPlid(),
            _layoutSetPrototypeJournalContentPortletId);

    layoutSetprototypeJxPreferences.setValue("showAvailableLocales", String.valueOf(false));

    updatePortletPreferences(
        _layoutSetPrototypeLayout.getPlid(),
        _layoutSetPrototypeJournalContentPortletId,
        layoutSetprototypeJxPreferences);

    // Check preferences after layout reset

    SitesUtil.resetPrototype(layout);

    jxPreferences =
        getPortletPreferences(
            _group.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    Assert.assertEquals(
        journalArticle.getArticleId(), jxPreferences.getValue("articleId", StringPool.BLANK));
    Assert.assertEquals(
        String.valueOf(journalArticle.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));
    Assert.assertEquals(
        Boolean.FALSE.toString(), jxPreferences.getValue("showAvailableLocales", StringPool.BLANK));

    // Update journal content portlet with a new globally scoped journal
    // article

    Company company = CompanyUtil.fetchByPrimaryKey(_layoutSetPrototypeLayout.getCompanyId());

    Group companyGroup = company.getGroup();

    JournalArticle globalScopeJournalArticle =
        addJournalArticle(companyGroup.getGroupId(), 0, "Global Article", "Global Content");

    layoutSetprototypeJxPreferences.setValue("articleId", globalScopeJournalArticle.getArticleId());
    layoutSetprototypeJxPreferences.setValue("groupId", Long.toString(companyGroup.getGroupId()));
    layoutSetprototypeJxPreferences.setValue("lfrScopeLayoutUuid", StringPool.BLANK);
    layoutSetprototypeJxPreferences.setValue("lfrScopeType", "company");

    updatePortletPreferences(
        _layoutSetPrototypeLayout.getPlid(),
        _layoutSetPrototypeJournalContentPortletId,
        layoutSetprototypeJxPreferences);

    jxPreferences =
        getPortletPreferences(
            _group.getCompanyId(), layout.getPlid(), _layoutSetPrototypeJournalContentPortletId);

    // Check preferences when journal article is from the global scope

    Assert.assertEquals(
        globalScopeJournalArticle.getArticleId(),
        jxPreferences.getValue("articleId", StringPool.BLANK));
    Assert.assertEquals(
        String.valueOf(companyGroup.getGroupId()),
        jxPreferences.getValue("groupId", StringPool.BLANK));
    Assert.assertEquals(
        StringPool.BLANK, jxPreferences.getValue("lfrScopeLayoutUuid", StringPool.BLANK));
    Assert.assertEquals("company", jxPreferences.getValue("lfrScopeType", StringPool.BLANK));
  }