PageRenderTime 42ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/test/persistence-test/src/testIntegration/java/com/liferay/portlet/documentlibrary/service/persistence/test/DLFileEntryPersistenceTest.java

http://github.com/liferay/liferay-portal
Java | 866 lines | 620 code | 230 blank | 16 comment | 1 complexity | 89add6da780bac52567043f5d264aeb3 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.portlet.documentlibrary.service.persistence.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.document.library.kernel.exception.NoSuchFileEntryException;
  17. import com.liferay.document.library.kernel.model.DLFileEntry;
  18. import com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil;
  19. import com.liferay.document.library.kernel.service.persistence.DLFileEntryPersistence;
  20. import com.liferay.document.library.kernel.service.persistence.DLFileEntryUtil;
  21. import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
  22. import com.liferay.portal.kernel.dao.orm.DynamicQuery;
  23. import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
  24. import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
  25. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  26. import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
  27. import com.liferay.portal.kernel.test.ReflectionTestUtil;
  28. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  29. import com.liferay.portal.kernel.test.util.RandomTestUtil;
  30. import com.liferay.portal.kernel.transaction.Propagation;
  31. import com.liferay.portal.kernel.util.IntegerWrapper;
  32. import com.liferay.portal.kernel.util.OrderByComparator;
  33. import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
  34. import com.liferay.portal.kernel.util.Time;
  35. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  36. import com.liferay.portal.test.rule.PersistenceTestRule;
  37. import com.liferay.portal.test.rule.TransactionalTestRule;
  38. import java.io.Serializable;
  39. import java.util.ArrayList;
  40. import java.util.HashSet;
  41. import java.util.Iterator;
  42. import java.util.List;
  43. import java.util.Map;
  44. import java.util.Objects;
  45. import java.util.Set;
  46. import org.junit.After;
  47. import org.junit.Assert;
  48. import org.junit.Before;
  49. import org.junit.ClassRule;
  50. import org.junit.Rule;
  51. import org.junit.Test;
  52. import org.junit.runner.RunWith;
  53. /**
  54. * @generated
  55. */
  56. @RunWith(Arquillian.class)
  57. public class DLFileEntryPersistenceTest {
  58. @ClassRule
  59. @Rule
  60. public static final AggregateTestRule aggregateTestRule =
  61. new AggregateTestRule(
  62. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  63. new TransactionalTestRule(Propagation.REQUIRED));
  64. @Before
  65. public void setUp() {
  66. _persistence = DLFileEntryUtil.getPersistence();
  67. Class<?> clazz = _persistence.getClass();
  68. _dynamicQueryClassLoader = clazz.getClassLoader();
  69. }
  70. @After
  71. public void tearDown() throws Exception {
  72. Iterator<DLFileEntry> iterator = _dlFileEntries.iterator();
  73. while (iterator.hasNext()) {
  74. _persistence.remove(iterator.next());
  75. iterator.remove();
  76. }
  77. }
  78. @Test
  79. public void testCreate() throws Exception {
  80. long pk = RandomTestUtil.nextLong();
  81. DLFileEntry dlFileEntry = _persistence.create(pk);
  82. Assert.assertNotNull(dlFileEntry);
  83. Assert.assertEquals(dlFileEntry.getPrimaryKey(), pk);
  84. }
  85. @Test
  86. public void testRemove() throws Exception {
  87. DLFileEntry newDLFileEntry = addDLFileEntry();
  88. _persistence.remove(newDLFileEntry);
  89. DLFileEntry existingDLFileEntry = _persistence.fetchByPrimaryKey(
  90. newDLFileEntry.getPrimaryKey());
  91. Assert.assertNull(existingDLFileEntry);
  92. }
  93. @Test
  94. public void testUpdateNew() throws Exception {
  95. addDLFileEntry();
  96. }
  97. @Test
  98. public void testUpdateExisting() throws Exception {
  99. long pk = RandomTestUtil.nextLong();
  100. DLFileEntry newDLFileEntry = _persistence.create(pk);
  101. newDLFileEntry.setMvccVersion(RandomTestUtil.nextLong());
  102. newDLFileEntry.setCtCollectionId(RandomTestUtil.nextLong());
  103. newDLFileEntry.setUuid(RandomTestUtil.randomString());
  104. newDLFileEntry.setGroupId(RandomTestUtil.nextLong());
  105. newDLFileEntry.setCompanyId(RandomTestUtil.nextLong());
  106. newDLFileEntry.setUserId(RandomTestUtil.nextLong());
  107. newDLFileEntry.setUserName(RandomTestUtil.randomString());
  108. newDLFileEntry.setCreateDate(RandomTestUtil.nextDate());
  109. newDLFileEntry.setModifiedDate(RandomTestUtil.nextDate());
  110. newDLFileEntry.setClassNameId(RandomTestUtil.nextLong());
  111. newDLFileEntry.setClassPK(RandomTestUtil.nextLong());
  112. newDLFileEntry.setRepositoryId(RandomTestUtil.nextLong());
  113. newDLFileEntry.setFolderId(RandomTestUtil.nextLong());
  114. newDLFileEntry.setTreePath(RandomTestUtil.randomString());
  115. newDLFileEntry.setName(RandomTestUtil.randomString());
  116. newDLFileEntry.setFileName(RandomTestUtil.randomString());
  117. newDLFileEntry.setExtension(RandomTestUtil.randomString());
  118. newDLFileEntry.setMimeType(RandomTestUtil.randomString());
  119. newDLFileEntry.setTitle(RandomTestUtil.randomString());
  120. newDLFileEntry.setDescription(RandomTestUtil.randomString());
  121. newDLFileEntry.setExtraSettings(RandomTestUtil.randomString());
  122. newDLFileEntry.setFileEntryTypeId(RandomTestUtil.nextLong());
  123. newDLFileEntry.setVersion(RandomTestUtil.randomString());
  124. newDLFileEntry.setSize(RandomTestUtil.nextLong());
  125. newDLFileEntry.setSmallImageId(RandomTestUtil.nextLong());
  126. newDLFileEntry.setLargeImageId(RandomTestUtil.nextLong());
  127. newDLFileEntry.setCustom1ImageId(RandomTestUtil.nextLong());
  128. newDLFileEntry.setCustom2ImageId(RandomTestUtil.nextLong());
  129. newDLFileEntry.setManualCheckInRequired(RandomTestUtil.randomBoolean());
  130. newDLFileEntry.setLastPublishDate(RandomTestUtil.nextDate());
  131. _dlFileEntries.add(_persistence.update(newDLFileEntry));
  132. DLFileEntry existingDLFileEntry = _persistence.findByPrimaryKey(
  133. newDLFileEntry.getPrimaryKey());
  134. Assert.assertEquals(
  135. existingDLFileEntry.getMvccVersion(),
  136. newDLFileEntry.getMvccVersion());
  137. Assert.assertEquals(
  138. existingDLFileEntry.getCtCollectionId(),
  139. newDLFileEntry.getCtCollectionId());
  140. Assert.assertEquals(
  141. existingDLFileEntry.getUuid(), newDLFileEntry.getUuid());
  142. Assert.assertEquals(
  143. existingDLFileEntry.getFileEntryId(),
  144. newDLFileEntry.getFileEntryId());
  145. Assert.assertEquals(
  146. existingDLFileEntry.getGroupId(), newDLFileEntry.getGroupId());
  147. Assert.assertEquals(
  148. existingDLFileEntry.getCompanyId(), newDLFileEntry.getCompanyId());
  149. Assert.assertEquals(
  150. existingDLFileEntry.getUserId(), newDLFileEntry.getUserId());
  151. Assert.assertEquals(
  152. existingDLFileEntry.getUserName(), newDLFileEntry.getUserName());
  153. Assert.assertEquals(
  154. Time.getShortTimestamp(existingDLFileEntry.getCreateDate()),
  155. Time.getShortTimestamp(newDLFileEntry.getCreateDate()));
  156. Assert.assertEquals(
  157. Time.getShortTimestamp(existingDLFileEntry.getModifiedDate()),
  158. Time.getShortTimestamp(newDLFileEntry.getModifiedDate()));
  159. Assert.assertEquals(
  160. existingDLFileEntry.getClassNameId(),
  161. newDLFileEntry.getClassNameId());
  162. Assert.assertEquals(
  163. existingDLFileEntry.getClassPK(), newDLFileEntry.getClassPK());
  164. Assert.assertEquals(
  165. existingDLFileEntry.getRepositoryId(),
  166. newDLFileEntry.getRepositoryId());
  167. Assert.assertEquals(
  168. existingDLFileEntry.getFolderId(), newDLFileEntry.getFolderId());
  169. Assert.assertEquals(
  170. existingDLFileEntry.getTreePath(), newDLFileEntry.getTreePath());
  171. Assert.assertEquals(
  172. existingDLFileEntry.getName(), newDLFileEntry.getName());
  173. Assert.assertEquals(
  174. existingDLFileEntry.getFileName(), newDLFileEntry.getFileName());
  175. Assert.assertEquals(
  176. existingDLFileEntry.getExtension(), newDLFileEntry.getExtension());
  177. Assert.assertEquals(
  178. existingDLFileEntry.getMimeType(), newDLFileEntry.getMimeType());
  179. Assert.assertEquals(
  180. existingDLFileEntry.getTitle(), newDLFileEntry.getTitle());
  181. Assert.assertEquals(
  182. existingDLFileEntry.getDescription(),
  183. newDLFileEntry.getDescription());
  184. Assert.assertEquals(
  185. existingDLFileEntry.getExtraSettings(),
  186. newDLFileEntry.getExtraSettings());
  187. Assert.assertEquals(
  188. existingDLFileEntry.getFileEntryTypeId(),
  189. newDLFileEntry.getFileEntryTypeId());
  190. Assert.assertEquals(
  191. existingDLFileEntry.getVersion(), newDLFileEntry.getVersion());
  192. Assert.assertEquals(
  193. existingDLFileEntry.getSize(), newDLFileEntry.getSize());
  194. Assert.assertEquals(
  195. existingDLFileEntry.getSmallImageId(),
  196. newDLFileEntry.getSmallImageId());
  197. Assert.assertEquals(
  198. existingDLFileEntry.getLargeImageId(),
  199. newDLFileEntry.getLargeImageId());
  200. Assert.assertEquals(
  201. existingDLFileEntry.getCustom1ImageId(),
  202. newDLFileEntry.getCustom1ImageId());
  203. Assert.assertEquals(
  204. existingDLFileEntry.getCustom2ImageId(),
  205. newDLFileEntry.getCustom2ImageId());
  206. Assert.assertEquals(
  207. existingDLFileEntry.isManualCheckInRequired(),
  208. newDLFileEntry.isManualCheckInRequired());
  209. Assert.assertEquals(
  210. Time.getShortTimestamp(existingDLFileEntry.getLastPublishDate()),
  211. Time.getShortTimestamp(newDLFileEntry.getLastPublishDate()));
  212. }
  213. @Test
  214. public void testCountByUuid() throws Exception {
  215. _persistence.countByUuid("");
  216. _persistence.countByUuid("null");
  217. _persistence.countByUuid((String)null);
  218. }
  219. @Test
  220. public void testCountByUUID_G() throws Exception {
  221. _persistence.countByUUID_G("", RandomTestUtil.nextLong());
  222. _persistence.countByUUID_G("null", 0L);
  223. _persistence.countByUUID_G((String)null, 0L);
  224. }
  225. @Test
  226. public void testCountByUuid_C() throws Exception {
  227. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  228. _persistence.countByUuid_C("null", 0L);
  229. _persistence.countByUuid_C((String)null, 0L);
  230. }
  231. @Test
  232. public void testCountByGroupId() throws Exception {
  233. _persistence.countByGroupId(RandomTestUtil.nextLong());
  234. _persistence.countByGroupId(0L);
  235. }
  236. @Test
  237. public void testCountByCompanyId() throws Exception {
  238. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  239. _persistence.countByCompanyId(0L);
  240. }
  241. @Test
  242. public void testCountByRepositoryId() throws Exception {
  243. _persistence.countByRepositoryId(RandomTestUtil.nextLong());
  244. _persistence.countByRepositoryId(0L);
  245. }
  246. @Test
  247. public void testCountByMimeType() throws Exception {
  248. _persistence.countByMimeType("");
  249. _persistence.countByMimeType("null");
  250. _persistence.countByMimeType((String)null);
  251. }
  252. @Test
  253. public void testCountByFileEntryTypeId() throws Exception {
  254. _persistence.countByFileEntryTypeId(RandomTestUtil.nextLong());
  255. _persistence.countByFileEntryTypeId(0L);
  256. }
  257. @Test
  258. public void testCountBySmallImageId() throws Exception {
  259. _persistence.countBySmallImageId(RandomTestUtil.nextLong());
  260. _persistence.countBySmallImageId(0L);
  261. }
  262. @Test
  263. public void testCountByLargeImageId() throws Exception {
  264. _persistence.countByLargeImageId(RandomTestUtil.nextLong());
  265. _persistence.countByLargeImageId(0L);
  266. }
  267. @Test
  268. public void testCountByCustom1ImageId() throws Exception {
  269. _persistence.countByCustom1ImageId(RandomTestUtil.nextLong());
  270. _persistence.countByCustom1ImageId(0L);
  271. }
  272. @Test
  273. public void testCountByCustom2ImageId() throws Exception {
  274. _persistence.countByCustom2ImageId(RandomTestUtil.nextLong());
  275. _persistence.countByCustom2ImageId(0L);
  276. }
  277. @Test
  278. public void testCountByG_U() throws Exception {
  279. _persistence.countByG_U(
  280. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  281. _persistence.countByG_U(0L, 0L);
  282. }
  283. @Test
  284. public void testCountByG_F() throws Exception {
  285. _persistence.countByG_F(
  286. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  287. _persistence.countByG_F(0L, 0L);
  288. }
  289. @Test
  290. public void testCountByG_FArrayable() throws Exception {
  291. _persistence.countByG_F(
  292. RandomTestUtil.nextLong(),
  293. new long[] {RandomTestUtil.nextLong(), 0L});
  294. }
  295. @Test
  296. public void testCountByR_F() throws Exception {
  297. _persistence.countByR_F(
  298. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  299. _persistence.countByR_F(0L, 0L);
  300. }
  301. @Test
  302. public void testCountByF_N() throws Exception {
  303. _persistence.countByF_N(RandomTestUtil.nextLong(), "");
  304. _persistence.countByF_N(0L, "null");
  305. _persistence.countByF_N(0L, (String)null);
  306. }
  307. @Test
  308. public void testCountByG_U_F() throws Exception {
  309. _persistence.countByG_U_F(
  310. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  311. RandomTestUtil.nextLong());
  312. _persistence.countByG_U_F(0L, 0L, 0L);
  313. }
  314. @Test
  315. public void testCountByG_U_FArrayable() throws Exception {
  316. _persistence.countByG_U_F(
  317. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  318. new long[] {RandomTestUtil.nextLong(), 0L});
  319. }
  320. @Test
  321. public void testCountByG_F_N() throws Exception {
  322. _persistence.countByG_F_N(
  323. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), "");
  324. _persistence.countByG_F_N(0L, 0L, "null");
  325. _persistence.countByG_F_N(0L, 0L, (String)null);
  326. }
  327. @Test
  328. public void testCountByG_F_FN() throws Exception {
  329. _persistence.countByG_F_FN(
  330. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), "");
  331. _persistence.countByG_F_FN(0L, 0L, "null");
  332. _persistence.countByG_F_FN(0L, 0L, (String)null);
  333. }
  334. @Test
  335. public void testCountByG_F_T() throws Exception {
  336. _persistence.countByG_F_T(
  337. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), "");
  338. _persistence.countByG_F_T(0L, 0L, "null");
  339. _persistence.countByG_F_T(0L, 0L, (String)null);
  340. }
  341. @Test
  342. public void testCountByG_F_F() throws Exception {
  343. _persistence.countByG_F_F(
  344. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  345. RandomTestUtil.nextLong());
  346. _persistence.countByG_F_F(0L, 0L, 0L);
  347. }
  348. @Test
  349. public void testCountByG_F_FArrayable() throws Exception {
  350. _persistence.countByG_F_F(
  351. RandomTestUtil.nextLong(),
  352. new long[] {RandomTestUtil.nextLong(), 0L},
  353. RandomTestUtil.nextLong());
  354. }
  355. @Test
  356. public void testCountByS_L_C1_C2() throws Exception {
  357. _persistence.countByS_L_C1_C2(
  358. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  359. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  360. _persistence.countByS_L_C1_C2(0L, 0L, 0L, 0L);
  361. }
  362. @Test
  363. public void testFindByPrimaryKeyExisting() throws Exception {
  364. DLFileEntry newDLFileEntry = addDLFileEntry();
  365. DLFileEntry existingDLFileEntry = _persistence.findByPrimaryKey(
  366. newDLFileEntry.getPrimaryKey());
  367. Assert.assertEquals(existingDLFileEntry, newDLFileEntry);
  368. }
  369. @Test(expected = NoSuchFileEntryException.class)
  370. public void testFindByPrimaryKeyMissing() throws Exception {
  371. long pk = RandomTestUtil.nextLong();
  372. _persistence.findByPrimaryKey(pk);
  373. }
  374. @Test
  375. public void testFindAll() throws Exception {
  376. _persistence.findAll(
  377. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  378. }
  379. @Test
  380. public void testFilterFindByGroupId() throws Exception {
  381. _persistence.filterFindByGroupId(
  382. 0, QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  383. }
  384. protected OrderByComparator<DLFileEntry> getOrderByComparator() {
  385. return OrderByComparatorFactoryUtil.create(
  386. "DLFileEntry", "mvccVersion", true, "ctCollectionId", true, "uuid",
  387. true, "fileEntryId", true, "groupId", true, "companyId", true,
  388. "userId", true, "userName", true, "createDate", true,
  389. "modifiedDate", true, "classNameId", true, "classPK", true,
  390. "repositoryId", true, "folderId", true, "treePath", true, "name",
  391. true, "fileName", true, "extension", true, "mimeType", true,
  392. "title", true, "description", true, "fileEntryTypeId", true,
  393. "version", true, "size", true, "smallImageId", true, "largeImageId",
  394. true, "custom1ImageId", true, "custom2ImageId", true,
  395. "manualCheckInRequired", true, "lastPublishDate", true);
  396. }
  397. @Test
  398. public void testFetchByPrimaryKeyExisting() throws Exception {
  399. DLFileEntry newDLFileEntry = addDLFileEntry();
  400. DLFileEntry existingDLFileEntry = _persistence.fetchByPrimaryKey(
  401. newDLFileEntry.getPrimaryKey());
  402. Assert.assertEquals(existingDLFileEntry, newDLFileEntry);
  403. }
  404. @Test
  405. public void testFetchByPrimaryKeyMissing() throws Exception {
  406. long pk = RandomTestUtil.nextLong();
  407. DLFileEntry missingDLFileEntry = _persistence.fetchByPrimaryKey(pk);
  408. Assert.assertNull(missingDLFileEntry);
  409. }
  410. @Test
  411. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  412. throws Exception {
  413. DLFileEntry newDLFileEntry1 = addDLFileEntry();
  414. DLFileEntry newDLFileEntry2 = addDLFileEntry();
  415. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  416. primaryKeys.add(newDLFileEntry1.getPrimaryKey());
  417. primaryKeys.add(newDLFileEntry2.getPrimaryKey());
  418. Map<Serializable, DLFileEntry> dlFileEntries =
  419. _persistence.fetchByPrimaryKeys(primaryKeys);
  420. Assert.assertEquals(2, dlFileEntries.size());
  421. Assert.assertEquals(
  422. newDLFileEntry1,
  423. dlFileEntries.get(newDLFileEntry1.getPrimaryKey()));
  424. Assert.assertEquals(
  425. newDLFileEntry2,
  426. dlFileEntries.get(newDLFileEntry2.getPrimaryKey()));
  427. }
  428. @Test
  429. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  430. throws Exception {
  431. long pk1 = RandomTestUtil.nextLong();
  432. long pk2 = RandomTestUtil.nextLong();
  433. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  434. primaryKeys.add(pk1);
  435. primaryKeys.add(pk2);
  436. Map<Serializable, DLFileEntry> dlFileEntries =
  437. _persistence.fetchByPrimaryKeys(primaryKeys);
  438. Assert.assertTrue(dlFileEntries.isEmpty());
  439. }
  440. @Test
  441. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  442. throws Exception {
  443. DLFileEntry newDLFileEntry = addDLFileEntry();
  444. long pk = RandomTestUtil.nextLong();
  445. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  446. primaryKeys.add(newDLFileEntry.getPrimaryKey());
  447. primaryKeys.add(pk);
  448. Map<Serializable, DLFileEntry> dlFileEntries =
  449. _persistence.fetchByPrimaryKeys(primaryKeys);
  450. Assert.assertEquals(1, dlFileEntries.size());
  451. Assert.assertEquals(
  452. newDLFileEntry, dlFileEntries.get(newDLFileEntry.getPrimaryKey()));
  453. }
  454. @Test
  455. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  456. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  457. Map<Serializable, DLFileEntry> dlFileEntries =
  458. _persistence.fetchByPrimaryKeys(primaryKeys);
  459. Assert.assertTrue(dlFileEntries.isEmpty());
  460. }
  461. @Test
  462. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  463. DLFileEntry newDLFileEntry = addDLFileEntry();
  464. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  465. primaryKeys.add(newDLFileEntry.getPrimaryKey());
  466. Map<Serializable, DLFileEntry> dlFileEntries =
  467. _persistence.fetchByPrimaryKeys(primaryKeys);
  468. Assert.assertEquals(1, dlFileEntries.size());
  469. Assert.assertEquals(
  470. newDLFileEntry, dlFileEntries.get(newDLFileEntry.getPrimaryKey()));
  471. }
  472. @Test
  473. public void testActionableDynamicQuery() throws Exception {
  474. final IntegerWrapper count = new IntegerWrapper();
  475. ActionableDynamicQuery actionableDynamicQuery =
  476. DLFileEntryLocalServiceUtil.getActionableDynamicQuery();
  477. actionableDynamicQuery.setPerformActionMethod(
  478. new ActionableDynamicQuery.PerformActionMethod<DLFileEntry>() {
  479. @Override
  480. public void performAction(DLFileEntry dlFileEntry) {
  481. Assert.assertNotNull(dlFileEntry);
  482. count.increment();
  483. }
  484. });
  485. actionableDynamicQuery.performActions();
  486. Assert.assertEquals(count.getValue(), _persistence.countAll());
  487. }
  488. @Test
  489. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  490. DLFileEntry newDLFileEntry = addDLFileEntry();
  491. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  492. DLFileEntry.class, _dynamicQueryClassLoader);
  493. dynamicQuery.add(
  494. RestrictionsFactoryUtil.eq(
  495. "fileEntryId", newDLFileEntry.getFileEntryId()));
  496. List<DLFileEntry> result = _persistence.findWithDynamicQuery(
  497. dynamicQuery);
  498. Assert.assertEquals(1, result.size());
  499. DLFileEntry existingDLFileEntry = result.get(0);
  500. Assert.assertEquals(existingDLFileEntry, newDLFileEntry);
  501. }
  502. @Test
  503. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  504. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  505. DLFileEntry.class, _dynamicQueryClassLoader);
  506. dynamicQuery.add(
  507. RestrictionsFactoryUtil.eq(
  508. "fileEntryId", RandomTestUtil.nextLong()));
  509. List<DLFileEntry> result = _persistence.findWithDynamicQuery(
  510. dynamicQuery);
  511. Assert.assertEquals(0, result.size());
  512. }
  513. @Test
  514. public void testDynamicQueryByProjectionExisting() throws Exception {
  515. DLFileEntry newDLFileEntry = addDLFileEntry();
  516. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  517. DLFileEntry.class, _dynamicQueryClassLoader);
  518. dynamicQuery.setProjection(
  519. ProjectionFactoryUtil.property("fileEntryId"));
  520. Object newFileEntryId = newDLFileEntry.getFileEntryId();
  521. dynamicQuery.add(
  522. RestrictionsFactoryUtil.in(
  523. "fileEntryId", new Object[] {newFileEntryId}));
  524. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  525. Assert.assertEquals(1, result.size());
  526. Object existingFileEntryId = result.get(0);
  527. Assert.assertEquals(existingFileEntryId, newFileEntryId);
  528. }
  529. @Test
  530. public void testDynamicQueryByProjectionMissing() throws Exception {
  531. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  532. DLFileEntry.class, _dynamicQueryClassLoader);
  533. dynamicQuery.setProjection(
  534. ProjectionFactoryUtil.property("fileEntryId"));
  535. dynamicQuery.add(
  536. RestrictionsFactoryUtil.in(
  537. "fileEntryId", new Object[] {RandomTestUtil.nextLong()}));
  538. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  539. Assert.assertEquals(0, result.size());
  540. }
  541. @Test
  542. public void testResetOriginalValues() throws Exception {
  543. DLFileEntry newDLFileEntry = addDLFileEntry();
  544. _persistence.clearCache();
  545. DLFileEntry existingDLFileEntry = _persistence.findByPrimaryKey(
  546. newDLFileEntry.getPrimaryKey());
  547. Assert.assertTrue(
  548. Objects.equals(
  549. existingDLFileEntry.getUuid(),
  550. ReflectionTestUtil.invoke(
  551. existingDLFileEntry, "getOriginalUuid", new Class<?>[0])));
  552. Assert.assertEquals(
  553. Long.valueOf(existingDLFileEntry.getGroupId()),
  554. ReflectionTestUtil.<Long>invoke(
  555. existingDLFileEntry, "getOriginalGroupId", new Class<?>[0]));
  556. Assert.assertEquals(
  557. Long.valueOf(existingDLFileEntry.getGroupId()),
  558. ReflectionTestUtil.<Long>invoke(
  559. existingDLFileEntry, "getOriginalGroupId", new Class<?>[0]));
  560. Assert.assertEquals(
  561. Long.valueOf(existingDLFileEntry.getFolderId()),
  562. ReflectionTestUtil.<Long>invoke(
  563. existingDLFileEntry, "getOriginalFolderId", new Class<?>[0]));
  564. Assert.assertTrue(
  565. Objects.equals(
  566. existingDLFileEntry.getName(),
  567. ReflectionTestUtil.invoke(
  568. existingDLFileEntry, "getOriginalName", new Class<?>[0])));
  569. Assert.assertEquals(
  570. Long.valueOf(existingDLFileEntry.getGroupId()),
  571. ReflectionTestUtil.<Long>invoke(
  572. existingDLFileEntry, "getOriginalGroupId", new Class<?>[0]));
  573. Assert.assertEquals(
  574. Long.valueOf(existingDLFileEntry.getFolderId()),
  575. ReflectionTestUtil.<Long>invoke(
  576. existingDLFileEntry, "getOriginalFolderId", new Class<?>[0]));
  577. Assert.assertTrue(
  578. Objects.equals(
  579. existingDLFileEntry.getFileName(),
  580. ReflectionTestUtil.invoke(
  581. existingDLFileEntry, "getOriginalFileName",
  582. new Class<?>[0])));
  583. Assert.assertEquals(
  584. Long.valueOf(existingDLFileEntry.getGroupId()),
  585. ReflectionTestUtil.<Long>invoke(
  586. existingDLFileEntry, "getOriginalGroupId", new Class<?>[0]));
  587. Assert.assertEquals(
  588. Long.valueOf(existingDLFileEntry.getFolderId()),
  589. ReflectionTestUtil.<Long>invoke(
  590. existingDLFileEntry, "getOriginalFolderId", new Class<?>[0]));
  591. Assert.assertTrue(
  592. Objects.equals(
  593. existingDLFileEntry.getTitle(),
  594. ReflectionTestUtil.invoke(
  595. existingDLFileEntry, "getOriginalTitle", new Class<?>[0])));
  596. }
  597. protected DLFileEntry addDLFileEntry() throws Exception {
  598. long pk = RandomTestUtil.nextLong();
  599. DLFileEntry dlFileEntry = _persistence.create(pk);
  600. dlFileEntry.setMvccVersion(RandomTestUtil.nextLong());
  601. dlFileEntry.setCtCollectionId(RandomTestUtil.nextLong());
  602. dlFileEntry.setUuid(RandomTestUtil.randomString());
  603. dlFileEntry.setGroupId(RandomTestUtil.nextLong());
  604. dlFileEntry.setCompanyId(RandomTestUtil.nextLong());
  605. dlFileEntry.setUserId(RandomTestUtil.nextLong());
  606. dlFileEntry.setUserName(RandomTestUtil.randomString());
  607. dlFileEntry.setCreateDate(RandomTestUtil.nextDate());
  608. dlFileEntry.setModifiedDate(RandomTestUtil.nextDate());
  609. dlFileEntry.setClassNameId(RandomTestUtil.nextLong());
  610. dlFileEntry.setClassPK(RandomTestUtil.nextLong());
  611. dlFileEntry.setRepositoryId(RandomTestUtil.nextLong());
  612. dlFileEntry.setFolderId(RandomTestUtil.nextLong());
  613. dlFileEntry.setTreePath(RandomTestUtil.randomString());
  614. dlFileEntry.setName(RandomTestUtil.randomString());
  615. dlFileEntry.setFileName(RandomTestUtil.randomString());
  616. dlFileEntry.setExtension(RandomTestUtil.randomString());
  617. dlFileEntry.setMimeType(RandomTestUtil.randomString());
  618. dlFileEntry.setTitle(RandomTestUtil.randomString());
  619. dlFileEntry.setDescription(RandomTestUtil.randomString());
  620. dlFileEntry.setExtraSettings(RandomTestUtil.randomString());
  621. dlFileEntry.setFileEntryTypeId(RandomTestUtil.nextLong());
  622. dlFileEntry.setVersion(RandomTestUtil.randomString());
  623. dlFileEntry.setSize(RandomTestUtil.nextLong());
  624. dlFileEntry.setSmallImageId(RandomTestUtil.nextLong());
  625. dlFileEntry.setLargeImageId(RandomTestUtil.nextLong());
  626. dlFileEntry.setCustom1ImageId(RandomTestUtil.nextLong());
  627. dlFileEntry.setCustom2ImageId(RandomTestUtil.nextLong());
  628. dlFileEntry.setManualCheckInRequired(RandomTestUtil.randomBoolean());
  629. dlFileEntry.setLastPublishDate(RandomTestUtil.nextDate());
  630. _dlFileEntries.add(_persistence.update(dlFileEntry));
  631. return dlFileEntry;
  632. }
  633. private List<DLFileEntry> _dlFileEntries = new ArrayList<DLFileEntry>();
  634. private DLFileEntryPersistence _persistence;
  635. private ClassLoader _dynamicQueryClassLoader;
  636. }