ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ab...@apache.org
Subject [1/9] ranger git commit: RANGER-2203, RANGER-2219: Review and update database schema for ranger policies and tag objects to minimize database queries/updates
Date Fri, 19 Oct 2018 17:01:32 GMT
Repository: ranger
Updated Branches:
  refs/heads/ranger-1 f2afe0c27 -> 48cfb403c


http://git-wip-us.apache.org/repos/asf/ranger/blob/48cfb403/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagDefService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagDefService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagDefService.java
index 8f19ffd..5032c12 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagDefService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagDefService.java
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.db.XXServiceVersionInfoDao;
-import org.apache.ranger.db.XXTagAttributeDefDao;
 import org.apache.ranger.db.XXTagDefDao;
 import org.apache.ranger.entity.XXTagAttributeDef;
 import org.apache.ranger.entity.XXTagDef;
@@ -35,7 +34,7 @@ import org.junit.runners.MethodSorters;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.runners.MockitoJUnitRunner;
 
 @RunWith(MockitoJUnitRunner.class)
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -81,21 +80,15 @@ public class TestRangerTagDefService {
 		xxTagAttributeDef.setName(name);
 		tagAttrDefList.add(xxTagAttributeDef);
 		
-		XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
 		XXServiceVersionInfoDao xxServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
-		
-		Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
-		Mockito.when(xxTagAttributeDefDao.findByTagDefId(tagDef.getId())).thenReturn(tagAttrDefList);
-		
+
 		Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xxServiceVersionInfoDao);
 		Mockito.doNothing().when(xxServiceVersionInfoDao).updateServiceVersionInfoForTagDefUpdate(tagDef.getId(),
tagDef.getUpdateTime());
 		
 		RangerTagDef result = rangerTagDefService.postUpdate(tagDef);
 		Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
 		Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
-		
-		Mockito.verify(daoMgr).getXXTagAttributeDef();
-		Mockito.verify(xxTagAttributeDefDao).findByTagDefId(tagDef.getId());
+
 		Mockito.verify(daoMgr).getXXServiceVersionInfo();
 		Mockito.verify(xxServiceVersionInfoDao).updateServiceVersionInfoForTagDefUpdate(tagDef.getId(),
tagDef.getUpdateTime());
 	}
@@ -117,19 +110,12 @@ public class TestRangerTagDefService {
 		xxTagAttributeDef.setName(name);
 		tagAttrDefList.add(xxTagAttributeDef);
 		
-		XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
-		
-		Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
-		Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
-		
 		RangerTagDef result = rangerTagDefService.getTagDefByGuid(guid);
 		Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
 		Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
 		
 		Mockito.verify(daoMgr).getXXTagDef();
 		Mockito.verify(xXTagDefDao).findByGuid(guid);
-		Mockito.verify(daoMgr).getXXTagAttributeDef();
-		Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
 	}
 	
 	@Test
@@ -167,19 +153,12 @@ public class TestRangerTagDefService {
 		xxTagAttributeDef.setName(name);
 		tagAttrDefList.add(xxTagAttributeDef);
 		
-		XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
-		
-		Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
-		Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
-		
 		RangerTagDef result = rangerTagDefService.getTagDefByName(name);
 		Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
 		Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
 		
 		Mockito.verify(daoMgr).getXXTagDef();
 		Mockito.verify(xXTagDefDao).findByName(name);
-		Mockito.verify(daoMgr).getXXTagAttributeDef();
-		Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
 	}
 	
 	@Test
@@ -215,19 +194,12 @@ public class TestRangerTagDefService {
 		xxTagAttributeDef.setName(name);
 		tagAttrDefList.add(xxTagAttributeDef);
 		
-		XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
-		
-		Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
-		Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
-		
 		List<RangerTagDef> result = rangerTagDefService.getTagDefsByServiceId(serviceId);
 		Assert.assertEquals(result.get(0).getId(), tagAttrDefList.get(0).getId());
 		Assert.assertEquals(result.get(0).getName(), tagAttrDefList.get(0).getName());
 		
 		Mockito.verify(daoMgr).getXXTagDef();
 		Mockito.verify(xXTagDefDao).findByServiceId(serviceId);
-		Mockito.verify(daoMgr).getXXTagAttributeDef();
-		Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
 	}
 	
 	
@@ -259,16 +231,8 @@ public class TestRangerTagDefService {
 		xxTagAttributeDef.setName(name);
 		tagAttrDefList.add(xxTagAttributeDef);
 		
-		XXTagAttributeDefDao xxTagAttributeDefDao = Mockito.mock(XXTagAttributeDefDao.class);
-		
-		Mockito.when(daoMgr.getXXTagAttributeDef()).thenReturn(xxTagAttributeDefDao);
-		Mockito.when(xxTagAttributeDefDao.findByTagDefId(xxTagDef.getId())).thenReturn(tagAttrDefList);
-		
 		RangerTagDef result = rangerTagDefService.getPopulatedViewObject(xxTagDef);
 		Assert.assertEquals(result.getId(), tagAttrDefList.get(0).getId());
 		Assert.assertEquals(result.getName(), tagAttrDefList.get(0).getName());
-		
-		Mockito.verify(daoMgr).getXXTagAttributeDef();
-		Mockito.verify(xxTagAttributeDefDao).findByTagDefId(xxTagDef.getId());
 	}
 }

http://git-wip-us.apache.org/repos/asf/ranger/blob/48cfb403/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
index 1175989..af80ed1 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
@@ -18,6 +18,8 @@
  */
 package org.apache.ranger.service;
 
+import org.apache.ranger.db.XXServiceResourceDao;
+import org.apache.ranger.entity.XXServiceResource;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -69,11 +71,16 @@ public class TestRangerTagService {
         @Mock
         XXTagDao xXTagDao;
 
+        @Mock
+    XXServiceResourceDao xxServiceResourceDao;
+
+        @Mock
+        XXServiceResource xxServiceResource;
+
         @Test
         public void test1postUpdate() {
                 Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
                 Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
-                Mockito.when(daoMgr.getXXTagAttribute()).thenReturn(xXTagAttributeDao);
                 Mockito.when(xXTagDefDao.getById(xXTag.getType())).thenReturn(xXTagDef);
                 Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xXServiceVersionInfoDao);
                 rangerTagService.postUpdate(xXTag);
@@ -86,7 +93,6 @@ public class TestRangerTagService {
                 Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
                 XXTag xXTag = createXXTag();
                 Mockito.when(xXTagDefDao.getById(1L)).thenReturn(xXTagDef);
-                Mockito.when(daoMgr.getXXTagAttribute()).thenReturn(xXTagAttributeDao);
                 rangerTagService.getPopulatedViewObject(xXTag);
 
         }
@@ -107,14 +113,17 @@ public class TestRangerTagService {
 
         @Test
         public void test5GetTagsForResourceId() {
-                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
-                rangerTagService.getTagsForResourceId(1L);
+                Mockito.when(daoMgr.getXXServiceResource()).thenReturn(xxServiceResourceDao);
+                Mockito.when(xxServiceResourceDao.getById(1L)).thenReturn(xxServiceResource);
+
+            rangerTagService.getTagsForResourceId(1L);
 
         }
 
         @Test
         public void test6GetTagsForResourceGuid() {
-                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+            Mockito.when(daoMgr.getXXServiceResource()).thenReturn(xxServiceResourceDao);
+            Mockito.when(xxServiceResourceDao.findByGuid("1")).thenReturn(xxServiceResource);
                 rangerTagService.getTagsForResourceGuid("1");
 
         }


Mime
View raw message