You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2017/01/03 08:17:08 UTC

[7/9] incubator-ranger git commit: RANGER-1170: Added Unit tests for PuclicAPIsv2 and PublicAPIs

RANGER-1170: Added Unit tests for PuclicAPIsv2 and PublicAPIs

Signed-off-by: Velmurugan Periasamy <ve...@apache.org>
(cherry picked from commit 53fb16a60aeb9557d56d76003831e9e442351244)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/9039504b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/9039504b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/9039504b

Branch: refs/heads/ranger-0.6
Commit: 9039504bc68e99dbb4459c4ee6b4bed14078c93f
Parents: dc873cb
Author: Sailaja Polavarapu <sp...@hortonworks.com>
Authored: Tue Sep 27 14:14:42 2016 -0700
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Mon Jan 2 23:56:17 2017 -0800

----------------------------------------------------------------------
 .../apache/ranger/rest/TestPublicAPIsv2.java    | 76 ++------------------
 1 file changed, 5 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/9039504b/security-admin/src/test/java/org/apache/ranger/rest/TestPublicAPIsv2.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestPublicAPIsv2.java b/security-admin/src/test/java/org/apache/ranger/rest/TestPublicAPIsv2.java
index 798e2a5..1404637 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestPublicAPIsv2.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestPublicAPIsv2.java
@@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.apache.ranger.common.ContextUtil;
 import org.apache.ranger.common.RESTErrorUtil;
-import org.apache.ranger.common.RangerSearchUtil;
 import org.apache.ranger.common.UserSessionBase;
 import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerService;
@@ -45,7 +44,6 @@ import org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef;
 import org.apache.ranger.plugin.util.SearchFilter;
 import org.apache.ranger.security.context.RangerContextHolder;
 import org.apache.ranger.security.context.RangerSecurityContext;
-import org.apache.ranger.service.RangerPolicyService;
 import org.apache.ranger.view.RangerPolicyList;
 import org.apache.ranger.view.RangerServiceDefList;
 import org.apache.ranger.view.RangerServiceList;
@@ -68,21 +66,13 @@ public class TestPublicAPIsv2 {
 
 	private static Long Id = 8L;
 	
-	private static Long Id2 =10L;
-
 	@InjectMocks
 	PublicAPIsv2 publicAPIsv2 = new PublicAPIsv2();
-
+	
 	@Mock
 	ServiceREST serviceREST;
 
 	@Mock
-	RangerSearchUtil searchUtil;
-
-	@Mock
-	RangerPolicyService policyService;
-
-	@Mock
 	RESTErrorUtil restErrorUtil;
 	
 	@Rule
@@ -195,46 +185,6 @@ public class TestPublicAPIsv2 {
 		return policy;
 	}
 	
-	private RangerPolicy rangerPolicy1() {
-		List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
-		List<String> users = new ArrayList<String>();
-		List<String> groups = new ArrayList<String>();
-		List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
-		List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
-		RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
-		rangerPolicyItem.setAccesses(accesses);
-		rangerPolicyItem.setConditions(conditions);
-		rangerPolicyItem.setGroups(groups);
-		rangerPolicyItem.setUsers(users);
-		rangerPolicyItem.setDelegateAdmin(false);
-
-		policyItems.add(rangerPolicyItem);
-
-		Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
-		RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
-		rangerPolicyResource.setIsExcludes(true);
-		rangerPolicyResource.setIsRecursive(true);
-		rangerPolicyResource.setValue("2");
-		rangerPolicyResource.setValues(users);
-		policyResource.put("resource", rangerPolicyResource);
-		RangerPolicy policy = new RangerPolicy();
-		policy.setId(Id2);
-		policy.setCreateTime(new Date());
-		policy.setDescription("policy");
-		policy.setGuid("policyguid");
-		policy.setIsEnabled(true);
-		policy.setName("HDFS_1-1-20150316062454");
-		policy.setUpdatedBy("Admin");
-		policy.setUpdateTime(new Date());
-		policy.setService("HDFS_1-1-20150316062454");
-		policy.setIsAuditEnabled(true);
-		policy.setPolicyItems(policyItems);
-		policy.setResources(policyResource);
-		policy.setService("HDFS_2");
-
-		return policy;
-	}
-
 	@Test
 	public void test1getServiceDef() throws Exception {
 		RangerServiceDef rangerServiceDef = rangerServiceDef();
@@ -516,16 +466,17 @@ public class TestPublicAPIsv2 {
 	
 	@Test
 	public void test21applyPolicy() throws Exception {
+		HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
 		RangerPolicy rangerPolicy = rangerPolicy();
-		Mockito.when(serviceREST.applyPolicy(rangerPolicy)).thenReturn(rangerPolicy);
-		RangerPolicy dbRangerPolicy = publicAPIsv2.applyPolicy(rangerPolicy);
+		Mockito.when(serviceREST.applyPolicy(rangerPolicy, request)).thenReturn(rangerPolicy);
+		RangerPolicy dbRangerPolicy = publicAPIsv2.applyPolicy(rangerPolicy, request);
 		Assert.assertNotNull(dbRangerPolicy);
 		Assert.assertEquals(dbRangerPolicy, rangerPolicy);
 		Assert.assertEquals(dbRangerPolicy.getId(),
 				rangerPolicy.getId());
 		Assert.assertEquals(dbRangerPolicy.getName(),
 				rangerPolicy.getName());
-		Mockito.verify(serviceREST).applyPolicy(rangerPolicy);
+		Mockito.verify(serviceREST).applyPolicy(rangerPolicy, request);
 	}
 	
 	@Test
@@ -586,21 +537,4 @@ public class TestPublicAPIsv2 {
 		Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.anyObject());
 		Mockito.verify(serviceREST).deletePolicy(Id);
 	}
-
-	@Test
-	public void test26getPolicies() throws Exception {
-		HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
-		RangerPolicyList policyList = Mockito.mock(RangerPolicyList.class);
-		List<RangerPolicy> rangerPolicies = new ArrayList<RangerPolicy>();
-		RangerPolicy rangerpolicy1 = rangerPolicy();
-		RangerPolicy rangerpolicy2 = rangerPolicy1();
-		rangerPolicies.add(rangerpolicy1);
-		rangerPolicies.add(rangerpolicy2);
-		Mockito.when(serviceREST.getPolicies(request)).thenReturn(policyList);
-		Mockito.when(policyList.getPolicies()).thenReturn(rangerPolicies);
-		List<RangerPolicy> dbRangerPolicies = publicAPIsv2.getPolicies(request);
-		Assert.assertNotNull(dbRangerPolicies);
-		Assert.assertEquals(dbRangerPolicies.size(), rangerPolicies.size());
-		Mockito.verify(serviceREST).getPolicies(request);
-	}
 }