PageRenderTime 35ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/liferay/liferay-portal
Java | 755 lines | 541 code | 198 blank | 16 comment | 1 complexity | fd02e24e10abd0eafcc376208702d535 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.NoSuchLayoutRevisionException;
  23. import com.liferay.portal.kernel.model.LayoutRevision;
  24. import com.liferay.portal.kernel.service.LayoutRevisionLocalServiceUtil;
  25. import com.liferay.portal.kernel.service.persistence.LayoutRevisionPersistence;
  26. import com.liferay.portal.kernel.service.persistence.LayoutRevisionUtil;
  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.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 LayoutRevisionPersistenceTest {
  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 = LayoutRevisionUtil.getPersistence();
  66. Class<?> clazz = _persistence.getClass();
  67. _dynamicQueryClassLoader = clazz.getClassLoader();
  68. }
  69. @After
  70. public void tearDown() throws Exception {
  71. Iterator<LayoutRevision> iterator = _layoutRevisions.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. LayoutRevision layoutRevision = _persistence.create(pk);
  81. Assert.assertNotNull(layoutRevision);
  82. Assert.assertEquals(layoutRevision.getPrimaryKey(), pk);
  83. }
  84. @Test
  85. public void testRemove() throws Exception {
  86. LayoutRevision newLayoutRevision = addLayoutRevision();
  87. _persistence.remove(newLayoutRevision);
  88. LayoutRevision existingLayoutRevision = _persistence.fetchByPrimaryKey(
  89. newLayoutRevision.getPrimaryKey());
  90. Assert.assertNull(existingLayoutRevision);
  91. }
  92. @Test
  93. public void testUpdateNew() throws Exception {
  94. addLayoutRevision();
  95. }
  96. @Test
  97. public void testUpdateExisting() throws Exception {
  98. long pk = RandomTestUtil.nextLong();
  99. LayoutRevision newLayoutRevision = _persistence.create(pk);
  100. newLayoutRevision.setMvccVersion(RandomTestUtil.nextLong());
  101. newLayoutRevision.setGroupId(RandomTestUtil.nextLong());
  102. newLayoutRevision.setCompanyId(RandomTestUtil.nextLong());
  103. newLayoutRevision.setUserId(RandomTestUtil.nextLong());
  104. newLayoutRevision.setUserName(RandomTestUtil.randomString());
  105. newLayoutRevision.setCreateDate(RandomTestUtil.nextDate());
  106. newLayoutRevision.setModifiedDate(RandomTestUtil.nextDate());
  107. newLayoutRevision.setLayoutSetBranchId(RandomTestUtil.nextLong());
  108. newLayoutRevision.setLayoutBranchId(RandomTestUtil.nextLong());
  109. newLayoutRevision.setParentLayoutRevisionId(RandomTestUtil.nextLong());
  110. newLayoutRevision.setHead(RandomTestUtil.randomBoolean());
  111. newLayoutRevision.setMajor(RandomTestUtil.randomBoolean());
  112. newLayoutRevision.setPlid(RandomTestUtil.nextLong());
  113. newLayoutRevision.setPrivateLayout(RandomTestUtil.randomBoolean());
  114. newLayoutRevision.setName(RandomTestUtil.randomString());
  115. newLayoutRevision.setTitle(RandomTestUtil.randomString());
  116. newLayoutRevision.setDescription(RandomTestUtil.randomString());
  117. newLayoutRevision.setKeywords(RandomTestUtil.randomString());
  118. newLayoutRevision.setRobots(RandomTestUtil.randomString());
  119. newLayoutRevision.setTypeSettings(RandomTestUtil.randomString());
  120. newLayoutRevision.setIconImageId(RandomTestUtil.nextLong());
  121. newLayoutRevision.setThemeId(RandomTestUtil.randomString());
  122. newLayoutRevision.setColorSchemeId(RandomTestUtil.randomString());
  123. newLayoutRevision.setCss(RandomTestUtil.randomString());
  124. newLayoutRevision.setStatus(RandomTestUtil.nextInt());
  125. newLayoutRevision.setStatusByUserId(RandomTestUtil.nextLong());
  126. newLayoutRevision.setStatusByUserName(RandomTestUtil.randomString());
  127. newLayoutRevision.setStatusDate(RandomTestUtil.nextDate());
  128. _layoutRevisions.add(_persistence.update(newLayoutRevision));
  129. LayoutRevision existingLayoutRevision = _persistence.findByPrimaryKey(
  130. newLayoutRevision.getPrimaryKey());
  131. Assert.assertEquals(
  132. existingLayoutRevision.getMvccVersion(),
  133. newLayoutRevision.getMvccVersion());
  134. Assert.assertEquals(
  135. existingLayoutRevision.getLayoutRevisionId(),
  136. newLayoutRevision.getLayoutRevisionId());
  137. Assert.assertEquals(
  138. existingLayoutRevision.getGroupId(),
  139. newLayoutRevision.getGroupId());
  140. Assert.assertEquals(
  141. existingLayoutRevision.getCompanyId(),
  142. newLayoutRevision.getCompanyId());
  143. Assert.assertEquals(
  144. existingLayoutRevision.getUserId(), newLayoutRevision.getUserId());
  145. Assert.assertEquals(
  146. existingLayoutRevision.getUserName(),
  147. newLayoutRevision.getUserName());
  148. Assert.assertEquals(
  149. Time.getShortTimestamp(existingLayoutRevision.getCreateDate()),
  150. Time.getShortTimestamp(newLayoutRevision.getCreateDate()));
  151. Assert.assertEquals(
  152. Time.getShortTimestamp(existingLayoutRevision.getModifiedDate()),
  153. Time.getShortTimestamp(newLayoutRevision.getModifiedDate()));
  154. Assert.assertEquals(
  155. existingLayoutRevision.getLayoutSetBranchId(),
  156. newLayoutRevision.getLayoutSetBranchId());
  157. Assert.assertEquals(
  158. existingLayoutRevision.getLayoutBranchId(),
  159. newLayoutRevision.getLayoutBranchId());
  160. Assert.assertEquals(
  161. existingLayoutRevision.getParentLayoutRevisionId(),
  162. newLayoutRevision.getParentLayoutRevisionId());
  163. Assert.assertEquals(
  164. existingLayoutRevision.isHead(), newLayoutRevision.isHead());
  165. Assert.assertEquals(
  166. existingLayoutRevision.isMajor(), newLayoutRevision.isMajor());
  167. Assert.assertEquals(
  168. existingLayoutRevision.getPlid(), newLayoutRevision.getPlid());
  169. Assert.assertEquals(
  170. existingLayoutRevision.isPrivateLayout(),
  171. newLayoutRevision.isPrivateLayout());
  172. Assert.assertEquals(
  173. existingLayoutRevision.getName(), newLayoutRevision.getName());
  174. Assert.assertEquals(
  175. existingLayoutRevision.getTitle(), newLayoutRevision.getTitle());
  176. Assert.assertEquals(
  177. existingLayoutRevision.getDescription(),
  178. newLayoutRevision.getDescription());
  179. Assert.assertEquals(
  180. existingLayoutRevision.getKeywords(),
  181. newLayoutRevision.getKeywords());
  182. Assert.assertEquals(
  183. existingLayoutRevision.getRobots(), newLayoutRevision.getRobots());
  184. Assert.assertEquals(
  185. existingLayoutRevision.getTypeSettings(),
  186. newLayoutRevision.getTypeSettings());
  187. Assert.assertEquals(
  188. existingLayoutRevision.getIconImageId(),
  189. newLayoutRevision.getIconImageId());
  190. Assert.assertEquals(
  191. existingLayoutRevision.getThemeId(),
  192. newLayoutRevision.getThemeId());
  193. Assert.assertEquals(
  194. existingLayoutRevision.getColorSchemeId(),
  195. newLayoutRevision.getColorSchemeId());
  196. Assert.assertEquals(
  197. existingLayoutRevision.getCss(), newLayoutRevision.getCss());
  198. Assert.assertEquals(
  199. existingLayoutRevision.getStatus(), newLayoutRevision.getStatus());
  200. Assert.assertEquals(
  201. existingLayoutRevision.getStatusByUserId(),
  202. newLayoutRevision.getStatusByUserId());
  203. Assert.assertEquals(
  204. existingLayoutRevision.getStatusByUserName(),
  205. newLayoutRevision.getStatusByUserName());
  206. Assert.assertEquals(
  207. Time.getShortTimestamp(existingLayoutRevision.getStatusDate()),
  208. Time.getShortTimestamp(newLayoutRevision.getStatusDate()));
  209. }
  210. @Test
  211. public void testCountByLayoutSetBranchId() throws Exception {
  212. _persistence.countByLayoutSetBranchId(RandomTestUtil.nextLong());
  213. _persistence.countByLayoutSetBranchId(0L);
  214. }
  215. @Test
  216. public void testCountByPlid() throws Exception {
  217. _persistence.countByPlid(RandomTestUtil.nextLong());
  218. _persistence.countByPlid(0L);
  219. }
  220. @Test
  221. public void testCountByStatus() throws Exception {
  222. _persistence.countByStatus(RandomTestUtil.nextInt());
  223. _persistence.countByStatus(0);
  224. }
  225. @Test
  226. public void testCountByL_H() throws Exception {
  227. _persistence.countByL_H(
  228. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean());
  229. _persistence.countByL_H(0L, RandomTestUtil.randomBoolean());
  230. }
  231. @Test
  232. public void testCountByL_P() throws Exception {
  233. _persistence.countByL_P(
  234. RandomTestUtil.nextLong(), RandomTestUtil.nextLong());
  235. _persistence.countByL_P(0L, 0L);
  236. }
  237. @Test
  238. public void testCountByL_S() throws Exception {
  239. _persistence.countByL_S(
  240. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  241. _persistence.countByL_S(0L, 0);
  242. }
  243. @Test
  244. public void testCountByH_P() throws Exception {
  245. _persistence.countByH_P(
  246. RandomTestUtil.randomBoolean(), RandomTestUtil.nextLong());
  247. _persistence.countByH_P(RandomTestUtil.randomBoolean(), 0L);
  248. }
  249. @Test
  250. public void testCountByP_NotS() throws Exception {
  251. _persistence.countByP_NotS(
  252. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  253. _persistence.countByP_NotS(0L, 0);
  254. }
  255. @Test
  256. public void testCountByL_L_P() throws Exception {
  257. _persistence.countByL_L_P(
  258. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  259. RandomTestUtil.nextLong());
  260. _persistence.countByL_L_P(0L, 0L, 0L);
  261. }
  262. @Test
  263. public void testCountByL_P_P() throws Exception {
  264. _persistence.countByL_P_P(
  265. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  266. RandomTestUtil.nextLong());
  267. _persistence.countByL_P_P(0L, 0L, 0L);
  268. }
  269. @Test
  270. public void testCountByL_H_P() throws Exception {
  271. _persistence.countByL_H_P(
  272. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  273. RandomTestUtil.nextLong());
  274. _persistence.countByL_H_P(0L, RandomTestUtil.randomBoolean(), 0L);
  275. }
  276. @Test
  277. public void testCountByL_H_P_Collection() throws Exception {
  278. _persistence.countByL_H_P_Collection(
  279. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  280. RandomTestUtil.nextLong());
  281. _persistence.countByL_H_P_Collection(
  282. 0L, RandomTestUtil.randomBoolean(), 0L);
  283. }
  284. @Test
  285. public void testCountByL_H_S() throws Exception {
  286. _persistence.countByL_H_S(
  287. RandomTestUtil.nextLong(), RandomTestUtil.randomBoolean(),
  288. RandomTestUtil.nextInt());
  289. _persistence.countByL_H_S(0L, RandomTestUtil.randomBoolean(), 0);
  290. }
  291. @Test
  292. public void testCountByL_P_S() throws Exception {
  293. _persistence.countByL_P_S(
  294. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  295. RandomTestUtil.nextInt());
  296. _persistence.countByL_P_S(0L, 0L, 0);
  297. }
  298. @Test
  299. public void testCountByL_L_H_P() throws Exception {
  300. _persistence.countByL_L_H_P(
  301. RandomTestUtil.nextLong(), RandomTestUtil.nextLong(),
  302. RandomTestUtil.randomBoolean(), RandomTestUtil.nextLong());
  303. _persistence.countByL_L_H_P(0L, 0L, RandomTestUtil.randomBoolean(), 0L);
  304. }
  305. @Test
  306. public void testFindByPrimaryKeyExisting() throws Exception {
  307. LayoutRevision newLayoutRevision = addLayoutRevision();
  308. LayoutRevision existingLayoutRevision = _persistence.findByPrimaryKey(
  309. newLayoutRevision.getPrimaryKey());
  310. Assert.assertEquals(existingLayoutRevision, newLayoutRevision);
  311. }
  312. @Test(expected = NoSuchLayoutRevisionException.class)
  313. public void testFindByPrimaryKeyMissing() throws Exception {
  314. long pk = RandomTestUtil.nextLong();
  315. _persistence.findByPrimaryKey(pk);
  316. }
  317. @Test
  318. public void testFindAll() throws Exception {
  319. _persistence.findAll(
  320. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  321. }
  322. protected OrderByComparator<LayoutRevision> getOrderByComparator() {
  323. return OrderByComparatorFactoryUtil.create(
  324. "LayoutRevision", "mvccVersion", true, "layoutRevisionId", true,
  325. "groupId", true, "companyId", true, "userId", true, "userName",
  326. true, "createDate", true, "modifiedDate", true, "layoutSetBranchId",
  327. true, "layoutBranchId", true, "parentLayoutRevisionId", true,
  328. "head", true, "major", true, "plid", true, "privateLayout", true,
  329. "name", true, "title", true, "description", true, "keywords", true,
  330. "robots", true, "iconImageId", true, "themeId", true,
  331. "colorSchemeId", true, "status", true, "statusByUserId", true,
  332. "statusByUserName", true, "statusDate", true);
  333. }
  334. @Test
  335. public void testFetchByPrimaryKeyExisting() throws Exception {
  336. LayoutRevision newLayoutRevision = addLayoutRevision();
  337. LayoutRevision existingLayoutRevision = _persistence.fetchByPrimaryKey(
  338. newLayoutRevision.getPrimaryKey());
  339. Assert.assertEquals(existingLayoutRevision, newLayoutRevision);
  340. }
  341. @Test
  342. public void testFetchByPrimaryKeyMissing() throws Exception {
  343. long pk = RandomTestUtil.nextLong();
  344. LayoutRevision missingLayoutRevision = _persistence.fetchByPrimaryKey(
  345. pk);
  346. Assert.assertNull(missingLayoutRevision);
  347. }
  348. @Test
  349. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  350. throws Exception {
  351. LayoutRevision newLayoutRevision1 = addLayoutRevision();
  352. LayoutRevision newLayoutRevision2 = addLayoutRevision();
  353. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  354. primaryKeys.add(newLayoutRevision1.getPrimaryKey());
  355. primaryKeys.add(newLayoutRevision2.getPrimaryKey());
  356. Map<Serializable, LayoutRevision> layoutRevisions =
  357. _persistence.fetchByPrimaryKeys(primaryKeys);
  358. Assert.assertEquals(2, layoutRevisions.size());
  359. Assert.assertEquals(
  360. newLayoutRevision1,
  361. layoutRevisions.get(newLayoutRevision1.getPrimaryKey()));
  362. Assert.assertEquals(
  363. newLayoutRevision2,
  364. layoutRevisions.get(newLayoutRevision2.getPrimaryKey()));
  365. }
  366. @Test
  367. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  368. throws Exception {
  369. long pk1 = RandomTestUtil.nextLong();
  370. long pk2 = RandomTestUtil.nextLong();
  371. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  372. primaryKeys.add(pk1);
  373. primaryKeys.add(pk2);
  374. Map<Serializable, LayoutRevision> layoutRevisions =
  375. _persistence.fetchByPrimaryKeys(primaryKeys);
  376. Assert.assertTrue(layoutRevisions.isEmpty());
  377. }
  378. @Test
  379. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  380. throws Exception {
  381. LayoutRevision newLayoutRevision = addLayoutRevision();
  382. long pk = RandomTestUtil.nextLong();
  383. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  384. primaryKeys.add(newLayoutRevision.getPrimaryKey());
  385. primaryKeys.add(pk);
  386. Map<Serializable, LayoutRevision> layoutRevisions =
  387. _persistence.fetchByPrimaryKeys(primaryKeys);
  388. Assert.assertEquals(1, layoutRevisions.size());
  389. Assert.assertEquals(
  390. newLayoutRevision,
  391. layoutRevisions.get(newLayoutRevision.getPrimaryKey()));
  392. }
  393. @Test
  394. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  395. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  396. Map<Serializable, LayoutRevision> layoutRevisions =
  397. _persistence.fetchByPrimaryKeys(primaryKeys);
  398. Assert.assertTrue(layoutRevisions.isEmpty());
  399. }
  400. @Test
  401. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  402. LayoutRevision newLayoutRevision = addLayoutRevision();
  403. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  404. primaryKeys.add(newLayoutRevision.getPrimaryKey());
  405. Map<Serializable, LayoutRevision> layoutRevisions =
  406. _persistence.fetchByPrimaryKeys(primaryKeys);
  407. Assert.assertEquals(1, layoutRevisions.size());
  408. Assert.assertEquals(
  409. newLayoutRevision,
  410. layoutRevisions.get(newLayoutRevision.getPrimaryKey()));
  411. }
  412. @Test
  413. public void testActionableDynamicQuery() throws Exception {
  414. final IntegerWrapper count = new IntegerWrapper();
  415. ActionableDynamicQuery actionableDynamicQuery =
  416. LayoutRevisionLocalServiceUtil.getActionableDynamicQuery();
  417. actionableDynamicQuery.setPerformActionMethod(
  418. new ActionableDynamicQuery.PerformActionMethod<LayoutRevision>() {
  419. @Override
  420. public void performAction(LayoutRevision layoutRevision) {
  421. Assert.assertNotNull(layoutRevision);
  422. count.increment();
  423. }
  424. });
  425. actionableDynamicQuery.performActions();
  426. Assert.assertEquals(count.getValue(), _persistence.countAll());
  427. }
  428. @Test
  429. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  430. LayoutRevision newLayoutRevision = addLayoutRevision();
  431. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  432. LayoutRevision.class, _dynamicQueryClassLoader);
  433. dynamicQuery.add(
  434. RestrictionsFactoryUtil.eq(
  435. "layoutRevisionId", newLayoutRevision.getLayoutRevisionId()));
  436. List<LayoutRevision> result = _persistence.findWithDynamicQuery(
  437. dynamicQuery);
  438. Assert.assertEquals(1, result.size());
  439. LayoutRevision existingLayoutRevision = result.get(0);
  440. Assert.assertEquals(existingLayoutRevision, newLayoutRevision);
  441. }
  442. @Test
  443. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  444. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  445. LayoutRevision.class, _dynamicQueryClassLoader);
  446. dynamicQuery.add(
  447. RestrictionsFactoryUtil.eq(
  448. "layoutRevisionId", RandomTestUtil.nextLong()));
  449. List<LayoutRevision> result = _persistence.findWithDynamicQuery(
  450. dynamicQuery);
  451. Assert.assertEquals(0, result.size());
  452. }
  453. @Test
  454. public void testDynamicQueryByProjectionExisting() throws Exception {
  455. LayoutRevision newLayoutRevision = addLayoutRevision();
  456. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  457. LayoutRevision.class, _dynamicQueryClassLoader);
  458. dynamicQuery.setProjection(
  459. ProjectionFactoryUtil.property("layoutRevisionId"));
  460. Object newLayoutRevisionId = newLayoutRevision.getLayoutRevisionId();
  461. dynamicQuery.add(
  462. RestrictionsFactoryUtil.in(
  463. "layoutRevisionId", new Object[] {newLayoutRevisionId}));
  464. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  465. Assert.assertEquals(1, result.size());
  466. Object existingLayoutRevisionId = result.get(0);
  467. Assert.assertEquals(existingLayoutRevisionId, newLayoutRevisionId);
  468. }
  469. @Test
  470. public void testDynamicQueryByProjectionMissing() throws Exception {
  471. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  472. LayoutRevision.class, _dynamicQueryClassLoader);
  473. dynamicQuery.setProjection(
  474. ProjectionFactoryUtil.property("layoutRevisionId"));
  475. dynamicQuery.add(
  476. RestrictionsFactoryUtil.in(
  477. "layoutRevisionId", new Object[] {RandomTestUtil.nextLong()}));
  478. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  479. Assert.assertEquals(0, result.size());
  480. }
  481. @Test
  482. public void testResetOriginalValues() throws Exception {
  483. LayoutRevision newLayoutRevision = addLayoutRevision();
  484. _persistence.clearCache();
  485. LayoutRevision existingLayoutRevision = _persistence.findByPrimaryKey(
  486. newLayoutRevision.getPrimaryKey());
  487. Assert.assertEquals(
  488. Long.valueOf(existingLayoutRevision.getLayoutSetBranchId()),
  489. ReflectionTestUtil.<Long>invoke(
  490. existingLayoutRevision, "getOriginalLayoutSetBranchId",
  491. new Class<?>[0]));
  492. Assert.assertEquals(
  493. Boolean.valueOf(existingLayoutRevision.getHead()),
  494. ReflectionTestUtil.<Boolean>invoke(
  495. existingLayoutRevision, "getOriginalHead", new Class<?>[0]));
  496. Assert.assertEquals(
  497. Long.valueOf(existingLayoutRevision.getPlid()),
  498. ReflectionTestUtil.<Long>invoke(
  499. existingLayoutRevision, "getOriginalPlid", new Class<?>[0]));
  500. Assert.assertEquals(
  501. Long.valueOf(existingLayoutRevision.getLayoutSetBranchId()),
  502. ReflectionTestUtil.<Long>invoke(
  503. existingLayoutRevision, "getOriginalLayoutSetBranchId",
  504. new Class<?>[0]));
  505. Assert.assertEquals(
  506. Long.valueOf(existingLayoutRevision.getLayoutBranchId()),
  507. ReflectionTestUtil.<Long>invoke(
  508. existingLayoutRevision, "getOriginalLayoutBranchId",
  509. new Class<?>[0]));
  510. Assert.assertEquals(
  511. Boolean.valueOf(existingLayoutRevision.getHead()),
  512. ReflectionTestUtil.<Boolean>invoke(
  513. existingLayoutRevision, "getOriginalHead", new Class<?>[0]));
  514. Assert.assertEquals(
  515. Long.valueOf(existingLayoutRevision.getPlid()),
  516. ReflectionTestUtil.<Long>invoke(
  517. existingLayoutRevision, "getOriginalPlid", new Class<?>[0]));
  518. }
  519. protected LayoutRevision addLayoutRevision() throws Exception {
  520. long pk = RandomTestUtil.nextLong();
  521. LayoutRevision layoutRevision = _persistence.create(pk);
  522. layoutRevision.setMvccVersion(RandomTestUtil.nextLong());
  523. layoutRevision.setGroupId(RandomTestUtil.nextLong());
  524. layoutRevision.setCompanyId(RandomTestUtil.nextLong());
  525. layoutRevision.setUserId(RandomTestUtil.nextLong());
  526. layoutRevision.setUserName(RandomTestUtil.randomString());
  527. layoutRevision.setCreateDate(RandomTestUtil.nextDate());
  528. layoutRevision.setModifiedDate(RandomTestUtil.nextDate());
  529. layoutRevision.setLayoutSetBranchId(RandomTestUtil.nextLong());
  530. layoutRevision.setLayoutBranchId(RandomTestUtil.nextLong());
  531. layoutRevision.setParentLayoutRevisionId(RandomTestUtil.nextLong());
  532. layoutRevision.setHead(RandomTestUtil.randomBoolean());
  533. layoutRevision.setMajor(RandomTestUtil.randomBoolean());
  534. layoutRevision.setPlid(RandomTestUtil.nextLong());
  535. layoutRevision.setPrivateLayout(RandomTestUtil.randomBoolean());
  536. layoutRevision.setName(RandomTestUtil.randomString());
  537. layoutRevision.setTitle(RandomTestUtil.randomString());
  538. layoutRevision.setDescription(RandomTestUtil.randomString());
  539. layoutRevision.setKeywords(RandomTestUtil.randomString());
  540. layoutRevision.setRobots(RandomTestUtil.randomString());
  541. layoutRevision.setTypeSettings(RandomTestUtil.randomString());
  542. layoutRevision.setIconImageId(RandomTestUtil.nextLong());
  543. layoutRevision.setThemeId(RandomTestUtil.randomString());
  544. layoutRevision.setColorSchemeId(RandomTestUtil.randomString());
  545. layoutRevision.setCss(RandomTestUtil.randomString());
  546. layoutRevision.setStatus(RandomTestUtil.nextInt());
  547. layoutRevision.setStatusByUserId(RandomTestUtil.nextLong());
  548. layoutRevision.setStatusByUserName(RandomTestUtil.randomString());
  549. layoutRevision.setStatusDate(RandomTestUtil.nextDate());
  550. _layoutRevisions.add(_persistence.update(layoutRevision));
  551. return layoutRevision;
  552. }
  553. private List<LayoutRevision> _layoutRevisions =
  554. new ArrayList<LayoutRevision>();
  555. private LayoutRevisionPersistence _persistence;
  556. private ClassLoader _dynamicQueryClassLoader;
  557. }