PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

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