/portal-impl/test/integration/com/liferay/portal/service/persistence/OrgGroupRolePersistenceTest.java

https://github.com/azzazzel/liferay-portal · Java · 233 lines · 155 code · 62 blank · 16 comment · 0 complexity · 53125a049b1412e9069f8b1b25a25e3c MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-2012 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;
  15. import com.liferay.portal.NoSuchOrgGroupRoleException;
  16. import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
  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.RestrictionsFactoryUtil;
  21. import com.liferay.portal.model.OrgGroupRole;
  22. import com.liferay.portal.service.ServiceTestUtil;
  23. import com.liferay.portal.service.persistence.PersistenceExecutionTestListener;
  24. import com.liferay.portal.test.ExecutionTestListeners;
  25. import com.liferay.portal.test.LiferayIntegrationJUnitTestRunner;
  26. import org.junit.Assert;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import java.util.List;
  31. /**
  32. * @author Brian Wing Shun Chan
  33. */
  34. @ExecutionTestListeners(listeners = {
  35. PersistenceExecutionTestListener.class})
  36. @RunWith(LiferayIntegrationJUnitTestRunner.class)
  37. public class OrgGroupRolePersistenceTest {
  38. @Before
  39. public void setUp() throws Exception {
  40. _persistence = (OrgGroupRolePersistence)PortalBeanLocatorUtil.locate(OrgGroupRolePersistence.class.getName());
  41. }
  42. @Test
  43. public void testCreate() throws Exception {
  44. OrgGroupRolePK pk = new OrgGroupRolePK(ServiceTestUtil.nextLong(),
  45. ServiceTestUtil.nextLong(), ServiceTestUtil.nextLong());
  46. OrgGroupRole orgGroupRole = _persistence.create(pk);
  47. Assert.assertNotNull(orgGroupRole);
  48. Assert.assertEquals(orgGroupRole.getPrimaryKey(), pk);
  49. }
  50. @Test
  51. public void testRemove() throws Exception {
  52. OrgGroupRole newOrgGroupRole = addOrgGroupRole();
  53. _persistence.remove(newOrgGroupRole);
  54. OrgGroupRole existingOrgGroupRole = _persistence.fetchByPrimaryKey(newOrgGroupRole.getPrimaryKey());
  55. Assert.assertNull(existingOrgGroupRole);
  56. }
  57. @Test
  58. public void testUpdateNew() throws Exception {
  59. addOrgGroupRole();
  60. }
  61. @Test
  62. public void testUpdateExisting() throws Exception {
  63. OrgGroupRolePK pk = new OrgGroupRolePK(ServiceTestUtil.nextLong(),
  64. ServiceTestUtil.nextLong(), ServiceTestUtil.nextLong());
  65. OrgGroupRole newOrgGroupRole = _persistence.create(pk);
  66. _persistence.update(newOrgGroupRole, false);
  67. OrgGroupRole existingOrgGroupRole = _persistence.findByPrimaryKey(newOrgGroupRole.getPrimaryKey());
  68. Assert.assertEquals(existingOrgGroupRole.getOrganizationId(),
  69. newOrgGroupRole.getOrganizationId());
  70. Assert.assertEquals(existingOrgGroupRole.getGroupId(),
  71. newOrgGroupRole.getGroupId());
  72. Assert.assertEquals(existingOrgGroupRole.getRoleId(),
  73. newOrgGroupRole.getRoleId());
  74. }
  75. @Test
  76. public void testFindByPrimaryKeyExisting() throws Exception {
  77. OrgGroupRole newOrgGroupRole = addOrgGroupRole();
  78. OrgGroupRole existingOrgGroupRole = _persistence.findByPrimaryKey(newOrgGroupRole.getPrimaryKey());
  79. Assert.assertEquals(existingOrgGroupRole, newOrgGroupRole);
  80. }
  81. @Test
  82. public void testFindByPrimaryKeyMissing() throws Exception {
  83. OrgGroupRolePK pk = new OrgGroupRolePK(ServiceTestUtil.nextLong(),
  84. ServiceTestUtil.nextLong(), ServiceTestUtil.nextLong());
  85. try {
  86. _persistence.findByPrimaryKey(pk);
  87. Assert.fail(
  88. "Missing entity did not throw NoSuchOrgGroupRoleException");
  89. }
  90. catch (NoSuchOrgGroupRoleException nsee) {
  91. }
  92. }
  93. @Test
  94. public void testFetchByPrimaryKeyExisting() throws Exception {
  95. OrgGroupRole newOrgGroupRole = addOrgGroupRole();
  96. OrgGroupRole existingOrgGroupRole = _persistence.fetchByPrimaryKey(newOrgGroupRole.getPrimaryKey());
  97. Assert.assertEquals(existingOrgGroupRole, newOrgGroupRole);
  98. }
  99. @Test
  100. public void testFetchByPrimaryKeyMissing() throws Exception {
  101. OrgGroupRolePK pk = new OrgGroupRolePK(ServiceTestUtil.nextLong(),
  102. ServiceTestUtil.nextLong(), ServiceTestUtil.nextLong());
  103. OrgGroupRole missingOrgGroupRole = _persistence.fetchByPrimaryKey(pk);
  104. Assert.assertNull(missingOrgGroupRole);
  105. }
  106. @Test
  107. public void testDynamicQueryByPrimaryKeyExisting()
  108. throws Exception {
  109. OrgGroupRole newOrgGroupRole = addOrgGroupRole();
  110. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class,
  111. OrgGroupRole.class.getClassLoader());
  112. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.organizationId",
  113. newOrgGroupRole.getOrganizationId()));
  114. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.groupId",
  115. newOrgGroupRole.getGroupId()));
  116. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.roleId",
  117. newOrgGroupRole.getRoleId()));
  118. List<OrgGroupRole> result = _persistence.findWithDynamicQuery(dynamicQuery);
  119. Assert.assertEquals(1, result.size());
  120. OrgGroupRole existingOrgGroupRole = result.get(0);
  121. Assert.assertEquals(existingOrgGroupRole, newOrgGroupRole);
  122. }
  123. @Test
  124. public void testDynamicQueryByPrimaryKeyMissing() throws Exception {
  125. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class,
  126. OrgGroupRole.class.getClassLoader());
  127. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.organizationId",
  128. ServiceTestUtil.nextLong()));
  129. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.groupId",
  130. ServiceTestUtil.nextLong()));
  131. dynamicQuery.add(RestrictionsFactoryUtil.eq("id.roleId",
  132. ServiceTestUtil.nextLong()));
  133. List<OrgGroupRole> result = _persistence.findWithDynamicQuery(dynamicQuery);
  134. Assert.assertEquals(0, result.size());
  135. }
  136. @Test
  137. public void testDynamicQueryByProjectionExisting()
  138. throws Exception {
  139. OrgGroupRole newOrgGroupRole = addOrgGroupRole();
  140. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class,
  141. OrgGroupRole.class.getClassLoader());
  142. dynamicQuery.setProjection(ProjectionFactoryUtil.property(
  143. "id.organizationId"));
  144. Object newOrganizationId = newOrgGroupRole.getOrganizationId();
  145. dynamicQuery.add(RestrictionsFactoryUtil.in("id.organizationId",
  146. new Object[] { newOrganizationId }));
  147. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  148. Assert.assertEquals(1, result.size());
  149. Object existingOrganizationId = result.get(0);
  150. Assert.assertEquals(existingOrganizationId, newOrganizationId);
  151. }
  152. @Test
  153. public void testDynamicQueryByProjectionMissing() throws Exception {
  154. DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(OrgGroupRole.class,
  155. OrgGroupRole.class.getClassLoader());
  156. dynamicQuery.setProjection(ProjectionFactoryUtil.property(
  157. "id.organizationId"));
  158. dynamicQuery.add(RestrictionsFactoryUtil.in("id.organizationId",
  159. new Object[] { ServiceTestUtil.nextLong() }));
  160. List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
  161. Assert.assertEquals(0, result.size());
  162. }
  163. protected OrgGroupRole addOrgGroupRole() throws Exception {
  164. OrgGroupRolePK pk = new OrgGroupRolePK(ServiceTestUtil.nextLong(),
  165. ServiceTestUtil.nextLong(), ServiceTestUtil.nextLong());
  166. OrgGroupRole orgGroupRole = _persistence.create(pk);
  167. _persistence.update(orgGroupRole, false);
  168. return orgGroupRole;
  169. }
  170. private OrgGroupRolePersistence _persistence;
  171. }