PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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