PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/apps/wiki/wiki-test/src/testIntegration/java/com/liferay/wiki/service/test/WikiPageLocalServiceTest.java

http://github.com/liferay/liferay-portal
Java | 1266 lines | 927 code | 322 blank | 17 comment | 9 complexity | 44b282db8f6937a55daca9475adb859b MD5 | raw file
Possible License(s): LGPL-2.0
  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.wiki.service.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.asset.kernel.exception.AssetCategoryException;
  17. import com.liferay.asset.kernel.model.AssetCategory;
  18. import com.liferay.asset.kernel.model.AssetEntry;
  19. import com.liferay.asset.kernel.model.AssetLink;
  20. import com.liferay.asset.kernel.model.AssetTag;
  21. import com.liferay.asset.kernel.model.AssetVocabulary;
  22. import com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil;
  23. import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
  24. import com.liferay.asset.kernel.service.AssetLinkLocalServiceUtil;
  25. import com.liferay.asset.kernel.service.AssetTagLocalServiceUtil;
  26. import com.liferay.asset.kernel.service.AssetVocabularyLocalServiceUtil;
  27. import com.liferay.asset.test.util.AssetTestUtil;
  28. import com.liferay.expando.kernel.model.ExpandoBridge;
  29. import com.liferay.expando.kernel.model.ExpandoColumn;
  30. import com.liferay.expando.kernel.model.ExpandoColumnConstants;
  31. import com.liferay.expando.kernel.model.ExpandoValue;
  32. import com.liferay.petra.string.CharPool;
  33. import com.liferay.petra.string.StringBundler;
  34. import com.liferay.petra.string.StringPool;
  35. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  36. import com.liferay.portal.kernel.exception.PortalException;
  37. import com.liferay.portal.kernel.log.Log;
  38. import com.liferay.portal.kernel.log.LogFactoryUtil;
  39. import com.liferay.portal.kernel.model.Group;
  40. import com.liferay.portal.kernel.repository.model.FileEntry;
  41. import com.liferay.portal.kernel.service.ServiceContext;
  42. import com.liferay.portal.kernel.test.AssertUtils;
  43. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  44. import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
  45. import com.liferay.portal.kernel.test.util.GroupTestUtil;
  46. import com.liferay.portal.kernel.test.util.RandomTestUtil;
  47. import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
  48. import com.liferay.portal.kernel.test.util.TestPropsValues;
  49. import com.liferay.portal.kernel.test.util.UserTestUtil;
  50. import com.liferay.portal.kernel.util.CalendarFactoryUtil;
  51. import com.liferay.portal.kernel.util.HashMapBuilder;
  52. import com.liferay.portal.kernel.util.ListUtil;
  53. import com.liferay.portal.kernel.util.PortalUtil;
  54. import com.liferay.portal.kernel.util.StringUtil;
  55. import com.liferay.portal.kernel.workflow.WorkflowConstants;
  56. import com.liferay.portal.kernel.workflow.WorkflowThreadLocal;
  57. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  58. import com.liferay.portlet.expando.util.test.ExpandoTestUtil;
  59. import com.liferay.wiki.exception.DuplicatePageException;
  60. import com.liferay.wiki.exception.DuplicatePageExternalReferenceCodeException;
  61. import com.liferay.wiki.exception.NoSuchPageResourceException;
  62. import com.liferay.wiki.exception.PageTitleException;
  63. import com.liferay.wiki.model.WikiNode;
  64. import com.liferay.wiki.model.WikiPage;
  65. import com.liferay.wiki.service.WikiPageLocalServiceUtil;
  66. import com.liferay.wiki.test.util.WikiTestUtil;
  67. import java.io.Serializable;
  68. import java.util.Arrays;
  69. import java.util.Calendar;
  70. import java.util.Date;
  71. import java.util.List;
  72. import java.util.Map;
  73. import org.junit.Assert;
  74. import org.junit.Before;
  75. import org.junit.ClassRule;
  76. import org.junit.Rule;
  77. import org.junit.Test;
  78. import org.junit.runner.RunWith;
  79. /**
  80. * @author Manuel de la Peña
  81. * @author Roberto Díaz
  82. */
  83. @RunWith(Arquillian.class)
  84. public class WikiPageLocalServiceTest {
  85. @ClassRule
  86. @Rule
  87. public static final AggregateTestRule aggregateTestRule =
  88. new LiferayIntegrationTestRule();
  89. @Before
  90. public void setUp() throws Exception {
  91. UserTestUtil.setUser(TestPropsValues.getUser());
  92. _group = GroupTestUtil.addGroup();
  93. _node = WikiTestUtil.addNode(_group.getGroupId());
  94. }
  95. @Test
  96. public void testAddFrontPageWithoutRequiredCategory() throws Exception {
  97. AssetVocabulary assetVocabulary = getRequiredAssetVocabulary();
  98. ServiceContext serviceContext =
  99. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  100. AssetCategoryLocalServiceUtil.addCategory(
  101. TestPropsValues.getUserId(), _group.getGroupId(), "category 1",
  102. assetVocabulary.getVocabularyId(), serviceContext);
  103. WikiPage frontPage = WikiTestUtil.addPage(
  104. TestPropsValues.getUserId(), _node.getNodeId(), "FrontPage",
  105. RandomTestUtil.randomString(), true, serviceContext);
  106. List<AssetCategory> categories =
  107. AssetCategoryLocalServiceUtil.getCategories(
  108. WikiPage.class.getName(), frontPage.getResourcePrimKey());
  109. Assert.assertTrue(ListUtil.isNull(categories));
  110. }
  111. @Test(expected = DuplicatePageExternalReferenceCodeException.class)
  112. public void testAddPageWithExistingExternalReferenceCode()
  113. throws Exception {
  114. ServiceContext serviceContext =
  115. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  116. WikiPage wikiPage = WikiTestUtil.addPage(
  117. TestPropsValues.getUserId(), _node.getNodeId(),
  118. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  119. serviceContext);
  120. WikiPageLocalServiceUtil.addPage(
  121. wikiPage.getExternalReferenceCode(), TestPropsValues.getUserId(),
  122. _node.getNodeId(), RandomTestUtil.randomString(),
  123. WorkflowConstants.ACTION_PUBLISH, RandomTestUtil.randomString(),
  124. RandomTestUtil.randomString(), false, "creole", true,
  125. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  126. serviceContext);
  127. }
  128. @Test
  129. public void testAddPageWithExternalReferenceCode() throws Exception {
  130. String externalReferenceCode = RandomTestUtil.randomString();
  131. WikiPage wikiPage = WikiPageLocalServiceUtil.addPage(
  132. externalReferenceCode, TestPropsValues.getUserId(),
  133. _node.getNodeId(), RandomTestUtil.randomString(),
  134. WorkflowConstants.ACTION_PUBLISH, RandomTestUtil.randomString(),
  135. RandomTestUtil.randomString(), false, "creole", true,
  136. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  137. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  138. Assert.assertEquals(
  139. externalReferenceCode, wikiPage.getExternalReferenceCode());
  140. }
  141. @Test
  142. public void testAddPageWithInvalidTitle() throws Exception {
  143. char[] invalidCharacters = "\\[]|:;%<>".toCharArray();
  144. for (char invalidCharacter : invalidCharacters) {
  145. try {
  146. ServiceContext serviceContext =
  147. ServiceContextTestUtil.getServiceContext(
  148. _group.getGroupId());
  149. WikiTestUtil.addPage(
  150. TestPropsValues.getUserId(), _node.getNodeId(),
  151. "ChildPage" + invalidCharacter,
  152. RandomTestUtil.randomString(), true, serviceContext);
  153. Assert.fail(
  154. "Created a page with invalid character " +
  155. invalidCharacter);
  156. }
  157. catch (PageTitleException pageTitleException) {
  158. }
  159. }
  160. }
  161. @Test
  162. public void testAddPageWithNbspTitle() throws Exception {
  163. WikiPage page = WikiTestUtil.addPage(
  164. TestPropsValues.getUserId(), _node.getNodeId(),
  165. "ChildPage" + CharPool.NO_BREAK_SPACE + "1",
  166. RandomTestUtil.randomString(), true,
  167. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  168. Assert.assertEquals("ChildPage 1", page.getTitle());
  169. }
  170. @Test
  171. public void testAddPageWithoutExternalReferenceCode() throws Exception {
  172. WikiPage wikiPage = WikiTestUtil.addPage(
  173. TestPropsValues.getUserId(), _node.getNodeId(),
  174. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  175. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  176. Assert.assertEquals(
  177. wikiPage.getExternalReferenceCode(),
  178. String.valueOf(wikiPage.getPageId()));
  179. }
  180. @Test(expected = AssetCategoryTestException.class)
  181. public void testAddPageWithoutRequiredCategory() throws Exception {
  182. AssetVocabulary assetVocabulary = getRequiredAssetVocabulary();
  183. ServiceContext serviceContext =
  184. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  185. AssetCategoryLocalServiceUtil.addCategory(
  186. TestPropsValues.getUserId(), _group.getGroupId(), "category 1",
  187. assetVocabulary.getVocabularyId(), serviceContext);
  188. try {
  189. WikiTestUtil.addPage(
  190. TestPropsValues.getUserId(), _node.getNodeId(),
  191. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  192. true, serviceContext);
  193. }
  194. catch (AssetCategoryException assetCategoryException) {
  195. if (_log.isDebugEnabled()) {
  196. _log.debug(assetCategoryException, assetCategoryException);
  197. }
  198. throw new AssetCategoryTestException();
  199. }
  200. }
  201. @Test
  202. public void testAddPageWithRequiredCategory() throws Exception {
  203. AssetVocabulary assetVocabulary = getRequiredAssetVocabulary();
  204. ServiceContext serviceContext =
  205. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  206. AssetCategory assetCategory = AssetCategoryLocalServiceUtil.addCategory(
  207. TestPropsValues.getUserId(), _group.getGroupId(), "category 1",
  208. assetVocabulary.getVocabularyId(), serviceContext);
  209. long categoryId = assetCategory.getCategoryId();
  210. serviceContext.setAssetCategoryIds(new long[] {categoryId});
  211. WikiPage page = WikiTestUtil.addPage(
  212. TestPropsValues.getUserId(), _node.getNodeId(),
  213. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  214. serviceContext);
  215. List<AssetCategory> assetCategories =
  216. AssetCategoryLocalServiceUtil.getCategories(
  217. WikiPage.class.getName(), page.getResourcePrimKey());
  218. Assert.assertEquals(
  219. assetCategories.toString(), 1, assetCategories.size());
  220. AssetCategory persistedAssetCategory = assetCategories.get(0);
  221. Assert.assertEquals(categoryId, persistedAssetCategory.getCategoryId());
  222. }
  223. @Test
  224. public void testChangeParent() throws Exception {
  225. testChangeParent(false);
  226. }
  227. @Test
  228. public void testChangeParentChangesAllWikiPageVersionsParentTitle()
  229. throws Exception {
  230. WikiTestUtil.addPage(
  231. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  232. "ParentPage1", true);
  233. WikiTestUtil.addPage(
  234. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  235. "ParentPage2", true);
  236. ServiceContext serviceContext =
  237. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  238. WikiPage childPage = WikiTestUtil.addPage(
  239. TestPropsValues.getUserId(), _node.getNodeId(), "ChildPage",
  240. RandomTestUtil.randomString(), "ParentPage1", true, serviceContext);
  241. WikiTestUtil.updatePage(
  242. childPage, TestPropsValues.getUserId(), StringUtil.randomString(),
  243. serviceContext);
  244. WikiPageLocalServiceUtil.changeParent(
  245. TestPropsValues.getUserId(), _node.getNodeId(),
  246. childPage.getTitle(), "ParentPage2", serviceContext);
  247. List<WikiPage> pages = WikiPageLocalServiceUtil.getPages(
  248. childPage.getNodeId(), childPage.getTitle(), QueryUtil.ALL_POS,
  249. QueryUtil.ALL_POS);
  250. Assert.assertEquals(pages.toString(), 3, pages.size());
  251. for (WikiPage curWikiPage : pages) {
  252. Assert.assertEquals("ParentPage2", curWikiPage.getParentTitle());
  253. }
  254. }
  255. @Test
  256. public void testChangeParentWithExpando() throws Exception {
  257. testChangeParent(true);
  258. }
  259. @Test
  260. public void testChangeParentWithWorkflowChangesParentAfterUpdateStatus()
  261. throws Exception {
  262. WikiTestUtil.addPage(
  263. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  264. "ParentPage1", true);
  265. WikiTestUtil.addPage(
  266. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  267. "ParentPage2", true);
  268. ServiceContext serviceContext =
  269. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  270. WikiPage childPage = WikiTestUtil.addPage(
  271. TestPropsValues.getUserId(), _node.getNodeId(), "ChildPage",
  272. RandomTestUtil.randomString(), "ParentPage1", true, serviceContext);
  273. boolean workflowEnabled = WorkflowThreadLocal.isEnabled();
  274. try {
  275. WorkflowThreadLocal.setEnabled(true);
  276. serviceContext = (ServiceContext)serviceContext.clone();
  277. serviceContext.setWorkflowAction(
  278. WorkflowConstants.ACTION_SAVE_DRAFT);
  279. WikiPage pendingChildPage = WikiPageLocalServiceUtil.changeParent(
  280. TestPropsValues.getUserId(), _node.getNodeId(),
  281. childPage.getTitle(), "ParentPage2", serviceContext);
  282. childPage = WikiPageLocalServiceUtil.getPage(
  283. _node.getNodeId(), childPage.getTitle(), true);
  284. Assert.assertEquals("ParentPage1", childPage.getParentTitle());
  285. Map<String, Serializable> workflowContext =
  286. HashMapBuilder.<String, Serializable>put(
  287. WorkflowConstants.CONTEXT_COMMAND,
  288. serviceContext.getCommand()
  289. ).build();
  290. WikiPageLocalServiceUtil.updateStatus(
  291. TestPropsValues.getUserId(), pendingChildPage,
  292. WorkflowConstants.STATUS_APPROVED, serviceContext,
  293. workflowContext);
  294. List<WikiPage> pages = WikiPageLocalServiceUtil.getPages(
  295. childPage.getNodeId(), childPage.getTitle(), QueryUtil.ALL_POS,
  296. QueryUtil.ALL_POS);
  297. Assert.assertEquals(pages.toString(), 2, pages.size());
  298. for (WikiPage curWikiPage : pages) {
  299. Assert.assertEquals(
  300. "ParentPage2", curWikiPage.getParentTitle());
  301. }
  302. }
  303. finally {
  304. WorkflowThreadLocal.setEnabled(workflowEnabled);
  305. }
  306. }
  307. @Test
  308. public void testCopyPage() throws Exception {
  309. WikiPage page = WikiTestUtil.addPage(
  310. _group.getGroupId(), _node.getNodeId(), true);
  311. WikiTestUtil.addWikiAttachment(
  312. page.getUserId(), page.getNodeId(), page.getTitle(), getClass());
  313. List<FileEntry> attachmentsFileEntries =
  314. page.getAttachmentsFileEntries();
  315. WikiPage copyPage = WikiTestUtil.copyPage(
  316. page, true,
  317. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  318. List<FileEntry> copyAttachmentsFileEntries =
  319. copyPage.getAttachmentsFileEntries();
  320. Assert.assertEquals(
  321. attachmentsFileEntries.toString(),
  322. copyAttachmentsFileEntries.size(), attachmentsFileEntries.size());
  323. FileEntry fileEntry = attachmentsFileEntries.get(0);
  324. FileEntry copyFileEntry = copyAttachmentsFileEntries.get(0);
  325. Assert.assertEquals(
  326. copyFileEntry.getExtension(), fileEntry.getExtension());
  327. Assert.assertEquals(
  328. copyFileEntry.getMimeType(), fileEntry.getMimeType());
  329. Assert.assertEquals(copyFileEntry.getTitle(), fileEntry.getTitle());
  330. Assert.assertEquals(copyFileEntry.getSize(), fileEntry.getSize());
  331. }
  332. @Test(expected = NoSuchPageResourceException.class)
  333. public void testDeletePage() throws Exception {
  334. WikiPage page = WikiTestUtil.addPage(
  335. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  336. "TestPage", true);
  337. WikiPageLocalServiceUtil.deletePage(page);
  338. WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());
  339. }
  340. @Test
  341. public void testDeleteParentPageWithChangedParentChild() throws Exception {
  342. WikiTestUtil.addPage(
  343. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  344. "ParentPage1", true);
  345. WikiTestUtil.addPage(
  346. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  347. "ParentPage2", true);
  348. ServiceContext serviceContext =
  349. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  350. WikiPage childPage = WikiTestUtil.addPage(
  351. TestPropsValues.getUserId(), _node.getNodeId(), "ChildPage",
  352. RandomTestUtil.randomString(), "ParentPage1", true, serviceContext);
  353. WikiPageLocalServiceUtil.changeParent(
  354. TestPropsValues.getUserId(), _node.getNodeId(),
  355. childPage.getTitle(), "ParentPage2", serviceContext);
  356. WikiPageLocalServiceUtil.deletePage(_node.getNodeId(), "ParentPage1");
  357. childPage = WikiPageLocalServiceUtil.getPage(
  358. _node.getNodeId(), childPage.getTitle());
  359. Assert.assertEquals("ChildPage", childPage.getTitle());
  360. }
  361. @Test
  362. public void testDeleteTrashedPageWithExplicitTrashedRedirectPage()
  363. throws Exception {
  364. WikiPage[] pages = WikiTestUtil.addRenamedTrashedPage(
  365. _group.getGroupId(), _node.getNodeId(), true);
  366. WikiPage page = pages[0];
  367. WikiPage redirectPage = pages[1];
  368. WikiPageLocalServiceUtil.deletePage(page);
  369. try {
  370. WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());
  371. Assert.fail();
  372. }
  373. catch (NoSuchPageResourceException noSuchPageResourceException) {
  374. redirectPage = WikiPageLocalServiceUtil.getPage(
  375. redirectPage.getResourcePrimKey());
  376. Assert.assertNull(redirectPage.fetchRedirectPage());
  377. }
  378. }
  379. @Test(expected = NoSuchPageResourceException.class)
  380. public void testDeleteTrashedPageWithImplicitTrashedRedirectPage()
  381. throws Exception {
  382. WikiPage[] pages = WikiTestUtil.addRenamedTrashedPage(
  383. _group.getGroupId(), _node.getNodeId(), false);
  384. WikiPage page = pages[0];
  385. WikiPage redirectPage = pages[1];
  386. WikiPageLocalServiceUtil.deletePage(page);
  387. try {
  388. WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());
  389. Assert.fail();
  390. }
  391. catch (NoSuchPageResourceException noSuchPageResourceException) {
  392. WikiPageLocalServiceUtil.getPage(redirectPage.getResourcePrimKey());
  393. }
  394. }
  395. @Test
  396. public void testDeleteTrashedPageWithRestoredChildPage() throws Exception {
  397. WikiPage[] pages = WikiTestUtil.addTrashedPageWithChildPage(
  398. _group.getGroupId(), _node.getNodeId(), true);
  399. WikiPage parentPage = pages[0];
  400. WikiPage childPage = pages[1];
  401. WikiPageLocalServiceUtil.restorePageFromTrash(
  402. TestPropsValues.getUserId(), childPage);
  403. WikiPageLocalServiceUtil.deletePage(parentPage);
  404. try {
  405. WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());
  406. Assert.fail();
  407. }
  408. catch (NoSuchPageResourceException noSuchPageResourceException) {
  409. childPage = WikiPageLocalServiceUtil.getPage(
  410. childPage.getResourcePrimKey());
  411. Assert.assertNull(childPage.fetchParentPage());
  412. Assert.assertEquals(
  413. WorkflowConstants.STATUS_APPROVED, childPage.getStatus());
  414. }
  415. }
  416. @Test
  417. public void testDeleteTrashedPageWithRestoredRedirectPage()
  418. throws Exception {
  419. WikiPage[] pages = WikiTestUtil.addRenamedTrashedPage(
  420. _group.getGroupId(), _node.getNodeId(), true);
  421. WikiPage page = pages[0];
  422. WikiPage redirectPage = pages[1];
  423. WikiPageLocalServiceUtil.restorePageFromTrash(
  424. TestPropsValues.getUserId(), redirectPage);
  425. WikiPageLocalServiceUtil.deletePage(page);
  426. try {
  427. WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());
  428. Assert.fail();
  429. }
  430. catch (NoSuchPageResourceException noSuchPageResourceException) {
  431. redirectPage = WikiPageLocalServiceUtil.getPageByPageId(
  432. redirectPage.getPageId());
  433. Assert.assertNull(redirectPage.fetchRedirectPage());
  434. Assert.assertEquals(
  435. WorkflowConstants.STATUS_APPROVED, redirectPage.getStatus());
  436. }
  437. }
  438. @Test
  439. public void testDeleteTrashedParentPageWithExplicitTrashedChildPage()
  440. throws Exception {
  441. WikiPage[] pages = WikiTestUtil.addTrashedPageWithChildPage(
  442. _group.getGroupId(), _node.getNodeId(), true);
  443. WikiPage parentPage = pages[0];
  444. WikiPage childPage = pages[1];
  445. WikiPageLocalServiceUtil.deletePage(parentPage);
  446. try {
  447. WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());
  448. Assert.fail();
  449. }
  450. catch (NoSuchPageResourceException noSuchPageResourceException) {
  451. childPage = WikiPageLocalServiceUtil.getPageByPageId(
  452. childPage.getPageId());
  453. Assert.assertNull(childPage.fetchParentPage());
  454. }
  455. }
  456. @Test(expected = NoSuchPageResourceException.class)
  457. public void testDeleteTrashedParentPageWithImplicitTrashedChildPage()
  458. throws Exception {
  459. WikiPage[] pages = WikiTestUtil.addTrashedPageWithChildPage(
  460. _group.getGroupId(), _node.getNodeId(), false);
  461. WikiPage parentPage = pages[0];
  462. WikiPage childPage = pages[1];
  463. WikiPageLocalServiceUtil.deletePage(parentPage);
  464. try {
  465. WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());
  466. Assert.fail();
  467. }
  468. catch (NoSuchPageResourceException noSuchPageResourceException) {
  469. WikiPageLocalServiceUtil.getPage(childPage.getResourcePrimKey());
  470. }
  471. }
  472. @Test
  473. public void testGetPage() throws Exception {
  474. WikiPage page = WikiTestUtil.addPage(
  475. _group.getGroupId(), _node.getNodeId(), true);
  476. WikiPage retrievedPage = WikiPageLocalServiceUtil.getPage(
  477. page.getResourcePrimKey());
  478. Assert.assertEquals(retrievedPage, page);
  479. }
  480. @Test
  481. public void testGetRecentChangesWithANonrecentCreatedPage()
  482. throws Exception {
  483. ServiceContext serviceContext =
  484. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  485. WikiPage page = WikiTestUtil.addPage(
  486. TestPropsValues.getUserId(), _node.getNodeId(), "Page1",
  487. RandomTestUtil.randomString(), true, serviceContext);
  488. Calendar cal = CalendarFactoryUtil.getCalendar();
  489. cal.add(Calendar.WEEK_OF_YEAR, -2);
  490. Date date = cal.getTime();
  491. serviceContext.setCreateDate(date);
  492. serviceContext.setModifiedDate(date);
  493. WikiTestUtil.addPage(
  494. TestPropsValues.getUserId(), _node.getNodeId(), "Page2",
  495. RandomTestUtil.randomString(), true, serviceContext);
  496. List<WikiPage> recentPages = WikiPageLocalServiceUtil.getRecentChanges(
  497. _group.getGroupId(), _node.getNodeId(), QueryUtil.ALL_POS,
  498. QueryUtil.ALL_POS);
  499. Assert.assertEquals(recentPages.toString(), 1, recentPages.size());
  500. Assert.assertEquals(page, recentPages.get(0));
  501. }
  502. @Test
  503. public void testGetRecentChangesWithAnUpdatedNonrecentCreatedPage()
  504. throws Exception {
  505. ServiceContext serviceContext =
  506. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  507. WikiPage page1 = WikiTestUtil.addPage(
  508. TestPropsValues.getUserId(), _node.getNodeId(), "Page1",
  509. RandomTestUtil.randomString(), true, serviceContext);
  510. Calendar cal = CalendarFactoryUtil.getCalendar();
  511. cal.add(Calendar.WEEK_OF_YEAR, -2);
  512. Date date = cal.getTime();
  513. serviceContext.setCreateDate(date);
  514. serviceContext.setModifiedDate(date);
  515. WikiPage page2 = WikiTestUtil.addPage(
  516. TestPropsValues.getUserId(), _node.getNodeId(), "Page2",
  517. RandomTestUtil.randomString(), true, serviceContext);
  518. WikiPage updatedPage2 = WikiTestUtil.updatePage(page2);
  519. List<WikiPage> recentPages = WikiPageLocalServiceUtil.getRecentChanges(
  520. _group.getGroupId(), _node.getNodeId(), QueryUtil.ALL_POS,
  521. QueryUtil.ALL_POS);
  522. Assert.assertEquals(recentPages.toString(), 2, recentPages.size());
  523. Assert.assertEquals(updatedPage2, recentPages.get(0));
  524. Assert.assertEquals(page1, recentPages.get(1));
  525. }
  526. @Test
  527. public void testOrderByModifiedDate() throws Exception {
  528. ServiceContext serviceContext =
  529. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  530. WikiPage page1 = WikiTestUtil.addPage(
  531. TestPropsValues.getUserId(), _node.getNodeId(), "Page1",
  532. RandomTestUtil.randomString(), true, serviceContext);
  533. WikiPage page2 = WikiTestUtil.addPage(
  534. TestPropsValues.getUserId(), _node.getNodeId(), "Page2",
  535. RandomTestUtil.randomString(), true, serviceContext);
  536. List<WikiPage> recentPages = WikiPageLocalServiceUtil.getRecentChanges(
  537. _group.getGroupId(), _node.getNodeId(), QueryUtil.ALL_POS,
  538. QueryUtil.ALL_POS);
  539. Assert.assertEquals(recentPages.toString(), 2, recentPages.size());
  540. Assert.assertEquals(page2, recentPages.get(0));
  541. Assert.assertEquals(page1, recentPages.get(1));
  542. }
  543. @Test
  544. public void testOrderByModifiedDateWithModifiedPages() throws Exception {
  545. ServiceContext serviceContext =
  546. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  547. WikiPage page1 = WikiTestUtil.addPage(
  548. TestPropsValues.getUserId(), _node.getNodeId(), "Page1",
  549. RandomTestUtil.randomString(), true, serviceContext);
  550. WikiPage page2 = WikiTestUtil.addPage(
  551. TestPropsValues.getUserId(), _node.getNodeId(), "Page2",
  552. RandomTestUtil.randomString(), true, serviceContext);
  553. WikiPage updatedPage1 = WikiTestUtil.updatePage(page1);
  554. List<WikiPage> recentPages = WikiPageLocalServiceUtil.getRecentChanges(
  555. _group.getGroupId(), _node.getNodeId(), QueryUtil.ALL_POS,
  556. QueryUtil.ALL_POS);
  557. Assert.assertEquals(recentPages.toString(), 2, recentPages.size());
  558. Assert.assertEquals(updatedPage1, recentPages.get(0));
  559. Assert.assertEquals(page2, recentPages.get(1));
  560. }
  561. @Test
  562. public void testRenameDefaultVersionPageWithAssetCategories()
  563. throws Exception {
  564. ServiceContext serviceContext =
  565. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  566. AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(
  567. _group.getGroupId());
  568. AssetCategory assetCategory1 = AssetTestUtil.addCategory(
  569. _group.getGroupId(), assetVocabulary.getVocabularyId());
  570. AssetCategory assetCategory2 = AssetTestUtil.addCategory(
  571. _group.getGroupId(), assetVocabulary.getVocabularyId());
  572. long[] assetCategoryIds = new long[2];
  573. assetCategoryIds[0] = assetCategory1.getCategoryId();
  574. assetCategoryIds[1] = assetCategory2.getCategoryId();
  575. serviceContext.setAssetCategoryIds(assetCategoryIds);
  576. WikiPage page = WikiTestUtil.addPage(
  577. TestPropsValues.getUserId(), _node.getNodeId(),
  578. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  579. serviceContext);
  580. serviceContext = ServiceContextTestUtil.getServiceContext(
  581. _group.getGroupId());
  582. WikiPageLocalServiceUtil.renamePage(
  583. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  584. "New Title", true, serviceContext);
  585. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  586. _node.getNodeId(), "New Title");
  587. long[] finalAssetCategoryIds =
  588. AssetCategoryLocalServiceUtil.getCategoryIds(
  589. WikiPage.class.getName(), renamedPage.getResourcePrimKey());
  590. _assertArrayEquals(assetCategoryIds, finalAssetCategoryIds);
  591. }
  592. @Test
  593. public void testRenameDefaultVersionPageWithAssetTags() throws Exception {
  594. ServiceContext serviceContext =
  595. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  596. AssetTag assetTag1 = AssetTestUtil.addTag(_group.getGroupId());
  597. AssetTag assetTag2 = AssetTestUtil.addTag(_group.getGroupId());
  598. String[] assetTagNames = new String[2];
  599. assetTagNames[0] = assetTag1.getName();
  600. assetTagNames[1] = assetTag2.getName();
  601. serviceContext.setAssetTagNames(assetTagNames);
  602. WikiPage page = WikiTestUtil.addPage(
  603. TestPropsValues.getUserId(), _node.getNodeId(),
  604. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  605. serviceContext);
  606. serviceContext = ServiceContextTestUtil.getServiceContext(
  607. _group.getGroupId());
  608. WikiPageLocalServiceUtil.renamePage(
  609. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  610. "New Title", true, serviceContext);
  611. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  612. _node.getNodeId(), "New Title");
  613. Assert.assertNotNull(renamedPage);
  614. String[] finalAssetTagNames = AssetTagLocalServiceUtil.getTagNames(
  615. WikiPage.class.getName(), renamedPage.getResourcePrimKey());
  616. _assertArrayEquals(assetTagNames, finalAssetTagNames);
  617. }
  618. @Test
  619. public void testRenameNondefaultVersionPageWithAssetCategories()
  620. throws Exception {
  621. ServiceContext defaultVersionPageServiceContext =
  622. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  623. AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(
  624. _group.getGroupId());
  625. AssetCategory defaultVersionPageAssetCategory1 =
  626. AssetTestUtil.addCategory(
  627. _group.getGroupId(), assetVocabulary.getVocabularyId());
  628. AssetCategory defaultVersionPageAssetCategory2 =
  629. AssetTestUtil.addCategory(
  630. _group.getGroupId(), assetVocabulary.getVocabularyId());
  631. long[] defaultVersionPageAssetCategoryIds = new long[2];
  632. defaultVersionPageAssetCategoryIds[0] =
  633. defaultVersionPageAssetCategory1.getCategoryId();
  634. defaultVersionPageAssetCategoryIds[1] =
  635. defaultVersionPageAssetCategory2.getCategoryId();
  636. defaultVersionPageServiceContext.setAssetCategoryIds(
  637. defaultVersionPageAssetCategoryIds);
  638. WikiPage page = WikiTestUtil.addPage(
  639. TestPropsValues.getUserId(), _node.getNodeId(),
  640. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  641. defaultVersionPageServiceContext);
  642. ServiceContext nondefaultVersionPageServiceContext =
  643. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  644. AssetCategory assetCategory3 = AssetTestUtil.addCategory(
  645. _group.getGroupId(), assetVocabulary.getVocabularyId());
  646. AssetCategory assetCategory4 = AssetTestUtil.addCategory(
  647. _group.getGroupId(), assetVocabulary.getVocabularyId());
  648. long[] nondefaultVersionPageAssetCategoryIds = new long[2];
  649. nondefaultVersionPageAssetCategoryIds[0] =
  650. assetCategory3.getCategoryId();
  651. nondefaultVersionPageAssetCategoryIds[1] =
  652. assetCategory4.getCategoryId();
  653. nondefaultVersionPageServiceContext.setAssetCategoryIds(
  654. nondefaultVersionPageAssetCategoryIds);
  655. WikiTestUtil.updatePage(
  656. page, TestPropsValues.getUserId(), StringUtil.randomString(),
  657. nondefaultVersionPageServiceContext);
  658. ServiceContext renamePageServiceContext =
  659. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  660. WikiPageLocalServiceUtil.renamePage(
  661. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  662. "New Title", true, renamePageServiceContext);
  663. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  664. _node.getNodeId(), "New Title");
  665. long[] finalAssetCategoryIds =
  666. AssetCategoryLocalServiceUtil.getCategoryIds(
  667. WikiPage.class.getName(), renamedPage.getResourcePrimKey());
  668. _assertArrayEquals(
  669. nondefaultVersionPageAssetCategoryIds, finalAssetCategoryIds);
  670. }
  671. @Test
  672. public void testRenameNondefaultVersionPageWithAssetTags()
  673. throws Exception {
  674. ServiceContext defaultVersionPageServiceContext =
  675. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  676. AssetTag defaultVersionPageAssetTag1 = AssetTestUtil.addTag(
  677. _group.getGroupId());
  678. AssetTag defaultVersionPageAssetTag2 = AssetTestUtil.addTag(
  679. _group.getGroupId());
  680. String[] defaultVersionPageAssetTagNames = new String[2];
  681. defaultVersionPageAssetTagNames[0] =
  682. defaultVersionPageAssetTag1.getName();
  683. defaultVersionPageAssetTagNames[1] =
  684. defaultVersionPageAssetTag2.getName();
  685. defaultVersionPageServiceContext.setAssetTagNames(
  686. defaultVersionPageAssetTagNames);
  687. WikiPage page = WikiTestUtil.addPage(
  688. TestPropsValues.getUserId(), _node.getNodeId(),
  689. RandomTestUtil.randomString(), RandomTestUtil.randomString(), true,
  690. defaultVersionPageServiceContext);
  691. ServiceContext nondefaultVersionPageServiceContext =
  692. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  693. AssetTag nondefaultVersionPageAssetTag1 = AssetTestUtil.addTag(
  694. _group.getGroupId());
  695. AssetTag nondefaultVersionPageAssetTag2 = AssetTestUtil.addTag(
  696. _group.getGroupId());
  697. String[] nondefaultVersionPageAssetTagNames = new String[2];
  698. nondefaultVersionPageAssetTagNames[0] =
  699. nondefaultVersionPageAssetTag1.getName();
  700. nondefaultVersionPageAssetTagNames[1] =
  701. nondefaultVersionPageAssetTag2.getName();
  702. nondefaultVersionPageServiceContext.setAssetTagNames(
  703. nondefaultVersionPageAssetTagNames);
  704. WikiTestUtil.updatePage(
  705. page, TestPropsValues.getUserId(), StringUtil.randomString(),
  706. nondefaultVersionPageServiceContext);
  707. ServiceContext renamePageServiceContext =
  708. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  709. WikiPageLocalServiceUtil.renamePage(
  710. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  711. "New Title", true, renamePageServiceContext);
  712. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  713. _node.getNodeId(), "New Title");
  714. String[] finalAssetTagNames = AssetTagLocalServiceUtil.getTagNames(
  715. WikiPage.class.getName(), renamedPage.getResourcePrimKey());
  716. _assertArrayEquals(
  717. nondefaultVersionPageAssetTagNames, finalAssetTagNames);
  718. }
  719. @Test
  720. public void testRenamePage() throws Exception {
  721. WikiPage page = WikiTestUtil.addPage(
  722. _group.getGroupId(), _node.getNodeId(), true);
  723. ServiceContext serviceContext =
  724. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  725. WikiPageLocalServiceUtil.renamePage(
  726. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  727. "New Title", true, serviceContext);
  728. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  729. _node.getNodeId(), "New Title");
  730. Assert.assertNotNull(renamedPage);
  731. checkPopulatedServiceContext(serviceContext, renamedPage, false);
  732. }
  733. @Test(expected = DuplicatePageException.class)
  734. public void testRenamePageSameName() throws Exception {
  735. WikiPage page = WikiTestUtil.addPage(
  736. _group.getGroupId(), _node.getNodeId(), true);
  737. WikiPageLocalServiceUtil.renamePage(
  738. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  739. page.getTitle(), true,
  740. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  741. }
  742. @Test
  743. public void testRenamePageWithExpando() throws Exception {
  744. WikiPage page = WikiTestUtil.addPage(
  745. _group.getGroupId(), _node.getNodeId(), true);
  746. addExpandoValueToPage(page);
  747. ServiceContext serviceContext =
  748. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  749. WikiPageLocalServiceUtil.renamePage(
  750. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  751. "New Title", true, serviceContext);
  752. WikiPage renamedPage = WikiPageLocalServiceUtil.getPage(
  753. _node.getNodeId(), "New Title");
  754. Assert.assertNotNull(renamedPage);
  755. checkPopulatedServiceContext(serviceContext, renamedPage, true);
  756. }
  757. @Test
  758. public void testRenamePageWithNbspTitle() throws Exception {
  759. WikiPage page = WikiTestUtil.addPage(
  760. _group.getGroupId(), _node.getNodeId(), true);
  761. WikiPageLocalServiceUtil.renamePage(
  762. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  763. "New" + CharPool.NO_BREAK_SPACE + "Title", true,
  764. ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
  765. WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "New Title");
  766. }
  767. @Test
  768. public void testRenameRenamedPage() throws Exception {
  769. WikiTestUtil.addPage(
  770. TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(),
  771. "A", true);
  772. ServiceContext serviceContext =
  773. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  774. WikiPageLocalServiceUtil.renamePage(
  775. TestPropsValues.getUserId(), _node.getNodeId(), "A", "B", true,
  776. serviceContext);
  777. WikiPageLocalServiceUtil.renamePage(
  778. TestPropsValues.getUserId(), _node.getNodeId(), "A", "C", true,
  779. serviceContext);
  780. WikiPage pageA = WikiPageLocalServiceUtil.getPage(
  781. _node.getNodeId(), "A");
  782. WikiPage pageB = WikiPageLocalServiceUtil.getPage(
  783. _node.getNodeId(), "B");
  784. WikiPage pageC = WikiPageLocalServiceUtil.getPage(
  785. _node.getNodeId(), "C");
  786. Assert.assertEquals("C", pageA.getRedirectTitle());
  787. Assert.assertEquals(StringPool.BLANK, pageB.getRedirectTitle());
  788. Assert.assertEquals(StringPool.BLANK, pageC.getRedirectTitle());
  789. Assert.assertEquals("Renamed as C", pageA.getSummary());
  790. Assert.assertEquals("Summary", pageB.getSummary());
  791. Assert.assertEquals(StringPool.BLANK, pageC.getSummary());
  792. Assert.assertEquals("[[C]]", pageA.getContent());
  793. Assert.assertEquals("[[B]]", pageC.getContent());
  794. }
  795. @Test
  796. public void testRestorePageFromTrash() throws Exception {
  797. testRestorePageFromTrash(false);
  798. }
  799. @Test
  800. public void testRestorePageFromTrashWithExpando() throws Exception {
  801. testRestorePageFromTrash(true);
  802. }
  803. @Test
  804. public void testRevertPage() throws Exception {
  805. testRevertPage(false);
  806. }
  807. @Test
  808. public void testRevertPageWithExpando() throws Exception {
  809. testRevertPage(true);
  810. }
  811. protected void addExpandoValueToPage(WikiPage page) throws Exception {
  812. ExpandoValue value = ExpandoTestUtil.addValue(
  813. PortalUtil.getClassNameId(WikiPage.class), page.getPrimaryKey(),
  814. RandomTestUtil.randomString());
  815. ExpandoBridge expandoBridge = page.getExpandoBridge();
  816. ExpandoColumn column = value.getColumn();
  817. expandoBridge.addAttribute(
  818. column.getName(), ExpandoColumnConstants.STRING, value.getString());
  819. }
  820. protected void checkPopulatedServiceContext(
  821. ServiceContext serviceContext, WikiPage page,
  822. boolean hasExpandoValues)
  823. throws Exception {
  824. long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(
  825. WikiPage.class.getName(), page.getResourcePrimKey());
  826. _assertArrayEquals(
  827. serviceContext.getAssetCategoryIds(), assetCategoryIds);
  828. AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
  829. WikiPage.class.getName(), page.getResourcePrimKey());
  830. List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(
  831. assetEntry.getEntryId());
  832. long[] assetLinkEntryIds = ListUtil.toLongArray(
  833. assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);
  834. _assertArrayEquals(
  835. serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds);
  836. String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(
  837. WikiPage.class.getName(), page.getResourcePrimKey());
  838. _assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames);
  839. if (hasExpandoValues) {
  840. ExpandoBridge expandoBridge = page.getExpandoBridge();
  841. AssertUtils.assertEquals(
  842. expandoBridge.getAttributes(),
  843. serviceContext.getExpandoBridgeAttributes());
  844. }
  845. }
  846. protected AssetVocabulary getRequiredAssetVocabulary()
  847. throws PortalException {
  848. AssetVocabulary assetVocabulary =
  849. AssetVocabularyLocalServiceUtil.addDefaultVocabulary(
  850. _group.getGroupId());
  851. long classNameId = PortalUtil.getClassNameId(WikiPage.class.getName());
  852. assetVocabulary.setSettings(
  853. StringBundler.concat(
  854. "multiValued=true\nrequiredClassNameIds=", classNameId,
  855. ":-1\nselectedClassNameIds=", classNameId, ":-1"));
  856. AssetVocabularyLocalServiceUtil.updateAssetVocabulary(assetVocabulary);
  857. return assetVocabulary;
  858. }
  859. protected void testChangeParent(boolean hasExpandoValues) throws Exception {
  860. WikiPage page = WikiTestUtil.addPage(
  861. _group.getGroupId(), _node.getNodeId(), true);
  862. if (hasExpandoValues) {
  863. addExpandoValueToPage(page);
  864. }
  865. WikiPage parentPage = WikiTestUtil.addPage(
  866. _group.getGroupId(), _node.getNodeId(), true);
  867. ServiceContext serviceContext =
  868. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  869. WikiPageLocalServiceUtil.changeParent(
  870. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle(),
  871. parentPage.getTitle(), serviceContext);
  872. WikiPage retrievedPage = WikiPageLocalServiceUtil.getPage(
  873. page.getResourcePrimKey());
  874. checkPopulatedServiceContext(
  875. serviceContext, retrievedPage, hasExpandoValues);
  876. }
  877. protected void testRestorePageFromTrash(boolean hasExpandoValues)
  878. throws Exception {
  879. WikiPage page = WikiTestUtil.addPage(
  880. _group.getGroupId(), _node.getNodeId(), true);
  881. if (hasExpandoValues) {
  882. addExpandoValueToPage(page);
  883. }
  884. page = WikiPageLocalServiceUtil.movePageToTrash(
  885. TestPropsValues.getUserId(), _node.getNodeId(), page.getTitle());
  886. WikiPageLocalServiceUtil.restorePageFromTrash(
  887. TestPropsValues.getUserId(), page);
  888. WikiPage restoredPage = WikiPageLocalServiceUtil.getPage(
  889. page.getResourcePrimKey());
  890. Assert.assertNotNull(restoredPage);
  891. if (hasExpandoValues) {
  892. ExpandoBridge expandoBridge = page.getExpandoBridge();
  893. ExpandoBridge restoredExpandoBridge =
  894. restoredPage.getExpandoBridge();
  895. AssertUtils.assertEquals(
  896. restoredExpandoBridge.getAttributes(),
  897. expandoBridge.getAttributes());
  898. }
  899. }
  900. protected void testRevertPage(boolean hasExpandoValues) throws Exception {
  901. ServiceContext serviceContext =
  902. ServiceContextTestUtil.getServiceContext(_group.getGroupId());
  903. String originalContent = RandomTestUtil.randomString();
  904. WikiPage originalPage = WikiTestUtil.addPage(
  905. TestPropsValues.getUserId(), _node.getNodeId(),
  906. RandomTestUtil.randomString(), originalContent, true,
  907. serviceContext);
  908. if (hasExpandoValues) {
  909. addExpandoValueToPage(originalPage);
  910. }
  911. WikiPage updatedPage1 = WikiTestUtil.updatePage(
  912. originalPage, TestPropsValues.getUserId(),
  913. originalContent + "\nAdded second line.", serviceContext);
  914. Assert.assertNotEquals(originalContent, updatedPage1.getContent());
  915. WikiPage updatedPage2 = WikiTestUtil.updatePage(
  916. updatedPage1, TestPropsValues.getUserId(),
  917. updatedPage1.getContent() + "\nAdded third line.", serviceContext);
  918. Assert.assertNotEquals(originalContent, updatedPage2.getContent());
  919. WikiPage revertedPage = WikiPageLocalServiceUtil.revertPage(
  920. TestPropsValues.getUserId(), _node.getNodeId(),
  921. updatedPage2.getTitle(), originalPage.getVersion(), serviceContext);
  922. Assert.assertEquals(revertedPage.getContent(), originalContent);
  923. checkPopulatedServiceContext(
  924. serviceContext, revertedPage, hasExpandoValues);
  925. }
  926. private void _assertArrayEquals(long[] expectedArray, long[] actualArray) {
  927. Arrays.sort(expectedArray);
  928. Arrays.sort(actualArray);
  929. Assert.assertArrayEquals(expectedArray, actualArray);
  930. }
  931. private void _assertArrayEquals(
  932. String[] expectedArray, String[] actualArray) {
  933. Arrays.sort(expectedArray);
  934. Arrays.sort(actualArray);
  935. Assert.assertArrayEquals(expectedArray, actualArray);
  936. }
  937. private static final Log _log = LogFactoryUtil.getLog(
  938. WikiPageLocalServiceTest.class);
  939. @DeleteAfterTestRun
  940. private Group _group;
  941. private WikiNode _node;
  942. private static class AssetCategoryTestException extends PortalException {
  943. }
  944. }