PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/test/persistence-test/src/testIntegration/java/com/liferay/portlet/announcements/service/persistence/test/AnnouncementsEntryPersistenceTest.java

http://github.com/liferay/liferay-portal
Java | 588 lines | 412 code | 160 blank | 16 comment | 1 complexity | 03e9c379562eb409418d93770e86768d 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.announcements.service.persistence.test;
  15. import com.liferay.announcements.kernel.exception.NoSuchEntryException;
  16. import com.liferay.announcements.kernel.model.AnnouncementsEntry;
  17. import com.liferay.announcements.kernel.service.AnnouncementsEntryLocalServiceUtil;
  18. import com.liferay.announcements.kernel.service.persistence.AnnouncementsEntryPersistence;
  19. import com.liferay.announcements.kernel.service.persistence.AnnouncementsEntryUtil;
  20. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  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.rule.AggregateTestRule;
  28. import com.liferay.portal.kernel.test.util.RandomTestUtil;
  29. import com.liferay.portal.kernel.transaction.Propagation;
  30. import com.liferay.portal.kernel.util.IntegerWrapper;
  31. import com.liferay.portal.kernel.util.OrderByComparator;
  32. import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
  33. import com.liferay.portal.kernel.util.Time;
  34. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  35. import com.liferay.portal.test.rule.PersistenceTestRule;
  36. import com.liferay.portal.test.rule.TransactionalTestRule;
  37. import java.io.Serializable;
  38. import java.util.ArrayList;
  39. import java.util.HashSet;
  40. import java.util.Iterator;
  41. import java.util.List;
  42. import java.util.Map;
  43. import java.util.Set;
  44. import org.junit.After;
  45. import org.junit.Assert;
  46. import org.junit.Before;
  47. import org.junit.ClassRule;
  48. import org.junit.Rule;
  49. import org.junit.Test;
  50. import org.junit.runner.RunWith;
  51. /**
  52. * @generated
  53. */
  54. @RunWith(Arquillian.class)
  55. public class AnnouncementsEntryPersistenceTest {
  56. @ClassRule
  57. @Rule
  58. public static final AggregateTestRule aggregateTestRule =
  59. new AggregateTestRule(
  60. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  61. new TransactionalTestRule(Propagation.REQUIRED));
  62. @Before
  63. public void setUp() {
  64. _persistence = AnnouncementsEntryUtil.getPersistence();
  65. Class<?> clazz = _persistence.getClass();
  66. _dynamicQueryClassLoader = clazz.getClassLoader();
  67. }
  68. @After
  69. public void tearDown() throws Exception {
  70. Iterator<AnnouncementsEntry> iterator =
  71. _announcementsEntries.iterator();
  72. while (iterator.hasNext()) {
  73. _persistence.remove(iterator.next());
  74. iterator.remove();
  75. }
  76. }
  77. @Test
  78. public void testCreate() throws Exception {
  79. long pk = RandomTestUtil.nextLong();
  80. AnnouncementsEntry announcementsEntry = _persistence.create(pk);
  81. Assert.assertNotNull(announcementsEntry);
  82. Assert.assertEquals(announcementsEntry.getPrimaryKey(), pk);
  83. }
  84. @Test
  85. public void testRemove() throws Exception {
  86. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  87. _persistence.remove(newAnnouncementsEntry);
  88. AnnouncementsEntry existingAnnouncementsEntry =
  89. _persistence.fetchByPrimaryKey(
  90. newAnnouncementsEntry.getPrimaryKey());
  91. Assert.assertNull(existingAnnouncementsEntry);
  92. }
  93. @Test
  94. public void testUpdateNew() throws Exception {
  95. addAnnouncementsEntry();
  96. }
  97. @Test
  98. public void testUpdateExisting() throws Exception {
  99. long pk = RandomTestUtil.nextLong();
  100. AnnouncementsEntry newAnnouncementsEntry = _persistence.create(pk);
  101. newAnnouncementsEntry.setMvccVersion(RandomTestUtil.nextLong());
  102. newAnnouncementsEntry.setUuid(RandomTestUtil.randomString());
  103. newAnnouncementsEntry.setCompanyId(RandomTestUtil.nextLong());
  104. newAnnouncementsEntry.setUserId(RandomTestUtil.nextLong());
  105. newAnnouncementsEntry.setUserName(RandomTestUtil.randomString());
  106. newAnnouncementsEntry.setCreateDate(RandomTestUtil.nextDate());
  107. newAnnouncementsEntry.setModifiedDate(RandomTestUtil.nextDate());
  108. newAnnouncementsEntry.setClassNameId(RandomTestUtil.nextLong());
  109. newAnnouncementsEntry.setClassPK(RandomTestUtil.nextLong());
  110. newAnnouncementsEntry.setTitle(RandomTestUtil.randomString());
  111. newAnnouncementsEntry.setContent(RandomTestUtil.randomString());
  112. newAnnouncementsEntry.setUrl(RandomTestUtil.randomString());
  113. newAnnouncementsEntry.setType(RandomTestUtil.randomString());
  114. newAnnouncementsEntry.setDisplayDate(RandomTestUtil.nextDate());
  115. newAnnouncementsEntry.setExpirationDate(RandomTestUtil.nextDate());
  116. newAnnouncementsEntry.setPriority(RandomTestUtil.nextInt());
  117. newAnnouncementsEntry.setAlert(RandomTestUtil.randomBoolean());
  118. _announcementsEntries.add(_persistence.update(newAnnouncementsEntry));
  119. AnnouncementsEntry existingAnnouncementsEntry =
  120. _persistence.findByPrimaryKey(
  121. newAnnouncementsEntry.getPrimaryKey());
  122. Assert.assertEquals(
  123. existingAnnouncementsEntry.getMvccVersion(),
  124. newAnnouncementsEntry.getMvccVersion());
  125. Assert.assertEquals(
  126. existingAnnouncementsEntry.getUuid(),
  127. newAnnouncementsEntry.getUuid());
  128. Assert.assertEquals(
  129. existingAnnouncementsEntry.getEntryId(),
  130. newAnnouncementsEntry.getEntryId());
  131. Assert.assertEquals(
  132. existingAnnouncementsEntry.getCompanyId(),
  133. newAnnouncementsEntry.getCompanyId());
  134. Assert.assertEquals(
  135. existingAnnouncementsEntry.getUserId(),
  136. newAnnouncementsEntry.getUserId());
  137. Assert.assertEquals(
  138. existingAnnouncementsEntry.getUserName(),
  139. newAnnouncementsEntry.getUserName());
  140. Assert.assertEquals(
  141. Time.getShortTimestamp(existingAnnouncementsEntry.getCreateDate()),
  142. Time.getShortTimestamp(newAnnouncementsEntry.getCreateDate()));
  143. Assert.assertEquals(
  144. Time.getShortTimestamp(
  145. existingAnnouncementsEntry.getModifiedDate()),
  146. Time.getShortTimestamp(newAnnouncementsEntry.getModifiedDate()));
  147. Assert.assertEquals(
  148. existingAnnouncementsEntry.getClassNameId(),
  149. newAnnouncementsEntry.getClassNameId());
  150. Assert.assertEquals(
  151. existingAnnouncementsEntry.getClassPK(),
  152. newAnnouncementsEntry.getClassPK());
  153. Assert.assertEquals(
  154. existingAnnouncementsEntry.getTitle(),
  155. newAnnouncementsEntry.getTitle());
  156. Assert.assertEquals(
  157. existingAnnouncementsEntry.getContent(),
  158. newAnnouncementsEntry.getContent());
  159. Assert.assertEquals(
  160. existingAnnouncementsEntry.getUrl(),
  161. newAnnouncementsEntry.getUrl());
  162. Assert.assertEquals(
  163. existingAnnouncementsEntry.getType(),
  164. newAnnouncementsEntry.getType());
  165. Assert.assertEquals(
  166. Time.getShortTimestamp(existingAnnouncementsEntry.getDisplayDate()),
  167. Time.getShortTimestamp(newAnnouncementsEntry.getDisplayDate()));
  168. Assert.assertEquals(
  169. Time.getShortTimestamp(
  170. existingAnnouncementsEntry.getExpirationDate()),
  171. Time.getShortTimestamp(newAnnouncementsEntry.getExpirationDate()));
  172. Assert.assertEquals(
  173. existingAnnouncementsEntry.getPriority(),
  174. newAnnouncementsEntry.getPriority());
  175. Assert.assertEquals(
  176. existingAnnouncementsEntry.isAlert(),
  177. newAnnouncementsEntry.isAlert());
  178. }
  179. @Test
  180. public void testCountByUuid() throws Exception {
  181. _persistence.countByUuid("");
  182. _persistence.countByUuid("null");
  183. _persistence.countByUuid((String)null);
  184. }
  185. @Test
  186. public void testCountByUuid_C() throws Exception {
  187. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  188. _persistence.countByUuid_C("null", 0L);
  189. _persistence.countByUuid_C((String)null, 0L);
  190. }
  191. @Test
  192. public void testCountByCompanyId() throws Exception {
  193. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  194. _persistence.countByCompanyId(0L);
  195. }
  196. @Test
  197. public void testCountByUserId() throws Exception {
  198. _persistence.countByUserId(RandomTestUtil.nextLong());
  199. _persistence.countByUserId(0L);
  200. }
  201. @Test
  202. public void testCountByC_C() throws Exception {
  203. _persistence.countByC_C(
  204. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  205. _persistence.countByC_C(0L, 0L);
  206. }
  207. @Test
  208. public void testCountByC_C_C() throws Exception {
  209. _persistence.countByC_C_C(
  210. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  211. RandomTestUtil.nextLong());
  212. _persistence.countByC_C_C(0L, 0L, 0L);
  213. }
  214. @Test
  215. public void testCountByC_C_A() throws Exception {
  216. _persistence.countByC_C_A(
  217. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  218. RandomTestUtil.randomBoolean());
  219. _persistence.countByC_C_A(0L, 0L, RandomTestUtil.randomBoolean());
  220. }
  221. @Test
  222. public void testCountByC_C_C_A() throws Exception {
  223. _persistence.countByC_C_C_A(
  224. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  225. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  226. _persistence.countByC_C_C_A(0L, 0L, 0L, RandomTestUtil.randomBoolean());
  227. }
  228. @Test
  229. public void testFindByPrimaryKeyExisting() throws Exception {
  230. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  231. AnnouncementsEntry existingAnnouncementsEntry =
  232. _persistence.findByPrimaryKey(
  233. newAnnouncementsEntry.getPrimaryKey());
  234. Assert.assertEquals(existingAnnouncementsEntry, newAnnouncementsEntry);
  235. }
  236. @Test(expected = NoSuchEntryException.class)
  237. public void testFindByPrimaryKeyMissing() throws Exception {
  238. long pk = RandomTestUtil.nextLong();
  239. _persistence.findByPrimaryKey(pk);
  240. }
  241. @Test
  242. public void testFindAll() throws Exception {
  243. _persistence.findAll(
  244. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  245. }
  246. protected OrderByComparator<AnnouncementsEntry> getOrderByComparator() {
  247. return OrderByComparatorFactoryUtil.create(
  248. "AnnouncementsEntry", "mvccVersion", true, "uuid", true, "entryId",
  249. true, "companyId", true, "userId", true, "userName", true,
  250. "createDate", true, "modifiedDate", true, "classNameId", true,
  251. "classPK", true, "title", true, "url", true, "type", true,
  252. "displayDate", true, "expirationDate", true, "priority", true,
  253. "alert", true);
  254. }
  255. @Test
  256. public void testFetchByPrimaryKeyExisting() throws Exception {
  257. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  258. AnnouncementsEntry existingAnnouncementsEntry =
  259. _persistence.fetchByPrimaryKey(
  260. newAnnouncementsEntry.getPrimaryKey());
  261. Assert.assertEquals(existingAnnouncementsEntry, newAnnouncementsEntry);
  262. }
  263. @Test
  264. public void testFetchByPrimaryKeyMissing() throws Exception {
  265. long pk = RandomTestUtil.nextLong();
  266. AnnouncementsEntry missingAnnouncementsEntry =
  267. _persistence.fetchByPrimaryKey(pk);
  268. Assert.assertNull(missingAnnouncementsEntry);
  269. }
  270. @Test
  271. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  272. throws Exception {
  273. AnnouncementsEntry newAnnouncementsEntry1 = addAnnouncementsEntry();
  274. AnnouncementsEntry newAnnouncementsEntry2 = addAnnouncementsEntry();
  275. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  276. primaryKeys.add(newAnnouncementsEntry1.getPrimaryKey());
  277. primaryKeys.add(newAnnouncementsEntry2.getPrimaryKey());
  278. Map<Serializable, AnnouncementsEntry> announcementsEntries =
  279. _persistence.fetchByPrimaryKeys(primaryKeys);
  280. Assert.assertEquals(2, announcementsEntries.size());
  281. Assert.assertEquals(
  282. newAnnouncementsEntry1,
  283. announcementsEntries.get(newAnnouncementsEntry1.getPrimaryKey()));
  284. Assert.assertEquals(
  285. newAnnouncementsEntry2,
  286. announcementsEntries.get(newAnnouncementsEntry2.getPrimaryKey()));
  287. }
  288. @Test
  289. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  290. throws Exception {
  291. long pk1 = RandomTestUtil.nextLong();
  292. long pk2 = RandomTestUtil.nextLong();
  293. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  294. primaryKeys.add(pk1);
  295. primaryKeys.add(pk2);
  296. Map<Serializable, AnnouncementsEntry> announcementsEntries =
  297. _persistence.fetchByPrimaryKeys(primaryKeys);
  298. Assert.assertTrue(announcementsEntries.isEmpty());
  299. }
  300. @Test
  301. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  302. throws Exception {
  303. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  304. long pk = RandomTestUtil.nextLong();
  305. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  306. primaryKeys.add(newAnnouncementsEntry.getPrimaryKey());
  307. primaryKeys.add(pk);
  308. Map<Serializable, AnnouncementsEntry> announcementsEntries =
  309. _persistence.fetchByPrimaryKeys(primaryKeys);
  310. Assert.assertEquals(1, announcementsEntries.size());
  311. Assert.assertEquals(
  312. newAnnouncementsEntry,
  313. announcementsEntries.get(newAnnouncementsEntry.getPrimaryKey()));
  314. }
  315. @Test
  316. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  317. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  318. Map<Serializable, AnnouncementsEntry> announcementsEntries =
  319. _persistence.fetchByPrimaryKeys(primaryKeys);
  320. Assert.assertTrue(announcementsEntries.isEmpty());
  321. }
  322. @Test
  323. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  324. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  325. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  326. primaryKeys.add(newAnnouncementsEntry.getPrimaryKey());
  327. Map<Serializable, AnnouncementsEntry> announcementsEntries =
  328. _persistence.fetchByPrimaryKeys(primaryKeys);
  329. Assert.assertEquals(1, announcementsEntries.size());
  330. Assert.assertEquals(
  331. newAnnouncementsEntry,
  332. announcementsEntries.get(newAnnouncementsEntry.getPrimaryKey()));
  333. }
  334. @Test
  335. public void testActionableDynamicQuery() throws Exception {
  336. final IntegerWrapper count = new IntegerWrapper();
  337. ActionableDynamicQuery actionableDynamicQuery =
  338. AnnouncementsEntryLocalServiceUtil.getActionableDynamicQuery();
  339. actionableDynamicQuery.setPerformActionMethod(
  340. new ActionableDynamicQuery.PerformActionMethod
  341. <AnnouncementsEntry>() {
  342. @Override
  343. public void performAction(
  344. AnnouncementsEntry announcementsEntry) {
  345. Assert.assertNotNull(announcementsEntry);
  346. count.increment();
  347. }
  348. });
  349. actionableDynamicQuery.performActions();
  350. Assert.assertEquals(count.getValue(), _persistence.countAll());
  351. }
  352. @Test
  353. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  354. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  355. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  356. AnnouncementsEntry.class, _dynamicQueryClassLoader);
  357. dynamicQuery.add(
  358. RestrictionsFactoryUtil.eq(
  359. "entryId", newAnnouncementsEntry.getEntryId()));
  360. List<AnnouncementsEntry> result = _persistence.findWithDynamicQuery(
  361. dynamicQuery);
  362. Assert.assertEquals(1, result.size());
  363. AnnouncementsEntry existingAnnouncementsEntry = result.get(0);
  364. Assert.assertEquals(existingAnnouncementsEntry, newAnnouncementsEntry);
  365. }
  366. @Test
  367. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  368. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  369. AnnouncementsEntry.class, _dynamicQueryClassLoader);
  370. dynamicQuery.add(
  371. RestrictionsFactoryUtil.eq("entryId", RandomTestUtil.nextLong()));
  372. List<AnnouncementsEntry> result = _persistence.findWithDynamicQuery(
  373. dynamicQuery);
  374. Assert.assertEquals(0, result.size());
  375. }
  376. @Test
  377. public void testDynamicQueryByProjectionExisting() throws Exception {
  378. AnnouncementsEntry newAnnouncementsEntry = addAnnouncementsEntry();
  379. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  380. AnnouncementsEntry.class, _dynamicQueryClassLoader);
  381. dynamicQuery.setProjection(ProjectionFactoryUtil.property("entryId"));
  382. Object newEntryId = newAnnouncementsEntry.getEntryId();
  383. dynamicQuery.add(
  384. RestrictionsFactoryUtil.in("entryId", new Object[] {newEntryId}));
  385. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  386. Assert.assertEquals(1, result.size());
  387. Object existingEntryId = result.get(0);
  388. Assert.assertEquals(existingEntryId, newEntryId);
  389. }
  390. @Test
  391. public void testDynamicQueryByProjectionMissing() throws Exception {
  392. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  393. AnnouncementsEntry.class, _dynamicQueryClassLoader);
  394. dynamicQuery.setProjection(ProjectionFactoryUtil.property("entryId"));
  395. dynamicQuery.add(
  396. RestrictionsFactoryUtil.in(
  397. "entryId", new Object[] {RandomTestUtil.nextLong()}));
  398. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  399. Assert.assertEquals(0, result.size());
  400. }
  401. protected AnnouncementsEntry addAnnouncementsEntry() throws Exception {
  402. long pk = RandomTestUtil.nextLong();
  403. AnnouncementsEntry announcementsEntry = _persistence.create(pk);
  404. announcementsEntry.setMvccVersion(RandomTestUtil.nextLong());
  405. announcementsEntry.setUuid(RandomTestUtil.randomString());
  406. announcementsEntry.setCompanyId(RandomTestUtil.nextLong());
  407. announcementsEntry.setUserId(RandomTestUtil.nextLong());
  408. announcementsEntry.setUserName(RandomTestUtil.randomString());
  409. announcementsEntry.setCreateDate(RandomTestUtil.nextDate());
  410. announcementsEntry.setModifiedDate(RandomTestUtil.nextDate());
  411. announcementsEntry.setClassNameId(RandomTestUtil.nextLong());
  412. announcementsEntry.setClassPK(RandomTestUtil.nextLong());
  413. announcementsEntry.setTitle(RandomTestUtil.randomString());
  414. announcementsEntry.setContent(RandomTestUtil.randomString());
  415. announcementsEntry.setUrl(RandomTestUtil.randomString());
  416. announcementsEntry.setType(RandomTestUtil.randomString());
  417. announcementsEntry.setDisplayDate(RandomTestUtil.nextDate());
  418. announcementsEntry.setExpirationDate(RandomTestUtil.nextDate());
  419. announcementsEntry.setPriority(RandomTestUtil.nextInt());
  420. announcementsEntry.setAlert(RandomTestUtil.randomBoolean());
  421. _announcementsEntries.add(_persistence.update(announcementsEntry));
  422. return announcementsEntry;
  423. }
  424. private List<AnnouncementsEntry> _announcementsEntries =
  425. new ArrayList<AnnouncementsEntry>();
  426. private AnnouncementsEntryPersistence _persistence;
  427. private ClassLoader _dynamicQueryClassLoader;
  428. }