PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/liferay/liferay-portal
Java | 513 lines | 354 code | 143 blank | 16 comment | 1 complexity | 5ccb685ac1378a9718d286341adf997d 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.NoSuchSystemEventException;
  23. import com.liferay.portal.kernel.model.SystemEvent;
  24. import com.liferay.portal.kernel.service.SystemEventLocalServiceUtil;
  25. import com.liferay.portal.kernel.service.persistence.SystemEventPersistence;
  26. import com.liferay.portal.kernel.service.persistence.SystemEventUtil;
  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 SystemEventPersistenceTest {
  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 = SystemEventUtil.getPersistence();
  65. Class<?> clazz = _persistence.getClass();
  66. _dynamicQueryClassLoader = clazz.getClassLoader();
  67. }
  68. @After
  69. public void tearDown() throws Exception {
  70. Iterator<SystemEvent> iterator = _systemEvents.iterator();
  71. while (iterator.hasNext()) {
  72. _persistence.remove(iterator.next());
  73. iterator.remove();
  74. }
  75. }
  76. @Test
  77. public void testCreate() throws Exception {
  78. long pk = RandomTestUtil.nextLong();
  79. SystemEvent systemEvent = _persistence.create(pk);
  80. Assert.assertNotNull(systemEvent);
  81. Assert.assertEquals(systemEvent.getPrimaryKey(), pk);
  82. }
  83. @Test
  84. public void testRemove() throws Exception {
  85. SystemEvent newSystemEvent = addSystemEvent();
  86. _persistence.remove(newSystemEvent);
  87. SystemEvent existingSystemEvent = _persistence.fetchByPrimaryKey(
  88. newSystemEvent.getPrimaryKey());
  89. Assert.assertNull(existingSystemEvent);
  90. }
  91. @Test
  92. public void testUpdateNew() throws Exception {
  93. addSystemEvent();
  94. }
  95. @Test
  96. public void testUpdateExisting() throws Exception {
  97. long pk = RandomTestUtil.nextLong();
  98. SystemEvent newSystemEvent = _persistence.create(pk);
  99. newSystemEvent.setMvccVersion(RandomTestUtil.nextLong());
  100. newSystemEvent.setGroupId(RandomTestUtil.nextLong());
  101. newSystemEvent.setCompanyId(RandomTestUtil.nextLong());
  102. newSystemEvent.setUserId(RandomTestUtil.nextLong());
  103. newSystemEvent.setUserName(RandomTestUtil.randomString());
  104. newSystemEvent.setCreateDate(RandomTestUtil.nextDate());
  105. newSystemEvent.setClassNameId(RandomTestUtil.nextLong());
  106. newSystemEvent.setClassPK(RandomTestUtil.nextLong());
  107. newSystemEvent.setClassUuid(RandomTestUtil.randomString());
  108. newSystemEvent.setReferrerClassNameId(RandomTestUtil.nextLong());
  109. newSystemEvent.setParentSystemEventId(RandomTestUtil.nextLong());
  110. newSystemEvent.setSystemEventSetKey(RandomTestUtil.nextLong());
  111. newSystemEvent.setType(RandomTestUtil.nextInt());
  112. newSystemEvent.setExtraData(RandomTestUtil.randomString());
  113. _systemEvents.add(_persistence.update(newSystemEvent));
  114. SystemEvent existingSystemEvent = _persistence.findByPrimaryKey(
  115. newSystemEvent.getPrimaryKey());
  116. Assert.assertEquals(
  117. existingSystemEvent.getMvccVersion(),
  118. newSystemEvent.getMvccVersion());
  119. Assert.assertEquals(
  120. existingSystemEvent.getSystemEventId(),
  121. newSystemEvent.getSystemEventId());
  122. Assert.assertEquals(
  123. existingSystemEvent.getGroupId(), newSystemEvent.getGroupId());
  124. Assert.assertEquals(
  125. existingSystemEvent.getCompanyId(), newSystemEvent.getCompanyId());
  126. Assert.assertEquals(
  127. existingSystemEvent.getUserId(), newSystemEvent.getUserId());
  128. Assert.assertEquals(
  129. existingSystemEvent.getUserName(), newSystemEvent.getUserName());
  130. Assert.assertEquals(
  131. Time.getShortTimestamp(existingSystemEvent.getCreateDate()),
  132. Time.getShortTimestamp(newSystemEvent.getCreateDate()));
  133. Assert.assertEquals(
  134. existingSystemEvent.getClassNameId(),
  135. newSystemEvent.getClassNameId());
  136. Assert.assertEquals(
  137. existingSystemEvent.getClassPK(), newSystemEvent.getClassPK());
  138. Assert.assertEquals(
  139. existingSystemEvent.getClassUuid(), newSystemEvent.getClassUuid());
  140. Assert.assertEquals(
  141. existingSystemEvent.getReferrerClassNameId(),
  142. newSystemEvent.getReferrerClassNameId());
  143. Assert.assertEquals(
  144. existingSystemEvent.getParentSystemEventId(),
  145. newSystemEvent.getParentSystemEventId());
  146. Assert.assertEquals(
  147. existingSystemEvent.getSystemEventSetKey(),
  148. newSystemEvent.getSystemEventSetKey());
  149. Assert.assertEquals(
  150. existingSystemEvent.getType(), newSystemEvent.getType());
  151. Assert.assertEquals(
  152. existingSystemEvent.getExtraData(), newSystemEvent.getExtraData());
  153. }
  154. @Test
  155. public void testCountByGroupId() throws Exception {
  156. _persistence.countByGroupId(RandomTestUtil.nextLong());
  157. _persistence.countByGroupId(0L);
  158. }
  159. @Test
  160. public void testCountByG_S() throws Exception {
  161. _persistence.countByG_S(
  162. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  163. _persistence.countByG_S(0L, 0L);
  164. }
  165. @Test
  166. public void testCountByG_C_C() throws Exception {
  167. _persistence.countByG_C_C(
  168. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  169. RandomTestUtil.nextLong());
  170. _persistence.countByG_C_C(0L, 0L, 0L);
  171. }
  172. @Test
  173. public void testCountByG_C_C_T() throws Exception {
  174. _persistence.countByG_C_C_T(
  175. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  176. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  177. _persistence.countByG_C_C_T(0L, 0L, 0L, 0);
  178. }
  179. @Test
  180. public void testFindByPrimaryKeyExisting() throws Exception {
  181. SystemEvent newSystemEvent = addSystemEvent();
  182. SystemEvent existingSystemEvent = _persistence.findByPrimaryKey(
  183. newSystemEvent.getPrimaryKey());
  184. Assert.assertEquals(existingSystemEvent, newSystemEvent);
  185. }
  186. @Test(expected = NoSuchSystemEventException.class)
  187. public void testFindByPrimaryKeyMissing() throws Exception {
  188. long pk = RandomTestUtil.nextLong();
  189. _persistence.findByPrimaryKey(pk);
  190. }
  191. @Test
  192. public void testFindAll() throws Exception {
  193. _persistence.findAll(
  194. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  195. }
  196. protected OrderByComparator<SystemEvent> getOrderByComparator() {
  197. return OrderByComparatorFactoryUtil.create(
  198. "SystemEvent", "mvccVersion", true, "systemEventId", true,
  199. "groupId", true, "companyId", true, "userId", true, "userName",
  200. true, "createDate", true, "classNameId", true, "classPK", true,
  201. "classUuid", true, "referrerClassNameId", true,
  202. "parentSystemEventId", true, "systemEventSetKey", true, "type",
  203. true);
  204. }
  205. @Test
  206. public void testFetchByPrimaryKeyExisting() throws Exception {
  207. SystemEvent newSystemEvent = addSystemEvent();
  208. SystemEvent existingSystemEvent = _persistence.fetchByPrimaryKey(
  209. newSystemEvent.getPrimaryKey());
  210. Assert.assertEquals(existingSystemEvent, newSystemEvent);
  211. }
  212. @Test
  213. public void testFetchByPrimaryKeyMissing() throws Exception {
  214. long pk = RandomTestUtil.nextLong();
  215. SystemEvent missingSystemEvent = _persistence.fetchByPrimaryKey(pk);
  216. Assert.assertNull(missingSystemEvent);
  217. }
  218. @Test
  219. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  220. throws Exception {
  221. SystemEvent newSystemEvent1 = addSystemEvent();
  222. SystemEvent newSystemEvent2 = addSystemEvent();
  223. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  224. primaryKeys.add(newSystemEvent1.getPrimaryKey());
  225. primaryKeys.add(newSystemEvent2.getPrimaryKey());
  226. Map<Serializable, SystemEvent> systemEvents =
  227. _persistence.fetchByPrimaryKeys(primaryKeys);
  228. Assert.assertEquals(2, systemEvents.size());
  229. Assert.assertEquals(
  230. newSystemEvent1, systemEvents.get(newSystemEvent1.getPrimaryKey()));
  231. Assert.assertEquals(
  232. newSystemEvent2, systemEvents.get(newSystemEvent2.getPrimaryKey()));
  233. }
  234. @Test
  235. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  236. throws Exception {
  237. long pk1 = RandomTestUtil.nextLong();
  238. long pk2 = RandomTestUtil.nextLong();
  239. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  240. primaryKeys.add(pk1);
  241. primaryKeys.add(pk2);
  242. Map<Serializable, SystemEvent> systemEvents =
  243. _persistence.fetchByPrimaryKeys(primaryKeys);
  244. Assert.assertTrue(systemEvents.isEmpty());
  245. }
  246. @Test
  247. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  248. throws Exception {
  249. SystemEvent newSystemEvent = addSystemEvent();
  250. long pk = RandomTestUtil.nextLong();
  251. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  252. primaryKeys.add(newSystemEvent.getPrimaryKey());
  253. primaryKeys.add(pk);
  254. Map<Serializable, SystemEvent> systemEvents =
  255. _persistence.fetchByPrimaryKeys(primaryKeys);
  256. Assert.assertEquals(1, systemEvents.size());
  257. Assert.assertEquals(
  258. newSystemEvent, systemEvents.get(newSystemEvent.getPrimaryKey()));
  259. }
  260. @Test
  261. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  262. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  263. Map<Serializable, SystemEvent> systemEvents =
  264. _persistence.fetchByPrimaryKeys(primaryKeys);
  265. Assert.assertTrue(systemEvents.isEmpty());
  266. }
  267. @Test
  268. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  269. SystemEvent newSystemEvent = addSystemEvent();
  270. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  271. primaryKeys.add(newSystemEvent.getPrimaryKey());
  272. Map<Serializable, SystemEvent> systemEvents =
  273. _persistence.fetchByPrimaryKeys(primaryKeys);
  274. Assert.assertEquals(1, systemEvents.size());
  275. Assert.assertEquals(
  276. newSystemEvent, systemEvents.get(newSystemEvent.getPrimaryKey()));
  277. }
  278. @Test
  279. public void testActionableDynamicQuery() throws Exception {
  280. final IntegerWrapper count = new IntegerWrapper();
  281. ActionableDynamicQuery actionableDynamicQuery =
  282. SystemEventLocalServiceUtil.getActionableDynamicQuery();
  283. actionableDynamicQuery.setPerformActionMethod(
  284. new ActionableDynamicQuery.PerformActionMethod<SystemEvent>() {
  285. @Override
  286. public void performAction(SystemEvent systemEvent) {
  287. Assert.assertNotNull(systemEvent);
  288. count.increment();
  289. }
  290. });
  291. actionableDynamicQuery.performActions();
  292. Assert.assertEquals(count.getValue(), _persistence.countAll());
  293. }
  294. @Test
  295. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  296. SystemEvent newSystemEvent = addSystemEvent();
  297. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  298. SystemEvent.class, _dynamicQueryClassLoader);
  299. dynamicQuery.add(
  300. RestrictionsFactoryUtil.eq(
  301. "systemEventId", newSystemEvent.getSystemEventId()));
  302. List<SystemEvent> result = _persistence.findWithDynamicQuery(
  303. dynamicQuery);
  304. Assert.assertEquals(1, result.size());
  305. SystemEvent existingSystemEvent = result.get(0);
  306. Assert.assertEquals(existingSystemEvent, newSystemEvent);
  307. }
  308. @Test
  309. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  310. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  311. SystemEvent.class, _dynamicQueryClassLoader);
  312. dynamicQuery.add(
  313. RestrictionsFactoryUtil.eq(
  314. "systemEventId", RandomTestUtil.nextLong()));
  315. List<SystemEvent> result = _persistence.findWithDynamicQuery(
  316. dynamicQuery);
  317. Assert.assertEquals(0, result.size());
  318. }
  319. @Test
  320. public void testDynamicQueryByProjectionExisting() throws Exception {
  321. SystemEvent newSystemEvent = addSystemEvent();
  322. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  323. SystemEvent.class, _dynamicQueryClassLoader);
  324. dynamicQuery.setProjection(
  325. ProjectionFactoryUtil.property("systemEventId"));
  326. Object newSystemEventId = newSystemEvent.getSystemEventId();
  327. dynamicQuery.add(
  328. RestrictionsFactoryUtil.in(
  329. "systemEventId", new Object[] {newSystemEventId}));
  330. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  331. Assert.assertEquals(1, result.size());
  332. Object existingSystemEventId = result.get(0);
  333. Assert.assertEquals(existingSystemEventId, newSystemEventId);
  334. }
  335. @Test
  336. public void testDynamicQueryByProjectionMissing() throws Exception {
  337. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  338. SystemEvent.class, _dynamicQueryClassLoader);
  339. dynamicQuery.setProjection(
  340. ProjectionFactoryUtil.property("systemEventId"));
  341. dynamicQuery.add(
  342. RestrictionsFactoryUtil.in(
  343. "systemEventId", new Object[] {RandomTestUtil.nextLong()}));
  344. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  345. Assert.assertEquals(0, result.size());
  346. }
  347. protected SystemEvent addSystemEvent() throws Exception {
  348. long pk = RandomTestUtil.nextLong();
  349. SystemEvent systemEvent = _persistence.create(pk);
  350. systemEvent.setMvccVersion(RandomTestUtil.nextLong());
  351. systemEvent.setGroupId(RandomTestUtil.nextLong());
  352. systemEvent.setCompanyId(RandomTestUtil.nextLong());
  353. systemEvent.setUserId(RandomTestUtil.nextLong());
  354. systemEvent.setUserName(RandomTestUtil.randomString());
  355. systemEvent.setCreateDate(RandomTestUtil.nextDate());
  356. systemEvent.setClassNameId(RandomTestUtil.nextLong());
  357. systemEvent.setClassPK(RandomTestUtil.nextLong());
  358. systemEvent.setClassUuid(RandomTestUtil.randomString());
  359. systemEvent.setReferrerClassNameId(RandomTestUtil.nextLong());
  360. systemEvent.setParentSystemEventId(RandomTestUtil.nextLong());
  361. systemEvent.setSystemEventSetKey(RandomTestUtil.nextLong());
  362. systemEvent.setType(RandomTestUtil.nextInt());
  363. systemEvent.setExtraData(RandomTestUtil.randomString());
  364. _systemEvents.add(_persistence.update(systemEvent));
  365. return systemEvent;
  366. }
  367. private List<SystemEvent> _systemEvents = new ArrayList<SystemEvent>();
  368. private SystemEventPersistence _persistence;
  369. private ClassLoader _dynamicQueryClassLoader;
  370. }