PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/liferay/liferay-portal
Java | 575 lines | 405 code | 154 blank | 16 comment | 1 complexity | d7082f6c0b48d632b107d253fbcd0bc4 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.NoSuchFileEntryTypeException;
  17. import com.liferay.document.library.kernel.model.DLFileEntryType;
  18. import com.liferay.document.library.kernel.service.DLFileEntryTypeLocalServiceUtil;
  19. import com.liferay.document.library.kernel.service.persistence.DLFileEntryTypePersistence;
  20. import com.liferay.document.library.kernel.service.persistence.DLFileEntryTypeUtil;
  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 DLFileEntryTypePersistenceTest {
  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 = DLFileEntryTypeUtil.getPersistence();
  67. Class<?> clazz = _persistence.getClass();
  68. _dynamicQueryClassLoader = clazz.getClassLoader();
  69. }
  70. @After
  71. public void tearDown() throws Exception {
  72. Iterator<DLFileEntryType> iterator = _dlFileEntryTypes.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. DLFileEntryType dlFileEntryType = _persistence.create(pk);
  82. Assert.assertNotNull(dlFileEntryType);
  83. Assert.assertEquals(dlFileEntryType.getPrimaryKey(), pk);
  84. }
  85. @Test
  86. public void testRemove() throws Exception {
  87. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  88. _persistence.remove(newDLFileEntryType);
  89. DLFileEntryType existingDLFileEntryType =
  90. _persistence.fetchByPrimaryKey(newDLFileEntryType.getPrimaryKey());
  91. Assert.assertNull(existingDLFileEntryType);
  92. }
  93. @Test
  94. public void testUpdateNew() throws Exception {
  95. addDLFileEntryType();
  96. }
  97. @Test
  98. public void testUpdateExisting() throws Exception {
  99. long pk = RandomTestUtil.nextLong();
  100. DLFileEntryType newDLFileEntryType = _persistence.create(pk);
  101. newDLFileEntryType.setMvccVersion(RandomTestUtil.nextLong());
  102. newDLFileEntryType.setCtCollectionId(RandomTestUtil.nextLong());
  103. newDLFileEntryType.setUuid(RandomTestUtil.randomString());
  104. newDLFileEntryType.setGroupId(RandomTestUtil.nextLong());
  105. newDLFileEntryType.setCompanyId(RandomTestUtil.nextLong());
  106. newDLFileEntryType.setUserId(RandomTestUtil.nextLong());
  107. newDLFileEntryType.setUserName(RandomTestUtil.randomString());
  108. newDLFileEntryType.setCreateDate(RandomTestUtil.nextDate());
  109. newDLFileEntryType.setModifiedDate(RandomTestUtil.nextDate());
  110. newDLFileEntryType.setFileEntryTypeKey(RandomTestUtil.randomString());
  111. newDLFileEntryType.setName(RandomTestUtil.randomString());
  112. newDLFileEntryType.setDescription(RandomTestUtil.randomString());
  113. newDLFileEntryType.setLastPublishDate(RandomTestUtil.nextDate());
  114. _dlFileEntryTypes.add(_persistence.update(newDLFileEntryType));
  115. DLFileEntryType existingDLFileEntryType = _persistence.findByPrimaryKey(
  116. newDLFileEntryType.getPrimaryKey());
  117. Assert.assertEquals(
  118. existingDLFileEntryType.getMvccVersion(),
  119. newDLFileEntryType.getMvccVersion());
  120. Assert.assertEquals(
  121. existingDLFileEntryType.getCtCollectionId(),
  122. newDLFileEntryType.getCtCollectionId());
  123. Assert.assertEquals(
  124. existingDLFileEntryType.getUuid(), newDLFileEntryType.getUuid());
  125. Assert.assertEquals(
  126. existingDLFileEntryType.getFileEntryTypeId(),
  127. newDLFileEntryType.getFileEntryTypeId());
  128. Assert.assertEquals(
  129. existingDLFileEntryType.getGroupId(),
  130. newDLFileEntryType.getGroupId());
  131. Assert.assertEquals(
  132. existingDLFileEntryType.getCompanyId(),
  133. newDLFileEntryType.getCompanyId());
  134. Assert.assertEquals(
  135. existingDLFileEntryType.getUserId(),
  136. newDLFileEntryType.getUserId());
  137. Assert.assertEquals(
  138. existingDLFileEntryType.getUserName(),
  139. newDLFileEntryType.getUserName());
  140. Assert.assertEquals(
  141. Time.getShortTimestamp(existingDLFileEntryType.getCreateDate()),
  142. Time.getShortTimestamp(newDLFileEntryType.getCreateDate()));
  143. Assert.assertEquals(
  144. Time.getShortTimestamp(existingDLFileEntryType.getModifiedDate()),
  145. Time.getShortTimestamp(newDLFileEntryType.getModifiedDate()));
  146. Assert.assertEquals(
  147. existingDLFileEntryType.getFileEntryTypeKey(),
  148. newDLFileEntryType.getFileEntryTypeKey());
  149. Assert.assertEquals(
  150. existingDLFileEntryType.getName(), newDLFileEntryType.getName());
  151. Assert.assertEquals(
  152. existingDLFileEntryType.getDescription(),
  153. newDLFileEntryType.getDescription());
  154. Assert.assertEquals(
  155. Time.getShortTimestamp(
  156. existingDLFileEntryType.getLastPublishDate()),
  157. Time.getShortTimestamp(newDLFileEntryType.getLastPublishDate()));
  158. }
  159. @Test
  160. public void testCountByUuid() throws Exception {
  161. _persistence.countByUuid("");
  162. _persistence.countByUuid("null");
  163. _persistence.countByUuid((String)null);
  164. }
  165. @Test
  166. public void testCountByUUID_G() throws Exception {
  167. _persistence.countByUUID_G("", RandomTestUtil.nextLong());
  168. _persistence.countByUUID_G("null", 0L);
  169. _persistence.countByUUID_G((String)null, 0L);
  170. }
  171. @Test
  172. public void testCountByUuid_C() throws Exception {
  173. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  174. _persistence.countByUuid_C("null", 0L);
  175. _persistence.countByUuid_C((String)null, 0L);
  176. }
  177. @Test
  178. public void testCountByGroupId() throws Exception {
  179. _persistence.countByGroupId(RandomTestUtil.nextLong());
  180. _persistence.countByGroupId(0L);
  181. }
  182. @Test
  183. public void testCountByGroupIdArrayable() throws Exception {
  184. _persistence.countByGroupId(new long[] {RandomTestUtil.nextLong(), 0L});
  185. }
  186. @Test
  187. public void testCountByG_F() throws Exception {
  188. _persistence.countByG_F(RandomTestUtil.nextLong(), "");
  189. _persistence.countByG_F(0L, "null");
  190. _persistence.countByG_F(0L, (String)null);
  191. }
  192. @Test
  193. public void testFindByPrimaryKeyExisting() throws Exception {
  194. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  195. DLFileEntryType existingDLFileEntryType = _persistence.findByPrimaryKey(
  196. newDLFileEntryType.getPrimaryKey());
  197. Assert.assertEquals(existingDLFileEntryType, newDLFileEntryType);
  198. }
  199. @Test(expected = NoSuchFileEntryTypeException.class)
  200. public void testFindByPrimaryKeyMissing() throws Exception {
  201. long pk = RandomTestUtil.nextLong();
  202. _persistence.findByPrimaryKey(pk);
  203. }
  204. @Test
  205. public void testFindAll() throws Exception {
  206. _persistence.findAll(
  207. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  208. }
  209. @Test
  210. public void testFilterFindByGroupId() throws Exception {
  211. _persistence.filterFindByGroupId(
  212. 0, QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  213. }
  214. protected OrderByComparator<DLFileEntryType> getOrderByComparator() {
  215. return OrderByComparatorFactoryUtil.create(
  216. "DLFileEntryType", "mvccVersion", true, "ctCollectionId", true,
  217. "uuid", true, "fileEntryTypeId", true, "groupId", true, "companyId",
  218. true, "userId", true, "userName", true, "createDate", true,
  219. "modifiedDate", true, "fileEntryTypeKey", true, "name", true,
  220. "description", true, "lastPublishDate", true);
  221. }
  222. @Test
  223. public void testFetchByPrimaryKeyExisting() throws Exception {
  224. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  225. DLFileEntryType existingDLFileEntryType =
  226. _persistence.fetchByPrimaryKey(newDLFileEntryType.getPrimaryKey());
  227. Assert.assertEquals(existingDLFileEntryType, newDLFileEntryType);
  228. }
  229. @Test
  230. public void testFetchByPrimaryKeyMissing() throws Exception {
  231. long pk = RandomTestUtil.nextLong();
  232. DLFileEntryType missingDLFileEntryType = _persistence.fetchByPrimaryKey(
  233. pk);
  234. Assert.assertNull(missingDLFileEntryType);
  235. }
  236. @Test
  237. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  238. throws Exception {
  239. DLFileEntryType newDLFileEntryType1 = addDLFileEntryType();
  240. DLFileEntryType newDLFileEntryType2 = addDLFileEntryType();
  241. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  242. primaryKeys.add(newDLFileEntryType1.getPrimaryKey());
  243. primaryKeys.add(newDLFileEntryType2.getPrimaryKey());
  244. Map<Serializable, DLFileEntryType> dlFileEntryTypes =
  245. _persistence.fetchByPrimaryKeys(primaryKeys);
  246. Assert.assertEquals(2, dlFileEntryTypes.size());
  247. Assert.assertEquals(
  248. newDLFileEntryType1,
  249. dlFileEntryTypes.get(newDLFileEntryType1.getPrimaryKey()));
  250. Assert.assertEquals(
  251. newDLFileEntryType2,
  252. dlFileEntryTypes.get(newDLFileEntryType2.getPrimaryKey()));
  253. }
  254. @Test
  255. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  256. throws Exception {
  257. long pk1 = RandomTestUtil.nextLong();
  258. long pk2 = RandomTestUtil.nextLong();
  259. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  260. primaryKeys.add(pk1);
  261. primaryKeys.add(pk2);
  262. Map<Serializable, DLFileEntryType> dlFileEntryTypes =
  263. _persistence.fetchByPrimaryKeys(primaryKeys);
  264. Assert.assertTrue(dlFileEntryTypes.isEmpty());
  265. }
  266. @Test
  267. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  268. throws Exception {
  269. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  270. long pk = RandomTestUtil.nextLong();
  271. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  272. primaryKeys.add(newDLFileEntryType.getPrimaryKey());
  273. primaryKeys.add(pk);
  274. Map<Serializable, DLFileEntryType> dlFileEntryTypes =
  275. _persistence.fetchByPrimaryKeys(primaryKeys);
  276. Assert.assertEquals(1, dlFileEntryTypes.size());
  277. Assert.assertEquals(
  278. newDLFileEntryType,
  279. dlFileEntryTypes.get(newDLFileEntryType.getPrimaryKey()));
  280. }
  281. @Test
  282. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  283. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  284. Map<Serializable, DLFileEntryType> dlFileEntryTypes =
  285. _persistence.fetchByPrimaryKeys(primaryKeys);
  286. Assert.assertTrue(dlFileEntryTypes.isEmpty());
  287. }
  288. @Test
  289. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  290. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  291. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  292. primaryKeys.add(newDLFileEntryType.getPrimaryKey());
  293. Map<Serializable, DLFileEntryType> dlFileEntryTypes =
  294. _persistence.fetchByPrimaryKeys(primaryKeys);
  295. Assert.assertEquals(1, dlFileEntryTypes.size());
  296. Assert.assertEquals(
  297. newDLFileEntryType,
  298. dlFileEntryTypes.get(newDLFileEntryType.getPrimaryKey()));
  299. }
  300. @Test
  301. public void testActionableDynamicQuery() throws Exception {
  302. final IntegerWrapper count = new IntegerWrapper();
  303. ActionableDynamicQuery actionableDynamicQuery =
  304. DLFileEntryTypeLocalServiceUtil.getActionableDynamicQuery();
  305. actionableDynamicQuery.setPerformActionMethod(
  306. new ActionableDynamicQuery.PerformActionMethod<DLFileEntryType>() {
  307. @Override
  308. public void performAction(DLFileEntryType dlFileEntryType) {
  309. Assert.assertNotNull(dlFileEntryType);
  310. count.increment();
  311. }
  312. });
  313. actionableDynamicQuery.performActions();
  314. Assert.assertEquals(count.getValue(), _persistence.countAll());
  315. }
  316. @Test
  317. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  318. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  319. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  320. DLFileEntryType.class, _dynamicQueryClassLoader);
  321. dynamicQuery.add(
  322. RestrictionsFactoryUtil.eq(
  323. "fileEntryTypeId", newDLFileEntryType.getFileEntryTypeId()));
  324. List<DLFileEntryType> result = _persistence.findWithDynamicQuery(
  325. dynamicQuery);
  326. Assert.assertEquals(1, result.size());
  327. DLFileEntryType existingDLFileEntryType = result.get(0);
  328. Assert.assertEquals(existingDLFileEntryType, newDLFileEntryType);
  329. }
  330. @Test
  331. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  332. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  333. DLFileEntryType.class, _dynamicQueryClassLoader);
  334. dynamicQuery.add(
  335. RestrictionsFactoryUtil.eq(
  336. "fileEntryTypeId", RandomTestUtil.nextLong()));
  337. List<DLFileEntryType> result = _persistence.findWithDynamicQuery(
  338. dynamicQuery);
  339. Assert.assertEquals(0, result.size());
  340. }
  341. @Test
  342. public void testDynamicQueryByProjectionExisting() throws Exception {
  343. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  344. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  345. DLFileEntryType.class, _dynamicQueryClassLoader);
  346. dynamicQuery.setProjection(
  347. ProjectionFactoryUtil.property("fileEntryTypeId"));
  348. Object newFileEntryTypeId = newDLFileEntryType.getFileEntryTypeId();
  349. dynamicQuery.add(
  350. RestrictionsFactoryUtil.in(
  351. "fileEntryTypeId", new Object[] {newFileEntryTypeId}));
  352. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  353. Assert.assertEquals(1, result.size());
  354. Object existingFileEntryTypeId = result.get(0);
  355. Assert.assertEquals(existingFileEntryTypeId, newFileEntryTypeId);
  356. }
  357. @Test
  358. public void testDynamicQueryByProjectionMissing() throws Exception {
  359. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  360. DLFileEntryType.class, _dynamicQueryClassLoader);
  361. dynamicQuery.setProjection(
  362. ProjectionFactoryUtil.property("fileEntryTypeId"));
  363. dynamicQuery.add(
  364. RestrictionsFactoryUtil.in(
  365. "fileEntryTypeId", new Object[] {RandomTestUtil.nextLong()}));
  366. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  367. Assert.assertEquals(0, result.size());
  368. }
  369. @Test
  370. public void testResetOriginalValues() throws Exception {
  371. DLFileEntryType newDLFileEntryType = addDLFileEntryType();
  372. _persistence.clearCache();
  373. DLFileEntryType existingDLFileEntryType = _persistence.findByPrimaryKey(
  374. newDLFileEntryType.getPrimaryKey());
  375. Assert.assertTrue(
  376. Objects.equals(
  377. existingDLFileEntryType.getUuid(),
  378. ReflectionTestUtil.invoke(
  379. existingDLFileEntryType, "getOriginalUuid",
  380. new Class<?>[0])));
  381. Assert.assertEquals(
  382. Long.valueOf(existingDLFileEntryType.getGroupId()),
  383. ReflectionTestUtil.<Long>invoke(
  384. existingDLFileEntryType, "getOriginalGroupId",
  385. new Class<?>[0]));
  386. Assert.assertEquals(
  387. Long.valueOf(existingDLFileEntryType.getGroupId()),
  388. ReflectionTestUtil.<Long>invoke(
  389. existingDLFileEntryType, "getOriginalGroupId",
  390. new Class<?>[0]));
  391. Assert.assertTrue(
  392. Objects.equals(
  393. existingDLFileEntryType.getFileEntryTypeKey(),
  394. ReflectionTestUtil.invoke(
  395. existingDLFileEntryType, "getOriginalFileEntryTypeKey",
  396. new Class<?>[0])));
  397. }
  398. protected DLFileEntryType addDLFileEntryType() throws Exception {
  399. long pk = RandomTestUtil.nextLong();
  400. DLFileEntryType dlFileEntryType = _persistence.create(pk);
  401. dlFileEntryType.setMvccVersion(RandomTestUtil.nextLong());
  402. dlFileEntryType.setCtCollectionId(RandomTestUtil.nextLong());
  403. dlFileEntryType.setUuid(RandomTestUtil.randomString());
  404. dlFileEntryType.setGroupId(RandomTestUtil.nextLong());
  405. dlFileEntryType.setCompanyId(RandomTestUtil.nextLong());
  406. dlFileEntryType.setUserId(RandomTestUtil.nextLong());
  407. dlFileEntryType.setUserName(RandomTestUtil.randomString());
  408. dlFileEntryType.setCreateDate(RandomTestUtil.nextDate());
  409. dlFileEntryType.setModifiedDate(RandomTestUtil.nextDate());
  410. dlFileEntryType.setFileEntryTypeKey(RandomTestUtil.randomString());
  411. dlFileEntryType.setName(RandomTestUtil.randomString());
  412. dlFileEntryType.setDescription(RandomTestUtil.randomString());
  413. dlFileEntryType.setLastPublishDate(RandomTestUtil.nextDate());
  414. _dlFileEntryTypes.add(_persistence.update(dlFileEntryType));
  415. return dlFileEntryType;
  416. }
  417. private List<DLFileEntryType> _dlFileEntryTypes =
  418. new ArrayList<DLFileEntryType>();
  419. private DLFileEntryTypePersistence _persistence;
  420. private ClassLoader _dynamicQueryClassLoader;
  421. }