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

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

http://github.com/liferay/liferay-portal
Java | 550 lines | 399 code | 135 blank | 16 comment | 1 complexity | dc29b6b086b20dea590a5b38ca4f57ec 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.NoSuchUserNotificationDeliveryException;
  23. import com.liferay.portal.kernel.model.UserNotificationDelivery;
  24. import com.liferay.portal.kernel.service.UserNotificationDeliveryLocalServiceUtil;
  25. import com.liferay.portal.kernel.service.persistence.UserNotificationDeliveryPersistence;
  26. import com.liferay.portal.kernel.service.persistence.UserNotificationDeliveryUtil;
  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.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.Objects;
  44. import java.util.Set;
  45. import org.junit.After;
  46. import org.junit.Assert;
  47. import org.junit.Before;
  48. import org.junit.ClassRule;
  49. import org.junit.Rule;
  50. import org.junit.Test;
  51. import org.junit.runner.RunWith;
  52. /**
  53. * @generated
  54. */
  55. @RunWith(Arquillian.class)
  56. public class UserNotificationDeliveryPersistenceTest {
  57. @ClassRule
  58. @Rule
  59. public static final AggregateTestRule aggregateTestRule =
  60. new AggregateTestRule(
  61. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  62. new TransactionalTestRule(Propagation.REQUIRED));
  63. @Before
  64. public void setUp() {
  65. _persistence = UserNotificationDeliveryUtil.getPersistence();
  66. Class<?> clazz = _persistence.getClass();
  67. _dynamicQueryClassLoader = clazz.getClassLoader();
  68. }
  69. @After
  70. public void tearDown() throws Exception {
  71. Iterator<UserNotificationDelivery> iterator =
  72. _userNotificationDeliveries.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. UserNotificationDelivery userNotificationDelivery = _persistence.create(
  82. pk);
  83. Assert.assertNotNull(userNotificationDelivery);
  84. Assert.assertEquals(userNotificationDelivery.getPrimaryKey(), pk);
  85. }
  86. @Test
  87. public void testRemove() throws Exception {
  88. UserNotificationDelivery newUserNotificationDelivery =
  89. addUserNotificationDelivery();
  90. _persistence.remove(newUserNotificationDelivery);
  91. UserNotificationDelivery existingUserNotificationDelivery =
  92. _persistence.fetchByPrimaryKey(
  93. newUserNotificationDelivery.getPrimaryKey());
  94. Assert.assertNull(existingUserNotificationDelivery);
  95. }
  96. @Test
  97. public void testUpdateNew() throws Exception {
  98. addUserNotificationDelivery();
  99. }
  100. @Test
  101. public void testUpdateExisting() throws Exception {
  102. long pk = RandomTestUtil.nextLong();
  103. UserNotificationDelivery newUserNotificationDelivery =
  104. _persistence.create(pk);
  105. newUserNotificationDelivery.setMvccVersion(RandomTestUtil.nextLong());
  106. newUserNotificationDelivery.setCompanyId(RandomTestUtil.nextLong());
  107. newUserNotificationDelivery.setUserId(RandomTestUtil.nextLong());
  108. newUserNotificationDelivery.setPortletId(RandomTestUtil.randomString());
  109. newUserNotificationDelivery.setClassNameId(RandomTestUtil.nextLong());
  110. newUserNotificationDelivery.setNotificationType(
  111. RandomTestUtil.nextInt());
  112. newUserNotificationDelivery.setDeliveryType(RandomTestUtil.nextInt());
  113. newUserNotificationDelivery.setDeliver(RandomTestUtil.randomBoolean());
  114. _userNotificationDeliveries.add(
  115. _persistence.update(newUserNotificationDelivery));
  116. UserNotificationDelivery existingUserNotificationDelivery =
  117. _persistence.findByPrimaryKey(
  118. newUserNotificationDelivery.getPrimaryKey());
  119. Assert.assertEquals(
  120. existingUserNotificationDelivery.getMvccVersion(),
  121. newUserNotificationDelivery.getMvccVersion());
  122. Assert.assertEquals(
  123. existingUserNotificationDelivery.getUserNotificationDeliveryId(),
  124. newUserNotificationDelivery.getUserNotificationDeliveryId());
  125. Assert.assertEquals(
  126. existingUserNotificationDelivery.getCompanyId(),
  127. newUserNotificationDelivery.getCompanyId());
  128. Assert.assertEquals(
  129. existingUserNotificationDelivery.getUserId(),
  130. newUserNotificationDelivery.getUserId());
  131. Assert.assertEquals(
  132. existingUserNotificationDelivery.getPortletId(),
  133. newUserNotificationDelivery.getPortletId());
  134. Assert.assertEquals(
  135. existingUserNotificationDelivery.getClassNameId(),
  136. newUserNotificationDelivery.getClassNameId());
  137. Assert.assertEquals(
  138. existingUserNotificationDelivery.getNotificationType(),
  139. newUserNotificationDelivery.getNotificationType());
  140. Assert.assertEquals(
  141. existingUserNotificationDelivery.getDeliveryType(),
  142. newUserNotificationDelivery.getDeliveryType());
  143. Assert.assertEquals(
  144. existingUserNotificationDelivery.isDeliver(),
  145. newUserNotificationDelivery.isDeliver());
  146. }
  147. @Test
  148. public void testCountByUserId() throws Exception {
  149. _persistence.countByUserId(RandomTestUtil.nextLong());
  150. _persistence.countByUserId(0L);
  151. }
  152. @Test
  153. public void testCountByU_P_C_N_D() throws Exception {
  154. _persistence.countByU_P_C_N_D(
  155. RandomTestUtil.nextLong(), "", RandomTestUtil.nextLong(),
  156. RandomTestUtil.nextInt(), RandomTestUtil.nextInt());
  157. _persistence.countByU_P_C_N_D(0L, "null", 0L, 0, 0);
  158. _persistence.countByU_P_C_N_D(0L, (String)null, 0L, 0, 0);
  159. }
  160. @Test
  161. public void testFindByPrimaryKeyExisting() throws Exception {
  162. UserNotificationDelivery newUserNotificationDelivery =
  163. addUserNotificationDelivery();
  164. UserNotificationDelivery existingUserNotificationDelivery =
  165. _persistence.findByPrimaryKey(
  166. newUserNotificationDelivery.getPrimaryKey());
  167. Assert.assertEquals(
  168. existingUserNotificationDelivery, newUserNotificationDelivery);
  169. }
  170. @Test(expected = NoSuchUserNotificationDeliveryException.class)
  171. public void testFindByPrimaryKeyMissing() throws Exception {
  172. long pk = RandomTestUtil.nextLong();
  173. _persistence.findByPrimaryKey(pk);
  174. }
  175. @Test
  176. public void testFindAll() throws Exception {
  177. _persistence.findAll(
  178. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  179. }
  180. protected OrderByComparator<UserNotificationDelivery>
  181. getOrderByComparator() {
  182. return OrderByComparatorFactoryUtil.create(
  183. "UserNotificationDelivery", "mvccVersion", true,
  184. "userNotificationDeliveryId", true, "companyId", true, "userId",
  185. true, "portletId", true, "classNameId", true, "notificationType",
  186. true, "deliveryType", true, "deliver", true);
  187. }
  188. @Test
  189. public void testFetchByPrimaryKeyExisting() throws Exception {
  190. UserNotificationDelivery newUserNotificationDelivery =
  191. addUserNotificationDelivery();
  192. UserNotificationDelivery existingUserNotificationDelivery =
  193. _persistence.fetchByPrimaryKey(
  194. newUserNotificationDelivery.getPrimaryKey());
  195. Assert.assertEquals(
  196. existingUserNotificationDelivery, newUserNotificationDelivery);
  197. }
  198. @Test
  199. public void testFetchByPrimaryKeyMissing() throws Exception {
  200. long pk = RandomTestUtil.nextLong();
  201. UserNotificationDelivery missingUserNotificationDelivery =
  202. _persistence.fetchByPrimaryKey(pk);
  203. Assert.assertNull(missingUserNotificationDelivery);
  204. }
  205. @Test
  206. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  207. throws Exception {
  208. UserNotificationDelivery newUserNotificationDelivery1 =
  209. addUserNotificationDelivery();
  210. UserNotificationDelivery newUserNotificationDelivery2 =
  211. addUserNotificationDelivery();
  212. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  213. primaryKeys.add(newUserNotificationDelivery1.getPrimaryKey());
  214. primaryKeys.add(newUserNotificationDelivery2.getPrimaryKey());
  215. Map<Serializable, UserNotificationDelivery> userNotificationDeliveries =
  216. _persistence.fetchByPrimaryKeys(primaryKeys);
  217. Assert.assertEquals(2, userNotificationDeliveries.size());
  218. Assert.assertEquals(
  219. newUserNotificationDelivery1,
  220. userNotificationDeliveries.get(
  221. newUserNotificationDelivery1.getPrimaryKey()));
  222. Assert.assertEquals(
  223. newUserNotificationDelivery2,
  224. userNotificationDeliveries.get(
  225. newUserNotificationDelivery2.getPrimaryKey()));
  226. }
  227. @Test
  228. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  229. throws Exception {
  230. long pk1 = RandomTestUtil.nextLong();
  231. long pk2 = RandomTestUtil.nextLong();
  232. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  233. primaryKeys.add(pk1);
  234. primaryKeys.add(pk2);
  235. Map<Serializable, UserNotificationDelivery> userNotificationDeliveries =
  236. _persistence.fetchByPrimaryKeys(primaryKeys);
  237. Assert.assertTrue(userNotificationDeliveries.isEmpty());
  238. }
  239. @Test
  240. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  241. throws Exception {
  242. UserNotificationDelivery newUserNotificationDelivery =
  243. addUserNotificationDelivery();
  244. long pk = RandomTestUtil.nextLong();
  245. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  246. primaryKeys.add(newUserNotificationDelivery.getPrimaryKey());
  247. primaryKeys.add(pk);
  248. Map<Serializable, UserNotificationDelivery> userNotificationDeliveries =
  249. _persistence.fetchByPrimaryKeys(primaryKeys);
  250. Assert.assertEquals(1, userNotificationDeliveries.size());
  251. Assert.assertEquals(
  252. newUserNotificationDelivery,
  253. userNotificationDeliveries.get(
  254. newUserNotificationDelivery.getPrimaryKey()));
  255. }
  256. @Test
  257. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  258. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  259. Map<Serializable, UserNotificationDelivery> userNotificationDeliveries =
  260. _persistence.fetchByPrimaryKeys(primaryKeys);
  261. Assert.assertTrue(userNotificationDeliveries.isEmpty());
  262. }
  263. @Test
  264. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  265. UserNotificationDelivery newUserNotificationDelivery =
  266. addUserNotificationDelivery();
  267. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  268. primaryKeys.add(newUserNotificationDelivery.getPrimaryKey());
  269. Map<Serializable, UserNotificationDelivery> userNotificationDeliveries =
  270. _persistence.fetchByPrimaryKeys(primaryKeys);
  271. Assert.assertEquals(1, userNotificationDeliveries.size());
  272. Assert.assertEquals(
  273. newUserNotificationDelivery,
  274. userNotificationDeliveries.get(
  275. newUserNotificationDelivery.getPrimaryKey()));
  276. }
  277. @Test
  278. public void testActionableDynamicQuery() throws Exception {
  279. final IntegerWrapper count = new IntegerWrapper();
  280. ActionableDynamicQuery actionableDynamicQuery =
  281. UserNotificationDeliveryLocalServiceUtil.
  282. getActionableDynamicQuery();
  283. actionableDynamicQuery.setPerformActionMethod(
  284. new ActionableDynamicQuery.PerformActionMethod
  285. <UserNotificationDelivery>() {
  286. @Override
  287. public void performAction(
  288. UserNotificationDelivery userNotificationDelivery) {
  289. Assert.assertNotNull(userNotificationDelivery);
  290. count.increment();
  291. }
  292. });
  293. actionableDynamicQuery.performActions();
  294. Assert.assertEquals(count.getValue(), _persistence.countAll());
  295. }
  296. @Test
  297. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  298. UserNotificationDelivery newUserNotificationDelivery =
  299. addUserNotificationDelivery();
  300. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  301. UserNotificationDelivery.class, _dynamicQueryClassLoader);
  302. dynamicQuery.add(
  303. RestrictionsFactoryUtil.eq(
  304. "userNotificationDeliveryId",
  305. newUserNotificationDelivery.getUserNotificationDeliveryId()));
  306. List<UserNotificationDelivery> result =
  307. _persistence.findWithDynamicQuery(dynamicQuery);
  308. Assert.assertEquals(1, result.size());
  309. UserNotificationDelivery existingUserNotificationDelivery = result.get(
  310. 0);
  311. Assert.assertEquals(
  312. existingUserNotificationDelivery, newUserNotificationDelivery);
  313. }
  314. @Test
  315. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  316. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  317. UserNotificationDelivery.class, _dynamicQueryClassLoader);
  318. dynamicQuery.add(
  319. RestrictionsFactoryUtil.eq(
  320. "userNotificationDeliveryId", RandomTestUtil.nextLong()));
  321. List<UserNotificationDelivery> result =
  322. _persistence.findWithDynamicQuery(dynamicQuery);
  323. Assert.assertEquals(0, result.size());
  324. }
  325. @Test
  326. public void testDynamicQueryByProjectionExisting() throws Exception {
  327. UserNotificationDelivery newUserNotificationDelivery =
  328. addUserNotificationDelivery();
  329. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  330. UserNotificationDelivery.class, _dynamicQueryClassLoader);
  331. dynamicQuery.setProjection(
  332. ProjectionFactoryUtil.property("userNotificationDeliveryId"));
  333. Object newUserNotificationDeliveryId =
  334. newUserNotificationDelivery.getUserNotificationDeliveryId();
  335. dynamicQuery.add(
  336. RestrictionsFactoryUtil.in(
  337. "userNotificationDeliveryId",
  338. new Object[] {newUserNotificationDeliveryId}));
  339. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  340. Assert.assertEquals(1, result.size());
  341. Object existingUserNotificationDeliveryId = result.get(0);
  342. Assert.assertEquals(
  343. existingUserNotificationDeliveryId, newUserNotificationDeliveryId);
  344. }
  345. @Test
  346. public void testDynamicQueryByProjectionMissing() throws Exception {
  347. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  348. UserNotificationDelivery.class, _dynamicQueryClassLoader);
  349. dynamicQuery.setProjection(
  350. ProjectionFactoryUtil.property("userNotificationDeliveryId"));
  351. dynamicQuery.add(
  352. RestrictionsFactoryUtil.in(
  353. "userNotificationDeliveryId",
  354. new Object[] {RandomTestUtil.nextLong()}));
  355. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  356. Assert.assertEquals(0, result.size());
  357. }
  358. @Test
  359. public void testResetOriginalValues() throws Exception {
  360. UserNotificationDelivery newUserNotificationDelivery =
  361. addUserNotificationDelivery();
  362. _persistence.clearCache();
  363. UserNotificationDelivery existingUserNotificationDelivery =
  364. _persistence.findByPrimaryKey(
  365. newUserNotificationDelivery.getPrimaryKey());
  366. Assert.assertEquals(
  367. Long.valueOf(existingUserNotificationDelivery.getUserId()),
  368. ReflectionTestUtil.<Long>invoke(
  369. existingUserNotificationDelivery, "getOriginalUserId",
  370. new Class<?>[0]));
  371. Assert.assertTrue(
  372. Objects.equals(
  373. existingUserNotificationDelivery.getPortletId(),
  374. ReflectionTestUtil.invoke(
  375. existingUserNotificationDelivery, "getOriginalPortletId",
  376. new Class<?>[0])));
  377. Assert.assertEquals(
  378. Long.valueOf(existingUserNotificationDelivery.getClassNameId()),
  379. ReflectionTestUtil.<Long>invoke(
  380. existingUserNotificationDelivery, "getOriginalClassNameId",
  381. new Class<?>[0]));
  382. Assert.assertEquals(
  383. Integer.valueOf(
  384. existingUserNotificationDelivery.getNotificationType()),
  385. ReflectionTestUtil.<Integer>invoke(
  386. existingUserNotificationDelivery, "getOriginalNotificationType",
  387. new Class<?>[0]));
  388. Assert.assertEquals(
  389. Integer.valueOf(existingUserNotificationDelivery.getDeliveryType()),
  390. ReflectionTestUtil.<Integer>invoke(
  391. existingUserNotificationDelivery, "getOriginalDeliveryType",
  392. new Class<?>[0]));
  393. }
  394. protected UserNotificationDelivery addUserNotificationDelivery()
  395. throws Exception {
  396. long pk = RandomTestUtil.nextLong();
  397. UserNotificationDelivery userNotificationDelivery = _persistence.create(
  398. pk);
  399. userNotificationDelivery.setMvccVersion(RandomTestUtil.nextLong());
  400. userNotificationDelivery.setCompanyId(RandomTestUtil.nextLong());
  401. userNotificationDelivery.setUserId(RandomTestUtil.nextLong());
  402. userNotificationDelivery.setPortletId(RandomTestUtil.randomString());
  403. userNotificationDelivery.setClassNameId(RandomTestUtil.nextLong());
  404. userNotificationDelivery.setNotificationType(RandomTestUtil.nextInt());
  405. userNotificationDelivery.setDeliveryType(RandomTestUtil.nextInt());
  406. userNotificationDelivery.setDeliver(RandomTestUtil.randomBoolean());
  407. _userNotificationDeliveries.add(
  408. _persistence.update(userNotificationDelivery));
  409. return userNotificationDelivery;
  410. }
  411. private List<UserNotificationDelivery> _userNotificationDeliveries =
  412. new ArrayList<UserNotificationDelivery>();
  413. private UserNotificationDeliveryPersistence _persistence;
  414. private ClassLoader _dynamicQueryClassLoader;
  415. }