protected PollsQuestion updatePollsQuestion( PollsQuestion pollsQuestion, String title, String description) throws Exception { Map<Locale, String> titleMap = new HashMap<Locale, String>(); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); for (Locale locale : _locales) { titleMap.put(locale, title.concat(LocaleUtil.toLanguageId(locale))); descriptionMap.put(locale, description.concat(LocaleUtil.toLanguageId(locale))); } return PollsQuestionLocalServiceUtil.updateQuestion( pollsQuestion.getUserId(), pollsQuestion.getQuestionId(), titleMap, descriptionMap, 0, 0, 0, 0, 0, true, pollsQuestion.getChoices(), ServiceTestUtil.getServiceContext()); }
protected PollsQuestion addPollsQuestion(long groupId, String title, String description) throws Exception { Map<Locale, String> titleMap = new HashMap<Locale, String>(); Map<Locale, String> descriptionMap = new HashMap<Locale, String>(); for (Locale locale : _locales) { titleMap.put(locale, title.concat(LocaleUtil.toLanguageId(locale))); descriptionMap.put(locale, description.concat(LocaleUtil.toLanguageId(locale))); } List<PollsChoice> pollsChoices = new ArrayList<PollsChoice>(); pollsChoices.add(addPollsChoice("optionA", "descriptionA")); pollsChoices.add(addPollsChoice("optionB", "descriptionB")); ServiceContext serviceContext = ServiceTestUtil.getServiceContext(); serviceContext.setScopeGroupId(groupId); return PollsQuestionLocalServiceUtil.addQuestion( TestPropsValues.getUserId(), titleMap, descriptionMap, 0, 0, 0, 0, 0, true, pollsChoices, serviceContext); }
protected void enableLocalStaging(boolean stageJournal, boolean stagePolls) throws Exception { Group group = ServiceTestUtil.addGroup(); ServiceTestUtil.addLayout(group.getGroupId(), "Page1"); ServiceTestUtil.addLayout(group.getGroupId(), "Page2"); int initialPagesCount = LayoutLocalServiceUtil.getLayoutsCount(group, false); // Create content JournalArticle journalArticle = addJournalArticle(group.getGroupId(), "Title", "content"); PollsQuestion pollsQuestion = addPollsQuestion(group.getGroupId(), "Question", "Description"); ServiceContext serviceContext = ServiceTestUtil.getServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); Map<String, String[]> parameters = StagingUtil.getStagingParameters(); parameters.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] {String.valueOf(false)}); parameters.put( PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.JOURNAL, new String[] {String.valueOf(stageJournal)}); parameters.put( PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.POLLS, new String[] {String.valueOf(stagePolls)}); for (String parameterName : parameters.keySet()) { serviceContext.setAttribute(parameterName, parameters.get(parameterName)[0]); } serviceContext.setAttribute( StagingConstants.STAGED_PORTLET + PortletKeys.JOURNAL, stageJournal); serviceContext.setAttribute(StagingConstants.STAGED_PORTLET + PortletKeys.POLLS, stagePolls); // Enable staging StagingUtil.enableLocalStaging( TestPropsValues.getUserId(), group, group, false, false, serviceContext); Group stagingGroup = group.getStagingGroup(); Assert.assertNotNull(stagingGroup); Assert.assertEquals( LayoutLocalServiceUtil.getLayoutsCount(stagingGroup, false), initialPagesCount); // Update content in staging JournalArticle stagingJournalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle( stagingGroup.getGroupId(), journalArticle.getUrlTitle()); stagingJournalArticle = updateJournalArticle(stagingJournalArticle, "Title2", stagingJournalArticle.getContent()); PollsQuestion stagingQuestion = PollsQuestionLocalServiceUtil.getPollsQuestionByUuidAndGroupId( pollsQuestion.getUuid(), stagingGroup.getGroupId()); stagingQuestion = updatePollsQuestion(stagingQuestion, "Question2", "Description2"); // Publish to live StagingUtil.publishLayouts( TestPropsValues.getUserId(), stagingGroup.getGroupId(), group.getGroupId(), false, parameters, null, null); // Retrieve content from live after publishing journalArticle = JournalArticleLocalServiceUtil.getArticle(journalArticle.getId()); pollsQuestion = PollsQuestionLocalServiceUtil.getQuestion(pollsQuestion.getQuestionId()); if (stagePolls) { for (Locale locale : _locales) { Assert.assertEquals(pollsQuestion.getTitle(locale), stagingQuestion.getTitle(locale)); } } else { for (Locale locale : _locales) { Assert.assertFalse(pollsQuestion.getTitle(locale).equals(stagingQuestion.getTitle(locale))); } } if (stageJournal) { for (Locale locale : _locales) { Assert.assertEquals( journalArticle.getTitle(locale), stagingJournalArticle.getTitle(locale)); } } else { for (Locale locale : _locales) { Assert.assertFalse( journalArticle.getTitle(locale).equals(stagingJournalArticle.getTitle(locale))); } } }