PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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