PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/test/persistence-test/src/testIntegration/java/com/liferay/portlet/exportimport/service/persistence/test/ExportImportConfigurationPersistenceTest.java

http://github.com/liferay/liferay-portal
Java | 596 lines | 430 code | 150 blank | 16 comment | 1 complexity | 919c70895573f02d4bb92bbc5ba4580e 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.portlet.exportimport.service.persistence.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.exportimport.kernel.exception.NoSuchConfigurationException;
  17. import com.liferay.exportimport.kernel.model.ExportImportConfiguration;
  18. import com.liferay.exportimport.kernel.service.ExportImportConfigurationLocalServiceUtil;
  19. import com.liferay.exportimport.kernel.service.persistence.ExportImportConfigurationPersistence;
  20. import com.liferay.exportimport.kernel.service.persistence.ExportImportConfigurationUtil;
  21. import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
  22. import com.liferay.portal.kernel.dao.orm.DynamicQuery;
  23. import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
  24. import com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil;
  25. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  26. import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil;
  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 ExportImportConfigurationPersistenceTest {
  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 = ExportImportConfigurationUtil.getPersistence();
  65. Class<?> clazz = _persistence.getClass();
  66. _dynamicQueryClassLoader = clazz.getClassLoader();
  67. }
  68. @After
  69. public void tearDown() throws Exception {
  70. Iterator<ExportImportConfiguration> iterator =
  71. _exportImportConfigurations.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. ExportImportConfiguration exportImportConfiguration =
  81. _persistence.create(pk);
  82. Assert.assertNotNull(exportImportConfiguration);
  83. Assert.assertEquals(exportImportConfiguration.getPrimaryKey(), pk);
  84. }
  85. @Test
  86. public void testRemove() throws Exception {
  87. ExportImportConfiguration newExportImportConfiguration =
  88. addExportImportConfiguration();
  89. _persistence.remove(newExportImportConfiguration);
  90. ExportImportConfiguration existingExportImportConfiguration =
  91. _persistence.fetchByPrimaryKey(
  92. newExportImportConfiguration.getPrimaryKey());
  93. Assert.assertNull(existingExportImportConfiguration);
  94. }
  95. @Test
  96. public void testUpdateNew() throws Exception {
  97. addExportImportConfiguration();
  98. }
  99. @Test
  100. public void testUpdateExisting() throws Exception {
  101. long pk = RandomTestUtil.nextLong();
  102. ExportImportConfiguration newExportImportConfiguration =
  103. _persistence.create(pk);
  104. newExportImportConfiguration.setMvccVersion(RandomTestUtil.nextLong());
  105. newExportImportConfiguration.setGroupId(RandomTestUtil.nextLong());
  106. newExportImportConfiguration.setCompanyId(RandomTestUtil.nextLong());
  107. newExportImportConfiguration.setUserId(RandomTestUtil.nextLong());
  108. newExportImportConfiguration.setUserName(RandomTestUtil.randomString());
  109. newExportImportConfiguration.setCreateDate(RandomTestUtil.nextDate());
  110. newExportImportConfiguration.setModifiedDate(RandomTestUtil.nextDate());
  111. newExportImportConfiguration.setName(RandomTestUtil.randomString());
  112. newExportImportConfiguration.setDescription(
  113. RandomTestUtil.randomString());
  114. newExportImportConfiguration.setType(RandomTestUtil.nextInt());
  115. newExportImportConfiguration.setSettings(RandomTestUtil.randomString());
  116. newExportImportConfiguration.setStatus(RandomTestUtil.nextInt());
  117. newExportImportConfiguration.setStatusByUserId(
  118. RandomTestUtil.nextLong());
  119. newExportImportConfiguration.setStatusByUserName(
  120. RandomTestUtil.randomString());
  121. newExportImportConfiguration.setStatusDate(RandomTestUtil.nextDate());
  122. _exportImportConfigurations.add(
  123. _persistence.update(newExportImportConfiguration));
  124. ExportImportConfiguration existingExportImportConfiguration =
  125. _persistence.findByPrimaryKey(
  126. newExportImportConfiguration.getPrimaryKey());
  127. Assert.assertEquals(
  128. existingExportImportConfiguration.getMvccVersion(),
  129. newExportImportConfiguration.getMvccVersion());
  130. Assert.assertEquals(
  131. existingExportImportConfiguration.getExportImportConfigurationId(),
  132. newExportImportConfiguration.getExportImportConfigurationId());
  133. Assert.assertEquals(
  134. existingExportImportConfiguration.getGroupId(),
  135. newExportImportConfiguration.getGroupId());
  136. Assert.assertEquals(
  137. existingExportImportConfiguration.getCompanyId(),
  138. newExportImportConfiguration.getCompanyId());
  139. Assert.assertEquals(
  140. existingExportImportConfiguration.getUserId(),
  141. newExportImportConfiguration.getUserId());
  142. Assert.assertEquals(
  143. existingExportImportConfiguration.getUserName(),
  144. newExportImportConfiguration.getUserName());
  145. Assert.assertEquals(
  146. Time.getShortTimestamp(
  147. existingExportImportConfiguration.getCreateDate()),
  148. Time.getShortTimestamp(
  149. newExportImportConfiguration.getCreateDate()));
  150. Assert.assertEquals(
  151. Time.getShortTimestamp(
  152. existingExportImportConfiguration.getModifiedDate()),
  153. Time.getShortTimestamp(
  154. newExportImportConfiguration.getModifiedDate()));
  155. Assert.assertEquals(
  156. existingExportImportConfiguration.getName(),
  157. newExportImportConfiguration.getName());
  158. Assert.assertEquals(
  159. existingExportImportConfiguration.getDescription(),
  160. newExportImportConfiguration.getDescription());
  161. Assert.assertEquals(
  162. existingExportImportConfiguration.getType(),
  163. newExportImportConfiguration.getType());
  164. Assert.assertEquals(
  165. existingExportImportConfiguration.getSettings(),
  166. newExportImportConfiguration.getSettings());
  167. Assert.assertEquals(
  168. existingExportImportConfiguration.getStatus(),
  169. newExportImportConfiguration.getStatus());
  170. Assert.assertEquals(
  171. existingExportImportConfiguration.getStatusByUserId(),
  172. newExportImportConfiguration.getStatusByUserId());
  173. Assert.assertEquals(
  174. existingExportImportConfiguration.getStatusByUserName(),
  175. newExportImportConfiguration.getStatusByUserName());
  176. Assert.assertEquals(
  177. Time.getShortTimestamp(
  178. existingExportImportConfiguration.getStatusDate()),
  179. Time.getShortTimestamp(
  180. newExportImportConfiguration.getStatusDate()));
  181. }
  182. @Test
  183. public void testCountByGroupId() throws Exception {
  184. _persistence.countByGroupId(RandomTestUtil.nextLong());
  185. _persistence.countByGroupId(0L);
  186. }
  187. @Test
  188. public void testCountByCompanyId() throws Exception {
  189. _persistence.countByCompanyId(RandomTestUtil.nextLong());
  190. _persistence.countByCompanyId(0L);
  191. }
  192. @Test
  193. public void testCountByG_T() throws Exception {
  194. _persistence.countByG_T(
  195. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  196. _persistence.countByG_T(0L, 0);
  197. }
  198. @Test
  199. public void testCountByG_S() throws Exception {
  200. _persistence.countByG_S(
  201. RandomTestUtil.nextLong(), RandomTestUtil.nextInt());
  202. _persistence.countByG_S(0L, 0);
  203. }
  204. @Test
  205. public void testCountByG_T_S() throws Exception {
  206. _persistence.countByG_T_S(
  207. RandomTestUtil.nextLong(), RandomTestUtil.nextInt(),
  208. RandomTestUtil.nextInt());
  209. _persistence.countByG_T_S(0L, 0, 0);
  210. }
  211. @Test
  212. public void testFindByPrimaryKeyExisting() throws Exception {
  213. ExportImportConfiguration newExportImportConfiguration =
  214. addExportImportConfiguration();
  215. ExportImportConfiguration existingExportImportConfiguration =
  216. _persistence.findByPrimaryKey(
  217. newExportImportConfiguration.getPrimaryKey());
  218. Assert.assertEquals(
  219. existingExportImportConfiguration, newExportImportConfiguration);
  220. }
  221. @Test(expected = NoSuchConfigurationException.class)
  222. public void testFindByPrimaryKeyMissing() throws Exception {
  223. long pk = RandomTestUtil.nextLong();
  224. _persistence.findByPrimaryKey(pk);
  225. }
  226. @Test
  227. public void testFindAll() throws Exception {
  228. _persistence.findAll(
  229. QueryUtil.ALL_POS, QueryUtil.ALL_POS, getOrderByComparator());
  230. }
  231. protected OrderByComparator<ExportImportConfiguration>
  232. getOrderByComparator() {
  233. return OrderByComparatorFactoryUtil.create(
  234. "ExportImportConfiguration", "mvccVersion", true,
  235. "exportImportConfigurationId", true, "groupId", true, "companyId",
  236. true, "userId", true, "userName", true, "createDate", true,
  237. "modifiedDate", true, "name", true, "description", true, "type",
  238. true, "status", true, "statusByUserId", true, "statusByUserName",
  239. true, "statusDate", true);
  240. }
  241. @Test
  242. public void testFetchByPrimaryKeyExisting() throws Exception {
  243. ExportImportConfiguration newExportImportConfiguration =
  244. addExportImportConfiguration();
  245. ExportImportConfiguration existingExportImportConfiguration =
  246. _persistence.fetchByPrimaryKey(
  247. newExportImportConfiguration.getPrimaryKey());
  248. Assert.assertEquals(
  249. existingExportImportConfiguration, newExportImportConfiguration);
  250. }
  251. @Test
  252. public void testFetchByPrimaryKeyMissing() throws Exception {
  253. long pk = RandomTestUtil.nextLong();
  254. ExportImportConfiguration missingExportImportConfiguration =
  255. _persistence.fetchByPrimaryKey(pk);
  256. Assert.assertNull(missingExportImportConfiguration);
  257. }
  258. @Test
  259. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
  260. throws Exception {
  261. ExportImportConfiguration newExportImportConfiguration1 =
  262. addExportImportConfiguration();
  263. ExportImportConfiguration newExportImportConfiguration2 =
  264. addExportImportConfiguration();
  265. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  266. primaryKeys.add(newExportImportConfiguration1.getPrimaryKey());
  267. primaryKeys.add(newExportImportConfiguration2.getPrimaryKey());
  268. Map<Serializable, ExportImportConfiguration>
  269. exportImportConfigurations = _persistence.fetchByPrimaryKeys(
  270. primaryKeys);
  271. Assert.assertEquals(2, exportImportConfigurations.size());
  272. Assert.assertEquals(
  273. newExportImportConfiguration1,
  274. exportImportConfigurations.get(
  275. newExportImportConfiguration1.getPrimaryKey()));
  276. Assert.assertEquals(
  277. newExportImportConfiguration2,
  278. exportImportConfigurations.get(
  279. newExportImportConfiguration2.getPrimaryKey()));
  280. }
  281. @Test
  282. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereNoPrimaryKeysExist()
  283. throws Exception {
  284. long pk1 = RandomTestUtil.nextLong();
  285. long pk2 = RandomTestUtil.nextLong();
  286. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  287. primaryKeys.add(pk1);
  288. primaryKeys.add(pk2);
  289. Map<Serializable, ExportImportConfiguration>
  290. exportImportConfigurations = _persistence.fetchByPrimaryKeys(
  291. primaryKeys);
  292. Assert.assertTrue(exportImportConfigurations.isEmpty());
  293. }
  294. @Test
  295. public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
  296. throws Exception {
  297. ExportImportConfiguration newExportImportConfiguration =
  298. addExportImportConfiguration();
  299. long pk = RandomTestUtil.nextLong();
  300. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  301. primaryKeys.add(newExportImportConfiguration.getPrimaryKey());
  302. primaryKeys.add(pk);
  303. Map<Serializable, ExportImportConfiguration>
  304. exportImportConfigurations = _persistence.fetchByPrimaryKeys(
  305. primaryKeys);
  306. Assert.assertEquals(1, exportImportConfigurations.size());
  307. Assert.assertEquals(
  308. newExportImportConfiguration,
  309. exportImportConfigurations.get(
  310. newExportImportConfiguration.getPrimaryKey()));
  311. }
  312. @Test
  313. public void testFetchByPrimaryKeysWithNoPrimaryKeys() throws Exception {
  314. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  315. Map<Serializable, ExportImportConfiguration>
  316. exportImportConfigurations = _persistence.fetchByPrimaryKeys(
  317. primaryKeys);
  318. Assert.assertTrue(exportImportConfigurations.isEmpty());
  319. }
  320. @Test
  321. public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
  322. ExportImportConfiguration newExportImportConfiguration =
  323. addExportImportConfiguration();
  324. Set<Serializable> primaryKeys = new HashSet<Serializable>();
  325. primaryKeys.add(newExportImportConfiguration.getPrimaryKey());
  326. Map<Serializable, ExportImportConfiguration>
  327. exportImportConfigurations = _persistence.fetchByPrimaryKeys(
  328. primaryKeys);
  329. Assert.assertEquals(1, exportImportConfigurations.size());
  330. Assert.assertEquals(
  331. newExportImportConfiguration,
  332. exportImportConfigurations.get(
  333. newExportImportConfiguration.getPrimaryKey()));
  334. }
  335. @Test
  336. public void testActionableDynamicQuery() throws Exception {
  337. final IntegerWrapper count = new IntegerWrapper();
  338. ActionableDynamicQuery actionableDynamicQuery =
  339. ExportImportConfigurationLocalServiceUtil.
  340. getActionableDynamicQuery();
  341. actionableDynamicQuery.setPerformActionMethod(
  342. new ActionableDynamicQuery.PerformActionMethod
  343. <ExportImportConfiguration>() {
  344. @Override
  345. public void performAction(
  346. ExportImportConfiguration exportImportConfiguration) {
  347. Assert.assertNotNull(exportImportConfiguration);
  348. count.increment();
  349. }
  350. });
  351. actionableDynamicQuery.performActions();
  352. Assert.assertEquals(count.getValue(), _persistence.countAll());
  353. }
  354. @Test
  355. public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
  356. ExportImportConfiguration newExportImportConfiguration =
  357. addExportImportConfiguration();
  358. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  359. ExportImportConfiguration.class, _dynamicQueryClassLoader);
  360. dynamicQuery.add(
  361. RestrictionsFactoryUtil.eq(
  362. "exportImportConfigurationId",
  363. newExportImportConfiguration.getExportImportConfigurationId()));
  364. List<ExportImportConfiguration> result =
  365. _persistence.findWithDynamicQuery(dynamicQuery);
  366. Assert.assertEquals(1, result.size());
  367. ExportImportConfiguration existingExportImportConfiguration =
  368. result.get(0);
  369. Assert.assertEquals(
  370. existingExportImportConfiguration, newExportImportConfiguration);
  371. }
  372. @Test
  373. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  374. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  375. ExportImportConfiguration.class, _dynamicQueryClassLoader);
  376. dynamicQuery.add(
  377. RestrictionsFactoryUtil.eq(
  378. "exportImportConfigurationId", RandomTestUtil.nextLong()));
  379. List<ExportImportConfiguration> result =
  380. _persistence.findWithDynamicQuery(dynamicQuery);
  381. Assert.assertEquals(0, result.size());
  382. }
  383. @Test
  384. public void testDynamicQueryByProjectionExisting() throws Exception {
  385. ExportImportConfiguration newExportImportConfiguration =
  386. addExportImportConfiguration();
  387. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  388. ExportImportConfiguration.class, _dynamicQueryClassLoader);
  389. dynamicQuery.setProjection(
  390. ProjectionFactoryUtil.property("exportImportConfigurationId"));
  391. Object newExportImportConfigurationId =
  392. newExportImportConfiguration.getExportImportConfigurationId();
  393. dynamicQuery.add(
  394. RestrictionsFactoryUtil.in(
  395. "exportImportConfigurationId",
  396. new Object[] {newExportImportConfigurationId}));
  397. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  398. Assert.assertEquals(1, result.size());
  399. Object existingExportImportConfigurationId = result.get(0);
  400. Assert.assertEquals(
  401. existingExportImportConfigurationId,
  402. newExportImportConfigurationId);
  403. }
  404. @Test
  405. public void testDynamicQueryByProjectionMissing() throws Exception {
  406. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
  407. ExportImportConfiguration.class, _dynamicQueryClassLoader);
  408. dynamicQuery.setProjection(
  409. ProjectionFactoryUtil.property("exportImportConfigurationId"));
  410. dynamicQuery.add(
  411. RestrictionsFactoryUtil.in(
  412. "exportImportConfigurationId",
  413. new Object[] {RandomTestUtil.nextLong()}));
  414. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  415. Assert.assertEquals(0, result.size());
  416. }
  417. protected ExportImportConfiguration addExportImportConfiguration()
  418. throws Exception {
  419. long pk = RandomTestUtil.nextLong();
  420. ExportImportConfiguration exportImportConfiguration =
  421. _persistence.create(pk);
  422. exportImportConfiguration.setMvccVersion(RandomTestUtil.nextLong());
  423. exportImportConfiguration.setGroupId(RandomTestUtil.nextLong());
  424. exportImportConfiguration.setCompanyId(RandomTestUtil.nextLong());
  425. exportImportConfiguration.setUserId(RandomTestUtil.nextLong());
  426. exportImportConfiguration.setUserName(RandomTestUtil.randomString());
  427. exportImportConfiguration.setCreateDate(RandomTestUtil.nextDate());
  428. exportImportConfiguration.setModifiedDate(RandomTestUtil.nextDate());
  429. exportImportConfiguration.setName(RandomTestUtil.randomString());
  430. exportImportConfiguration.setDescription(RandomTestUtil.randomString());
  431. exportImportConfiguration.setType(RandomTestUtil.nextInt());
  432. exportImportConfiguration.setSettings(RandomTestUtil.randomString());
  433. exportImportConfiguration.setStatus(RandomTestUtil.nextInt());
  434. exportImportConfiguration.setStatusByUserId(RandomTestUtil.nextLong());
  435. exportImportConfiguration.setStatusByUserName(
  436. RandomTestUtil.randomString());
  437. exportImportConfiguration.setStatusDate(RandomTestUtil.nextDate());
  438. _exportImportConfigurations.add(
  439. _persistence.update(exportImportConfiguration));
  440. return exportImportConfiguration;
  441. }
  442. private List<ExportImportConfiguration> _exportImportConfigurations =
  443. new ArrayList<ExportImportConfiguration>();
  444. private ExportImportConfigurationPersistence _persistence;
  445. private ClassLoader _dynamicQueryClassLoader;
  446. }