ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zsom...@apache.org
Subject [1/2] ranger git commit: RANGER-2107: Add @Service annotations to the DAOs, and use Spring for injecting into as 'entityDao' by generic types, and remove the unnecessary code from the 'RangerDaoManager' classes, and from the RangerBizUtil
Date Tue, 22 May 2018 13:27:26 GMT
Repository: ranger
Updated Branches:
  refs/heads/master 6504a70ee -> 845133347


http://git-wip-us.apache.org/repos/asf/ranger/blob/84513334/security-admin/src/test/java/org/apache/ranger/biz/TestRangerBizUtil.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestRangerBizUtil.java b/security-admin/src/test/java/org/apache/ranger/biz/TestRangerBizUtil.java
index 7dda83e..22e290a 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestRangerBizUtil.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestRangerBizUtil.java
@@ -16,7 +16,6 @@
  */
 package org.apache.ranger.biz;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -303,147 +302,7 @@ public class TestRangerBizUtil {
 		String publicNameChk = rangerBizUtil.generatePublicName(vXPortalUser, null);
 		Assert.assertNull(publicNameChk);
 	}
-	
-	@Test
-	public void testGetDisplayName_EmptyName() {
-		String displayNameChk = rangerBizUtil.getDisplayName(null);
-		Assert.assertEquals(rangerBizUtil.EMPTY_CONTENT_DISPLAY_NAME, displayNameChk);
-	}
-	
-	@Test
-	public void testGetDisplayName_AssetName() {
-		XXAsset obj = new XXAsset();
-		obj.setDescription(resourceName);
-		String displayNameChk = rangerBizUtil.getDisplayName(obj);
-		Assert.assertEquals(resourceName, displayNameChk);
-	}
-	
-	@Test
-	public void testGetDisplayName_MoreThanMaxLen() {
-		XXAsset obj = new XXAsset();
-		String name = resourceName;
-		for(int i=0;i<16;i++){
-			name = name + "_" + name + "1";
-		}
-		obj.setDescription(name);
-		String displayNameChk = rangerBizUtil.getDisplayName(obj);
-		Assert.assertEquals(displayNameChk.length(), 150);
-	}
-	
-	@Test
-	public void testGetDisplayNameForClassName(){
-		XXAsset obj = new XXAsset();
-		String displayNameChk = rangerBizUtil.getDisplayNameForClassName(obj);
-		Assert.assertEquals("Asset",displayNameChk);
-	}
-	
-	@Test
-	public void testGetFileNameWithoutExtension(){
-		File file = new File("test.txt");
-		String fileNameChk = rangerBizUtil.getFileNameWithoutExtension(file);
-		Assert.assertEquals("test",fileNameChk);
-	}
-	
-	@Test
-	public void testGetFileNameWithoutExtension_NoFile(){
-		String fileNameChk = rangerBizUtil.getFileNameWithoutExtension(null);
-		Assert.assertNull(fileNameChk);
-	}
-	
-	@Test
-	public void testGetFileNameWithoutExtension_noExt(){
-		File file = new File("test");
-		String fileNameChk = rangerBizUtil.getFileNameWithoutExtension(file);
-		Assert.assertEquals("test",fileNameChk);
-	}
-	
-	@Test
-	public void testGetImageExtension_TestJPG(){
-		String contentType = "img.JPG";
-		String extChk = rangerBizUtil.getImageExtension(contentType);
-		Assert.assertEquals("jpg",extChk);
-	}
-	
-	@Test
-	public void testGetImageExtension_TestJPEG(){
-		String contentType = "img.JPEG";
-		String extChk = rangerBizUtil.getImageExtension(contentType);
-		Assert.assertEquals("jpg",extChk);
-	}
-	
-	@Test
-	public void testGetImageExtension_TestPNG(){
-		String contentType = "img.PNG";
-		String extChk = rangerBizUtil.getImageExtension(contentType);
-		Assert.assertEquals("png",extChk);
-	}
-	
-	@Test
-	public void testGetImageExtension_NoExt(){
-		String contentType = "img";
-		String extChk = rangerBizUtil.getImageExtension(contentType);
-		Assert.assertEquals("",extChk);
-	}
-	
-	@Test
-	public void testGetMimeType_ForJPG(){
-		String mimeTypeChk = rangerBizUtil.getMimeType(RangerConstants.MIME_JPEG);
-		Assert.assertEquals("jpg",mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeType_ForPNG(){
-		String mimeTypeChk = rangerBizUtil.getMimeType(RangerConstants.MIME_PNG);
-		Assert.assertEquals("png",mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeType_ForEmpty(){
-		String mimeTypeChk = rangerBizUtil.getMimeType(1);
-		Assert.assertEquals("",mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_ForUnknow(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("");
-		Assert.assertEquals(RangerConstants.MIME_UNKNOWN, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_Forjpg(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("jpg");
-		Assert.assertEquals(RangerConstants.MIME_JPEG, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_ForJPEG(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("JPEG");
-		Assert.assertEquals(RangerConstants.MIME_JPEG, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_EndsWithJPEG(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("txt.jpeg");
-		Assert.assertEquals(RangerConstants.MIME_JPEG, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_EndsWithJPG(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("txt.jpg");
-		Assert.assertEquals(RangerConstants.MIME_JPEG, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_EndsWithPNG(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("txt.png");
-		Assert.assertEquals(RangerConstants.MIME_PNG, mimeTypeChk);
-	}
-	
-	@Test
-	public void testGetMimeTypeInt_ForPNG(){
-		int mimeTypeChk = rangerBizUtil.getMimeTypeInt("png");
-		Assert.assertEquals(RangerConstants.MIME_PNG, mimeTypeChk);		
-	}	
+
 
 	@Test
 	public void testMatchHdfsPolicy_NoResourceName(){

http://git-wip-us.apache.org/repos/asf/ranger/blob/84513334/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
index 685c8ea..f4ea957 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
@@ -73,6 +73,9 @@ public class TestRangerServiceDefService {
 	@Mock
 	XUserService xUserService;
 
+	@Mock
+	XXServiceDefDao xServiceDefDao;
+
 	@Rule
 	public ExpectedException thrown = ExpectedException.none();
 
@@ -344,7 +347,6 @@ public class TestRangerServiceDefService {
 
 	@Test
 	public void test4getAllServiceDefs() {
-		XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
 		XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
 
 		XXResourceDefDao xResourceDefDao = Mockito.mock(XXResourceDefDao.class);
@@ -497,7 +499,6 @@ public class TestRangerServiceDefService {
 		enumElementDefObj.setOrder(0);
 		xElementsList.add(enumElementDefObj);
 
-		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
 		Mockito.when(xServiceDefDao.getAll()).thenReturn(xServiceDefList);
 
 		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
@@ -541,7 +542,6 @@ public class TestRangerServiceDefService {
 		List<RangerServiceDef> dbRangerServiceDef = serviceDefService
 				.getAllServiceDefs();
 		Assert.assertNotNull(dbRangerServiceDef);
-		Mockito.verify(daoManager).getXXServiceConfigDef();
 		Mockito.verify(daoManager).getXXResourceDef();
 		Mockito.verify(daoManager).getXXAccessTypeDef();
 		Mockito.verify(daoManager).getXXPolicyConditionDef();

http://git-wip-us.apache.org/repos/asf/ranger/blob/84513334/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
index a56809d..74f1dd0 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
@@ -100,6 +100,9 @@ public class TestRangerServiceDefServiceBase {
 	@Mock
 	JSONUtil jsonUtil;
 
+	@Mock
+	BaseDao<XXServiceDef> baseDao;
+
 	@Rule
 	public ExpectedException thrown = ExpectedException.none();
 
@@ -784,14 +787,8 @@ public class TestRangerServiceDefServiceBase {
 		searchFilter.setParam(SearchFilter.POLICY_NAME, "policyName");
 		searchFilter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
 
-		BaseDao baseDao = Mockito.mock(BaseDao.class);
-
-		Mockito.when(daoManager.getDaoForClassName(Mockito.anyString()))
-				.thenReturn(baseDao);
-
 		RangerServiceDefList dbRangerServiceDefList = rangerServiceDefService
 				.searchRangerServiceDefs(searchFilter);
 		Assert.assertNotNull(dbRangerServiceDefList);
-		Mockito.verify(daoManager).getDaoForClassName(Mockito.anyString());
 	}
 }

http://git-wip-us.apache.org/repos/asf/ranger/blob/84513334/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
index 43c49e4..d90e978 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
@@ -66,6 +66,9 @@ public class TestRangerServiceServiceBase {
 	@Mock
 	RangerBizUtil bizUtil;
 
+	@Mock
+	BaseDao<XXService> baseDao;
+
 	@Rule
 	public ExpectedException thrown = ExpectedException.none();
 
@@ -205,13 +208,9 @@ public class TestRangerServiceServiceBase {
 		searchFilter.setParam(SearchFilter.POLICY_NAME, "policyName");
 		searchFilter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
 
-		BaseDao baseDao = Mockito.mock(BaseDao.class);
-		Mockito.when(daoManager.getDaoForClassName(Mockito.anyString()))
-				.thenReturn(baseDao);
 		RangerServiceList dbRangerServiceList = rangerServiceService
 				.searchRangerServices(searchFilter);
 		Assert.assertNotNull(dbRangerServiceList);
-		Mockito.verify(daoManager).getDaoForClassName(Mockito.anyString());
 
 	}
 }


Mime
View raw message