PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/liferay/liferay-portal
Java | 754 lines | 534 code | 204 blank | 16 comment | 1 complexity | 142269f2ae23fe145661ebf4dca04e85 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.NoSuchFolderException;
  17. import com.liferay.document.library.kernel.model.DLFolder;
  18. import com.liferay.document.library.kernel.service.DLFolderLocalServiceUtil;
  19. import com.liferay.document.library.kernel.service.persistence.DLFolderPersistence;
  20. import com.liferay.document.library.kernel.service.persistence.DLFolderUtil;
  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 DLFolderPersistenceTest {
  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 = DLFolderUtil.getPersistence();
  67. Class<?> clazz = _persistence.getClass();
  68. _dynamicQueryClassLoader = clazz.getClassLoader();
  69. }
  70. @After
  71. public void tearDown() throws Exception {
  72. Iterator<DLFolder> iterator = _dlFolders.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. DLFolder dlFolder = _persistence.create(pk);
  82. Assert.assertNotNull(dlFolder);
  83. Assert.assertEquals(dlFolder.getPrimaryKey(), pk);
  84. }
  85. @Test
  86. public void testRemove() throws Exception {
  87. DLFolder newDLFolder = addDLFolder();
  88. _persistence.remove(newDLFolder);
  89. DLFolder existingDLFolder = _persistence.fetchByPrimaryKey(
  90. newDLFolder.getPrimaryKey());
  91. Assert.assertNull(existingDLFolder);
  92. }
  93. @Test
  94. public void testUpdateNew() throws Exception {
  95. addDLFolder();
  96. }
  97. @Test
  98. public void testUpdateExisting() throws Exception {
  99. long pk = RandomTestUtil.nextLong();
  100. DLFolder newDLFolder = _persistence.create(pk);
  101. newDLFolder.setMvccVersion(RandomTestUtil.nextLong());
  102. newDLFolder.setCtCollectionId(RandomTestUtil.nextLong());
  103. newDLFolder.setUuid(RandomTestUtil.randomString());
  104. newDLFolder.setGroupId(RandomTestUtil.nextLong());
  105. newDLFolder.setCompanyId(RandomTestUtil.nextLong());
  106. newDLFolder.setUserId(RandomTestUtil.nextLong());
  107. newDLFolder.setUserName(RandomTestUtil.randomString());
  108. newDLFolder.setCreateDate(RandomTestUtil.nextDate());
  109. newDLFolder.setModifiedDate(RandomTestUtil.nextDate());
  110. newDLFolder.setRepositoryId(RandomTestUtil.nextLong());
  111. newDLFolder.setMountPoint(RandomTestUtil.randomBoolean());
  112. newDLFolder.setParentFolderId(RandomTestUtil.nextLong());
  113. newDLFolder.setTreePath(RandomTestUtil.randomString());
  114. newDLFolder.setName(RandomTestUtil.randomString());
  115. newDLFolder.setDescription(RandomTestUtil.randomString());
  116. newDLFolder.setLastPostDate(RandomTestUtil.nextDate());
  117. newDLFolder.setDefaultFileEntryTypeId(RandomTestUtil.nextLong());
  118. newDLFolder.setHidden(RandomTestUtil.randomBoolean());
  119. newDLFolder.setRestrictionType(RandomTestUtil.nextInt());
  120. newDLFolder.setLastPublishDate(RandomTestUtil.nextDate());
  121. newDLFolder.setStatus(RandomTestUtil.nextInt());
  122. newDLFolder.setStatusByUserId(RandomTestUtil.nextLong());
  123. newDLFolder.setStatusByUserName(RandomTestUtil.randomString());
  124. newDLFolder.setStatusDate(RandomTestUtil.nextDate());
  125. _dlFolders.add(_persistence.update(newDLFolder));
  126. DLFolder existingDLFolder = _persistence.findByPrimaryKey(
  127. newDLFolder.getPrimaryKey());
  128. Assert.assertEquals(
  129. existingDLFolder.getMvccVersion(), newDLFolder.getMvccVersion());
  130. Assert.assertEquals(
  131. existingDLFolder.getCtCollectionId(),
  132. newDLFolder.getCtCollectionId());
  133. Assert.assertEquals(existingDLFolder.getUuid(), newDLFolder.getUuid());
  134. Assert.assertEquals(
  135. existingDLFolder.getFolderId(), newDLFolder.getFolderId());
  136. Assert.assertEquals(
  137. existingDLFolder.getGroupId(), newDLFolder.getGroupId());
  138. Assert.assertEquals(
  139. existingDLFolder.getCompanyId(), newDLFolder.getCompanyId());
  140. Assert.assertEquals(
  141. existingDLFolder.getUserId(), newDLFolder.getUserId());
  142. Assert.assertEquals(
  143. existingDLFolder.getUserName(), newDLFolder.getUserName());
  144. Assert.assertEquals(
  145. Time.getShortTimestamp(existingDLFolder.getCreateDate()),
  146. Time.getShortTimestamp(newDLFolder.getCreateDate()));
  147. Assert.assertEquals(
  148. Time.getShortTimestamp(existingDLFolder.getModifiedDate()),
  149. Time.getShortTimestamp(newDLFolder.getModifiedDate()));
  150. Assert.assertEquals(
  151. existingDLFolder.getRepositoryId(), newDLFolder.getRepositoryId());
  152. Assert.assertEquals(
  153. existingDLFolder.isMountPoint(), newDLFolder.isMountPoint());
  154. Assert.assertEquals(
  155. existingDLFolder.getParentFolderId(),
  156. newDLFolder.getParentFolderId());
  157. Assert.assertEquals(
  158. existingDLFolder.getTreePath(), newDLFolder.getTreePath());
  159. Assert.assertEquals(existingDLFolder.getName(), newDLFolder.getName());
  160. Assert.assertEquals(
  161. existingDLFolder.getDescription(), newDLFolder.getDescription());
  162. Assert.assertEquals(
  163. Time.getShortTimestamp(existingDLFolder.getLastPostDate()),
  164. Time.getShortTimestamp(newDLFolder.getLastPostDate()));
  165. Assert.assertEquals(
  166. existingDLFolder.getDefaultFileEntryTypeId(),
  167. newDLFolder.getDefaultFileEntryTypeId());
  168. Assert.assertEquals(
  169. existingDLFolder.isHidden(), newDLFolder.isHidden());
  170. Assert.assertEquals(
  171. existingDLFolder.getRestrictionType(),
  172. newDLFolder.getRestrictionType());
  173. Assert.assertEquals(
  174. Time.getShortTimestamp(existingDLFolder.getLastPublishDate()),
  175. Time.getShortTimestamp(newDLFolder.getLastPublishDate()));
  176. Assert.assertEquals(
  177. existingDLFolder.getStatus(), newDLFolder.getStatus());
  178. Assert.assertEquals(
  179. existingDLFolder.getStatusByUserId(),
  180. newDLFolder.getStatusByUserId());
  181. Assert.assertEquals(
  182. existingDLFolder.getStatusByUserName(),
  183. newDLFolder.getStatusByUserName());
  184. Assert.assertEquals(
  185. Time.getShortTimestamp(existingDLFolder.getStatusDate()),
  186. Time.getShortTimestamp(newDLFolder.getStatusDate()));
  187. }
  188. @Test
  189. public void testCountByUuid() throws Exception {
  190. _persistence.countByUuid("");
  191. _persistence.countByUuid("null");
  192. _persistence.countByUuid((String)null);
  193. }
  194. @Test
  195. public void testCountByUUID_G() throws Exception {
  196. _persistence.countByUUID_G("", RandomTestUtil.nextLong());
  197. _persistence.countByUUID_G("null", 0L);
  198. _persistence.countByUUID_G((String)null, 0L);
  199. }
  200. @Test
  201. public void testCountByUuid_C() throws Exception {
  202. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  203. _persistence.countByUuid_C("null", 0L);
  204. _persistence.countByUuid_C((String)null, 0L);
  205. }
  206. @Test
  207. public void testCountByGroupId() throws Exception {
  208. _persistence.countByGroupId(RandomTestUtil.nextLong());
  209. _persistence.countByGroupId(0L);
  210. }
  211. @Test
  212. public void testCountByCompanyId() throws Exception {
  213. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  214. _persistence.countByCompanyId(0L);
  215. }
  216. @Test
  217. public void testCountByRepositoryId() throws Exception {
  218. _persistence.countByRepositoryId(RandomTestUtil.nextLong());
  219. _persistence.countByRepositoryId(0L);
  220. }
  221. @Test
  222. public void testCountByG_P() throws Exception {
  223. _persistence.countByG_P(
  224. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  225. _persistence.countByG_P(0L, 0L);
  226. }
  227. @Test
  228. public void testCountByC_NotS() throws Exception {
  229. _persistence.countByC_NotS(
  230. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  231. _persistence.countByC_NotS(0L, 0);
  232. }
  233. @Test
  234. public void testCountByR_M() throws Exception {
  235. _persistence.countByR_M(
  236. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  237. _persistence.countByR_M(0L, RandomTestUtil.randomBoolean());
  238. }
  239. @Test
  240. public void testCountByR_P() throws Exception {
  241. _persistence.countByR_P(
  242. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  243. _persistence.countByR_P(0L, 0L);
  244. }
  245. @Test
  246. public void testCountByP_N() throws Exception {
  247. _persistence.countByP_N(RandomTestUtil.nextLong(), "");
  248. _persistence.countByP_N(0L, "null");
  249. _persistence.countByP_N(0L, (String)null);
  250. }
  251. @Test
  252. public void testCountByG_M_P() throws Exception {
  253. _persistence.countByG_M_P(
  254. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  255. RandomTestUtil.nextLong());
  256. _persistence.countByG_M_P(0L, RandomTestUtil.randomBoolean(), 0L);
  257. }
  258. @Test
  259. public void testCountByG_P_N() throws Exception {
  260. _persistence.countByG_P_N(
  261. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(), "");
  262. _persistence.countByG_P_N(0L, 0L, "null");
  263. _persistence.countByG_P_N(0L, 0L, (String)null);
  264. }
  265. @Test
  266. public void testCountByF_C_P_NotS() throws Exception {
  267. _persistence.countByF_C_P_NotS(
  268. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  269. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  270. _persistence.countByF_C_P_NotS(0L, 0L, 0L, 0);
  271. }
  272. @Test
  273. public void testCountByG_M_P_H() throws Exception {
  274. _persistence.countByG_M_P_H(
  275. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  276. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  277. _persistence.countByG_M_P_H(
  278. 0L, RandomTestUtil.randomBoolean(), 0L,
  279. RandomTestUtil.randomBoolean());
  280. }
  281. @Test
  282. public void testCountByG_M_T_H() throws Exception {
  283. _persistence.countByG_M_T_H(
  284. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "",
  285. RandomTestUtil.randomBoolean());
  286. _persistence.countByG_M_T_H(
  287. 0L, RandomTestUtil.randomBoolean(), "null",
  288. RandomTestUtil.randomBoolean());
  289. _persistence.countByG_M_T_H(
  290. 0L, RandomTestUtil.randomBoolean(), (String)null,
  291. RandomTestUtil.randomBoolean());
  292. }
  293. @Test
  294. public void testCountByG_P_H_S() throws Exception {
  295. _persistence.countByG_P_H_S(
  296. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  297. RandomTestUtil.randomBoolean(), RandomTestUtil.nextInt());
  298. _persistence.countByG_P_H_S(0L, 0L, RandomTestUtil.randomBoolean(), 0);
  299. }
  300. @Test
  301. public void testCountByG_M_P_H_S() throws Exception {
  302. _persistence.countByG_M_P_H_S(
  303. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  304. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  305. RandomTestUtil.nextInt());
  306. _persistence.countByG_M_P_H_S(
  307. 0L, RandomTestUtil.randomBoolean(), 0L,
  308. RandomTestUtil.randomBoolean(), 0);
  309. }
  310. @Test
  311. public void testFindByPrimaryKeyExisting() throws Exception {
  312. DLFolder newDLFolder = addDLFolder();
  313. DLFolder existingDLFolder = _persistence.findByPrimaryKey(
  314. newDLFolder.getPrimaryKey());
  315. Assert.assertEquals(existingDLFolder, newDLFolder);
  316. }
  317. @Test(expected = NoSuchFolderException.class)
  318. public void testFindByPrimaryKeyMissing() throws Exception {
  319. long pk = RandomTestUtil.nextLong();
  320. _persistence.findByPrimaryKey(pk);
  321. }
  322. @Test
  323. public void testFindAll() throws Exception {
  324. _persistence.findAll(
  325. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  326. }
  327. @Test
  328. public void testFilterFindByGroupId() throws Exception {
  329. _persistence.filterFindByGroupId(
  330. 0, QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  331. }
  332. protected OrderByComparator<DLFolder> getOrderByComparator() {
  333. return OrderByComparatorFactoryUtil.create(
  334. "DLFolder", "mvccVersion", true, "ctCollectionId", true, "uuid",
  335. true, "folderId", true, "groupId", true, "companyId", true,
  336. "userId", true, "userName", true, "createDate", true,
  337. "modifiedDate", true, "repositoryId", true, "mountPoint", true,
  338. "parentFolderId", true, "treePath", true, "name", true,
  339. "description", true, "lastPostDate", true, "defaultFileEntryTypeId",
  340. true, "hidden", true, "restrictionType", true, "lastPublishDate",
  341. true, "status", true, "statusByUserId", true, "statusByUserName",
  342. true, "statusDate", true);
  343. }
  344. @Test
  345. public void testFetchByPrimaryKeyExisting() throws Exception {
  346. DLFolder newDLFolder = addDLFolder();
  347. DLFolder existingDLFolder = _persistence.fetchByPrimaryKey(
  348. newDLFolder.getPrimaryKey());
  349. Assert.assertEquals(existingDLFolder, newDLFolder);
  350. }
  351. @Test
  352. public void testFetchByPrimaryKeyMissing() throws Exception {
  353. long pk = RandomTestUtil.nextLong();
  354. DLFolder missingDLFolder = _persistence.fetchByPrimaryKey(pk);
  355. Assert.assertNull(missingDLFolder);
  356. }
  357. @Test
  358. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  359. throws Exception {
  360. DLFolder newDLFolder1 = addDLFolder();
  361. DLFolder newDLFolder2 = addDLFolder();
  362. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  363. primaryKeys.add(newDLFolder1.getPrimaryKey());
  364. primaryKeys.add(newDLFolder2.getPrimaryKey());
  365. Map<Serializable, DLFolder> dlFolders = _persistence.fetchByPrimaryKeys(
  366. primaryKeys);
  367. Assert.assertEquals(2, dlFolders.size());
  368. Assert.assertEquals(
  369. newDLFolder1, dlFolders.get(newDLFolder1.getPrimaryKey()));
  370. Assert.assertEquals(
  371. newDLFolder2, dlFolders.get(newDLFolder2.getPrimaryKey()));
  372. }
  373. @Test
  374. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  375. throws Exception {
  376. long pk1 = RandomTestUtil.nextLong();
  377. long pk2 = RandomTestUtil.nextLong();
  378. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  379. primaryKeys.add(pk1);
  380. primaryKeys.add(pk2);
  381. Map<Serializable, DLFolder> dlFolders = _persistence.fetchByPrimaryKeys(
  382. primaryKeys);
  383. Assert.assertTrue(dlFolders.isEmpty());
  384. }
  385. @Test
  386. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  387. throws Exception {
  388. DLFolder newDLFolder = addDLFolder();
  389. long pk = RandomTestUtil.nextLong();
  390. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  391. primaryKeys.add(newDLFolder.getPrimaryKey());
  392. primaryKeys.add(pk);
  393. Map<Serializable, DLFolder> dlFolders = _persistence.fetchByPrimaryKeys(
  394. primaryKeys);
  395. Assert.assertEquals(1, dlFolders.size());
  396. Assert.assertEquals(
  397. newDLFolder, dlFolders.get(newDLFolder.getPrimaryKey()));
  398. }
  399. @Test
  400. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  401. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  402. Map<Serializable, DLFolder> dlFolders = _persistence.fetchByPrimaryKeys(
  403. primaryKeys);
  404. Assert.assertTrue(dlFolders.isEmpty());
  405. }
  406. @Test
  407. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  408. DLFolder newDLFolder = addDLFolder();
  409. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  410. primaryKeys.add(newDLFolder.getPrimaryKey());
  411. Map<Serializable, DLFolder> dlFolders = _persistence.fetchByPrimaryKeys(
  412. primaryKeys);
  413. Assert.assertEquals(1, dlFolders.size());
  414. Assert.assertEquals(
  415. newDLFolder, dlFolders.get(newDLFolder.getPrimaryKey()));
  416. }
  417. @Test
  418. public void testActionableDynamicQuery() throws Exception {
  419. final IntegerWrapper count = new IntegerWrapper();
  420. ActionableDynamicQuery actionableDynamicQuery =
  421. DLFolderLocalServiceUtil.getActionableDynamicQuery();
  422. actionableDynamicQuery.setPerformActionMethod(
  423. new ActionableDynamicQuery.PerformActionMethod<DLFolder>() {
  424. @Override
  425. public void performAction(DLFolder dlFolder) {
  426. Assert.assertNotNull(dlFolder);
  427. count.increment();
  428. }
  429. });
  430. actionableDynamicQuery.performActions();
  431. Assert.assertEquals(count.getValue(), _persistence.countAll());
  432. }
  433. @Test
  434. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  435. DLFolder newDLFolder = addDLFolder();
  436. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  437. DLFolder.class, _dynamicQueryClassLoader);
  438. dynamicQuery.add(
  439. RestrictionsFactoryUtil.eq("folderId", newDLFolder.getFolderId()));
  440. List<DLFolder> result = _persistence.findWithDynamicQuery(dynamicQuery);
  441. Assert.assertEquals(1, result.size());
  442. DLFolder existingDLFolder = result.get(0);
  443. Assert.assertEquals(existingDLFolder, newDLFolder);
  444. }
  445. @Test
  446. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  447. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  448. DLFolder.class, _dynamicQueryClassLoader);
  449. dynamicQuery.add(
  450. RestrictionsFactoryUtil.eq("folderId", RandomTestUtil.nextLong()));
  451. List<DLFolder> result = _persistence.findWithDynamicQuery(dynamicQuery);
  452. Assert.assertEquals(0, result.size());
  453. }
  454. @Test
  455. public void testDynamicQueryByProjectionExisting() throws Exception {
  456. DLFolder newDLFolder = addDLFolder();
  457. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  458. DLFolder.class, _dynamicQueryClassLoader);
  459. dynamicQuery.setProjection(ProjectionFactoryUtil.property("folderId"));
  460. Object newFolderId = newDLFolder.getFolderId();
  461. dynamicQuery.add(
  462. RestrictionsFactoryUtil.in("folderId", new Object[] {newFolderId}));
  463. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  464. Assert.assertEquals(1, result.size());
  465. Object existingFolderId = result.get(0);
  466. Assert.assertEquals(existingFolderId, newFolderId);
  467. }
  468. @Test
  469. public void testDynamicQueryByProjectionMissing() throws Exception {
  470. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  471. DLFolder.class, _dynamicQueryClassLoader);
  472. dynamicQuery.setProjection(ProjectionFactoryUtil.property("folderId"));
  473. dynamicQuery.add(
  474. RestrictionsFactoryUtil.in(
  475. "folderId", new Object[] {RandomTestUtil.nextLong()}));
  476. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  477. Assert.assertEquals(0, result.size());
  478. }
  479. @Test
  480. public void testResetOriginalValues() throws Exception {
  481. DLFolder newDLFolder = addDLFolder();
  482. _persistence.clearCache();
  483. DLFolder existingDLFolder = _persistence.findByPrimaryKey(
  484. newDLFolder.getPrimaryKey());
  485. Assert.assertTrue(
  486. Objects.equals(
  487. existingDLFolder.getUuid(),
  488. ReflectionTestUtil.invoke(
  489. existingDLFolder, "getOriginalUuid", new Class<?>[0])));
  490. Assert.assertEquals(
  491. Long.valueOf(existingDLFolder.getGroupId()),
  492. ReflectionTestUtil.<Long>invoke(
  493. existingDLFolder, "getOriginalGroupId", new Class<?>[0]));
  494. Assert.assertEquals(
  495. Long.valueOf(existingDLFolder.getRepositoryId()),
  496. ReflectionTestUtil.<Long>invoke(
  497. existingDLFolder, "getOriginalRepositoryId", new Class<?>[0]));
  498. Assert.assertEquals(
  499. Boolean.valueOf(existingDLFolder.getMountPoint()),
  500. ReflectionTestUtil.<Boolean>invoke(
  501. existingDLFolder, "getOriginalMountPoint", new Class<?>[0]));
  502. Assert.assertEquals(
  503. Long.valueOf(existingDLFolder.getGroupId()),
  504. ReflectionTestUtil.<Long>invoke(
  505. existingDLFolder, "getOriginalGroupId", new Class<?>[0]));
  506. Assert.assertEquals(
  507. Long.valueOf(existingDLFolder.getParentFolderId()),
  508. ReflectionTestUtil.<Long>invoke(
  509. existingDLFolder, "getOriginalParentFolderId",
  510. new Class<?>[0]));
  511. Assert.assertTrue(
  512. Objects.equals(
  513. existingDLFolder.getName(),
  514. ReflectionTestUtil.invoke(
  515. existingDLFolder, "getOriginalName", new Class<?>[0])));
  516. }
  517. protected DLFolder addDLFolder() throws Exception {
  518. long pk = RandomTestUtil.nextLong();
  519. DLFolder dlFolder = _persistence.create(pk);
  520. dlFolder.setMvccVersion(RandomTestUtil.nextLong());
  521. dlFolder.setCtCollectionId(RandomTestUtil.nextLong());
  522. dlFolder.setUuid(RandomTestUtil.randomString());
  523. dlFolder.setGroupId(RandomTestUtil.nextLong());
  524. dlFolder.setCompanyId(RandomTestUtil.nextLong());
  525. dlFolder.setUserId(RandomTestUtil.nextLong());
  526. dlFolder.setUserName(RandomTestUtil.randomString());
  527. dlFolder.setCreateDate(RandomTestUtil.nextDate());
  528. dlFolder.setModifiedDate(RandomTestUtil.nextDate());
  529. dlFolder.setRepositoryId(RandomTestUtil.nextLong());
  530. dlFolder.setMountPoint(RandomTestUtil.randomBoolean());
  531. dlFolder.setParentFolderId(RandomTestUtil.nextLong());
  532. dlFolder.setTreePath(RandomTestUtil.randomString());
  533. dlFolder.setName(RandomTestUtil.randomString());
  534. dlFolder.setDescription(RandomTestUtil.randomString());
  535. dlFolder.setLastPostDate(RandomTestUtil.nextDate());
  536. dlFolder.setDefaultFileEntryTypeId(RandomTestUtil.nextLong());
  537. dlFolder.setHidden(RandomTestUtil.randomBoolean());
  538. dlFolder.setRestrictionType(RandomTestUtil.nextInt());
  539. dlFolder.setLastPublishDate(RandomTestUtil.nextDate());
  540. dlFolder.setStatus(RandomTestUtil.nextInt());
  541. dlFolder.setStatusByUserId(RandomTestUtil.nextLong());
  542. dlFolder.setStatusByUserName(RandomTestUtil.randomString());
  543. dlFolder.setStatusDate(RandomTestUtil.nextDate());
  544. _dlFolders.add(_persistence.update(dlFolder));
  545. return dlFolder;
  546. }
  547. private List<DLFolder> _dlFolders = new ArrayList<DLFolder>();
  548. private DLFolderPersistence _persistence;
  549. private ClassLoader _dynamicQueryClassLoader;
  550. }