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

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

http://github.com/liferay/liferay-portal
Java | 938 lines | 668 code | 254 blank | 16 comment | 1 complexity | 11b3cb54bddcea6408c72c25c6417ae2 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.NoSuchLayoutException;
  23. import com.liferay.portal.kernel.model.Layout;
  24. import com.liferay.portal.kernel.service.LayoutLocalServiceUtil;
  25. import com.liferay.portal.kernel.service.persistence.LayoutPersistence;
  26. import com.liferay.portal.kernel.service.persistence.LayoutUtil;
  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.kernel.util.Time;
  35. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  36. import com.liferay.portal.test.rule.PersistenceTestRule;
  37. import com.liferay.portal.test.rule.TransactionalTestRule;
  38. import java.io.Serializable;
  39. import java.util.ArrayList;
  40. import java.util.HashSet;
  41. import java.util.Iterator;
  42. import java.util.List;
  43. import java.util.Map;
  44. import java.util.Objects;
  45. import java.util.Set;
  46. import org.junit.After;
  47. import org.junit.Assert;
  48. import org.junit.Before;
  49. import org.junit.ClassRule;
  50. import org.junit.Rule;
  51. import org.junit.Test;
  52. import org.junit.runner.RunWith;
  53. /**
  54. * @generated
  55. */
  56. @RunWith(Arquillian.class)
  57. public class LayoutPersistenceTest {
  58. @ClassRule
  59. @Rule
  60. public static final AggregateTestRule aggregateTestRule =
  61. new AggregateTestRule(
  62. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  63. new TransactionalTestRule(Propagation.REQUIRED));
  64. @Before
  65. public void setUp() {
  66. _persistence = LayoutUtil.getPersistence();
  67. Class<?> clazz = _persistence.getClass();
  68. _dynamicQueryClassLoader = clazz.getClassLoader();
  69. }
  70. @After
  71. public void tearDown() throws Exception {
  72. Iterator<Layout> iterator = _layouts.iterator();
  73. while (iterator.hasNext()) {
  74. _persistence.remove(iterator.next());
  75. iterator.remove();
  76. }
  77. }
  78. @Test
  79. public void testCreate() throws Exception {
  80. long pk = RandomTestUtil.nextLong();
  81. Layout layout = _persistence.create(pk);
  82. Assert.assertNotNull(layout);
  83. Assert.assertEquals(layout.getPrimaryKey(), pk);
  84. }
  85. @Test
  86. public void testRemove() throws Exception {
  87. Layout newLayout = addLayout();
  88. _persistence.remove(newLayout);
  89. Layout existingLayout = _persistence.fetchByPrimaryKey(
  90. newLayout.getPrimaryKey());
  91. Assert.assertNull(existingLayout);
  92. }
  93. @Test
  94. public void testUpdateNew() throws Exception {
  95. addLayout();
  96. }
  97. @Test
  98. public void testUpdateExisting() throws Exception {
  99. long pk = RandomTestUtil.nextLong();
  100. Layout newLayout = _persistence.create(pk);
  101. newLayout.setMvccVersion(RandomTestUtil.nextLong());
  102. newLayout.setCtCollectionId(RandomTestUtil.nextLong());
  103. newLayout.setUuid(RandomTestUtil.randomString());
  104. newLayout.setGroupId(RandomTestUtil.nextLong());
  105. newLayout.setCompanyId(RandomTestUtil.nextLong());
  106. newLayout.setUserId(RandomTestUtil.nextLong());
  107. newLayout.setUserName(RandomTestUtil.randomString());
  108. newLayout.setCreateDate(RandomTestUtil.nextDate());
  109. newLayout.setModifiedDate(RandomTestUtil.nextDate());
  110. newLayout.setParentPlid(RandomTestUtil.nextLong());
  111. newLayout.setPrivateLayout(RandomTestUtil.randomBoolean());
  112. newLayout.setLayoutId(RandomTestUtil.nextLong());
  113. newLayout.setParentLayoutId(RandomTestUtil.nextLong());
  114. newLayout.setClassNameId(RandomTestUtil.nextLong());
  115. newLayout.setClassPK(RandomTestUtil.nextLong());
  116. newLayout.setName(RandomTestUtil.randomString());
  117. newLayout.setTitle(RandomTestUtil.randomString());
  118. newLayout.setDescription(RandomTestUtil.randomString());
  119. newLayout.setKeywords(RandomTestUtil.randomString());
  120. newLayout.setRobots(RandomTestUtil.randomString());
  121. newLayout.setType(RandomTestUtil.randomString());
  122. newLayout.setTypeSettings(RandomTestUtil.randomString());
  123. newLayout.setHidden(RandomTestUtil.randomBoolean());
  124. newLayout.setSystem(RandomTestUtil.randomBoolean());
  125. newLayout.setFriendlyURL(RandomTestUtil.randomString());
  126. newLayout.setIconImageId(RandomTestUtil.nextLong());
  127. newLayout.setThemeId(RandomTestUtil.randomString());
  128. newLayout.setColorSchemeId(RandomTestUtil.randomString());
  129. newLayout.setCss(RandomTestUtil.randomString());
  130. newLayout.setPriority(RandomTestUtil.nextInt());
  131. newLayout.setMasterLayoutPlid(RandomTestUtil.nextLong());
  132. newLayout.setLayoutPrototypeUuid(RandomTestUtil.randomString());
  133. newLayout.setLayoutPrototypeLinkEnabled(RandomTestUtil.randomBoolean());
  134. newLayout.setSourcePrototypeLayoutUuid(RandomTestUtil.randomString());
  135. newLayout.setPublishDate(RandomTestUtil.nextDate());
  136. newLayout.setLastPublishDate(RandomTestUtil.nextDate());
  137. newLayout.setStatus(RandomTestUtil.nextInt());
  138. newLayout.setStatusByUserId(RandomTestUtil.nextLong());
  139. newLayout.setStatusByUserName(RandomTestUtil.randomString());
  140. newLayout.setStatusDate(RandomTestUtil.nextDate());
  141. _layouts.add(_persistence.update(newLayout));
  142. Layout existingLayout = _persistence.findByPrimaryKey(
  143. newLayout.getPrimaryKey());
  144. Assert.assertEquals(
  145. existingLayout.getMvccVersion(), newLayout.getMvccVersion());
  146. Assert.assertEquals(
  147. existingLayout.getCtCollectionId(), newLayout.getCtCollectionId());
  148. Assert.assertEquals(existingLayout.getUuid(), newLayout.getUuid());
  149. Assert.assertEquals(existingLayout.getPlid(), newLayout.getPlid());
  150. Assert.assertEquals(
  151. existingLayout.getGroupId(), newLayout.getGroupId());
  152. Assert.assertEquals(
  153. existingLayout.getCompanyId(), newLayout.getCompanyId());
  154. Assert.assertEquals(existingLayout.getUserId(), newLayout.getUserId());
  155. Assert.assertEquals(
  156. existingLayout.getUserName(), newLayout.getUserName());
  157. Assert.assertEquals(
  158. Time.getShortTimestamp(existingLayout.getCreateDate()),
  159. Time.getShortTimestamp(newLayout.getCreateDate()));
  160. Assert.assertEquals(
  161. Time.getShortTimestamp(existingLayout.getModifiedDate()),
  162. Time.getShortTimestamp(newLayout.getModifiedDate()));
  163. Assert.assertEquals(
  164. existingLayout.getParentPlid(), newLayout.getParentPlid());
  165. Assert.assertEquals(
  166. existingLayout.isPrivateLayout(), newLayout.isPrivateLayout());
  167. Assert.assertEquals(
  168. existingLayout.getLayoutId(), newLayout.getLayoutId());
  169. Assert.assertEquals(
  170. existingLayout.getParentLayoutId(), newLayout.getParentLayoutId());
  171. Assert.assertEquals(
  172. existingLayout.getClassNameId(), newLayout.getClassNameId());
  173. Assert.assertEquals(
  174. existingLayout.getClassPK(), newLayout.getClassPK());
  175. Assert.assertEquals(existingLayout.getName(), newLayout.getName());
  176. Assert.assertEquals(existingLayout.getTitle(), newLayout.getTitle());
  177. Assert.assertEquals(
  178. existingLayout.getDescription(), newLayout.getDescription());
  179. Assert.assertEquals(
  180. existingLayout.getKeywords(), newLayout.getKeywords());
  181. Assert.assertEquals(existingLayout.getRobots(), newLayout.getRobots());
  182. Assert.assertEquals(existingLayout.getType(), newLayout.getType());
  183. Assert.assertEquals(
  184. existingLayout.getTypeSettings(), newLayout.getTypeSettings());
  185. Assert.assertEquals(existingLayout.isHidden(), newLayout.isHidden());
  186. Assert.assertEquals(existingLayout.isSystem(), newLayout.isSystem());
  187. Assert.assertEquals(
  188. existingLayout.getFriendlyURL(), newLayout.getFriendlyURL());
  189. Assert.assertEquals(
  190. existingLayout.getIconImageId(), newLayout.getIconImageId());
  191. Assert.assertEquals(
  192. existingLayout.getThemeId(), newLayout.getThemeId());
  193. Assert.assertEquals(
  194. existingLayout.getColorSchemeId(), newLayout.getColorSchemeId());
  195. Assert.assertEquals(existingLayout.getCss(), newLayout.getCss());
  196. Assert.assertEquals(
  197. existingLayout.getPriority(), newLayout.getPriority());
  198. Assert.assertEquals(
  199. existingLayout.getMasterLayoutPlid(),
  200. newLayout.getMasterLayoutPlid());
  201. Assert.assertEquals(
  202. existingLayout.getLayoutPrototypeUuid(),
  203. newLayout.getLayoutPrototypeUuid());
  204. Assert.assertEquals(
  205. existingLayout.isLayoutPrototypeLinkEnabled(),
  206. newLayout.isLayoutPrototypeLinkEnabled());
  207. Assert.assertEquals(
  208. existingLayout.getSourcePrototypeLayoutUuid(),
  209. newLayout.getSourcePrototypeLayoutUuid());
  210. Assert.assertEquals(
  211. Time.getShortTimestamp(existingLayout.getPublishDate()),
  212. Time.getShortTimestamp(newLayout.getPublishDate()));
  213. Assert.assertEquals(
  214. Time.getShortTimestamp(existingLayout.getLastPublishDate()),
  215. Time.getShortTimestamp(newLayout.getLastPublishDate()));
  216. Assert.assertEquals(existingLayout.getStatus(), newLayout.getStatus());
  217. Assert.assertEquals(
  218. existingLayout.getStatusByUserId(), newLayout.getStatusByUserId());
  219. Assert.assertEquals(
  220. existingLayout.getStatusByUserName(),
  221. newLayout.getStatusByUserName());
  222. Assert.assertEquals(
  223. Time.getShortTimestamp(existingLayout.getStatusDate()),
  224. Time.getShortTimestamp(newLayout.getStatusDate()));
  225. }
  226. @Test
  227. public void testCountByUuid() throws Exception {
  228. _persistence.countByUuid("");
  229. _persistence.countByUuid("null");
  230. _persistence.countByUuid((String)null);
  231. }
  232. @Test
  233. public void testCountByUUID_G_P() throws Exception {
  234. _persistence.countByUUID_G_P(
  235. "", RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  236. _persistence.countByUUID_G_P(
  237. "null", 0L, RandomTestUtil.randomBoolean());
  238. _persistence.countByUUID_G_P(
  239. (String)null, 0L, RandomTestUtil.randomBoolean());
  240. }
  241. @Test
  242. public void testCountByUuid_C() throws Exception {
  243. _persistence.countByUuid_C("", RandomTestUtil.nextLong());
  244. _persistence.countByUuid_C("null", 0L);
  245. _persistence.countByUuid_C((String)null, 0L);
  246. }
  247. @Test
  248. public void testCountByGroupId() throws Exception {
  249. _persistence.countByGroupId(RandomTestUtil.nextLong());
  250. _persistence.countByGroupId(0L);
  251. }
  252. @Test
  253. public void testCountByCompanyId() throws Exception {
  254. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  255. _persistence.countByCompanyId(0L);
  256. }
  257. @Test
  258. public void testCountByParentPlid() throws Exception {
  259. _persistence.countByParentPlid(RandomTestUtil.nextLong());
  260. _persistence.countByParentPlid(0L);
  261. }
  262. @Test
  263. public void testCountByIconImageId() throws Exception {
  264. _persistence.countByIconImageId(RandomTestUtil.nextLong());
  265. _persistence.countByIconImageId(0L);
  266. }
  267. @Test
  268. public void testCountByLayoutPrototypeUuid() throws Exception {
  269. _persistence.countByLayoutPrototypeUuid("");
  270. _persistence.countByLayoutPrototypeUuid("null");
  271. _persistence.countByLayoutPrototypeUuid((String)null);
  272. }
  273. @Test
  274. public void testCountBySourcePrototypeLayoutUuid() throws Exception {
  275. _persistence.countBySourcePrototypeLayoutUuid("");
  276. _persistence.countBySourcePrototypeLayoutUuid("null");
  277. _persistence.countBySourcePrototypeLayoutUuid((String)null);
  278. }
  279. @Test
  280. public void testCountByG_P() throws Exception {
  281. _persistence.countByG_P(
  282. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  283. _persistence.countByG_P(0L, RandomTestUtil.randomBoolean());
  284. }
  285. @Test
  286. public void testCountByG_T() throws Exception {
  287. _persistence.countByG_T(RandomTestUtil.nextLong(), "");
  288. _persistence.countByG_T(0L, "null");
  289. _persistence.countByG_T(0L, (String)null);
  290. }
  291. @Test
  292. public void testCountByG_MLP() throws Exception {
  293. _persistence.countByG_MLP(
  294. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  295. _persistence.countByG_MLP(0L, 0L);
  296. }
  297. @Test
  298. public void testCountByC_L() throws Exception {
  299. _persistence.countByC_L(RandomTestUtil.nextLong(), "");
  300. _persistence.countByC_L(0L, "null");
  301. _persistence.countByC_L(0L, (String)null);
  302. }
  303. @Test
  304. public void testCountByP_I() throws Exception {
  305. _persistence.countByP_I(
  306. RandomTestUtil.randomBoolean(), RandomTestUtil.nextLong());
  307. _persistence.countByP_I(RandomTestUtil.randomBoolean(), 0L);
  308. }
  309. @Test
  310. public void testCountByC_C() throws Exception {
  311. _persistence.countByC_C(
  312. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  313. _persistence.countByC_C(0L, 0L);
  314. }
  315. @Test
  316. public void testCountByG_P_L() throws Exception {
  317. _persistence.countByG_P_L(
  318. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  319. RandomTestUtil.nextLong());
  320. _persistence.countByG_P_L(0L, RandomTestUtil.randomBoolean(), 0L);
  321. }
  322. @Test
  323. public void testCountByG_P_P() throws Exception {
  324. _persistence.countByG_P_P(
  325. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  326. RandomTestUtil.nextLong());
  327. _persistence.countByG_P_P(0L, RandomTestUtil.randomBoolean(), 0L);
  328. }
  329. @Test
  330. public void testCountByG_P_PArrayable() throws Exception {
  331. _persistence.countByG_P_P(
  332. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  333. new long[] {RandomTestUtil.nextLong(), 0L});
  334. }
  335. @Test
  336. public void testCountByG_P_T() throws Exception {
  337. _persistence.countByG_P_T(
  338. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "");
  339. _persistence.countByG_P_T(0L, RandomTestUtil.randomBoolean(), "null");
  340. _persistence.countByG_P_T(
  341. 0L, RandomTestUtil.randomBoolean(), (String)null);
  342. }
  343. @Test
  344. public void testCountByG_P_F() throws Exception {
  345. _persistence.countByG_P_F(
  346. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "");
  347. _persistence.countByG_P_F(0L, RandomTestUtil.randomBoolean(), "null");
  348. _persistence.countByG_P_F(
  349. 0L, RandomTestUtil.randomBoolean(), (String)null);
  350. }
  351. @Test
  352. public void testCountByG_P_SPLU() throws Exception {
  353. _persistence.countByG_P_SPLU(
  354. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(), "");
  355. _persistence.countByG_P_SPLU(
  356. 0L, RandomTestUtil.randomBoolean(), "null");
  357. _persistence.countByG_P_SPLU(
  358. 0L, RandomTestUtil.randomBoolean(), (String)null);
  359. }
  360. @Test
  361. public void testCountByG_P_P_H() throws Exception {
  362. _persistence.countByG_P_P_H(
  363. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  364. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  365. _persistence.countByG_P_P_H(
  366. 0L, RandomTestUtil.randomBoolean(), 0L,
  367. RandomTestUtil.randomBoolean());
  368. }
  369. @Test
  370. public void testCountByG_P_P_HArrayable() throws Exception {
  371. _persistence.countByG_P_P_H(
  372. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  373. new long[] {RandomTestUtil.nextLong(), 0L},
  374. RandomTestUtil.randomBoolean());
  375. }
  376. @Test
  377. public void testCountByG_P_P_LtP() throws Exception {
  378. _persistence.countByG_P_P_LtP(
  379. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  380. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  381. _persistence.countByG_P_P_LtP(
  382. 0L, RandomTestUtil.randomBoolean(), 0L, 0);
  383. }
  384. @Test
  385. public void testFindByPrimaryKeyExisting() throws Exception {
  386. Layout newLayout = addLayout();
  387. Layout existingLayout = _persistence.findByPrimaryKey(
  388. newLayout.getPrimaryKey());
  389. Assert.assertEquals(existingLayout, newLayout);
  390. }
  391. @Test(expected = NoSuchLayoutException.class)
  392. public void testFindByPrimaryKeyMissing() throws Exception {
  393. long pk = RandomTestUtil.nextLong();
  394. _persistence.findByPrimaryKey(pk);
  395. }
  396. @Test
  397. public void testFindAll() throws Exception {
  398. _persistence.findAll(
  399. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  400. }
  401. @Test
  402. public void testFilterFindByGroupId() throws Exception {
  403. _persistence.filterFindByGroupId(
  404. 0, QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  405. }
  406. protected OrderByComparator<Layout> getOrderByComparator() {
  407. return OrderByComparatorFactoryUtil.create(
  408. "Layout", "mvccVersion", true, "ctCollectionId", true, "uuid", true,
  409. "plid", true, "groupId", true, "companyId", true, "userId", true,
  410. "userName", true, "createDate", true, "modifiedDate", true,
  411. "parentPlid", true, "privateLayout", true, "layoutId", true,
  412. "parentLayoutId", true, "classNameId", true, "classPK", true,
  413. "name", true, "title", true, "description", true, "keywords", true,
  414. "robots", true, "type", true, "hidden", true, "system", true,
  415. "friendlyURL", true, "iconImageId", true, "themeId", true,
  416. "colorSchemeId", true, "priority", true, "masterLayoutPlid", true,
  417. "layoutPrototypeUuid", true, "layoutPrototypeLinkEnabled", true,
  418. "sourcePrototypeLayoutUuid", true, "publishDate", true,
  419. "lastPublishDate", true, "status", true, "statusByUserId", true,
  420. "statusByUserName", true, "statusDate", true);
  421. }
  422. @Test
  423. public void testFetchByPrimaryKeyExisting() throws Exception {
  424. Layout newLayout = addLayout();
  425. Layout existingLayout = _persistence.fetchByPrimaryKey(
  426. newLayout.getPrimaryKey());
  427. Assert.assertEquals(existingLayout, newLayout);
  428. }
  429. @Test
  430. public void testFetchByPrimaryKeyMissing() throws Exception {
  431. long pk = RandomTestUtil.nextLong();
  432. Layout missingLayout = _persistence.fetchByPrimaryKey(pk);
  433. Assert.assertNull(missingLayout);
  434. }
  435. @Test
  436. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  437. throws Exception {
  438. Layout newLayout1 = addLayout();
  439. Layout newLayout2 = addLayout();
  440. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  441. primaryKeys.add(newLayout1.getPrimaryKey());
  442. primaryKeys.add(newLayout2.getPrimaryKey());
  443. Map<Serializable, Layout> layouts = _persistence.fetchByPrimaryKeys(
  444. primaryKeys);
  445. Assert.assertEquals(2, layouts.size());
  446. Assert.assertEquals(
  447. newLayout1, layouts.get(newLayout1.getPrimaryKey()));
  448. Assert.assertEquals(
  449. newLayout2, layouts.get(newLayout2.getPrimaryKey()));
  450. }
  451. @Test
  452. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  453. throws Exception {
  454. long pk1 = RandomTestUtil.nextLong();
  455. long pk2 = RandomTestUtil.nextLong();
  456. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  457. primaryKeys.add(pk1);
  458. primaryKeys.add(pk2);
  459. Map<Serializable, Layout> layouts = _persistence.fetchByPrimaryKeys(
  460. primaryKeys);
  461. Assert.assertTrue(layouts.isEmpty());
  462. }
  463. @Test
  464. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  465. throws Exception {
  466. Layout newLayout = addLayout();
  467. long pk = RandomTestUtil.nextLong();
  468. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  469. primaryKeys.add(newLayout.getPrimaryKey());
  470. primaryKeys.add(pk);
  471. Map<Serializable, Layout> layouts = _persistence.fetchByPrimaryKeys(
  472. primaryKeys);
  473. Assert.assertEquals(1, layouts.size());
  474. Assert.assertEquals(newLayout, layouts.get(newLayout.getPrimaryKey()));
  475. }
  476. @Test
  477. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  478. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  479. Map<Serializable, Layout> layouts = _persistence.fetchByPrimaryKeys(
  480. primaryKeys);
  481. Assert.assertTrue(layouts.isEmpty());
  482. }
  483. @Test
  484. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  485. Layout newLayout = addLayout();
  486. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  487. primaryKeys.add(newLayout.getPrimaryKey());
  488. Map<Serializable, Layout> layouts = _persistence.fetchByPrimaryKeys(
  489. primaryKeys);
  490. Assert.assertEquals(1, layouts.size());
  491. Assert.assertEquals(newLayout, layouts.get(newLayout.getPrimaryKey()));
  492. }
  493. @Test
  494. public void testActionableDynamicQuery() throws Exception {
  495. final IntegerWrapper count = new IntegerWrapper();
  496. ActionableDynamicQuery actionableDynamicQuery =
  497. LayoutLocalServiceUtil.getActionableDynamicQuery();
  498. actionableDynamicQuery.setPerformActionMethod(
  499. new ActionableDynamicQuery.PerformActionMethod<Layout>() {
  500. @Override
  501. public void performAction(Layout layout) {
  502. Assert.assertNotNull(layout);
  503. count.increment();
  504. }
  505. });
  506. actionableDynamicQuery.performActions();
  507. Assert.assertEquals(count.getValue(), _persistence.countAll());
  508. }
  509. @Test
  510. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  511. Layout newLayout = addLayout();
  512. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  513. Layout.class, _dynamicQueryClassLoader);
  514. dynamicQuery.add(
  515. RestrictionsFactoryUtil.eq("plid", newLayout.getPlid()));
  516. List<Layout> result = _persistence.findWithDynamicQuery(dynamicQuery);
  517. Assert.assertEquals(1, result.size());
  518. Layout existingLayout = result.get(0);
  519. Assert.assertEquals(existingLayout, newLayout);
  520. }
  521. @Test
  522. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  523. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  524. Layout.class, _dynamicQueryClassLoader);
  525. dynamicQuery.add(
  526. RestrictionsFactoryUtil.eq("plid", RandomTestUtil.nextLong()));
  527. List<Layout> result = _persistence.findWithDynamicQuery(dynamicQuery);
  528. Assert.assertEquals(0, result.size());
  529. }
  530. @Test
  531. public void testDynamicQueryByProjectionExisting() throws Exception {
  532. Layout newLayout = addLayout();
  533. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  534. Layout.class, _dynamicQueryClassLoader);
  535. dynamicQuery.setProjection(ProjectionFactoryUtil.property("plid"));
  536. Object newPlid = newLayout.getPlid();
  537. dynamicQuery.add(
  538. RestrictionsFactoryUtil.in("plid", new Object[] {newPlid}));
  539. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  540. Assert.assertEquals(1, result.size());
  541. Object existingPlid = result.get(0);
  542. Assert.assertEquals(existingPlid, newPlid);
  543. }
  544. @Test
  545. public void testDynamicQueryByProjectionMissing() throws Exception {
  546. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  547. Layout.class, _dynamicQueryClassLoader);
  548. dynamicQuery.setProjection(ProjectionFactoryUtil.property("plid"));
  549. dynamicQuery.add(
  550. RestrictionsFactoryUtil.in(
  551. "plid", new Object[] {RandomTestUtil.nextLong()}));
  552. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  553. Assert.assertEquals(0, result.size());
  554. }
  555. @Test
  556. public void testResetOriginalValues() throws Exception {
  557. Layout newLayout = addLayout();
  558. _persistence.clearCache();
  559. Layout existingLayout = _persistence.findByPrimaryKey(
  560. newLayout.getPrimaryKey());
  561. Assert.assertTrue(
  562. Objects.equals(
  563. existingLayout.getUuid(),
  564. ReflectionTestUtil.invoke(
  565. existingLayout, "getOriginalUuid", new Class<?>[0])));
  566. Assert.assertEquals(
  567. Long.valueOf(existingLayout.getGroupId()),
  568. ReflectionTestUtil.<Long>invoke(
  569. existingLayout, "getOriginalGroupId", new Class<?>[0]));
  570. Assert.assertEquals(
  571. Boolean.valueOf(existingLayout.getPrivateLayout()),
  572. ReflectionTestUtil.<Boolean>invoke(
  573. existingLayout, "getOriginalPrivateLayout", new Class<?>[0]));
  574. Assert.assertEquals(
  575. Long.valueOf(existingLayout.getIconImageId()),
  576. ReflectionTestUtil.<Long>invoke(
  577. existingLayout, "getOriginalIconImageId", new Class<?>[0]));
  578. Assert.assertEquals(
  579. Boolean.valueOf(existingLayout.getPrivateLayout()),
  580. ReflectionTestUtil.<Boolean>invoke(
  581. existingLayout, "getOriginalPrivateLayout", new Class<?>[0]));
  582. Assert.assertEquals(
  583. Long.valueOf(existingLayout.getIconImageId()),
  584. ReflectionTestUtil.<Long>invoke(
  585. existingLayout, "getOriginalIconImageId", new Class<?>[0]));
  586. Assert.assertEquals(
  587. Long.valueOf(existingLayout.getClassNameId()),
  588. ReflectionTestUtil.<Long>invoke(
  589. existingLayout, "getOriginalClassNameId", new Class<?>[0]));
  590. Assert.assertEquals(
  591. Long.valueOf(existingLayout.getClassPK()),
  592. ReflectionTestUtil.<Long>invoke(
  593. existingLayout, "getOriginalClassPK", new Class<?>[0]));
  594. Assert.assertEquals(
  595. Long.valueOf(existingLayout.getGroupId()),
  596. ReflectionTestUtil.<Long>invoke(
  597. existingLayout, "getOriginalGroupId", new Class<?>[0]));
  598. Assert.assertEquals(
  599. Boolean.valueOf(existingLayout.getPrivateLayout()),
  600. ReflectionTestUtil.<Boolean>invoke(
  601. existingLayout, "getOriginalPrivateLayout", new Class<?>[0]));
  602. Assert.assertEquals(
  603. Long.valueOf(existingLayout.getLayoutId()),
  604. ReflectionTestUtil.<Long>invoke(
  605. existingLayout, "getOriginalLayoutId", new Class<?>[0]));
  606. Assert.assertEquals(
  607. Long.valueOf(existingLayout.getGroupId()),
  608. ReflectionTestUtil.<Long>invoke(
  609. existingLayout, "getOriginalGroupId", new Class<?>[0]));
  610. Assert.assertEquals(
  611. Boolean.valueOf(existingLayout.getPrivateLayout()),
  612. ReflectionTestUtil.<Boolean>invoke(
  613. existingLayout, "getOriginalPrivateLayout", new Class<?>[0]));
  614. Assert.assertTrue(
  615. Objects.equals(
  616. existingLayout.getFriendlyURL(),
  617. ReflectionTestUtil.invoke(
  618. existingLayout, "getOriginalFriendlyURL",
  619. new Class<?>[0])));
  620. Assert.assertEquals(
  621. Long.valueOf(existingLayout.getGroupId()),
  622. ReflectionTestUtil.<Long>invoke(
  623. existingLayout, "getOriginalGroupId", new Class<?>[0]));
  624. Assert.assertEquals(
  625. Boolean.valueOf(existingLayout.getPrivateLayout()),
  626. ReflectionTestUtil.<Boolean>invoke(
  627. existingLayout, "getOriginalPrivateLayout", new Class<?>[0]));
  628. Assert.assertTrue(
  629. Objects.equals(
  630. existingLayout.getSourcePrototypeLayoutUuid(),
  631. ReflectionTestUtil.invoke(
  632. existingLayout, "getOriginalSourcePrototypeLayoutUuid",
  633. new Class<?>[0])));
  634. }
  635. protected Layout addLayout() throws Exception {
  636. long pk = RandomTestUtil.nextLong();
  637. Layout layout = _persistence.create(pk);
  638. layout.setMvccVersion(RandomTestUtil.nextLong());
  639. layout.setCtCollectionId(RandomTestUtil.nextLong());
  640. layout.setUuid(RandomTestUtil.randomString());
  641. layout.setGroupId(RandomTestUtil.nextLong());
  642. layout.setCompanyId(RandomTestUtil.nextLong());
  643. layout.setUserId(RandomTestUtil.nextLong());
  644. layout.setUserName(RandomTestUtil.randomString());
  645. layout.setCreateDate(RandomTestUtil.nextDate());
  646. layout.setModifiedDate(RandomTestUtil.nextDate());
  647. layout.setParentPlid(RandomTestUtil.nextLong());
  648. layout.setPrivateLayout(RandomTestUtil.randomBoolean());
  649. layout.setLayoutId(RandomTestUtil.nextLong());
  650. layout.setParentLayoutId(RandomTestUtil.nextLong());
  651. layout.setClassNameId(RandomTestUtil.nextLong());
  652. layout.setClassPK(RandomTestUtil.nextLong());
  653. layout.setName(RandomTestUtil.randomString());
  654. layout.setTitle(RandomTestUtil.randomString());
  655. layout.setDescription(RandomTestUtil.randomString());
  656. layout.setKeywords(RandomTestUtil.randomString());
  657. layout.setRobots(RandomTestUtil.randomString());
  658. layout.setType(RandomTestUtil.randomString());
  659. layout.setTypeSettings(RandomTestUtil.randomString());
  660. layout.setHidden(RandomTestUtil.randomBoolean());
  661. layout.setSystem(RandomTestUtil.randomBoolean());
  662. layout.setFriendlyURL(RandomTestUtil.randomString());
  663. layout.setIconImageId(RandomTestUtil.nextLong());
  664. layout.setThemeId(RandomTestUtil.randomString());
  665. layout.setColorSchemeId(RandomTestUtil.randomString());
  666. layout.setCss(RandomTestUtil.randomString());
  667. layout.setPriority(RandomTestUtil.nextInt());
  668. layout.setMasterLayoutPlid(RandomTestUtil.nextLong());
  669. layout.setLayoutPrototypeUuid(RandomTestUtil.randomString());
  670. layout.setLayoutPrototypeLinkEnabled(RandomTestUtil.randomBoolean());
  671. layout.setSourcePrototypeLayoutUuid(RandomTestUtil.randomString());
  672. layout.setPublishDate(RandomTestUtil.nextDate());
  673. layout.setLastPublishDate(RandomTestUtil.nextDate());
  674. layout.setStatus(RandomTestUtil.nextInt());
  675. layout.setStatusByUserId(RandomTestUtil.nextLong());
  676. layout.setStatusByUserName(RandomTestUtil.randomString());
  677. layout.setStatusDate(RandomTestUtil.nextDate());
  678. _layouts.add(_persistence.update(layout));
  679. return layout;
  680. }
  681. private List<Layout> _layouts = new ArrayList<Layout>();
  682. private LayoutPersistence _persistence;
  683. private ClassLoader _dynamicQueryClassLoader;
  684. }