PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/test/persistence-test/src/testIntegration/java/com/liferay/portal/service/persistence/test/RepositoryEntryPersistenceTest.java

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