Ravi Nori has uploaded a new change for review.

Change subject: engine : Fix EngineSession DAO failures
......................................................................

engine : Fix EngineSession DAO failures

EngineSessionDAO tests fail when invoked second time
with out reiniting the database.

Change-Id: I04ecb20abeaafe7a009efab3bf532a2339267d13
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EngineSessionDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/QuotaDAOTest.java
4 files changed, 46 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/37142/1

diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
index d7f60d2..90dc53d 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/BaseDAOTestCase.java
@@ -44,9 +44,9 @@
 @Transactional
 public abstract class BaseDAOTestCase {
     protected static final Guid PRIVILEGED_USER_ID = new 
Guid("9bf7c640-b620-456f-a550-0348f366544b");
-    protected static final long PRIVILEGED_USER_SESSION_ID = 2;
+    protected static final String PRIVILEGED_USER_ENGINE_SESSION_ID = 
"c6f975b2-6f67-11e4-8455-3c970e14c386";
     protected static final Guid UNPRIVILEGED_USER_ID = new 
Guid("9bf7c640-b620-456f-a550-0348f366544a");
-    protected static final long UNPRIVILEGED_USER_SESSION_ID = 1;
+    protected static final String UNPRIVILEGED_USER_ENGINE_SESSION_ID = 
"9ee57fd0-6f67-11e4-9e67-3c970e14c386";
 
     protected static DbFacade dbFacade;
     private static Object dataFactory;
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EngineSessionDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EngineSessionDAOTest.java
index b20bc51..df81c26 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EngineSessionDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EngineSessionDAOTest.java
@@ -37,7 +37,7 @@
         newEngineSession.setGroupIds(new 
HashSet<Guid>(Arrays.asList(FixturesTool.EXISTING_GROUP_ID)));
         newEngineSession.setUserName("");
 
-        existingEngineSession = dao.get(PRIVILEGED_USER_SESSION_ID);
+        existingEngineSession = 
dao.getBySessionId(PRIVILEGED_USER_ENGINE_SESSION_ID);
     }
 
     /**
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
index 5bd1498..66a8bfe 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
@@ -14,6 +14,7 @@
 import org.junit.Test;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
+import org.ovirt.engine.core.common.businessentities.EngineSession;
 import org.ovirt.engine.core.common.businessentities.Permissions;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
@@ -40,6 +41,8 @@
 
     private PermissionDAO dao;
     private Permissions new_permissions;
+    private EngineSession unprivilegedUserSession;
+    private EngineSession privilegedUserSession;
 
     @Override
     public void setUp() throws Exception {
@@ -50,6 +53,9 @@
         new_permissions = new Permissions(AD_ELEMENT_ID, ROLE_ID, 
STORAGE_POOL_ID,
                 VdcObjectType.StoragePool);
 
+        EngineSessionDAO engineDao = dbFacade.getEngineSessionDao();
+        unprivilegedUserSession = 
engineDao.getBySessionId(UNPRIVILEGED_USER_ENGINE_SESSION_ID);
+        privilegedUserSession = 
engineDao.getBySessionId(PRIVILEGED_USER_ENGINE_SESSION_ID);
     }
 
     /**
@@ -157,7 +163,8 @@
      */
     @Test
     public void testGetAllForAdElementFilteredWithPermissions() {
-        List<Permissions> result = dao.getAllForAdElement(AD_ELEMENT_ID, 
PRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(privilegedUserSession);
+        List<Permissions> result = dao.getAllForAdElement(AD_ELEMENT_ID, 
privilegedUserSession.getId(), true);
 
         assertValidGetByAdElement(result);
     }
@@ -167,7 +174,8 @@
      */
     @Test
     public void testGetAllForAdElementFilteredWithNoPermissions() {
-        List<Permissions> result = dao.getAllForAdElement(AD_ELEMENT_ID, 
UNPRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(unprivilegedUserSession);
+        List<Permissions> result = dao.getAllForAdElement(AD_ELEMENT_ID, 
unprivilegedUserSession.getId(), true);
 
         assertInvalidGetPermissionList(result);
     }
@@ -228,7 +236,8 @@
      */
     @Test
     public void testGetAllForEntityFilteredWithPermissions() {
-        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
PRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(privilegedUserSession);
+        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
privilegedUserSession.getId(), true);
 
         assertGetAllForEntityResult(result);
     }
@@ -238,7 +247,8 @@
      */
     @Test
     public void 
testGetAllForEntityFilteredWithNoPermissionsFilteringDisabled() {
-        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
UNPRIVILEGED_USER_SESSION_ID, false);
+        assertNotNull(unprivilegedUserSession);
+        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
unprivilegedUserSession.getId(), false);
 
         assertGetAllForEntityResult(result);
     }
@@ -248,14 +258,16 @@
      */
     @Test
     public void testGetAllForEntityFilteredWithNoPermissions() {
-        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
UNPRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(unprivilegedUserSession);
+        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
unprivilegedUserSession.getId(), true);
 
         assertInvalidGetPermissionList(result);
     }
 
     @Test
     public void testGetAllUsersWithPermissionsOnEntity() {
-        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
PRIVILEGED_USER_SESSION_ID, true, true);
+        assertNotNull(privilegedUserSession);
+        List<Permissions> result = dao.getAllForEntity(VM_ENTITY_ID, 
privilegedUserSession.getId(), true, true);
 
         assertNotNull(result);
         assertEquals(2, result.size());
@@ -452,29 +464,33 @@
 
     @Test
     public void testGetTreeForEntityWithRoleTypeFilteredWithPermissions() {
-        baseTestGetTreeForEntityFiltered(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, PRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(privilegedUserSession);
+        baseTestGetTreeForEntityFiltered(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, privilegedUserSession.getId(), true);
     }
 
     @Test
     public void 
testGetTreeForEntityWithRoleTypeFilteredWithNoPermissionsCheckDisabled() {
-        baseTestGetTreeForEntityFiltered(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, UNPRIVILEGED_USER_SESSION_ID, false);
+        assertNotNull(unprivilegedUserSession);
+        baseTestGetTreeForEntityFiltered(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, unprivilegedUserSession.getId(), false);
     }
 
     @Test
     public void testGetTreeForEntityWithRoleTypeFilteredWithNoPermissions() {
+        assertNotNull(unprivilegedUserSession);
         List<Permissions> result =
-                dao.getTreeForEntity(STORAGE_ENTITY_ID, VdcObjectType.Storage, 
UNPRIVILEGED_USER_SESSION_ID, true);
+                dao.getTreeForEntity(STORAGE_ENTITY_ID, VdcObjectType.Storage, 
unprivilegedUserSession.getId(), true);
         assertInvalidGetPermissionList(result);
     }
     @Test
     public void testGetTreeForEntityWithAppMode() {
-        List<Permissions> result = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, PRIVILEGED_USER_SESSION_ID, true, 
ApplicationMode.AllModes.getValue());
+        assertNotNull(privilegedUserSession);
+        List<Permissions> result = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, privilegedUserSession.getId(), true, 
ApplicationMode.AllModes.getValue());
         assertEquals(1, result.size());
 
-        List<Permissions> result2 = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, PRIVILEGED_USER_SESSION_ID, true, 
ApplicationMode.VirtOnly.getValue());
+        List<Permissions> result2 = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, privilegedUserSession.getId(), true, 
ApplicationMode.VirtOnly.getValue());
         assertEquals(1, result2.size());
 
-        List<Permissions> result3 = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, PRIVILEGED_USER_SESSION_ID, true, 
ApplicationMode.GlusterOnly.getValue());
+        List<Permissions> result3 = dao.getTreeForEntity(STORAGE_ENTITY_ID, 
VdcObjectType.Storage, privilegedUserSession.getId(), true, 
ApplicationMode.GlusterOnly.getValue());
         assertEquals(1, result3.size());
     }
     /**
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/QuotaDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/QuotaDAOTest.java
index 6ff5dd3..d9fe78f 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/QuotaDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/QuotaDAOTest.java
@@ -8,6 +8,7 @@
 import java.util.List;
 
 import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.EngineSession;
 import org.ovirt.engine.core.common.businessentities.Quota;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.QuotaStorage;
@@ -21,11 +22,17 @@
     private static final Long unlimited = -1L;
     private static final int STORAGE_NUM_QUOTAS = 4;
     private static final int VDS_GRUOP_NUM_QUOTAS = 3;
+    private EngineSession unprivilegedUserSession;
+    private EngineSession privilegedUserSession;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
         dao = dbFacade.getQuotaDao();
+
+        EngineSessionDAO engineDao = dbFacade.getEngineSessionDao();
+        unprivilegedUserSession = 
engineDao.getBySessionId(UNPRIVILEGED_USER_ENGINE_SESSION_ID);
+        privilegedUserSession = 
engineDao.getBySessionId(PRIVILEGED_USER_ENGINE_SESSION_ID);
     }
 
     @Test
@@ -491,7 +498,8 @@
      * Asserts that {@link #expectedQuotas} are relevant for the given {@link 
#storageId}
      */
     private void assertGetAllRelevantQuoatsForStorage(Guid storageId, int 
expectedQuotas) {
-        List<Quota> quotas = dao.getAllRelevantQuotasForStorage(storageId, 
PRIVILEGED_USER_SESSION_ID, false);
+        assertNotNull(privilegedUserSession);
+        List<Quota> quotas = dao.getAllRelevantQuotasForStorage(storageId, 
privilegedUserSession.getId(), false);
         assertEquals("Wrong number of quotas retuend", expectedQuotas, 
quotas.size());
     }
 
@@ -528,7 +536,8 @@
      */
     @Test
     public void testGetRelevantStorageQuotaForUserWithoutPrivileges() throws 
Exception {
-        List<Quota> quotas = 
dao.getAllRelevantQuotasForStorage(FixturesTool.STORAGE_DOAMIN_NFS_MASTER, 
UNPRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(unprivilegedUserSession);
+        List<Quota> quotas = 
dao.getAllRelevantQuotasForStorage(FixturesTool.STORAGE_DOAMIN_NFS_MASTER, 
unprivilegedUserSession.getId(), true);
         assertEquals("Unprivileged user is not allowed to fetch for quota", 0, 
quotas.size());
     }
 
@@ -538,7 +547,8 @@
      */
     @Test
     public void testGetRelevantVdsGroupQuotaForUserWithoutPrivileges() throws 
Exception {
-        List<Quota> quotas = 
dao.getAllRelevantQuotasForVdsGroup(FixturesTool.VDS_GROUP_RHEL6_NFS, 
UNPRIVILEGED_USER_SESSION_ID, true);
+        assertNotNull(unprivilegedUserSession);
+        List<Quota> quotas = 
dao.getAllRelevantQuotasForVdsGroup(FixturesTool.VDS_GROUP_RHEL6_NFS, 
unprivilegedUserSession.getId(), true);
         assertEquals("Unprivileged user is not allowed to fetch for quota", 0, 
quotas.size());
     }
 
@@ -546,7 +556,8 @@
      * Asserts that {@link #expectedQuotas} are relevant for the given {@link 
#vdsGroupId}
      */
     private void assertGetAllRelevantQuoatsForVdsGroup(Guid vdsGroupId, int 
expectedQuotas) {
-        List<Quota> quotas = dao.getAllRelevantQuotasForVdsGroup(vdsGroupId, 
PRIVILEGED_USER_SESSION_ID, false);
+        assertNotNull(privilegedUserSession);
+        List<Quota> quotas = dao.getAllRelevantQuotasForVdsGroup(vdsGroupId, 
privilegedUserSession.getId(), false);
         assertEquals("Wrong number of quotas retuend", expectedQuotas, 
quotas.size());
     }
 


-- 
To view, visit http://gerrit.ovirt.org/37142
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04ecb20abeaafe7a009efab3bf532a2339267d13
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <rn...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to