PageRenderTime 78ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

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

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