PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/liferay/liferay-portal
Java | 1010 lines | 723 code | 271 blank | 16 comment | 2 complexity | 3b07678a5275095360bb0184837b7238 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.persistence.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
  17. import com.liferay.portal.kernel.dao.orm.DynamicQuery;
  18. import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
  19. import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
  20. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  21. import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
  22. import com.liferay.portal.kernel.dao.orm.Session;
  23. import com.liferay.portal.kernel.test.AssertUtils;
  24. import com.liferay.portal.kernel.test.ReflectionTestUtil;
  25. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  26. import com.liferay.portal.kernel.test.util.RandomTestUtil;
  27. import com.liferay.portal.kernel.transaction.Propagation;
  28. import com.liferay.portal.kernel.util.IntegerWrapper;
  29. import com.liferay.portal.kernel.util.OrderByComparator;
  30. import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
  31. import com.liferay.portal.kernel.util.Time;
  32. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  33. import com.liferay.portal.test.rule.PersistenceTestRule;
  34. import com.liferay.portal.test.rule.TransactionalTestRule;
  35. import com.liferay.wiki.exception.NoSuchPageException;
  36. import com.liferay.wiki.model.WikiPage;
  37. import com.liferay.wiki.service.WikiPageLocalServiceUtil;
  38. import com.liferay.wiki.service.persistence.WikiPagePersistence;
  39. import com.liferay.wiki.service.persistence.WikiPageUtil;
  40. import java.io.Serializable;
  41. import java.util.ArrayList;
  42. import java.util.HashSet;
  43. import java.util.Iterator;
  44. import java.util.List;
  45. import java.util.Map;
  46. import java.util.Set;
  47. import org.junit.After;
  48. import org.junit.Assert;
  49. import org.junit.Before;
  50. import org.junit.ClassRule;
  51. import org.junit.Rule;
  52. import org.junit.Test;
  53. import org.junit.runner.RunWith;
  54. /**
  55. * @generated
  56. */
  57. @RunWith(Arquillian.class)
  58. public class WikiPagePersistenceTest {
  59. @ClassRule
  60. @Rule
  61. public static final AggregateTestRule aggregateTestRule =
  62. new AggregateTestRule(
  63. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  64. new TransactionalTestRule(
  65. Propagation.REQUIRED, "com.liferay.wiki.service"));
  66. @Before
  67. public void setUp() {
  68. _persistence = WikiPageUtil.getPersistence();
  69. Class<?> clazz = _persistence.getClass();
  70. _dynamicQueryClassLoader = clazz.getClassLoader();
  71. }
  72. @After
  73. public void tearDown() throws Exception {
  74. Iterator<WikiPage> iterator = _wikiPages.iterator();
  75. while (iterator.hasNext()) {
  76. _persistence.remove(iterator.next());
  77. iterator.remove();
  78. }
  79. }
  80. @Test
  81. public void testCreate() throws Exception {
  82. long pk = RandomTestUtil.nextLong();
  83. WikiPage wikiPage = _persistence.create(pk);
  84. Assert.assertNotNull(wikiPage);
  85. Assert.assertEquals(wikiPage.getPrimaryKey(), pk);
  86. }
  87. @Test
  88. public void testRemove() throws Exception {
  89. WikiPage newWikiPage = addWikiPage();
  90. _persistence.remove(newWikiPage);
  91. WikiPage existingWikiPage = _persistence.fetchByPrimaryKey(
  92. newWikiPage.getPrimaryKey());
  93. Assert.assertNull(existingWikiPage);
  94. }
  95. @Test
  96. public void testUpdateNew() throws Exception {
  97. addWikiPage();
  98. }
  99. @Test
  100. public void testUpdateExisting() throws Exception {
  101. long pk = RandomTestUtil.nextLong();
  102. WikiPage newWikiPage = _persistence.create(pk);
  103. newWikiPage.setMvccVersion(RandomTestUtil.nextLong());
  104. newWikiPage.setUuid(RandomTestUtil.randomString());
  105. newWikiPage.setResourcePrimKey(RandomTestUtil.nextLong());
  106. newWikiPage.setGroupId(RandomTestUtil.nextLong());
  107. newWikiPage.setCompanyId(RandomTestUtil.nextLong());
  108. newWikiPage.setUserId(RandomTestUtil.nextLong());
  109. newWikiPage.setUserName(RandomTestUtil.randomString());
  110. newWikiPage.setCreateDate(RandomTestUtil.nextDate());
  111. newWikiPage.setModifiedDate(RandomTestUtil.nextDate());
  112. newWikiPage.setExternalReferenceCode(RandomTestUtil.randomString());
  113. newWikiPage.setNodeId(RandomTestUtil.nextLong());
  114. newWikiPage.setTitle(RandomTestUtil.randomString());
  115. newWikiPage.setVersion(RandomTestUtil.nextDouble());
  116. newWikiPage.setMinorEdit(RandomTestUtil.randomBoolean());
  117. newWikiPage.setContent(RandomTestUtil.randomString());
  118. newWikiPage.setSummary(RandomTestUtil.randomString());
  119. newWikiPage.setFormat(RandomTestUtil.randomString());
  120. newWikiPage.setHead(RandomTestUtil.randomBoolean());
  121. newWikiPage.setParentTitle(RandomTestUtil.randomString());
  122. newWikiPage.setRedirectTitle(RandomTestUtil.randomString());
  123. newWikiPage.setLastPublishDate(RandomTestUtil.nextDate());
  124. newWikiPage.setStatus(RandomTestUtil.nextInt());
  125. newWikiPage.setStatusByUserId(RandomTestUtil.nextLong());
  126. newWikiPage.setStatusByUserName(RandomTestUtil.randomString());
  127. newWikiPage.setStatusDate(RandomTestUtil.nextDate());
  128. _wikiPages.add(_persistence.update(newWikiPage));
  129. WikiPage existingWikiPage = _persistence.findByPrimaryKey(
  130. newWikiPage.getPrimaryKey());
  131. Assert.assertEquals(
  132. existingWikiPage.getMvccVersion(), newWikiPage.getMvccVersion());
  133. Assert.assertEquals(existingWikiPage.getUuid(), newWikiPage.getUuid());
  134. Assert.assertEquals(
  135. existingWikiPage.getPageId(), newWikiPage.getPageId());
  136. Assert.assertEquals(
  137. existingWikiPage.getResourcePrimKey(),
  138. newWikiPage.getResourcePrimKey());
  139. Assert.assertEquals(
  140. existingWikiPage.getGroupId(), newWikiPage.getGroupId());
  141. Assert.assertEquals(
  142. existingWikiPage.getCompanyId(), newWikiPage.getCompanyId());
  143. Assert.assertEquals(
  144. existingWikiPage.getUserId(), newWikiPage.getUserId());
  145. Assert.assertEquals(
  146. existingWikiPage.getUserName(), newWikiPage.getUserName());
  147. Assert.assertEquals(
  148. Time.getShortTimestamp(existingWikiPage.getCreateDate()),
  149. Time.getShortTimestamp(newWikiPage.getCreateDate()));
  150. Assert.assertEquals(
  151. Time.getShortTimestamp(existingWikiPage.getModifiedDate()),
  152. Time.getShortTimestamp(newWikiPage.getModifiedDate()));
  153. Assert.assertEquals(
  154. existingWikiPage.getExternalReferenceCode(),
  155. newWikiPage.getExternalReferenceCode());
  156. Assert.assertEquals(
  157. existingWikiPage.getNodeId(), newWikiPage.getNodeId());
  158. Assert.assertEquals(
  159. existingWikiPage.getTitle(), newWikiPage.getTitle());
  160. AssertUtils.assertEquals(
  161. existingWikiPage.getVersion(), newWikiPage.getVersion());
  162. Assert.assertEquals(
  163. existingWikiPage.isMinorEdit(), newWikiPage.isMinorEdit());
  164. Assert.assertEquals(
  165. existingWikiPage.getContent(), newWikiPage.getContent());
  166. Assert.assertEquals(
  167. existingWikiPage.getSummary(), newWikiPage.getSummary());
  168. Assert.assertEquals(
  169. existingWikiPage.getFormat(), newWikiPage.getFormat());
  170. Assert.assertEquals(existingWikiPage.isHead(), newWikiPage.isHead());
  171. Assert.assertEquals(
  172. existingWikiPage.getParentTitle(), newWikiPage.getParentTitle());
  173. Assert.assertEquals(
  174. existingWikiPage.getRedirectTitle(),
  175. newWikiPage.getRedirectTitle());
  176. Assert.assertEquals(
  177. Time.getShortTimestamp(existingWikiPage.getLastPublishDate()),
  178. Time.getShortTimestamp(newWikiPage.getLastPublishDate()));
  179. Assert.assertEquals(
  180. existingWikiPage.getStatus(), newWikiPage.getStatus());
  181. Assert.assertEquals(
  182. existingWikiPage.getStatusByUserId(),
  183. newWikiPage.getStatusByUserId());
  184. Assert.assertEquals(
  185. existingWikiPage.getStatusByUserName(),
  186. newWikiPage.getStatusByUserName());
  187. Assert.assertEquals(
  188. Time.getShortTimestamp(existingWikiPage.getStatusDate()),
  189. Time.getShortTimestamp(newWikiPage.getStatusDate()));
  190. }
  191. @Test
  192. public void testCountByResourcePrimKey() throws Exception {
  193. _persistence.countByResourcePrimKey(RandomTestUtil.nextLong());
  194. _persistence.countByResourcePrimKey(0L);
  195. }
  196. @Test
  197. public void testCountByUuid() throws Exception {
  198. _persistence.countByUuid("");
  199. _persistence.countByUuid("null");
  200. _persistence.countByUuid((String)null);
  201. }
  202. @Test
  203. public void testCountByUUID_G() throws Exception {
  204. _persistence.countByUUID_G("", RandomTestUtil.nextLong());
  205. _persistence.countByUUID_G("null", 0L);
  206. _persistence.countByUUID_G((String)null, 0L);
  207. }
  208. @Test
  209. public void testCountByUuid_C() throws Exception {
  210. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  211. _persistence.countByUuid_C("null", 0L);
  212. _persistence.countByUuid_C((String)null, 0L);
  213. }
  214. @Test
  215. public void testCountByCompanyId() throws Exception {
  216. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  217. _persistence.countByCompanyId(0L);
  218. }
  219. @Test
  220. public void testCountByNodeId() throws Exception {
  221. _persistence.countByNodeId(RandomTestUtil.nextLong());
  222. _persistence.countByNodeId(0L);
  223. }
  224. @Test
  225. public void testCountByFormat() throws Exception {
  226. _persistence.countByFormat("");
  227. _persistence.countByFormat("null");
  228. _persistence.countByFormat((String)null);
  229. }
  230. @Test
  231. public void testCountByR_N() throws Exception {
  232. _persistence.countByR_N(
  233. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  234. _persistence.countByR_N(0L, 0L);
  235. }
  236. @Test
  237. public void testCountByR_S() throws Exception {
  238. _persistence.countByR_S(
  239. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  240. _persistence.countByR_S(0L, 0);
  241. }
  242. @Test
  243. public void testCountByG_ERC() throws Exception {
  244. _persistence.countByG_ERC(RandomTestUtil.nextLong(), "");
  245. _persistence.countByG_ERC(0L, "null");
  246. _persistence.countByG_ERC(0L, (String)null);
  247. }
  248. @Test
  249. public void testCountByN_T() throws Exception {
  250. _persistence.countByN_T(RandomTestUtil.nextLong(), "");
  251. _persistence.countByN_T(0L, "null");
  252. _persistence.countByN_T(0L, (String)null);
  253. }
  254. @Test
  255. public void testCountByN_H() throws Exception {
  256. _persistence.countByN_H(
  257. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  258. _persistence.countByN_H(0L, RandomTestUtil.randomBoolean());
  259. }
  260. @Test
  261. public void testCountByN_P() throws Exception {
  262. _persistence.countByN_P(RandomTestUtil.nextLong(), "");
  263. _persistence.countByN_P(0L, "null");
  264. _persistence.countByN_P(0L, (String)null);
  265. }
  266. @Test
  267. public void testCountByN_R() throws Exception {
  268. _persistence.countByN_R(RandomTestUtil.nextLong(), "");
  269. _persistence.countByN_R(0L, "null");
  270. _persistence.countByN_R(0L, (String)null);
  271. }
  272. @Test
  273. public void testCountByN_S() throws Exception {
  274. _persistence.countByN_S(
  275. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  276. _persistence.countByN_S(0L, 0);
  277. }
  278. @Test
  279. public void testCountByR_N_V() throws Exception {
  280. _persistence.countByR_N_V(
  281. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  282. RandomTestUtil.nextDouble());
  283. _persistence.countByR_N_V(0L, 0L, 0D);
  284. }
  285. @Test
  286. public void testCountByR_N_H() throws Exception {
  287. _persistence.countByR_N_H(
  288. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  289. RandomTestUtil.randomBoolean());
  290. _persistence.countByR_N_H(0L, 0L, RandomTestUtil.randomBoolean());
  291. }
  292. @Test
  293. public void testCountByR_N_S() throws Exception {
  294. _persistence.countByR_N_S(
  295. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  296. RandomTestUtil.nextInt());
  297. _persistence.countByR_N_S(0L, 0L, 0);
  298. }
  299. @Test
  300. public void testCountByG_ERC_V() throws Exception {
  301. _persistence.countByG_ERC_V(
  302. RandomTestUtil.nextLong(), "", RandomTestUtil.nextDouble());
  303. _persistence.countByG_ERC_V(0L, "null", 0D);
  304. _persistence.countByG_ERC_V(0L, (String)null, 0D);
  305. }
  306. @Test
  307. public void testCountByG_N_H() throws Exception {
  308. _persistence.countByG_N_H(
  309. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  310. RandomTestUtil.randomBoolean());
  311. _persistence.countByG_N_H(0L, 0L, RandomTestUtil.randomBoolean());
  312. }
  313. @Test
  314. public void testCountByG_N_S() throws Exception {
  315. _persistence.countByG_N_S(
  316. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  317. RandomTestUtil.nextInt());
  318. _persistence.countByG_N_S(0L, 0L, 0);
  319. }
  320. @Test
  321. public void testCountByU_N_S() throws Exception {
  322. _persistence.countByU_N_S(
  323. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  324. RandomTestUtil.nextInt());
  325. _persistence.countByU_N_S(0L, 0L, 0);
  326. }
  327. @Test
  328. public void testCountByN_T_V() throws Exception {
  329. _persistence.countByN_T_V(
  330. RandomTestUtil.nextLong(), "", RandomTestUtil.nextDouble());
  331. _persistence.countByN_T_V(0L, "null", 0D);
  332. _persistence.countByN_T_V(0L, (String)null, 0D);
  333. }
  334. @Test
  335. public void testCountByN_T_H() throws Exception {
  336. _persistence.countByN_T_H(
  337. RandomTestUtil.nextLong(), "", RandomTestUtil.randomBoolean());
  338. _persistence.countByN_T_H(0L, "null", RandomTestUtil.randomBoolean());
  339. _persistence.countByN_T_H(
  340. 0L, (String)null, RandomTestUtil.randomBoolean());
  341. }
  342. @Test
  343. public void testCountByN_T_S() throws Exception {
  344. _persistence.countByN_T_S(
  345. RandomTestUtil.nextLong(), "", RandomTestUtil.nextInt());
  346. _persistence.countByN_T_S(0L, "null", 0);
  347. _persistence.countByN_T_S(0L, (String)null, 0);
  348. }
  349. @Test
  350. public void testCountByN_H_P() throws Exception {
  351. _persistence.countByN_H_P(
  352. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "");
  353. _persistence.countByN_H_P(0L, RandomTestUtil.randomBoolean(), "null");
  354. _persistence.countByN_H_P(
  355. 0L, RandomTestUtil.randomBoolean(), (String)null);
  356. }
  357. @Test
  358. public void testCountByN_H_R() throws Exception {
  359. _persistence.countByN_H_R(
  360. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "");
  361. _persistence.countByN_H_R(0L, RandomTestUtil.randomBoolean(), "null");
  362. _persistence.countByN_H_R(
  363. 0L, RandomTestUtil.randomBoolean(), (String)null);
  364. }
  365. @Test
  366. public void testCountByN_H_S() throws Exception {
  367. _persistence.countByN_H_S(
  368. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  369. RandomTestUtil.nextInt());
  370. _persistence.countByN_H_S(0L, RandomTestUtil.randomBoolean(), 0);
  371. }
  372. @Test
  373. public void testCountByN_H_NotS() throws Exception {
  374. _persistence.countByN_H_NotS(
  375. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  376. RandomTestUtil.nextInt());
  377. _persistence.countByN_H_NotS(0L, RandomTestUtil.randomBoolean(), 0);
  378. }
  379. @Test
  380. public void testCountByG_U_N_S() throws Exception {
  381. _persistence.countByG_U_N_S(
  382. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  383. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  384. _persistence.countByG_U_N_S(0L, 0L, 0L, 0);
  385. }
  386. @Test
  387. public void testCountByG_N_T_H() throws Exception {
  388. _persistence.countByG_N_T_H(
  389. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), "",
  390. RandomTestUtil.randomBoolean());
  391. _persistence.countByG_N_T_H(
  392. 0L, 0L, "null", RandomTestUtil.randomBoolean());
  393. _persistence.countByG_N_T_H(
  394. 0L, 0L, (String)null, RandomTestUtil.randomBoolean());
  395. }
  396. @Test
  397. public void testCountByG_N_H_S() throws Exception {
  398. _persistence.countByG_N_H_S(
  399. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  400. RandomTestUtil.randomBoolean(), RandomTestUtil.nextInt());
  401. _persistence.countByG_N_H_S(0L, 0L, RandomTestUtil.randomBoolean(), 0);
  402. }
  403. @Test
  404. public void testCountByN_H_P_S() throws Exception {
  405. _persistence.countByN_H_P_S(
  406. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "",
  407. RandomTestUtil.nextInt());
  408. _persistence.countByN_H_P_S(
  409. 0L, RandomTestUtil.randomBoolean(), "null", 0);
  410. _persistence.countByN_H_P_S(
  411. 0L, RandomTestUtil.randomBoolean(), (String)null, 0);
  412. }
  413. @Test
  414. public void testCountByN_H_P_NotS() throws Exception {
  415. _persistence.countByN_H_P_NotS(
  416. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "",
  417. RandomTestUtil.nextInt());
  418. _persistence.countByN_H_P_NotS(
  419. 0L, RandomTestUtil.randomBoolean(), "null", 0);
  420. _persistence.countByN_H_P_NotS(
  421. 0L, RandomTestUtil.randomBoolean(), (String)null, 0);
  422. }
  423. @Test
  424. public void testCountByN_H_R_S() throws Exception {
  425. _persistence.countByN_H_R_S(
  426. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "",
  427. RandomTestUtil.nextInt());
  428. _persistence.countByN_H_R_S(
  429. 0L, RandomTestUtil.randomBoolean(), "null", 0);
  430. _persistence.countByN_H_R_S(
  431. 0L, RandomTestUtil.randomBoolean(), (String)null, 0);
  432. }
  433. @Test
  434. public void testCountByN_H_R_NotS() throws Exception {
  435. _persistence.countByN_H_R_NotS(
  436. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "",
  437. RandomTestUtil.nextInt());
  438. _persistence.countByN_H_R_NotS(
  439. 0L, RandomTestUtil.randomBoolean(), "null", 0);
  440. _persistence.countByN_H_R_NotS(
  441. 0L, RandomTestUtil.randomBoolean(), (String)null, 0);
  442. }
  443. @Test
  444. public void testCountByG_N_H_P_S() throws Exception {
  445. _persistence.countByG_N_H_P_S(
  446. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  447. RandomTestUtil.randomBoolean(), "", RandomTestUtil.nextInt());
  448. _persistence.countByG_N_H_P_S(
  449. 0L, 0L, RandomTestUtil.randomBoolean(), "null", 0);
  450. _persistence.countByG_N_H_P_S(
  451. 0L, 0L, RandomTestUtil.randomBoolean(), (String)null, 0);
  452. }
  453. @Test
  454. public void testFindByPrimaryKeyExisting() throws Exception {
  455. WikiPage newWikiPage = addWikiPage();
  456. WikiPage existingWikiPage = _persistence.findByPrimaryKey(
  457. newWikiPage.getPrimaryKey());
  458. Assert.assertEquals(existingWikiPage, newWikiPage);
  459. }
  460. @Test(expected = NoSuchPageException.class)
  461. public void testFindByPrimaryKeyMissing() throws Exception {
  462. long pk = RandomTestUtil.nextLong();
  463. _persistence.findByPrimaryKey(pk);
  464. }
  465. @Test
  466. public void testFindAll() throws Exception {
  467. _persistence.findAll(
  468. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  469. }
  470. protected OrderByComparator<WikiPage> getOrderByComparator() {
  471. return OrderByComparatorFactoryUtil.create(
  472. "WikiPage", "mvccVersion", true, "uuid", true, "pageId", true,
  473. "resourcePrimKey", true, "groupId", true, "companyId", true,
  474. "userId", true, "userName", true, "createDate", true,
  475. "modifiedDate", true, "externalReferenceCode", true, "nodeId", true,
  476. "title", true, "version", true, "minorEdit", true, "summary", true,
  477. "format", true, "head", true, "parentTitle", true, "redirectTitle",
  478. true, "lastPublishDate", true, "status", true, "statusByUserId",
  479. true, "statusByUserName", true, "statusDate", true);
  480. }
  481. @Test
  482. public void testFetchByPrimaryKeyExisting() throws Exception {
  483. WikiPage newWikiPage = addWikiPage();
  484. WikiPage existingWikiPage = _persistence.fetchByPrimaryKey(
  485. newWikiPage.getPrimaryKey());
  486. Assert.assertEquals(existingWikiPage, newWikiPage);
  487. }
  488. @Test
  489. public void testFetchByPrimaryKeyMissing() throws Exception {
  490. long pk = RandomTestUtil.nextLong();
  491. WikiPage missingWikiPage = _persistence.fetchByPrimaryKey(pk);
  492. Assert.assertNull(missingWikiPage);
  493. }
  494. @Test
  495. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  496. throws Exception {
  497. WikiPage newWikiPage1 = addWikiPage();
  498. WikiPage newWikiPage2 = addWikiPage();
  499. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  500. primaryKeys.add(newWikiPage1.getPrimaryKey());
  501. primaryKeys.add(newWikiPage2.getPrimaryKey());
  502. Map<Serializable, WikiPage> wikiPages = _persistence.fetchByPrimaryKeys(
  503. primaryKeys);
  504. Assert.assertEquals(2, wikiPages.size());
  505. Assert.assertEquals(
  506. newWikiPage1, wikiPages.get(newWikiPage1.getPrimaryKey()));
  507. Assert.assertEquals(
  508. newWikiPage2, wikiPages.get(newWikiPage2.getPrimaryKey()));
  509. }
  510. @Test
  511. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  512. throws Exception {
  513. long pk1 = RandomTestUtil.nextLong();
  514. long pk2 = RandomTestUtil.nextLong();
  515. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  516. primaryKeys.add(pk1);
  517. primaryKeys.add(pk2);
  518. Map<Serializable, WikiPage> wikiPages = _persistence.fetchByPrimaryKeys(
  519. primaryKeys);
  520. Assert.assertTrue(wikiPages.isEmpty());
  521. }
  522. @Test
  523. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  524. throws Exception {
  525. WikiPage newWikiPage = addWikiPage();
  526. long pk = RandomTestUtil.nextLong();
  527. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  528. primaryKeys.add(newWikiPage.getPrimaryKey());
  529. primaryKeys.add(pk);
  530. Map<Serializable, WikiPage> wikiPages = _persistence.fetchByPrimaryKeys(
  531. primaryKeys);
  532. Assert.assertEquals(1, wikiPages.size());
  533. Assert.assertEquals(
  534. newWikiPage, wikiPages.get(newWikiPage.getPrimaryKey()));
  535. }
  536. @Test
  537. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  538. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  539. Map<Serializable, WikiPage> wikiPages = _persistence.fetchByPrimaryKeys(
  540. primaryKeys);
  541. Assert.assertTrue(wikiPages.isEmpty());
  542. }
  543. @Test
  544. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  545. WikiPage newWikiPage = addWikiPage();
  546. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  547. primaryKeys.add(newWikiPage.getPrimaryKey());
  548. Map<Serializable, WikiPage> wikiPages = _persistence.fetchByPrimaryKeys(
  549. primaryKeys);
  550. Assert.assertEquals(1, wikiPages.size());
  551. Assert.assertEquals(
  552. newWikiPage, wikiPages.get(newWikiPage.getPrimaryKey()));
  553. }
  554. @Test
  555. public void testActionableDynamicQuery() throws Exception {
  556. final IntegerWrapper count = new IntegerWrapper();
  557. ActionableDynamicQuery actionableDynamicQuery =
  558. WikiPageLocalServiceUtil.getActionableDynamicQuery();
  559. actionableDynamicQuery.setPerformActionMethod(
  560. new ActionableDynamicQuery.PerformActionMethod<WikiPage>() {
  561. @Override
  562. public void performAction(WikiPage wikiPage) {
  563. Assert.assertNotNull(wikiPage);
  564. count.increment();
  565. }
  566. });
  567. actionableDynamicQuery.performActions();
  568. Assert.assertEquals(count.getValue(), _persistence.countAll());
  569. }
  570. @Test
  571. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  572. WikiPage newWikiPage = addWikiPage();
  573. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  574. WikiPage.class, _dynamicQueryClassLoader);
  575. dynamicQuery.add(
  576. RestrictionsFactoryUtil.eq("pageId", newWikiPage.getPageId()));
  577. List<WikiPage> result = _persistence.findWithDynamicQuery(dynamicQuery);
  578. Assert.assertEquals(1, result.size());
  579. WikiPage existingWikiPage = result.get(0);
  580. Assert.assertEquals(existingWikiPage, newWikiPage);
  581. }
  582. @Test
  583. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  584. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  585. WikiPage.class, _dynamicQueryClassLoader);
  586. dynamicQuery.add(
  587. RestrictionsFactoryUtil.eq("pageId", RandomTestUtil.nextLong()));
  588. List<WikiPage> result = _persistence.findWithDynamicQuery(dynamicQuery);
  589. Assert.assertEquals(0, result.size());
  590. }
  591. @Test
  592. public void testDynamicQueryByProjectionExisting() throws Exception {
  593. WikiPage newWikiPage = addWikiPage();
  594. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  595. WikiPage.class, _dynamicQueryClassLoader);
  596. dynamicQuery.setProjection(ProjectionFactoryUtil.property("pageId"));
  597. Object newPageId = newWikiPage.getPageId();
  598. dynamicQuery.add(
  599. RestrictionsFactoryUtil.in("pageId", new Object[] {newPageId}));
  600. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  601. Assert.assertEquals(1, result.size());
  602. Object existingPageId = result.get(0);
  603. Assert.assertEquals(existingPageId, newPageId);
  604. }
  605. @Test
  606. public void testDynamicQueryByProjectionMissing() throws Exception {
  607. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  608. WikiPage.class, _dynamicQueryClassLoader);
  609. dynamicQuery.setProjection(ProjectionFactoryUtil.property("pageId"));
  610. dynamicQuery.add(
  611. RestrictionsFactoryUtil.in(
  612. "pageId", new Object[] {RandomTestUtil.nextLong()}));
  613. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  614. Assert.assertEquals(0, result.size());
  615. }
  616. @Test
  617. public void testResetOriginalValues() throws Exception {
  618. WikiPage newWikiPage = addWikiPage();
  619. _persistence.clearCache();
  620. _assertOriginalValues(
  621. _persistence.findByPrimaryKey(newWikiPage.getPrimaryKey()));
  622. }
  623. @Test
  624. public void testResetOriginalValuesWithDynamicQueryLoadFromDatabase()
  625. throws Exception {
  626. _testResetOriginalValuesWithDynamicQuery(true);
  627. }
  628. @Test
  629. public void testResetOriginalValuesWithDynamicQueryLoadFromSession()
  630. throws Exception {
  631. _testResetOriginalValuesWithDynamicQuery(false);
  632. }
  633. private void _testResetOriginalValuesWithDynamicQuery(boolean clearSession)
  634. throws Exception {
  635. WikiPage newWikiPage = addWikiPage();
  636. if (clearSession) {
  637. Session session = _persistence.openSession();
  638. session.flush();
  639. session.clear();
  640. }
  641. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  642. WikiPage.class, _dynamicQueryClassLoader);
  643. dynamicQuery.add(
  644. RestrictionsFactoryUtil.eq("pageId", newWikiPage.getPageId()));
  645. List<WikiPage> result = _persistence.findWithDynamicQuery(dynamicQuery);
  646. _assertOriginalValues(result.get(0));
  647. }
  648. private void _assertOriginalValues(WikiPage wikiPage) {
  649. Assert.assertEquals(
  650. wikiPage.getUuid(),
  651. ReflectionTestUtil.invoke(
  652. wikiPage, "getColumnOriginalValue",
  653. new Class<?>[] {String.class}, "uuid_"));
  654. Assert.assertEquals(
  655. Long.valueOf(wikiPage.getGroupId()),
  656. ReflectionTestUtil.<Long>invoke(
  657. wikiPage, "getColumnOriginalValue",
  658. new Class<?>[] {String.class}, "groupId"));
  659. Assert.assertEquals(
  660. Long.valueOf(wikiPage.getResourcePrimKey()),
  661. ReflectionTestUtil.<Long>invoke(
  662. wikiPage, "getColumnOriginalValue",
  663. new Class<?>[] {String.class}, "resourcePrimKey"));
  664. Assert.assertEquals(
  665. Long.valueOf(wikiPage.getNodeId()),
  666. ReflectionTestUtil.<Long>invoke(
  667. wikiPage, "getColumnOriginalValue",
  668. new Class<?>[] {String.class}, "nodeId"));
  669. AssertUtils.assertEquals(
  670. wikiPage.getVersion(),
  671. ReflectionTestUtil.<Double>invoke(
  672. wikiPage, "getColumnOriginalValue",
  673. new Class<?>[] {String.class}, "version"));
  674. Assert.assertEquals(
  675. Long.valueOf(wikiPage.getGroupId()),
  676. ReflectionTestUtil.<Long>invoke(
  677. wikiPage, "getColumnOriginalValue",
  678. new Class<?>[] {String.class}, "groupId"));
  679. Assert.assertEquals(
  680. wikiPage.getExternalReferenceCode(),
  681. ReflectionTestUtil.invoke(
  682. wikiPage, "getColumnOriginalValue",
  683. new Class<?>[] {String.class}, "externalReferenceCode"));
  684. AssertUtils.assertEquals(
  685. wikiPage.getVersion(),
  686. ReflectionTestUtil.<Double>invoke(
  687. wikiPage, "getColumnOriginalValue",
  688. new Class<?>[] {String.class}, "version"));
  689. Assert.assertEquals(
  690. Long.valueOf(wikiPage.getNodeId()),
  691. ReflectionTestUtil.<Long>invoke(
  692. wikiPage, "getColumnOriginalValue",
  693. new Class<?>[] {String.class}, "nodeId"));
  694. Assert.assertEquals(
  695. wikiPage.getTitle(),
  696. ReflectionTestUtil.invoke(
  697. wikiPage, "getColumnOriginalValue",
  698. new Class<?>[] {String.class}, "title"));
  699. AssertUtils.assertEquals(
  700. wikiPage.getVersion(),
  701. ReflectionTestUtil.<Double>invoke(
  702. wikiPage, "getColumnOriginalValue",
  703. new Class<?>[] {String.class}, "version"));
  704. }
  705. protected WikiPage addWikiPage() throws Exception {
  706. long pk = RandomTestUtil.nextLong();
  707. WikiPage wikiPage = _persistence.create(pk);
  708. wikiPage.setMvccVersion(RandomTestUtil.nextLong());
  709. wikiPage.setUuid(RandomTestUtil.randomString());
  710. wikiPage.setResourcePrimKey(RandomTestUtil.nextLong());
  711. wikiPage.setGroupId(RandomTestUtil.nextLong());
  712. wikiPage.setCompanyId(RandomTestUtil.nextLong());
  713. wikiPage.setUserId(RandomTestUtil.nextLong());
  714. wikiPage.setUserName(RandomTestUtil.randomString());
  715. wikiPage.setCreateDate(RandomTestUtil.nextDate());
  716. wikiPage.setModifiedDate(RandomTestUtil.nextDate());
  717. wikiPage.setExternalReferenceCode(RandomTestUtil.randomString());
  718. wikiPage.setNodeId(RandomTestUtil.nextLong());
  719. wikiPage.setTitle(RandomTestUtil.randomString());
  720. wikiPage.setVersion(RandomTestUtil.nextDouble());
  721. wikiPage.setMinorEdit(RandomTestUtil.randomBoolean());
  722. wikiPage.setContent(RandomTestUtil.randomString());
  723. wikiPage.setSummary(RandomTestUtil.randomString());
  724. wikiPage.setFormat(RandomTestUtil.randomString());
  725. wikiPage.setHead(RandomTestUtil.randomBoolean());
  726. wikiPage.setParentTitle(RandomTestUtil.randomString());
  727. wikiPage.setRedirectTitle(RandomTestUtil.randomString());
  728. wikiPage.setLastPublishDate(RandomTestUtil.nextDate());
  729. wikiPage.setStatus(RandomTestUtil.nextInt());
  730. wikiPage.setStatusByUserId(RandomTestUtil.nextLong());
  731. wikiPage.setStatusByUserName(RandomTestUtil.randomString());
  732. wikiPage.setStatusDate(RandomTestUtil.nextDate());
  733. _wikiPages.add(_persistence.update(wikiPage));
  734. return wikiPage;
  735. }
  736. private List<WikiPage> _wikiPages = new ArrayList<WikiPage>();
  737. private WikiPagePersistence _persistence;
  738. private ClassLoader _dynamicQueryClassLoader;
  739. }