PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

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